/*
  الأجهزة: ثلاث مسابح (خشب، كهرمان، عقيق) وعدّادان (رقمي، يدوي).
  الزر يغطي الجهاز كله في جميع الأشكال، فالضغط على أي جزء منه يعدّ.
*/
.misbaha { display: grid; justify-items: center; gap: 14px; }
.ring { --size: clamp(270px, min(82vw, 46dvh), 350px); position: relative; width: var(--size); height: var(--size); }
.tap { position: absolute; inset: 0; border: 0; background: none; cursor: pointer; font: inherit; color: var(--ink); touch-action: manipulation; user-select: none; display: grid; align-content: center; justify-items: center; gap: 6px; }
.say { display: grid; justify-items: center; gap: 2px; }
.translit { font-size: calc(var(--size) * .038); opacity: .85; line-height: 1.4; }
.translit:empty { display: none; }
.phrase { font-family: Scheherazade, serif; font-weight: 500; font-size: calc(var(--size) * .074); line-height: 1.75; text-wrap: balance; }
.tap-label { font-size: .75rem; color: var(--muted); }
.knob, .readout, .shell { display: none; }
@property --fill { syntax: '<percentage>'; inherits: false; initial-value: 100%; }
@keyframes breathe { from { --fill: 0%; } to { --fill: 100%; } }
.ring::after { content: ''; position: absolute; pointer-events: none; opacity: 0; }
.ring.waiting::after { opacity: .9; animation: breathe var(--gap, 1500ms) linear forwards; }

