/* Self-hosted fonts (SIL Open Font License, see assets/fonts/OFL.txt) */
@font-face { font-family: "Cinzel"; font-weight: 900; font-display: swap; src: url(assets/fonts/cinzel-900-latin.4b6ed4773d.woff2) format("woff2"); }
@font-face { font-family: "IM Fell English SC"; font-weight: 400; font-display: swap; src: url(assets/fonts/im-fell-english-sc-latin.f0f85c4edd.woff2) format("woff2"); }

:root {
  /* warm candlelit tones to sit in the music room (they used to be navy) */
  --bg: #2b1e1a;
  --panel: rgba(66, 46, 40, .9);
  --edge: rgba(217, 178, 90, .32);
  --text: #f4ecdc;
  --muted: #c4b29b;
  --well: rgba(0, 0, 0, .28);      /* recessed bits: bars, key caps, buttons */
  --board: #2a201d;
  /* gilding, matched to the letter on the celebration banner */
  --gold0: #fff4c8;
  --gold1: #f0c860;
  --gold2: #c8862c;
  --gold3: #7a4a14;
}
* { box-sizing: border-box; }
html { height: 100%; background: var(--bg); }
body {
  margin: 0; height: 100%;
  /* Panini's painting of a concert at the Teatro Argentina, Rome, 1747 (public domain), lightly
     dimmed so the game stays readable, a little more behind the board than at the edges */
  background:
    radial-gradient(ellipse 34% 70% at 50% 55%, rgba(24,15,12,.45), rgba(24,15,12,0)),
    linear-gradient(rgba(24,15,12,.18), rgba(24,15,12,.18)),
    url(assets/teatro-argentina-1747.aeaa12506e.webp) center 75% / cover no-repeat,
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
#stage { height: 100%; will-change: transform; }
#topbar { position: relative; height: 56px; display: flex; align-items: flex-end; justify-content: center; }
#timer { font: 700 30px ui-monospace, "SF Mono", Menlo, monospace;
         font-variant-numeric: tabular-nums; letter-spacing: .06em; color: var(--text); text-shadow: 0 0 18px rgba(255,190,110,.45); }
