/* What The Clock V2 — shared structure. Themes set the vars + dial art. */
:root {
  --bg: #0b0b0f;
  --ink: #e8e6df;
  --ac: #2f6bff;
  --good: #4dff8a;
  --mid: #ffb86b;
  --bad: #ff6464;
  --display: 'Clash Display', sans-serif;
  --body: 'Satoshi', sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-io: cubic-bezier(0.77, 0, 0.175, 1);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

.grain {
  position: fixed; inset: -50%; z-index: 40; pointer-events: none; opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 0.9s steps(4) infinite;
}
@keyframes grain {
  0% { transform: translate(0,0) } 25% { transform: translate(-2%,3%) }
  50% { transform: translate(3%,-2%) } 75% { transform: translate(-3%,-3%) } 100% { transform: translate(2%,2%) }
}

.back {
  position: fixed; top: 18px; left: 18px; z-index: 50;
  font-family: var(--display); font-weight: 600; font-size: 12px;
  letter-spacing: 0.14em; text-transform: uppercase; text-decoration: none;
  color: var(--ink); opacity: 0.55; display: flex; align-items: center; gap: 7px;
  transition: opacity 180ms ease, transform 160ms var(--ease);
}
.back:hover { opacity: 1; }
.back:active { transform: scale(0.96); }
.back svg { display: block; }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.on { display: flex; }

.wipe {
  position: fixed; inset: 0; z-index: 60; background: var(--ac);
  transform: translateY(101%); pointer-events: none;
}
.wipe.run-in  { transition: transform 420ms var(--ease-io); transform: translateY(0); }
.wipe.run-out { transition: transform 420ms var(--ease-io); transform: translateY(-101%); }

/* ---------- intro ---------- */
#intro { align-items: center; justify-content: center; gap: clamp(18px, 3.5vh, 40px); }
.title { font-family: var(--display); font-weight: 700; text-align: center; line-height: 0.86; letter-spacing: -0.02em; }
.title .l1 { font-size: clamp(40px, 10vw, 118px); display: block; }
.title .l2 { font-size: clamp(66px, 17vw, 210px); display: flex; align-items: center; justify-content: center; }
.title .o-logo { display: inline-block; width: 0.82em; height: 0.82em; margin: 0 0.03em; }
.rise { opacity: 0; transform: translateY(40px); animation: rise 800ms var(--ease) forwards; }
/* returning to the menu later: entrance animation must not replay (Safari
   fails to restart animations after display:none, leaving elements invisible) */
.screen.revisit .rise { animation: none; opacity: 1; transform: none; }
.rise.d1 { animation-delay: 90ms; } .rise.d2 { animation-delay: 200ms; } .rise.d3 { animation-delay: 320ms; }
@keyframes rise { to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
.lh-min  { transform-origin: 50px 50px; animation: spin 6s linear infinite; }
.lh-hour { transform-origin: 50px 50px; animation: spin 72s linear infinite; }

.btn-big {
  font-family: var(--display); font-weight: 700; text-transform: uppercase;
  font-size: clamp(20px, 4vw, 34px); letter-spacing: 0.12em;
  color: var(--bg); background: var(--ink);
  padding: clamp(13px, 2.4vh, 22px) clamp(44px, 8vw, 100px);
  border-radius: 999px;
  transition: transform 160ms var(--ease);
}
.btn-big:hover { transform: scale(1.04); }
.btn-big:active { transform: scale(0.97); }
.hint { font-size: 14px; opacity: 0.55; letter-spacing: 0.04em; text-align: center; max-width: 340px; line-height: 1.5; }

/* ---------- play ---------- */
#play { padding: max(12px, env(safe-area-inset-top)) 18px max(12px, env(safe-area-inset-bottom)); }
.hud { display: flex; justify-content: center; align-items: baseline; gap: 18px; flex-shrink: 0; padding-top: 38px; }
.hud .round { font-family: var(--display); font-weight: 700; font-size: clamp(15px, 2.4vw, 22px); letter-spacing: 0.1em; text-transform: uppercase; }
.hud .timer { font-variant-numeric: tabular-nums; font-weight: 500; font-size: clamp(13px, 2vw, 18px); opacity: 0.6; }

.flap { display: flex; align-items: center; justify-content: center; gap: 0.04em; flex-shrink: 0; margin-top: clamp(2px, 1.2vh, 12px); }
.flap .cell {
  position: relative; overflow: hidden; height: 1em; width: 0.62em;
  font-family: var(--display); font-weight: 700;
  font-size: clamp(52px, 11vh, 104px); line-height: 1;
}
.flap .colon { width: 0.34em; text-align: center; }
@keyframes blink { 50% { opacity: 0.25; } }
.flap .reel { position: absolute; left: 0; top: 0; width: 100%; text-align: center; transition: transform 700ms var(--ease-io); }
.flap .reel span { display: block; height: 1em; }

.dial-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.dial-wrap svg { height: 100%; width: auto; max-width: 92vw; touch-action: none; cursor: grab; overflow: visible; display: block; }
.dial-wrap svg.grabbing { cursor: grabbing; }
.ghost { opacity: 0; transition: opacity 350ms ease; }
svg.reveal .ghost { opacity: 1; }
/* between rounds the hands glide back to 10:10 */
#dial.homing #handH, #dial.homing #handM { transition: transform 680ms cubic-bezier(0.77, 0, 0.175, 1); }

/* round progress strip */
.strip { flex-shrink: 0; display: flex; gap: 6px; width: min(560px, 92vw); margin: 0 auto clamp(8px, 1.6vh, 14px); }
.scell {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 7px 2px; border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--ink) 14%, transparent);
  background: color-mix(in srgb, var(--ink) 3%, transparent);
  transition: border-color 300ms ease, background 300ms ease;
}
.scell .slbl { font-family: var(--display); font-weight: 600; font-size: 10px; letter-spacing: 0.16em; opacity: 0.45; }
.scell .sval { font-variant-numeric: tabular-nums; font-weight: 700; font-size: clamp(11px, 1.9vw, 14px); opacity: 0.3; }
.scell.current { border-color: color-mix(in srgb, var(--ac) 70%, transparent); background: color-mix(in srgb, var(--ac) 8%, transparent); }
.scell.current .slbl { opacity: 0.8; }
.scell.done .sval { opacity: 1; }
.scell.done.good .sval { color: var(--good); }
.scell.done.mid  .sval { color: var(--mid); }
.scell.done.bad  .sval { color: var(--bad); }
.scell.done { border-color: color-mix(in srgb, var(--ink) 22%, transparent); }