/* ───── المسبحة: ترسم على لوحة canvas في misbaha.js ───── */
[data-kind="misbaha"] .ring { margin-bottom: calc(var(--size) * .25); }
[data-kind="misbaha"] .tap { border-radius: 50%; padding: 20%; z-index: 1; }
[data-kind="misbaha"] .tap:focus-visible { outline-offset: -13%; }
[data-kind="misbaha"] .ring::after { inset: 17%; border-radius: 50%; background: conic-gradient(var(--accent) var(--fill), transparent 0); mask: radial-gradient(closest-side, transparent calc(100% - 3px), #000 calc(100% - 2px)); }
.misbaha-canvas { position: absolute; top: calc(var(--size) * -.04); left: calc(var(--size) * -.04); width: calc(var(--size) * 1.08); height: calc(var(--size) * 1.31); pointer-events: none; display: none; }
[data-kind="misbaha"] .misbaha-canvas { display: block; }

/* ───── الكلاسيكي: زر مسطح تحيط به ٣٣ حبة ───── */
.dot { display: none; }
[data-kind="classic"] .dot { display: block; position: absolute; top: 50%; left: 50%; width: calc(var(--size) * .052); aspect-ratio: 1; margin: calc(var(--size) * -.026); border-radius: 50%; background: var(--line); transform: rotate(calc(var(--k) * -360deg / 33)) translateY(calc(var(--size) * -.465)); transition: background-color .4s; }
[data-kind="classic"] .dot.on { background: var(--accent); }
[data-kind="classic"] .tap { inset: 11%; border-radius: 50%; padding: 18px; color: var(--on-accent); background: var(--accent); box-shadow: var(--shadow), inset 0 1px 0 rgb(255 255 255 / .18); transition: transform .2s cubic-bezier(.16, 1, .3, 1); }
[data-kind="classic"] .tap:active { transform: scale(.97); }
[data-kind="classic"] .tap-label { color: var(--on-accent); opacity: .9; }
[data-kind="classic"] .ring::after { inset: 8.2%; border-radius: 50%; background: conic-gradient(var(--accent) var(--fill), transparent 0); mask: radial-gradient(closest-side, transparent calc(100% - 4px), #000 calc(100% - 3px)); }
.beads { position: absolute; inset: 0; pointer-events: none; }

/* ───── العدّادان ───── */
[data-kind="counter"] .ring { margin-bottom: 8px; height: calc(var(--size) * 1.18); }
[data-kind="counter"] :is(.beads) { display: none; }
[data-kind="counter"] :is(.shell, .knob, .readout) { display: block; }
.shell { position: absolute; pointer-events: none; }
.readout { position: absolute; left: 50%; transform: translateX(-50%); pointer-events: none; direction: ltr; z-index: 1; }
.lcd, .drum { display: none; }
[data-kind="counter"] .tap { z-index: 1; border-radius: 40px; align-content: end; color: var(--body-ink); }
[data-kind="counter"] .tap-label { color: var(--body-ink); opacity: .85; }
.knob { border-radius: 50%; transition: transform .09s, box-shadow .09s; }
.tap:active .knob { transform: translateY(6px); }

/* العداد الرقمي: جسم بلاستيكي وشاشة بلورية */
[data-theme="raqami"] .shell { inset: 0 8%; border-radius: 46% 46% 40% 40% / 32% 32% 44% 44%; background: linear-gradient(155deg, var(--body-1), var(--body-2) 55%, var(--body-3)); box-shadow: var(--shadow), inset 0 3px 3px rgb(255 255 255 / .35), inset 0 -10px 18px rgb(0 0 0 / .28); }
[data-theme="raqami"] .readout { top: 12%; width: 62%; }
[data-theme="raqami"] .lcd { display: flex; justify-content: center; gap: 5%; padding: 9% 7%; border-radius: 14px; background: var(--lcd); border: 5px solid var(--bezel); box-shadow: inset 0 3px 10px rgb(0 0 0 / .35); }
.digit { position: relative; width: 15%; aspect-ratio: 10 / 18; transform: skewX(-5deg); }
.digit i { position: absolute; background: var(--lcd-ink); opacity: .09; }
.digit i.on { opacity: 1; }
.digit i:nth-child(1), .digit i:nth-child(4), .digit i:nth-child(7) { left: 14%; width: 72%; height: 9%; clip-path: polygon(10% 0, 90% 0, 100% 50%, 90% 100%, 10% 100%, 0 50%); }
.digit i:nth-child(2), .digit i:nth-child(3), .digit i:nth-child(5), .digit i:nth-child(6) { width: 17%; height: 41%; clip-path: polygon(50% 0, 100% 10%, 100% 90%, 50% 100%, 0 90%, 0 10%); }
.digit i:nth-child(1) { top: 0; }
.digit i:nth-child(2) { top: 6%; right: 0; }
.digit i:nth-child(3) { bottom: 6%; right: 0; }
.digit i:nth-child(4) { bottom: 0; }
.digit i:nth-child(5) { bottom: 6%; left: 0; }
.digit i:nth-child(6) { top: 6%; left: 0; }
.digit i:nth-child(7) { top: 45.5%; }
[data-theme="raqami"] .tap { padding: 0 14% 6%; }
[data-theme="raqami"] .say { position: absolute; top: 42%; inset-inline: 14%; }
[data-theme="raqami"] .knob { width: calc(var(--size) * .3); aspect-ratio: 1; background: radial-gradient(circle at 36% 28%, var(--knob-1), var(--knob-2) 60%, var(--knob-3)); box-shadow: 0 0 0 7px rgb(0 0 0 / .18), 0 13px 14px rgb(0 0 0 / .35), inset 0 2px 3px rgb(255 255 255 / .45); }
[data-theme="raqami"] .tap:active .knob { box-shadow: 0 0 0 7px rgb(0 0 0 / .18), 0 5px 7px rgb(0 0 0 / .35), inset 0 3px 8px rgb(0 0 0 / .3); }

/* العداد اليدوي: معدن مصقول وعجلات أرقام تدور */
[data-theme="yadawi"] .shell { left: 2%; right: 2%; bottom: 0; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, transparent 66%, rgb(255 255 255 / .28) 67%, rgb(0 0 0 / .22) 69%, transparent 70%), conic-gradient(from 20deg, var(--body-1), var(--body-3), var(--body-2), var(--body-1), var(--body-3), var(--body-2), var(--body-1)); box-shadow: var(--shadow), inset 0 2px 3px rgb(255 255 255 / .6), inset 0 -8px 16px rgb(0 0 0 / .3); }
[data-theme="yadawi"] .readout { top: 33%; width: 62%; }
[data-theme="yadawi"] .drum { display: flex; gap: 3px; padding: 7px; border-radius: 12px; background: var(--bezel); box-shadow: 0 2px 0 rgb(255 255 255 / .45), inset 0 3px 8px #000; }
.wheel { position: relative; flex: 1; height: calc(var(--size) * .17); overflow: hidden; border-radius: 4px; background: #101112; }
.wheel b { position: absolute; inset: 0 0 auto; display: grid; grid-auto-rows: calc(var(--size) * .17); justify-items: center; align-items: center; font: 600 calc(var(--size) * .115) / 1 Figures, monospace; color: #f4f4f0; transition: transform .4s cubic-bezier(.3, 1.2, .5, 1); transform: translateY(calc(var(--d, 0) * var(--size) * -.17)); }
.wheel::after { content: ''; position: absolute; inset: 0; background: linear-gradient(#000 0, transparent 32%, rgb(255 255 255 / .1) 50%, transparent 68%, #000 100%); }
[data-theme="yadawi"] .tap { padding: 0 12% 11%; }
[data-theme="yadawi"] .say { position: absolute; top: 56%; inset-inline: 14%; }
[data-theme="yadawi"] .knob { position: absolute; top: 0; left: 50%; width: calc(var(--size) * .25); aspect-ratio: 1; margin-left: calc(var(--size) * -.125); background: radial-gradient(circle at 36% 28%, var(--knob-1), var(--knob-2) 58%, var(--knob-3)); box-shadow: 0 0 0 6px var(--body-2), 0 9px 0 6px var(--body-3), inset 0 2px 4px rgb(255 255 255 / .45); }
[data-kind="counter"] .ring::after { left: 36%; right: 36%; height: 5px; border-radius: var(--pill); background: linear-gradient(to left, var(--lamp) var(--fill), rgb(0 0 0 / .25) 0); z-index: 2; }
[data-theme="raqami"] .ring::after { top: 37%; }
[data-theme="yadawi"] .ring::after { top: 52%; }

.hint { min-height: 1.7em; color: var(--muted); }
.hint.nudge { color: var(--accent); font-weight: 500; }

@media (min-width: 860px) { .ring { --size: clamp(300px, min(38vw, 54dvh), 430px); } }
@media (prefers-reduced-motion: reduce) {
  .ring.waiting::after { animation: none; opacity: 0; }
  .ring.waiting .tap { opacity: .75; }
}