#app { display: flex; gap: 20px; justify-content: center; align-items: center; height: calc(100% - 56px); padding: 12px 16px 16px; }
.side { display: flex; flex-direction: column; gap: 12px; width: 180px; }
.box { background: var(--panel); border: 1px solid var(--edge); border-radius: 10px; padding: 10px 12px; }
.label { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
canvas { display: block; }
#boardWrap { position: relative; --frame: 14px; }
/* A gilt picture frame, like the ones in the painting: banded gold moulding, a highlight on the
   outer edge, a rosette in each corner, and a dark bronze liner against the board. */
#boardWrap::before {
  content: ""; position: absolute; inset: calc(-1 * var(--frame)); border-radius: 5px; pointer-events: none;
  background:
    radial-gradient(circle at 7px 7px, #fff6cf 0 2px, #b07a2a 3px, #5a3510 4.5px, transparent 5.5px),
    radial-gradient(circle at calc(100% - 7px) 7px, #fff6cf 0 2px, #b07a2a 3px, #5a3510 4.5px, transparent 5.5px),
    radial-gradient(circle at 7px calc(100% - 7px), #fff6cf 0 2px, #b07a2a 3px, #5a3510 4.5px, transparent 5.5px),
    radial-gradient(circle at calc(100% - 7px) calc(100% - 7px), #fff6cf 0 2px, #b07a2a 3px, #5a3510 4.5px, transparent 5.5px),
    linear-gradient(135deg, #fff0b4 0%, #d8a443 14%, #8a5a1c 28%, #f4d27a 44%, #a86e22 58%, #f0c860 72%, #7a4a14 88%, #e3b04e 100%);
  box-shadow: 0 22px 60px rgba(0,0,0,.6), 0 0 0 1px rgba(40,22,6,.8),
              inset 0 0 0 1.5px rgba(255,243,200,.75), inset 0 0 0 3px rgba(110,67,16,.55), inset 0 0 8px 2px rgba(60,30,0,.45);
}
.nowplaying #nowPiece { font: italic 13px/1.35 Georgia, "Times New Roman", serif; color: var(--text); margin-top: 6px; }
.nowplaying #nowComposer { font-size: 11px; opacity: .6; margin-top: 3px; }
#board { position: relative; z-index: 1; border-radius: 3px; background: var(--board); box-shadow: 0 0 0 3px #3e2408, inset 0 0 0 1px rgba(0,0,0,.4); }
/* Board outline and danger glow live on their own layers: the big blurred shadows are painted once,
   and only opacity/transform change per frame, which the compositor handles without repainting. */
.glow { position: absolute; inset: 0; border-radius: 3px; pointer-events: none; }
#glowBase { box-shadow: 0 0 0 5px var(--edge); }
.glow.danger { opacity: 0; will-change: opacity, transform; }
#glowFar  { box-shadow: 0 0 200px 46px rgba(255,20,30,.55); }
#glowNear { box-shadow: 0 0 44px 12px rgba(255,45,45,.85); }
#glowRing { box-shadow: 0 0 0 3.5px hsl(0,95%,72%); }

.gilt-text {
  background: linear-gradient(120deg, var(--gold2), var(--gold1), var(--gold0), var(--gold1), var(--gold2));
  background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: flow 4s linear infinite;
}
@keyframes flow { to { background-position: 300% 0; } }
@keyframes pulse { 50% { opacity: .55; } }

#stageLetter { font-size: 72px; font-weight: 900; line-height: 1; text-align: center; font-family: Cinzel, "Times New Roman", serif;
               filter: drop-shadow(0 2px 0 rgba(0,0,0,.55)) drop-shadow(0 0 12px rgba(240,190,90,.4)); }
#goal { font-size: 13px; color: var(--muted); text-align: center; margin-top: 6px; min-height: 34px; }
#goal b { color: var(--text); }
.bar { height: 6px; background: var(--well); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold2), var(--gold1)); transition: width .2s; }

#alpha { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
#alpha span { font-size: 12px; text-align: center; padding: 3px 0; border-radius: 4px; background: var(--well); color: #a08c75; font-weight: 700; }
#alpha span.done { background: linear-gradient(160deg, var(--gold0), var(--gold1) 45%, var(--gold2)); color: #3a2208; }
#alpha span.cur { box-shadow: inset 0 0 0 1.5px var(--gold1); color: var(--gold0); animation: pulse 1.2s infinite; }

.keys { font-size: 12px; color: var(--muted); line-height: 1.7; }
.keys kbd { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 4px; background: var(--well); border: 1px solid var(--edge); color: var(--text); font: 11px ui-monospace, monospace; text-align: center; }

.overlay { position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
           background: rgba(38,26,22,.86); border-radius: 3px; text-align: center; padding: 24px; }
.overlay.hidden { display: none; }
.overlay.solid { background: var(--bg); }            /* pause hides the board so it can't be studied for free */
.paused #next { visibility: hidden; }
.overlay h1 { margin: 0; font: 900 44px/1.1 Cinzel, "Times New Roman", serif; letter-spacing: .04em; filter: drop-shadow(0 2px 0 rgba(0,0,0,.5)); }
.overlay h2 { margin: 0; font-size: 28px; }
.overlay p { margin: 0; color: var(--muted); max-width: 320px; line-height: 1.5; font-size: 14px; }
.opts { display: flex; gap: 12px; }
.opts label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
select, button { font: inherit; background: var(--well); color: var(--text); border: 1px solid var(--edge); border-radius: 6px; padding: 6px 10px; }
button { cursor: pointer; padding: 8px 20px; font-weight: 700; color: #2e1a06; border: 0;
         background: linear-gradient(180deg, var(--gold0), var(--gold1) 45%, var(--gold2)); box-shadow: inset 0 -2px 0 rgba(90,50,10,.45), 0 2px 6px rgba(0,0,0,.35); }

.record { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 18px; border-radius: 10px;
          background: rgba(255,255,255,.04); border: 1px solid var(--edge); }
.record .label { margin: 0; }
.record div { font-size: 20px; font-variant-numeric: tabular-nums; }
.record div b.gilt-text { font-size: 30px; font-weight: 900; vertical-align: -3px; }
.record .sub { font-size: 11px; color: var(--muted); }
/* ---- Letter-complete celebration: a medieval heraldic banner ---- */
.fest { position: fixed; inset: 0; z-index: 50; pointer-events: none; display: flex; justify-content: center; align-items: flex-start; }
.fest.hidden { display: none; }
.fest-backdrop { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 40%, rgba(40,10,0,.25), rgba(0,0,0,.65)); opacity: 0; }
.fest.show .fest-backdrop { animation: festFade .4s ease-out forwards; }
.fest.out .fest-backdrop { animation: festFadeOut .45s ease-in forwards; }
#festCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.fest-inner { position: relative; margin-top: 120px; width: min(390px, 84vw); transform: translateY(-140%); }
.fest.show .fest-inner { animation: festDrop .6s cubic-bezier(.2,1.35,.45,1) forwards; }
.fest.out .fest-inner { animation: festLift .45s cubic-bezier(.5,0,.8,.3) forwards; }
.fest-ropes { position: absolute; left: 0; right: 0; bottom: calc(100% - 4px); height: 48px; width: 100%; overflow: visible; }
.fest-pole { position: relative; z-index: 2; height: 18px; width: 120%; margin-left: -10%; border-radius: 9px;
             background: linear-gradient(#a8743d, #6b4019 55%, #3d230b); box-shadow: 0 4px 10px rgba(0,0,0,.5), inset 0 2px 0 rgba(255,220,170,.35); }
.fest-finial { position: absolute; top: -6px; width: 30px; height: 30px; border-radius: 50%;
               background: radial-gradient(circle at 35% 30%, var(--m0), var(--m-flat) 35%, var(--m2) 75%, var(--m-shadow)); box-shadow: 0 3px 8px rgba(0,0,0,.5); }
.fest-finial.l { left: -16px; } .fest-finial.r { right: -16px; }
.fest-sway { transform-origin: 50% 0; filter: drop-shadow(0 22px 30px rgba(0,0,0,.6)); }
.fest.show .fest-sway { animation: festSway 2.6s .9s ease-in-out infinite; }
.fest-cloth { position: relative; margin: -8px 5% 0; height: min(460px, 60vh); transform-origin: 50% 0; transform: scaleY(0); }
.fest.show .fest-cloth { animation: festUnfurl .75s .3s cubic-bezier(.25,1.4,.5,1) forwards; }
.fest-cloth svg.bg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.fest-tassel { position: absolute; width: 14px; height: 34px; margin-left: -7px; margin-top: -2px; transform-origin: 50% 0;
               background: linear-gradient(90deg, var(--m2), var(--m1) 45%, var(--m4)); border-radius: 40% 40% 30% 30% / 25% 25% 75% 75%; }
.fest-tassel::before { content: ""; position: absolute; left: 3px; top: -6px; width: 8px; height: 8px; border-radius: 50%; background: var(--m-flat); }
.fest.show .fest-tassel { animation: festSwing 1.3s 1s ease-in-out infinite alternate; }
.fest-content { position: relative; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 40px 22px 0; text-align: center; }
.fest-frame { position: relative; width: 56%; aspect-ratio: 1; display: grid; place-items: center; border-radius: 6px;
              background: radial-gradient(circle at 50% 40%, var(--p1), var(--p2) 70%, var(--p3));
              box-shadow: 0 0 0 3px var(--m-flat), 0 0 0 7px var(--cloth-dark), 0 0 0 9px var(--m-flat), 0 12px 26px rgba(0,0,0,.55), inset 0 0 30px rgba(0,0,0,.5); }
.fest-frame::before, .fest-frame::after { content: var(--orn); position: absolute; color: var(--m-flat); font-size: 20px; line-height: 1; }
.fest-frame::before { top: 6px; left: 8px; } .fest-frame::after { bottom: 6px; right: 8px; transform: rotate(180deg); }
.fest-letter { font: 900 clamp(90px, 20vw, 150px)/1 Cinzel, "Times New Roman", serif; transform: scale(0);
               background: linear-gradient(180deg, var(--l0) 0%, var(--l1) 35%, var(--l2) 58%, var(--l3) 78%, var(--l4) 100%);
               -webkit-background-clip: text; background-clip: text; color: transparent;
               filter: drop-shadow(0 3px 0 var(--m-shadow)) drop-shadow(0 0 14px var(--m-glow)); }
.fest.show .fest-letter { animation: festPop .6s .85s cubic-bezier(.2,1.6,.4,1) forwards, festGlow 1.4s 1.5s ease-in-out infinite; }
.fest-caption { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 20px 9px; border-radius: 5px; opacity: 0;
                background: linear-gradient(rgba(12,8,6,.72), rgba(12,8,6,.55)); box-shadow: 0 0 0 1px var(--m-flat), 0 0 0 3px rgba(0,0,0,.35), 0 6px 14px rgba(0,0,0,.4); }
.fest-title { font: 28px "IM Fell English SC", Georgia, serif; color: #fbf3e2; text-shadow: 0 2px 0 rgba(0,0,0,.6); }
.fest-time { font: 700 18px ui-monospace, Menlo, monospace; color: var(--m1); letter-spacing: .08em; }
.fest.show .fest-caption { animation: festFade .4s 1.15s forwards; }
.fest-skip { position: absolute; left: 0; right: 0; bottom: 3vh; text-align: center; font-size: 12px; color: rgba(255,255,255,.45); }
/* ---- The results banner (game over / whole alphabet): the same banner, bigger type, with buttons ---- */
.fest:not(.ending) .fest-end, .fest.ending .fest-cele, .fest.ending .fest-skip { display: none; }
.fest.ending { pointer-events: auto; overflow-y: auto; overscroll-behavior: contain; }
.fest-end { margin: 64px 0 48px; width: min(470px, 92vw); }
.fest-end .fest-cloth { height: auto; margin-top: -8px; }
.end-content { height: auto; gap: 14px; padding: 34px 26px 96px; }
.end-title { font: 52px/1 "IM Fell English SC", Georgia, serif; color: #fbf3e2; text-shadow: 0 3px 0 rgba(0,0,0,.55), 0 0 18px rgba(0,0,0,.4); }
.fest.won .end-title { background: linear-gradient(180deg, var(--l0), var(--l1) 40%, var(--l2) 62%, var(--l3) 82%, var(--l4));
                       -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none;
                       filter: drop-shadow(0 3px 0 var(--m-shadow)) drop-shadow(0 0 16px var(--m-glow)); }
.end-frame { width: 44%; }
.end-frame .fest-letter { font-size: clamp(76px, 18vw, 124px); }
.end-frame .fest-letter.az { font-size: clamp(40px, 9vw, 64px); white-space: nowrap; letter-spacing: -.02em; }
.end-line { font: 22px "IM Fell English SC", Georgia, serif; color: #fbf3e2; }
.end-line b { color: var(--m1); }
.end-caption .fest-time { font-size: 28px; }
.end-cmp { display: flex; flex-direction: column; align-items: center; gap: 4px; max-width: 390px; padding: 12px 22px 10px; border-radius: 6px;
           background: linear-gradient(rgba(12,8,6,.78), rgba(12,8,6,.6));
           box-shadow: 0 0 0 1.5px var(--m-flat), 0 0 0 4px rgba(0,0,0,.35), 0 0 0 5px var(--m2), 0 8px 18px rgba(0,0,0,.45); }
.cmp-lead { font: 600 19px/1.25 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; text-wrap: balance; color: #fbf3e2; text-shadow: 0 2px 0 rgba(0,0,0,.6); }
.rec { display: flex; align-items: baseline; gap: 10px; }
.rec::before, .rec::after { content: var(--orn); color: var(--m-flat); font-size: 16px; opacity: .85; align-self: center; }
.rec::after { transform: scaleX(-1); }
.rec-letter { font: 800 38px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
              background: linear-gradient(180deg, var(--l0), var(--l1) 38%, var(--l2) 60%, var(--l3) 80%, var(--l4));
              -webkit-background-clip: text; background-clip: text; color: transparent;
              filter: drop-shadow(0 2px 0 var(--m-shadow)) drop-shadow(0 0 10px var(--m-glow)); }
.rec-in { font: 600 18px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: rgba(251,243,226,.75); }
.rec-time { font: 700 28px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; color: var(--m1); text-shadow: 0 2px 0 rgba(0,0,0,.6); }
.rec-note { font: 600 18px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: rgba(251,243,226,.85); }
.end-content .endstrip { width: 100%; gap: 4px; padding: 8px; border-radius: 6px; background: rgba(12,8,6,.5); }
.end-content .endstrip span { font-size: 16px; line-height: 28px; background: rgba(0,0,0,.4); color: #b5a088; }
.end-content .endstrip span.done { background: linear-gradient(160deg, var(--gold0), var(--gold1) 45%, var(--gold2)); color: #3a2208; }
.end-content .endstrip span.miss { box-shadow: inset 0 0 0 2px #ff6a3d; color: #ffcbb5; background: rgba(120,20,0,.45); }
.end-content .endstrip span.pb::after { width: 6px; height: 6px; margin-left: -3px; bottom: -8px; }
.end-buttons { margin-top: 4px; }
.end-buttons button { font-size: 20px; padding: 12px 28px; border-radius: 8px; }
.end-buttons button.ghost { background: rgba(12,8,6,.6); border-color: var(--m-flat); }
.end-newbest { font: 800 18px system-ui, sans-serif; letter-spacing: .2em; text-transform: uppercase; color: #2e1a06; padding: 6px 18px; border-radius: 4px;
               background: linear-gradient(180deg, var(--gold0), var(--gold1) 50%, var(--gold2)); box-shadow: 0 3px 10px rgba(0,0,0,.45);
               transform: rotate(-3deg); animation: newbestPulse 1.2s ease-in-out infinite; }
@keyframes newbestPulse { 50% { transform: rotate(-3deg) scale(1.07); } }
.fest.show .end-cmp, .fest.show .end-content .endstrip, .fest.show .end-buttons { opacity: 0; animation: festFade .4s 1.35s forwards; }
/* game over: the banner drops in, then a rope gives way and it sags, crooked */
.fest.lost .fest-backdrop { background: radial-gradient(ellipse at 50% 40%, rgba(20,6,0,.45), rgba(0,0,0,.8)); }
.fest.show.lost .fest-end .fest-sway { transform-origin: 7% 0; animation: endDroop 1s 1.2s cubic-bezier(.3,1.8,.5,1) forwards, endSag 3.2s 2.2s ease-in-out infinite; }
@keyframes endDroop { from { transform: rotate(0); } to { transform: rotate(6deg); } }
@keyframes endSag { 0%, 100% { transform: rotate(6deg); } 50% { transform: rotate(7.6deg); } }
.fest.show.lost .end-frame .fest-letter { animation: endThud .75s .8s cubic-bezier(.4,0,.6,1) forwards; }
@keyframes endThud { 0% { transform: translateY(-90px) rotate(-8deg); opacity: 0; } 55% { transform: translateY(0) scale(1.12, .86) rotate(4deg); opacity: 1; }
                     75% { transform: scale(.95, 1.06) rotate(-2deg); } 100% { transform: rotate(3deg); opacity: 1; } }
@media (max-width: 520px) {        /* narrow screens: a gentler sag, so the banner stays on screen */
  .fest.show.lost .fest-end .fest-sway { animation-name: endDroopSmall, endSagSmall; }
  .end-title { font-size: 44px; }
}
@keyframes endDroopSmall { from { transform: rotate(0); } to { transform: rotate(3deg); } }
@keyframes endSagSmall { 0%, 100% { transform: rotate(3deg); } 50% { transform: rotate(4deg); } }
@media (max-height: 760px) {
  .fest-end { margin-top: 44px; }
  .end-content { gap: 10px; padding-top: 26px; }
  .end-title { font-size: 42px; }
  .end-frame { width: 32%; }
}
@keyframes festFade { to { opacity: 1; } }
@keyframes festFadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes festDrop { from { transform: translateY(-140%); } to { transform: translateY(0); } }
@keyframes festLift { from { transform: translateY(0); } to { transform: translateY(-150%); } }
@keyframes festUnfurl { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes festSway { 0%,100% { transform: rotate(-1.2deg) skewX(.8deg); } 50% { transform: rotate(1.2deg) skewX(-.8deg); } }
@keyframes festSwing { from { transform: rotate(-12deg); } to { transform: rotate(12deg); } }
@keyframes festPop { from { transform: scale(0) rotate(-12deg); } to { transform: scale(1) rotate(0); } }
@keyframes festGlow { 50% { filter: drop-shadow(0 3px 0 var(--m-shadow)) drop-shadow(0 0 26px var(--m-glow-hi)); } }

/* ---- Small pieces of UI ---- */
.dim { opacity: .6; }
#speedBar { background: linear-gradient(90deg,#e9c46a,#e07a5f); }
.statsbox { display: flex; gap: 12px; }
.statsbox .stat { flex: 1; }
.statsbox .stat.wide { flex: 1.4; }
#best { white-space: nowrap; font-size: 18px; line-height: 30px; }
.overlay .hint { font-size: 12px; }
.overlay .credit { font-size: 11px; opacity: .55; }
.overlay .version { margin-top: 2px; }
/* results card: comparison with the record, and the run on an A-Z strip */
.overlay p.cmp { font-size: 13px; max-width: 300px; }
.overlay p.cmp b { color: var(--gold1); }
.endstrip { display: grid; grid-template-columns: repeat(13, 1fr); gap: 3px; width: min(300px, 100%); }
.endstrip span { position: relative; font: 700 11px/20px system-ui, sans-serif; text-align: center; border-radius: 4px; background: var(--well); color: #8a7763; }
.endstrip span.done { background: linear-gradient(160deg, var(--gold0), var(--gold1) 45%, var(--gold2)); color: #3a2208; }
.endstrip span.miss { box-shadow: inset 0 0 0 1.5px #e2582f; color: #ffb59c; }
.endstrip span.pb::after { content: ""; position: absolute; left: 50%; bottom: -5px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--gold1); }   /* your record */
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
button.ghost { background: var(--well); color: var(--text); border: 1px solid var(--edge); box-shadow: none; font-weight: 600; padding: 7px 14px; }
.newbest { font: 800 14px system-ui, sans-serif; letter-spacing: .18em; text-transform: uppercase; color: #1a1205;
           padding: 4px 12px; border-radius: 999px; background: linear-gradient(135deg, #ffe08a, #f0b53a); box-shadow: 0 0 18px rgba(255,200,90,.5); }
.version { font: 10px ui-monospace, Menlo, monospace; color: var(--muted); opacity: .6; margin-top: 6px; }
/* Slow time stopwatch, beside the clock */
.slowwatch { position: absolute; left: calc(50% + 84px); bottom: 0; width: 36px; height: 40px; pointer-events: none;
             opacity: 0; transform: scale(.4); transition: opacity .25s, transform .4s cubic-bezier(.2,1.6,.4,1);
             filter: drop-shadow(0 0 8px rgba(120,200,255,.75)); }
.slowwatch svg { width: 100%; height: 100%; display: block; }
.slowwatch.on { opacity: 1; transform: scale(1); }
.slowwatch.on.ending { animation: swBlink .5s steps(2, jump-none) infinite; }
@keyframes swBlink { 50% { opacity: .35; } }
.sw-case { fill: #1b2a44; stroke: #a8dcff; stroke-width: 2.5; }
.sw-face { fill: #0d1626; }
.sw-wedge { fill: #7cc8ff; }
.sw-ticks { stroke: #a8dcff; stroke-width: 1.6; stroke-linecap: round; }
.sw-hand { stroke: #fff; stroke-width: 2; stroke-linecap: round; }
.sw-metal { fill: #a8dcff; }
.sw-pin { fill: #fff; }
#timer { transition: color .3s, text-shadow .3s; }
#timer.slowed { color: #a8dcff; text-shadow: 0 0 18px rgba(120,200,255,.65); }
.touch .slowwatch { width: 26px; height: 29px; left: calc(50% + 60px); bottom: auto; top: calc(6px + env(safe-area-inset-top)); }
.tbtn { position: absolute; right: 10px; bottom: 4px; width: 40px; height: 32px; padding: 0; border-radius: 8px;
        background: rgba(48,33,28,.8); border: 1px solid var(--edge); font-size: 13px; color: var(--text); }
html:not(.touch) .touch-only { display: none !important; }
.touch .kbd-only { display: none !important; }

/* ---- Phones and tablets: compact HUD, board in the middle, thumb controls ---- */
.touch body { touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.touch #topbar { height: auto; min-height: 40px; padding-top: env(safe-area-inset-top); align-items: center; }
.touch #timer { font-size: 22px; }
.touch .tbtn { bottom: auto; top: calc(4px + env(safe-area-inset-top)); }
.touch #app { display: grid; height: calc(100% - 40px - env(safe-area-inset-top)); gap: 8px;
              padding: 4px 8px calc(8px + env(safe-area-inset-bottom));
              grid-template-columns: 84px minmax(0, 1fr) auto; grid-template-rows: auto auto 1fr auto;
              grid-template-areas: "strip strip strip" "best letter next" "board board board" "padL . padR";
              align-items: center; justify-items: center; }
.touch.landscape #app { grid-template-columns: 1fr auto 1fr; grid-template-rows: auto auto auto 1fr;
                        grid-template-areas: "letter board next" "best board ." "strip board ." "padL board padR"; }
.touch .side { display: contents; }
.touch .alphabox, .touch .nowplaying, .touch .statsbox, .touch .speedbox, .touch .keys { display: none; }
/* phones: best time in the spare corner, and the alphabet as a thin strip */
.touch .bestmini { grid-area: best; justify-self: stretch; align-self: stretch; text-align: center; display: flex; flex-direction: column; justify-content: center; }
.touch.landscape .bestmini { justify-self: center; width: 150px; align-self: start; }
#bestMini { font: 700 12px ui-monospace, "SF Mono", Menlo, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#miniAlpha { grid-area: strip; display: grid; grid-template-columns: repeat(26, 1fr); gap: 2px; width: 100%; max-width: 520px; }
.touch.landscape #miniAlpha { grid-template-columns: repeat(13, 1fr); width: 150px; align-self: start; }
#miniAlpha span { font: 700 9px/14px system-ui, sans-serif; text-align: center; border-radius: 3px; background: rgba(30,20,16,.72); color: #a08c75; }
#miniAlpha span.done { background: linear-gradient(160deg, var(--gold0), var(--gold1) 45%, var(--gold2)); color: #3a2208; }
#miniAlpha span.cur { box-shadow: inset 0 0 0 1px var(--gold1); color: var(--gold0); background: rgba(30,20,16,.85); }
/* tablets: the full side panels come back beside the board */
.touch.roomy #app { grid-template-columns: 1fr auto 1fr; grid-template-rows: auto auto auto 1fr; align-items: start; gap: 12px 20px;
                    grid-template-areas: "letter board next" "alpha board stats" "now board speed" "padL board padR"; }
.touch.roomy .bestmini, .touch.roomy #miniAlpha { display: none; }
.touch.roomy .alphabox, .touch.roomy .nowplaying, .touch.roomy .statsbox, .touch.roomy .speedbox { display: block; width: 180px; }
.touch.roomy .alphabox { grid-area: alpha; } .touch.roomy .nowplaying { grid-area: now; }
.touch.roomy .statsbox { grid-area: stats; display: flex; } .touch.roomy .speedbox { grid-area: speed; }
.touch.roomy .letterbox, .touch.roomy.landscape .letterbox { width: 180px; max-width: none; }
.touch.roomy .letterbox .label { display: block; }
.touch.roomy .nextbox { justify-self: center; }
.touch.roomy #stageLetter { font-size: 56px; }
.touch.roomy #goal { font-size: 13px; white-space: normal; }
.touch.roomy .label { font-size: 10px; }
.touch.roomy .padL, .touch.roomy .padR { align-self: end; }
/* portrait tablets: panels above and below the board, so the board can use the full width */
.touch.roomy:not(.landscape) #app { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: auto 1fr auto auto auto; align-items: start;
  grid-template-areas: "letter alpha next" "board board board" "padL stats padR" "padL speed padR" "padL now padR"; }
.touch.roomy:not(.landscape) .alphabox, .touch.roomy:not(.landscape) .statsbox, .touch.roomy:not(.landscape) .speedbox,
.touch.roomy:not(.landscape) .nowplaying { justify-self: center; width: 220px; }
.touch.roomy:not(.landscape) .letterbox, .touch.roomy:not(.landscape) .nextbox { justify-self: center; }
.touch.roomy:not(.landscape) .padL, .touch.roomy:not(.landscape) .padR { align-self: center; justify-self: center; }
.touch .box { padding: 6px 8px; border-radius: 8px; }
.touch .label { font-size: 9px; margin-bottom: 3px; }
.touch .nextbox { grid-area: next; }
.touch .letterbox { grid-area: letter; width: 100%; max-width: 170px; min-width: 0; text-align: center; }
.touch .nextbox { justify-self: stretch; }
.touch.landscape .nextbox { justify-self: center; }
.touch .nextbox canvas { margin: 0 auto; }
.touch.landscape .letterbox { width: 150px; }
.touch .letterbox .label { display: none; }
.touch #stageLetter { font-size: 30px; }
.touch #goal { font-size: 11px; min-height: 0; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.touch .bar { margin-top: 4px; }
.touch #boardWrap { grid-area: board; touch-action: none; margin: var(--frame); }   /* room for the gilt frame */
.touch .padL { grid-area: padL; justify-self: start; }
.touch .padR { grid-area: padR; justify-self: end; }
.touch.landscape .padL, .touch.landscape .padR { justify-self: center; }
.touch.landscape .padL, .touch.landscape .padR { align-self: end; }
.pad { display: grid; gap: 10px; grid-template-columns: repeat(2, var(--btn)); touch-action: none; --btn: 62px; }
@media (max-width: 380px) { .pad { --btn: 54px; gap: 8px; } }
.pad button { height: var(--btn); padding: 0; border-radius: 16px; font: 600 24px system-ui, sans-serif; color: var(--text);
              background: rgba(48,33,28,.8); border: 1px solid var(--edge); touch-action: none; -webkit-tap-highlight-color: transparent; }
.pad button.on { background: rgba(200,134,44,.55); border-color: var(--gold1); }
.pad button.wide { grid-column: span 2; height: 50px; }
.pad button.small { font-size: 12px; font-weight: 800; letter-spacing: .1em; }
.touch .overlay { position: fixed; inset: 0; z-index: 40; border-radius: 0; overflow-y: auto;
                  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom)); }
.touch .overlay h1 { font-size: 38px; }

/* ---- Reduced motion: no looping decoration (the game itself also drops shake and softens flashes) ---- */
@media (prefers-reduced-motion: reduce) {
  .gilt-text, #alpha span.cur, .slowwatch.on.ending { animation: none; }
  .fest.show .fest-sway, .fest.show .fest-tassel { animation: none; }
  .fest.show.lost .fest-end .fest-sway { animation: none; transform: rotate(6deg); transform-origin: 7% 0; }
  .end-newbest { animation: none; }
  .fest.show .fest-letter { animation: festPop .6s .85s cubic-bezier(.2,1.6,.4,1) forwards; }
}

/* the not-found page (404.html) */
.notfound { display: grid; place-items: center; overflow: auto; }
.notfound-card { background: var(--panel); border: 1px solid var(--edge); border-radius: 12px; padding: 28px 36px; text-align: center; margin: 16px; }
.notfound-card h1 { margin: 0 0 8px; font: 900 34px Cinzel, "Times New Roman", serif; color: #f0c860; }
.notfound-card p { margin: 6px 0; color: var(--muted); }
.notfound-card a { color: #f0c860; font-weight: 700; }
