/* BimBam — un obiect ținut în mână, pe telefon, în portret. */

:root {
  --bg: #F3ECDF;
  --bg-deep: #E3D8C3;
  --ink: #3B3630;
  --c0: #FF6B4A;
  --c1: #FFC531;
  --c2: #3D9BE9;
  --c3: #5CC27A;

  --pad: 10px;
  --ring-size: min(82vw, 42vh, 360px);
  --track: calc(var(--ring-size) * 0.055);
  --slot-size: calc(var(--ring-size) * 0.165);
  --stone-size: min(26vw, 13.5vh, 112px);
  --side-size: min(16vw, 9vh, 66px);
  --ghost-size: calc(var(--slot-size) * 0.9);
  --thumb: 52px;
}
@supports (height: 100dvh) {
  :root {
    --ring-size: min(82vw, 42dvh, 360px);
    --stone-size: min(26vw, 13.5dvh, 112px);
    --side-size: min(16vw, 9dvh, 66px);
  }
}
/* The three dials need one more text row than the former sliders. */
@media (max-height: 650px) {
  :root { --ring-size: min(78vw, 39vh, 360px); }
  @supports (height: 100dvh) { :root { --ring-size: min(78vw, 39dvh, 360px); } }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  height: 100%;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  position: fixed; inset: 0; margin: 0;          /* fără rubber-band pe iOS */
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ---------- formele celor patru pietre (folosite și pentru urme și fantomă) ---------- */

.shape-0 { --c: var(--c0); }   /* cerc */
.shape-1 { --c: var(--c1); }   /* pătrat */
.shape-2 { --c: var(--c2); }   /* triunghi */
.shape-3 { --c: var(--c3); }   /* stea */

/* Forma desenată în SVG: halo (în mână), muchie (dedesubt), față (culoarea). */
.shape { display: block; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.shape .face { fill: var(--c); }
.shape .edge { fill: color-mix(in srgb, var(--c) 65%, var(--ink)); transform: translate(0, 7px); }
.shape .halo { display: none; }

/* ---------- ecranul de pornire ---------- */

.welcome {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px;
  background: var(--bg);
}
.start {
  width: min(50vw, 200px); aspect-ratio: 1; border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center;
  background: var(--c0); cursor: pointer;
  box-shadow: 0 10px 0 color-mix(in srgb, var(--c0) 65%, var(--ink)), 0 18px 28px rgba(59, 54, 48, .18);
}
.start:active { translate: 0 8px; box-shadow: 0 2px 0 color-mix(in srgb, var(--c0) 65%, var(--ink)); }
.start:disabled { opacity: .6; }
.start svg { width: 62%; height: 62%; display: block; }
.welcome p { margin: 0; font-size: 20px; text-align: center; max-width: 80vw; }

/* ---------- așezarea ---------- */

.toy {
  height: 100%; max-width: 430px; margin: 0 auto;
  display: grid;
  grid-template-rows: 1fr auto auto;
  align-items: center;
  justify-items: center;
  padding: max(var(--pad), env(safe-area-inset-top)) var(--pad) max(var(--pad), env(safe-area-inset-bottom));
  gap: 10px;
}

/* jucăria adormită (compoziție salvată, încă neatinsă): cercul stă, discul din
   centru arată un triunghi de play; la fel și când ciclul e pe pauză */
.toy.asleep .sweep { display: none; }
.toy.asleep .controls { pointer-events: none; }
.toy.awaiting-start button:not(.library-button) { visibility: hidden; }
.hole::after {
  content: ''; position: absolute; left: 54%; top: 50%; translate: -50% -50%;
  width: 44%; height: 48%;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  background: #fff; opacity: 0; transition: opacity .2s;
}
.toy.asleep .hole::after, .ring.paused .hole::after { opacity: 1; }
.ring.paused .hole::after { background: var(--ink); opacity: .7; }

/* ---------- cercul ---------- */

.ring-area { position: relative; display: grid; place-items: center; width: 100%; height: 100%; }

.ring { position: relative; width: var(--ring-size); height: var(--ring-size); }

/* S1, colțul liber din stânga-sus al cercului: intrarea în raftul comun de discuri. */
.library-button {
  position: absolute; z-index: 21;
  left: 0; top: 0;
  width: var(--side-size); height: var(--side-size); border-radius: 50%;
  border: 0; padding: 0; appearance: none; cursor: pointer;
  display: grid; place-items: center;
  color: var(--ink); background: #fff;
  box-shadow: 0 6px 0 #CFC4AD, 0 10px 14px rgba(59, 54, 48, .15);
  transition: translate .07s, box-shadow .07s;
}
.library-button:active { translate: 0 4px; box-shadow: 0 2px 0 #CFC4AD, 0 4px 8px rgba(59, 54, 48, .15); }
.library-button svg { width: 68%; height: 68%; overflow: visible; }
.library-button circle:first-child { fill: #25211E; }
.library-button circle.label { fill: var(--c0); }
.library-button path { fill: none; stroke: var(--ink); stroke-width: 6; stroke-linecap: round; opacity: .55; }
.library-button:focus-visible, .library-close:focus-visible, .disc-delete:focus-visible, .disc-keep:focus-visible,
.disc-load:focus-visible, .disc-save-form button:focus-visible {
  outline: 3px solid var(--ink); outline-offset: 3px;
}
.ring-track {
  position: absolute; inset: 0; border-radius: 50%;
  border: var(--track) solid var(--bg-deep);
}

/* „Întinderea" sunetului: cât din tură umple sunetul din fantomă, desenat ca o
   linie subțire chiar pe interiorul șinei (raza 43 din 100, marginea interioară a
   șinei fiind la 44,5), în culoarea tare a pietrei. Stă sub poziții (z-index 1). */
.reach {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
  opacity: 0; transition: opacity .12s;
}
.reach.on { opacity: .95; }
.reach circle {
  fill: none; stroke: var(--c, var(--ink)); stroke-width: 1.6; stroke-linecap: round;
  stroke-dasharray: 0 100;
}


.sweep {
  position: absolute; z-index: 2; pointer-events: none;
  left: calc(50% - 3px); top: calc(var(--track) / 2);
  width: 6px; height: calc(50% - var(--track) / 2);
  transform-origin: 50% 100%;
  border-radius: 3px;
  background: linear-gradient(to top, transparent 35%, rgba(59, 54, 48, .22));
}
.sweep::after {
  content: ''; position: absolute; left: 50%; top: 0; translate: -50% -50%;
  width: calc(var(--slot-size) * 1.25); height: calc(var(--slot-size) * 1.25); border-radius: 50%;
  background: rgba(255, 255, 255, .45);
  box-shadow: 0 0 18px 5px rgba(255, 255, 255, .55);
}
.ring.paused .sweep { opacity: .35; }

.slot {
  --pos: rotate(var(--angle)) translateY(calc((var(--ring-size) - var(--track)) / -2)) rotate(calc(-1 * var(--angle)));
  position: absolute; z-index: 1;
  left: 50%; top: 50%;
  width: var(--slot-size); height: var(--slot-size);
  margin: calc(var(--slot-size) / -2) 0 0 calc(var(--slot-size) / -2);
  transform: var(--pos);
  cursor: pointer;
}
.cup {
  width: 100%; height: 100%; border-radius: 50%;
  background: var(--bg);
  border: 3px solid var(--bg-deep);
  box-shadow: inset 0 3px 6px rgba(59, 54, 48, .12);
  padding: 9%; gap: 4%;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; align-content: center;
  transition: scale .12s, border-color .12s;
}
.slot.active .cup { border-color: var(--ink); scale: 1.12; }
.slot.hover .cup { scale: 1.3; border-color: var(--ink); background: #fff; }

.mark { width: 100%; height: 100%; }
.mark .edge { transform: translate(0, 5px); }
.slot:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 50%; }

.slot[data-count="2"] .mark,
.slot[data-count="3"] .mark,
.slot[data-count="4"] .mark { width: 46%; height: 46%; }

/* „Asistentul": cu o piatră în mână, două poziții pulsează în culoarea ei — locuri
   bune de încercat. Inelul stă pe cupă (nu pe .slot, care e poziționat pe cerc);
   forma ștearsă apare doar în cupele goale, ca o umbră a pietrei. */
.slot.hint .cup {
  border-color: var(--c);
  animation: hint 1.3s ease-in-out infinite;
}
@keyframes hint {
  0%, 100% { box-shadow: inset 0 3px 6px rgba(59, 54, 48, .12), 0 0 0 0 color-mix(in srgb, var(--c) 55%, transparent); }
  50%      { box-shadow: inset 0 3px 6px rgba(59, 54, 48, .12), 0 0 0 7px color-mix(in srgb, var(--c) 0%, transparent); }
}
.slot .hint-shape {
  position: absolute; inset: 22%; pointer-events: none; opacity: .45;
}
.slot .hint-shape .edge { display: none; }
.slot .hint-shape .face { fill: var(--c); }
.slot.active.hint .cup, .slot.hover.hint .cup { animation: none; }

/* ---------- un control tactil (Ritm), deasupra pietrelor ---------- */
.controls { width: 100%; }
.effect-panel {
  --dial-size: min(14vw, 7.5vh, 58px);
  display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center;
  gap: 4px 8px; align-items: start; padding: 8px 4px 0;
}
@supports (height: 100dvh) { .effect-panel { --dial-size: min(14vw, 7.5dvh, 58px); } }
.effect-control {
  appearance: none; border: 0; margin: 0; padding: 4px 0;
  display: grid; justify-items: center; gap: 4px; min-width: 0;
  color: var(--ink); background: transparent; font: inherit; cursor: pointer;
  touch-action: manipulation; border-radius: 12px;
}
.effect-name { font-size: 12px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; }
.effect-value { max-width: 100%; font-size: 12px; line-height: 16px; white-space: nowrap; }
.effect-dial {
  display: block; position: relative;
  width: calc(var(--dial-size) * 1.5); height: calc(var(--dial-size) * 1.5);
}
.effect-cap {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%;
  width: var(--dial-size); height: var(--dial-size); border-radius: 50%;
  background: linear-gradient(145deg, #FCF8F0, #E3D8C3);
  border: 1px solid #B8AF9E;
  box-shadow: inset 0 1px 1px #FCF8F0, 0 4px 0 #CFC4AD, 0 7px 10px #3b36302b;
  transition: translate .12s, box-shadow .12s;
}
.effect-cap i {
  position: absolute; inset: 0; border-radius: inherit;
  rotate: var(--angle); transition: rotate .18s ease-out;
}
.effect-cap i::after {
  content: ''; position: absolute; left: 50%; top: 10%; translate: -50% 0;
  width: 4px; height: 34%; border-radius: 2px; background: var(--ink);
}
[data-effect=pulse] .effect-cap i::after { background: #C54820; }
.effect-detent {
  position: absolute; top: 50%; left: 50%; margin: -2px;
  width: 4px; height: 4px; border-radius: 50%; background: #B8AF9E;
  transform: rotate(var(--a)) translateY(calc(var(--dial-size) * -.65));
}
.effect-detent.selected { background: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.effect-control:active:not(:disabled) .effect-cap { translate: -50% calc(-50% + 3px); box-shadow: inset 0 1px 1px #FCF8F0, 0 1px 0 #CFC4AD, 0 3px 5px #3b363020; }
.effect-control:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.effect-control:disabled { opacity: .4; cursor: default; }
.effect-control[aria-busy=true] .effect-value { opacity: .55; }
.effect-panel.inviting .effect-control:not(:disabled) .effect-cap {
  animation: effect-invite 900ms ease-in-out 2;
  border-color: var(--selected-color);
}
.effect-panel.inviting [data-effect=pulse] .effect-cap { animation-delay: 180ms; }
@keyframes effect-invite {
  0%, 100% { scale: 1; }
  45% { scale: 1.12; }
}
.effect-status { grid-column: 1 / -1; min-height: 16px; margin: 0; text-align: center; font-size: 11px; color: var(--ink); line-height: 16px; }
@media (hover: hover) { .effect-control:hover:not(:disabled) .effect-cap { border-color: var(--ink); } }
@media (prefers-reduced-motion: reduce) { .effect-cap, .effect-cap i { transition: none; } }
@media (prefers-reduced-motion: reduce) { .effect-panel.inviting .effect-cap { animation: none !important; } }

/* ---------- rândul de jos: gura, pietrele, groapa ---------- */

.bottom { display: grid; grid-template-columns: var(--side-size) 1fr var(--side-size); align-items: center; gap: 8px; width: 100%; }
.bottom > .stones { grid-column: 2; justify-self: center; }
.stones {
  display: grid; grid-template-columns: repeat(2, var(--stone-size)); gap: 8px;
}
.stone {
  position: relative;
  width: var(--stone-size); height: var(--stone-size);
  border: 0; padding: 0; margin: 0; appearance: none; font: inherit;
  background: none; cursor: pointer; outline: none;
  transition: translate .07s;
}
.stone .shape { transition: transform .07s; }
.stone .shape .edge { transition: transform .07s; }
.stone.filled .shape { filter: drop-shadow(0 8px 8px rgba(59, 54, 48, .2)); }
.stone.filled.pressed { translate: 0 5px; }
.stone.filled.pressed .shape { filter: drop-shadow(0 3px 4px rgba(59, 54, 48, .2)); }
.stone.filled.pressed .shape .edge { transform: translate(0, 2px); }
.stone.empty .shape .edge { display: none; }
.stone.empty .shape .face {
  fill: color-mix(in srgb, var(--c) 14%, var(--bg));
  stroke: color-mix(in srgb, var(--c) 60%, var(--bg));
  stroke-width: 4; stroke-dasharray: 7 6; stroke-linecap: round;
}
.stone.empty.pressed:not(.recording) .shape .face { fill: color-mix(in srgb, var(--c) 30%, var(--bg)); }
/* Deschisă: crește și respiră încet cât așteaptă un sunet; conturul devine plin. */
.stone.listening { animation: breathe 1.6s ease-in-out infinite alternate; }
.stone.listening .shape .face {
  fill: color-mix(in srgb, var(--c) 45%, var(--bg)); stroke: var(--c);
  stroke-width: 4; stroke-dasharray: none;
}
.stone.listening .shape { filter: drop-shadow(0 0 10px color-mix(in srgb, var(--c) 55%, transparent)); }
.stone.recording { scale: calc(1 + var(--level, 0) * 0.3); }
.stone.recording .shape { filter: drop-shadow(0 0 calc(4px + var(--level, 0) * 14px) rgba(255, 90, 60, .85)); }
.stone.recording .shape .edge { display: none; }
.stone.recording .shape .face { fill: var(--c); stroke: #fff; stroke-width: 4; stroke-dasharray: none; }
.stone.held .shape .halo {
  display: inline; fill: none; stroke: var(--c); stroke-width: 4; opacity: .55;
  transform: translate(50px, 50px) scale(1.24) translate(-50px, -50px);
}
.stone .arc {
  position: absolute; inset: -12px; width: calc(100% + 24px); height: calc(100% + 24px);
  rotate: -90deg; pointer-events: none; display: none;
}
.stone.recording .arc, .stone.listening .arc { display: block; }
.stone .arc circle {
  fill: none; stroke: #fff; stroke-width: 7; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: 100;
}

/* Gura (stânga): ții apăsat și vorbești; sunetul intră în prima piatră goală,
   iar dacă toate sunt pline, înlocuiește sunetul pietrei din mână. */
.mouth {
  flex: none; position: relative;
  width: var(--side-size); height: var(--side-size); border-radius: 50%;
  border: 0; padding: 0; appearance: none; cursor: pointer; outline: none;
  display: grid; place-items: center;
  background: #fff;
  box-shadow: 0 6px 0 #CFC4AD, 0 10px 14px rgba(59, 54, 48, .15);
  transition: translate .07s, box-shadow .07s;
}
.mouth svg { width: 58%; height: 58%; fill: var(--ink); stroke: var(--ink); opacity: .75; }
.mouth.pressed { translate: 0 4px; box-shadow: 0 2px 0 #CFC4AD, 0 4px 8px rgba(59, 54, 48, .15); }
.mouth.recording {
  scale: calc(1 + var(--level, 0) * 0.3);
  box-shadow: 0 0 0 calc(5px + var(--level, 0) * 16px) rgba(255, 90, 60, .4);
}
.mouth.recording svg { opacity: 1; fill: #E5482B; stroke: #E5482B; }
.mouth.listening { animation: breathe 1.6s ease-in-out infinite alternate; box-shadow: 0 0 0 6px rgba(229, 72, 43, .25), 0 6px 0 #CFC4AD; }
.mouth.listening svg { opacity: 1; fill: #E5482B; stroke: #E5482B; }
@keyframes breathe { from { scale: 1.12; } to { scale: 1.28; } }

/* Centrul cercului: în repaus e butonul de play/pauză (un disc plin).
   Ținut apăsat se face disc; când tragi o piatră deasupra ei, crește. */
.hole {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%; z-index: 3;
  width: 27%; height: 27%; border-radius: 50%;
  cursor: pointer;
  border: 5px solid #5B544B;
  background: #5B544B;
  box-shadow: 0 5px 0 #3B3630, 0 9px 14px rgba(59, 54, 48, .2);
  transition: scale .15s, box-shadow .2s, background .2s, border-color .2s;
}

.hole.hover {
  scale: 1.35;
  background: #0E0C0A;
  box-shadow: 0 0 0 10px rgba(59, 54, 48, .18);
}
/* cât ții discul apăsat, un inel se umple în jurul lui */
.hole::before {
  content: ''; position: absolute; inset: -12px; border-radius: 50%;
  border: 5px solid transparent; border-top-color: #fff; opacity: 0;
}
.hole.holding::before { opacity: 1; animation: fillring .7s linear forwards; }
@keyframes fillring { from { rotate: 0deg; } to { rotate: 720deg; } }
.ring.paused .hole {
  border-color: var(--bg-deep);
  background: var(--bg-deep);
  box-shadow: inset 0 5px 9px rgba(59, 54, 48, .18);
}
/* discul: un vinil cu eticheta celor patru forme; se învârte cât se face, apoi așteaptă un tap */
.disc {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%; z-index: 6;
  width: 64%; height: 64%; border-radius: 50%;
  background:
    radial-gradient(circle, transparent 0 21%, rgba(0, 0, 0, .35) 21.5% 22.5%, transparent 23%),
    repeating-radial-gradient(circle, #1E1B18 0 2px, #2B2622 2px 5px);
  box-shadow: 0 14px 28px rgba(0, 0, 0, .35), 0 0 0 4px rgba(255, 255, 255, .5);
  display: grid; place-items: center;
  cursor: pointer;
}
.disc .label {
  width: 42%; height: 42%; border-radius: 50%; background: var(--bg);
  display: grid; grid-template-columns: 1fr 1fr; gap: 6%; padding: 14%;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .15);
}
.disc .label i { display: block; }
.disc .label .shape .edge { display: none; }
.disc.making { animation: spin 1.6s linear infinite; }
@keyframes spin { to { rotate: 360deg; } }
.disc .arc {
  position: absolute; inset: -14px; width: calc(100% + 28px); height: calc(100% + 28px);
  rotate: -90deg; pointer-events: none;
}
.disc .arc circle {
  fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: 100;
}
.disc.making .arc { animation: spin 1.6s linear infinite reverse; }   /* arcul stă pe loc cât discul se învârte */
.disc.ready .arc { display: none; }
.disc.ready { animation: glow 1.2s ease-in-out infinite alternate; }
@keyframes glow {
  from { box-shadow: 0 14px 28px rgba(0, 0, 0, .35), 0 0 0 4px rgba(255, 255, 255, .5); }
  to   { box-shadow: 0 14px 28px rgba(0, 0, 0, .35), 0 0 0 12px rgba(255, 255, 255, .9), 0 0 30px 10px rgba(255, 255, 255, .6); }
}

/* ---------- raftul comun de discuri ---------- */

.disc-library { position: fixed; inset: 0; z-index: 28; display: grid; place-items: stretch center; }
.library-backdrop {
  position: absolute; inset: 0; border: 0; padding: 0; background: rgba(59, 54, 48, .3);
}
.library-panel {
  position: relative; width: min(100%, 430px); height: 100%;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 16px;
  background: var(--bg); box-shadow: 0 0 35px rgba(59, 54, 48, .28);
}
.library-panel > header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.library-panel > :not(.disc-list) { flex-shrink: 0; }
.library-panel .disc-list { flex: 1; }
.new-play { display: grid; gap: 8px; }
.new-play > button:first-child {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 48px; padding: 8px 16px; border: 2px solid var(--ink); border-radius: 16px;
  background: var(--bg-deep); color: var(--ink); font: 750 18px/1.3 system-ui, sans-serif; cursor: pointer;
}
.new-play > button:first-child span { font-size: 26px; }
.new-play p { margin: 0; font-size: 13px; line-height: 1.4; }
.restore-play {
  min-height: 44px; padding: 8px 12px; border: 1px solid var(--ink); border-radius: 12px;
  background: var(--bg); color: var(--ink); font: 650 14px/1.2 system-ui, sans-serif; cursor: pointer;
}
.new-play button, .restore-play { transition: background .2s, scale .15s; }
.new-play button:disabled, .restore-play:disabled { opacity: .45; cursor: default; }
.new-play button:focus-visible, .restore-play:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.new-play button:active:not(:disabled), .restore-play:active:not(:disabled) { scale: .97; }
@media (hover: hover) {
  .new-play button:hover:not(:disabled), .restore-play:hover:not(:disabled) { background: color-mix(in srgb, var(--bg-deep) 70%, var(--bg)); }
}
.play-undo {
  position: fixed; top: max(12px, env(safe-area-inset-top)); left: 50%; translate: -50% 0;
  z-index: 20; width: 150px; text-align: center;
}
.library-open .play-undo { visibility: hidden; }
.discarded-stones {
  position: fixed; bottom: max(8px, env(safe-area-inset-bottom)); left: 50%; translate: -50% 0;
  z-index: 20; display: flex; justify-content: center; gap: 12px;
}
.discarded-stone {
  position: relative; width: 52px; height: 52px; padding: 7px; border: 1px solid var(--ink); border-radius: 12px;
  background: var(--bg-deep); color: var(--ink); cursor: pointer; touch-action: manipulation;
}
.discarded-stone:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.discarded-stone:active { scale: .94; }
@media (hover: hover) { .discarded-stone:hover { background: var(--bg); } }
.discard-return { position: absolute; right: 1px; top: -5px; font: 700 20px/1 system-ui, sans-serif; }
.discard-time {
  position: absolute; bottom: 2px; left: 6px; right: 6px; height: 3px; border-radius: 2px;
  background: var(--ink); transform-origin: left; animation: discard-countdown var(--discard-duration) linear forwards;
}
@keyframes discard-countdown { to { scale: 0 1; } }
@media (prefers-reduced-motion: reduce) { .discard-time { animation: none; } }
.ghost.discarding { opacity: .65; }
.library-open .discarded-stones { visibility: hidden; }
body:has(#discarded-stones:not([hidden])) .toy {
  padding-bottom: calc(max(var(--pad), env(safe-area-inset-bottom)) + 60px);
}
/* Reserve a utility row so recovery never covers a beat on a small phone. */
body:has(#play-undo:not([hidden])) .toy {
  padding-top: calc(max(var(--pad), env(safe-area-inset-top)) + 54px);
}
body:has(#play-undo:not([hidden])) .ring-area > .library-button { top: -54px; }
@media (max-height: 650px) {
  :root:has(#play-undo:not([hidden])), :root:has(#discarded-stones:not([hidden])) { --ring-size: min(76vw, 28vh, 200px); }
  :root:has(#play-undo:not([hidden])):has(#discarded-stones:not([hidden])) { --ring-size: min(66vw, 18vh, 160px); }
  @supports (height: 100dvh) {
    :root:has(#play-undo:not([hidden])), :root:has(#discarded-stones:not([hidden])) { --ring-size: min(76vw, 28dvh, 200px); }
    :root:has(#play-undo:not([hidden])):has(#discarded-stones:not([hidden])) { --ring-size: min(66vw, 18dvh, 160px); }
  }
}
.library-panel > header div { display: flex; flex-direction: column; }
.library-panel > header h1 { margin: 0; font-size: 30px; line-height: 1; font-weight: 850; letter-spacing: -.03em; }
.library-panel > header strong { margin-top: 4px; font-size: 12px; font-weight: 650; opacity: .72; }
.library-close, .disc-delete {
  flex: none; width: 48px; height: 48px; border-radius: 50%; border: 0; padding: 0;
  color: var(--ink); background: var(--bg-deep); font: 32px/1 system-ui, sans-serif; cursor: pointer;
  transition: background .2s ease, scale .2s ease;
}
.disc-save-form { display: grid; gap: 8px; }
.disc-save-form label { font-size: 14px; font-weight: 750; }
.disc-save-form > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.disc-save-form input {
  min-width: 0; height: 48px; border: 3px solid var(--bg-deep); border-radius: 16px;
  padding: 0 12px; color: var(--ink); background: #fff; outline: none;
  font: 600 16px/1 system-ui, sans-serif; user-select: text; -webkit-user-select: text;
  transition: border-color .2s ease;
}
.disc-save-form input:focus { border-color: var(--ink); }
.disc-save-form button {
  min-width: 92px; height: 48px; border: 0; border-radius: 16px; padding: 0 16px;
  color: #fff; background: var(--c0); font: 750 19px/1 system-ui, sans-serif; cursor: pointer;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--c0) 65%, var(--ink));
  transition: background .2s ease, translate .2s ease, box-shadow .2s ease;
}
.disc-save-form button:active { translate: 0 3px; box-shadow: 0 1px 0 color-mix(in srgb, var(--c0) 65%, var(--ink)); }
.disc-save-form button:disabled { cursor: not-allowed; opacity: .6; }
.disc-save-form.busy { opacity: .55; }
.disc-status { margin: -8px 0; min-height: 16px; font-size: 14px; opacity: .72; }
.disc-list { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 4px 12px; }
.disc-list.busy { opacity: .6; }
.disc-empty { margin: 24px 0; text-align: center; font-size: 16px; opacity: .72; }
.saved-disc {
  flex: none; min-height: 72px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: 8px; border-radius: 16px; background: #fff; box-shadow: 0 4px 0 #D8CDB8;
  transition: translate .2s ease, box-shadow .2s ease;
}
.disc-load {
  min-width: 0; align-self: stretch; display: flex; align-items: center; gap: 12px;
  border: 0; padding: 0 4px; color: var(--ink); background: transparent; text-align: left; cursor: pointer;
}
.mini-disc {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  background: radial-gradient(circle, var(--c1) 0 17%, #201D1A 18% 25%, #302B27 26% 34%, #1D1A18 35% 44%, #302B27 45% 54%, #1D1A18 55%);
  box-shadow: 0 3px 7px rgba(59, 54, 48, .25);
}
.saved-disc-label { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.saved-disc-label span { overflow: hidden; font-size: 16px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.disc-delete { color: color-mix(in srgb, var(--c0) 70%, var(--ink)); background: color-mix(in srgb, var(--c0) 13%, var(--bg)); }
.saved-disc.confirming { grid-template-columns: minmax(0, 1fr) auto auto; }
.saved-disc.confirming .disc-delete {
  width: auto; padding: 0 16px; border-radius: 999px;
  color: #fff; background: var(--c0); font: 750 16px/1 system-ui, sans-serif;
}
.disc-keep {
  flex: none; height: 48px; border: 0; border-radius: 999px; padding: 0 16px;
  color: var(--ink); background: var(--bg-deep); font: 750 16px/1 system-ui, sans-serif; cursor: pointer;
}
@media (hover: hover) {
  .library-button:hover { translate: 0 -2px; box-shadow: 0 8px 0 #CFC4AD, 0 12px 18px rgba(59, 54, 48, .18); }
  .library-close:hover { background: color-mix(in srgb, var(--bg-deep) 72%, #fff); }
  .disc-delete:hover { background: color-mix(in srgb, var(--c0) 22%, var(--bg)); }
  .saved-disc.confirming .disc-delete:hover { background: color-mix(in srgb, var(--c0) 90%, var(--ink)); }
  .saved-disc:hover { translate: 0 -2px; box-shadow: 0 6px 0 #D8CDB8; }
  .disc-save-form button:hover:not(:disabled) { background: color-mix(in srgb, var(--c0) 90%, var(--ink)); }
}
.library-close:active, .disc-delete:active { scale: .92; }
.saved-disc:has(.disc-load:active) { translate: 0 2px; box-shadow: 0 2px 0 #D8CDB8; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- elemente trecătoare ---------- */

.ghost {
  position: fixed; left: 0; top: 0; z-index: 10; pointer-events: none;
  width: var(--ghost-size); height: var(--ghost-size);
  margin: calc(var(--ghost-size) / -2) 0 0 calc(var(--ghost-size) / -2);
}
.ghost .shape { filter: drop-shadow(0 10px 10px rgba(59, 54, 48, .35)); }
.poof {
  position: fixed; z-index: 10; pointer-events: none;
  width: var(--ghost-size); height: var(--ghost-size);
  translate: -50% -50%;
}
.poof .shape .edge { display: none; }


.debug {
  position: fixed; left: 0; right: 0; top: env(safe-area-inset-top, 0); z-index: 40;
  font: 11px/1.4 ui-monospace, monospace; text-align: center; color: var(--ink); opacity: .7;
  pointer-events: none;
}

/* ---------- telefon ținut orizontal: doar un semn să-l întorci ---------- */

.rotate {
  position: fixed; inset: 0; z-index: 30; display: none;
  place-items: center; background: var(--bg);
}
.rotate .phone {
  width: 44px; height: 80px; border-radius: 10px; border: 4px solid var(--ink);
  animation: turn 1.6s ease-in-out infinite alternate;
}
@keyframes turn { from { rotate: -90deg; } to { rotate: 0deg; } }
@media (orientation: landscape) and (max-height: 520px) {
  .rotate { display: grid; }
}

/* ---------- banda de dezvoltare ----------
   Doar pe desktop, pentru testare; pe telefon nu apare niciodată (js/devbar.js
   nici nu o construiește dacă nu există mouse fin și un ecran de 700 px). */

.devbar {
  position: fixed; right: 10px; bottom: 10px; z-index: 25;   /* și peste ecranul de start */
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px;
  max-width: min(100vw - 20px, 520px);
  pointer-events: auto;
  font: 12px/1.4 ui-monospace, monospace;
  color: color-mix(in srgb, var(--ink) 55%, var(--bg));
}
.devbar button {
  font: inherit; color: inherit; cursor: pointer;
  padding: 4px 8px; border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--ink) 25%, var(--bg));
  background: var(--bg-deep);
}
.devbar button:active { translate: 0 1px; }
.devbar .note { opacity: .75; }