.set-row { flex-shrink: 0; display: flex; justify-content: center; padding-bottom: clamp(4px, 1.6vh, 14px); }
#setBtn {
  width: min(560px, 92vw);
  font-family: var(--display); font-weight: 700; text-transform: uppercase;
  font-size: clamp(19px, 3.4vw, 30px); letter-spacing: 0.24em;
  color: var(--bg); background: var(--ink);
  padding: clamp(12px, 2vh, 18px) 0; border-radius: 999px;
  transition: transform 150ms var(--ease), opacity 200ms ease;
}
#setBtn:active { transform: scale(0.97); }
#setBtn:disabled { opacity: 0.25; cursor: default; }

/* accuracy stamp */
.stamp { position: fixed; inset: 0; z-index: 45; display: none; align-items: center; justify-content: center; pointer-events: none; }
.stamp.on { display: flex; }
.stamp .val {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(72px, 19vw, 240px); letter-spacing: -0.03em; line-height: 1;
  color: var(--ac);
  transform: rotate(-8deg) scale(1.6); opacity: 0;
  text-shadow: 0 0 60px color-mix(in srgb, var(--ac) 45%, transparent);
}
.stamp.on .val { animation: slam 480ms var(--ease) forwards; }
/* score grading: 90%+ green, 80-90% yellow, below 80% red (beats theme colors) */
.stamp.g-green .val  { color: #4dff8a !important; text-shadow: 0 0 60px rgba(77,255,138,0.45) !important; }
.stamp.g-yellow .val { color: #ffd84d !important; text-shadow: 0 0 60px rgba(255,216,77,0.45) !important; }
.stamp.g-red .val    { color: #ff5a4d !important; text-shadow: 0 0 60px rgba(255,90,77,0.45) !important; }
@keyframes slam {
  0% { transform: rotate(-8deg) scale(1.6); opacity: 0; }
  60% { transform: rotate(-8deg) scale(0.96); opacity: 1; }
  100% { transform: rotate(-8deg) scale(1); opacity: 1; }
}

/* ---------- end ---------- */
#end { align-items: center; justify-content: center; gap: clamp(12px, 2.4vh, 24px); text-align: center; padding: 20px; }
.end-label { font-family: var(--display); font-weight: 600; font-size: clamp(14px, 2.2vw, 18px); letter-spacing: 0.3em; text-transform: uppercase; opacity: 0.6; }
.end-score { font-family: var(--display); font-weight: 700; font-size: clamp(80px, 20vw, 230px); line-height: 0.9; letter-spacing: -0.03em; }
.end-time { font-variant-numeric: tabular-nums; font-size: clamp(15px, 2.4vw, 20px); opacity: 0.65; }
.bars { display: flex; gap: 10px; align-items: flex-end; height: 90px; }
.bars .bar { width: clamp(30px, 7vw, 52px); background: var(--ink); border-radius: 4px 4px 0 0; transform: scaleY(0); transform-origin: bottom; animation: grow 600ms var(--ease) forwards; }
.bars .bar.good { background: var(--good); } .bars .bar.mid { background: var(--mid); } .bars .bar.bad { background: var(--bad); }
@keyframes grow { to { transform: scaleY(1); } }
.bars .bar .pct { font-family: var(--display); font-weight: 600; font-size: 11px; letter-spacing: 0.02em; position: relative; top: -20px; display: block; text-align: center; color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .grain, .flap .colon { animation: none !important; }
  .rise { animation-duration: 1ms; }
  * { transition-duration: 1ms !important; }
}
