/* ==========================================================================
   The Wind-Up Parade — stylesheet

   Type: Fraunces (display) + Nunito (UI), both self-hosted woff2 subsets so
   every device on the LAN gets the same typography. Fallback stacks are
   deliberately chosen for tone, not just metrics: Georgia and Trebuchet keep
   the friendly, printed-poster feel if a font fails to load.
   ========================================================================== */

@font-face {
  font-family: 'Fraunces';
  src: url('fonts/fraunces.woff2') format('woff2');
  font-weight: 600 900;
  font-style: normal;
  font-display: swap;
  font-optical-sizing: auto;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Nunito';
  src: url('fonts/nunito.woff2') format('woff2');
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --ink: #2b4038;
  --cream: #fff2d0;
  --paper: #f6e5bd;
  --paper-2: #e7d0a1;
  --teal: #25453c;
  --teal-deep: #193732;
  --gold: #ffcf69;
  --gold-deep: #f4ad42;
  --gold-shadow: #a37238;
  --aqua: #a7d4bc;
  --radius: 19px;
  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --ui: 'Nunito', 'Trebuchet MS', ui-rounded, system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--teal-deep);
}

body {
  margin: 0;
  min-height: 100svh;
  font: 400 16px/1.5 var(--ui);
  color: var(--cream);
  background: var(--teal-deep);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main {
  width: min(1080px, 95vw);
  min-height: 100svh;
  margin: 0 auto;
  padding: clamp(9px, 2.3vh, 28px) 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.deck, .pads, .hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* --- panels ------------------------------------------------------------ */

.box {
  border: 4px solid #203630;
  border-radius: var(--radius);
  box-shadow: 0 5px 0 #152f29, 0 18px 32px #0e211f45;
  overflow: hidden;
  background: var(--paper);
  color: #293d32;
}

.theatre {
  position: relative;
  isolation: isolate;
  /* the canvas paints the whole scene; no hidden marquee image underneath */
  background: #7bb7a9;
}

.theatre canvas { width: 100%; display: block; }

/* sound control sits inside the frame, not floating above it */
.audio-fab {
  position: absolute;
  top: clamp(8px, 1.4vw, 16px);
  right: clamp(8px, 1.4vw, 16px);
  z-index: 3;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #213d35d9;
  color: #fff1ce;
  border: 1px solid #d6c79a66;
  box-shadow: 0 2px 0 #142b26aa;
  font-size: 16px;
  line-height: 1;
}

/* --- title playbill ---------------------------------------------------- */

.bill {
  position: absolute;
  top: 11%;
  left: 4%;
  width: 45%;
  text-align: center;
  padding: 3.4% 2.4% 2.6%;
  border: 5px solid #d29855;
  outline: 2px solid #734c34;
  border-radius: 48% 48% 12% 12% / 18% 18% 7% 7%;
  background: radial-gradient(at 42% 20%, #2d7667, #234c43);
  box-shadow: inset 0 0 0 3px #f3c783, 0 7px 0 #674931, 0 13px 18px #374d313c;
  color: #ffdf97;
  transform: rotate(-2deg);
}

.bill .cast {
  margin: 0 0 8px;
  color: #ffda83;
  font-weight: 900;
  font-size: clamp(9px, 1vw, 12px);
  letter-spacing: 0.2em;
  text-shadow: 0 1px #b77f42, 0 2px #674a32;
}

.bill h1 { margin: 0; font-family: var(--display); }

.bill .clay-title {
  display: block;
  width: 94%;
  height: auto;
  margin: 2% auto 0;
  filter: drop-shadow(1px 3px 1px #153d38c9);
}

.bill .kicker {
  margin: 2.5% 0 0;
  font-size: clamp(10px, 1.1vw, 13px);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #ffe6ad;
  opacity: 0.82;
  text-transform: uppercase;
}

.bill .best {
  margin: 6px 0 0;
  font-size: 11px;
  color: #ffeab4;
  opacity: 0.72;
  font-variant-numeric: tabular-nums;
}

/* --- difficulty switch ------------------------------------------------- */

.diff {
  display: flex;
  gap: 5px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 8px 0 0;
}

.diff button {
  font: 700 12px/1 var(--ui);
  padding: 6px 11px;
  border-radius: 9px;
  background: #20453c66;
  color: #fff1cc;
  border: 1px solid #d6c79a55;
  letter-spacing: 0.02em;
}

.diff button[aria-pressed="true"] {
  background: linear-gradient(var(--gold), var(--gold-deep));
  color: #41381f;
  border-color: var(--gold-shadow);
  box-shadow: 0 2px 0 var(--gold-shadow);
}

.choices {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 7%;
}

.bill .quiet { color: #fff1cc; border-color: #d6c79a77; }

/* --- buttons ----------------------------------------------------------- */

button {
  font: 700 15px/1.2 var(--ui);
  color: inherit;
  border: 1px solid #84775b;
  cursor: pointer;
  background: #ffefce;
  border-radius: 10px;
  padding: 10px 15px;
  touch-action: manipulation;
  transition: transform .08s ease, filter .15s ease;
}

button:focus-visible { outline: 3px solid #ff942b; outline-offset: 2px; }
button:active { transform: translateY(2px); }
button:disabled { opacity: .55; cursor: default; }

.gold, .aqua {
  background: linear-gradient(var(--gold), var(--gold-deep));
  color: #41381f;
  box-shadow: 0 3px 0 var(--gold-shadow);
}

.aqua {
  background: linear-gradient(var(--aqua), #81bba8);
  box-shadow: 0 3px 0 #638575;
  color: #203f37;
}

.duckpad { background: #e8c2a0; box-shadow: 0 3px 0 #966e52; }
.quiet { background: transparent; }

kbd {
  font: 600 11px/1 var(--mono);
  opacity: .8;
  padding: 3px 5px;
  margin-left: 3px;
  border: 1px solid #846d4566;
  border-bottom-width: 2px;
  border-radius: 5px;
}

/* --- stage ------------------------------------------------------------- */

#stage { position: relative; background: #97c4b1; }
canvas { width: 100%; display: block; }

#stage .vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 78% 74% at 50% 46%, rgba(16, 40, 36, 0) 40%, rgba(16, 40, 36, .34) 100%);
}

#stage.fever .vignette {
  background: radial-gradient(ellipse 78% 74% at 50% 46%, rgba(16, 40, 36, 0) 36%, rgba(126, 63, 20, .34) 100%);
}

.hud {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  justify-content: flex-start;
  gap: 6px;
  flex-wrap: nowrap;
}

.pill {
  background: #213d35eb;
  color: #fff1ce;
  border-radius: 18px;
  font-weight: 800;
  font-size: 13px;
  padding: 6px 11px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.pill.num { min-width: 44px; text-align: center; }

.hud #audioBtnGame {
  margin-left: auto;
  background: #213d35eb;
  color: #fff1ce;
  border: 0;
  border-radius: 18px;
  padding: 6px 11px;
  font-size: 13px;
  line-height: 1;
}

.hud #pause {
  margin-left: 0;
  background: #213d35eb;
  color: #fff1ce;
  border: 0;
  border-radius: 18px;
  padding: 6px 11px;
  font-size: 13px;
}

/* streak multiplier ----------------------------------------------------- */

.combo {
  position: relative;
  overflow: hidden;
  min-width: 50px;
  text-align: center;
  transition: background .2s ease;
}

.combo b {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(0);
  background: linear-gradient(90deg, #ffd166, #ffb03a);
  opacity: .3;
  border-radius: inherit;
}

.combo.hot { color: #ffe6a0; background: #3b3220e8; }
.combo.blazing { box-shadow: 0 0 0 2px #ffd166, 0 0 16px #ffc95f88; }
.combo.blazing b { opacity: .45; }
.combo.fever { background: #3b3220f0; color: #ffe6a0; box-shadow: 0 0 0 2px #ffd166, 0 0 20px #ffc95fb0; }
.combo.fever b { opacity: .62; }

/* spring / health ------------------------------------------------------- */

.wind {
  position: relative;
  display: block;
  width: 54px;
  height: 9px;
  background: #162f2a;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px #3d5c5140;
}

.wind i {
  position: absolute;
  inset: 0;
  display: block;
  transform-origin: left center;
  background: linear-gradient(90deg, #7fc9a8, #c9e88a);
  transition: background .3s ease;
}

.wind.low i { background: linear-gradient(90deg, #e0884a, #f2c25a); }
.wind.low { animation: windwarn 1s ease-in-out infinite; }

@keyframes windwarn { 50% { box-shadow: 0 0 0 2px #e0884a88; } }

/* cue + progress -------------------------------------------------------- */

#cue {
  position: absolute;
  bottom: 5%;
  left: 50%;
  transform: translateX(-50%);
  background: #213d35eb;
  color: #fff1ce;
  border-radius: 18px;
  font-weight: 800;
  font-size: 13px;
  padding: 6px 12px;
  white-space: nowrap;
  pointer-events: none;
}

#cue:empty { display: none; }
#cue.pop { animation: cuepop .32s cubic-bezier(.2, 1.5, .4, 1); }

@keyframes cuepop {
  from { transform: translateX(-50%) translateY(6px) scale(.94); opacity: .2; }
  to { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}

.meter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: #775c3a40;
}

.meter i {
  display: block;
  height: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, #fecc60, #ffdf8f);
}

/* --- deck -------------------------------------------------------------- */

.scene { min-width: 0; }

.showtitle {
  margin: 0 0 1px;
  font: 800 11px/1.2 var(--ui);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #7a6a45;
  opacity: 0.9;
}

.keychips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin: 7px 0 0;
  padding: 0;
  font-size: 12px;
  font-weight: 700;
  color: #4a5d4f;
  letter-spacing: 0.01em;
}

.keychips span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #ffffff70;
  border: 1px solid #84775b33;
  border-radius: 7px;
  padding: 2px 7px 2px 3px;
}

.keychips b {
  font: 800 11px/1 var(--mono);
  background: #213d35;
  color: #ffe6a0;
  border-radius: 5px;
  padding: 4px 6px;
  letter-spacing: 0.02em;
}


.deck {
  padding: clamp(13px, 2vw, 22px) clamp(16px, 3vw, 34px);
  background: linear-gradient(115deg, #fff1cd, var(--paper-2));
  align-items: center;
}

.deck strong {
  display: block;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(20px, 2.5vw, 31px);
  letter-spacing: -0.02em;
}

.deck small {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  font-weight: 600;
  opacity: .66;
  letter-spacing: 0.01em;
}

@media (max-width: 650px) {
  .showtitle { font-size: 9px; letter-spacing: 0.14em; }
  .keychips { margin-top: 5px; font-size: 11px; }
  .keychips b { font-size: 10px; padding: 3px 5px; }
}

.pads { gap: 7px; flex-shrink: 0; }
.pads button { position: relative; min-width: 92px; }

/* --- dialogs ----------------------------------------------------------- */

dialog {
  /* top/left are set in script so the card centres on the stage */
  color: var(--ink);
  background: #fff0cc;
  border: 3px solid #394e3d;
  border-radius: 16px;
  padding: 26px;
  max-width: min(470px, 92vw);
  box-shadow: 0 8px 0 #162e27;
}

dialog::backdrop { background: #122c26b8; }

dialog h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: -0.02em;
}

#copy p { margin: 11px 0; }
#copy b { font-weight: 800; }
#copy .verdict { font-size: 16px; margin: 0 0 8px; font-weight: 700; }
.muted { opacity: .68; font-size: 14px; }
.muted.small { font-size: 12px; margin-top: 6px; }

.rankrow { display: flex; align-items: center; gap: 16px; margin: 4px 0 2px; }

.rankletter {
  display: block;
  font-family: var(--display);
  font-weight: 900;
  font-size: 68px;
  line-height: 1;
  text-shadow: 0 2px 0 #ffffff90;
  font-variant-numeric: tabular-nums;
}

.rankscore {
  font-family: var(--display);
  font-weight: 700;
  font-size: 23px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.rankscore small {
  display: block;
  margin-top: 5px;
  font: 700 12px/1.5 var(--ui);
  opacity: .66;
  letter-spacing: 0.01em;
}

.stats {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 6px;
  margin: 14px 0 0;
  padding: 0;
}

.stats li {
  background: #ffffff66;
  border: 1px solid #84775b33;
  border-radius: 9px;
  padding: 7px 4px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  opacity: .9;
}

.stats li b {
  display: block;
  font-family: var(--display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

.stats li span { opacity: .7; }

#options { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* sync row + key table inside dialogs ---------------------------------- */

.sync {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 0;
  padding: 9px 11px;
  background: #ffffff66;
  border: 1px solid #84775b33;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 700;
}

.sync span { flex: 1; }
.sync b { font-variant-numeric: tabular-nums; min-width: 62px; text-align: center; }
.sync button { padding: 4px 9px; font-size: 12px; border-radius: 7px; }

.keys {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}

.keys th {
  text-align: left;
  font: 700 11px/1 var(--mono);
  padding: 7px 10px 7px 0;
  opacity: .62;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.keys td { padding: 7px 0; font-weight: 600; }
.keys tr + tr { border-top: 1px solid #84775b33; }

[hidden] { display: none !important; }

/* --- responsive -------------------------------------------------------- */

@media (max-width: 650px) {
  /* the playbill moves under the art on phones: a 16:9 overlay is too short
     for the title, buttons and best line */
  .theatre { display: flex; flex-direction: column; }
  .bill {
    position: relative;
    top: auto;
    left: auto;
    width: auto;
    margin: -12% 0 0;
    padding: 4% 4% 3%;
    transform: none;
    border-width: 2px;
  }
  .bill .choices { flex-direction: row; gap: 5px; }
  .bill button { font-size: 12px; padding: 7px 10px; }
  .bill .quiet { border: 0; padding: 3px; }
  .bill .cast { font-size: 9px; margin-bottom: 5px; }
  .bill .kicker { display: none; }
  .diff { gap: 3px; margin-top: 6px; }
  .diff button { font-size: 10px; padding: 4px 6px; }
  .hud { gap: 4px; top: 6px; left: 6px; right: 6px; }
  .pill, .hud #audioBtnGame, .hud #pause { font-size: 11px; padding: 3px 7px; }
  .wind { width: 34px; height: 7px; }
  .pads { justify-content: space-between; width: 100%; }
  .pads button { min-width: 0; flex: 1; font-size: 13px; }
  .pads kbd { display: none; }
  .deck { align-items: stretch; flex-direction: column; padding: 12px; }
  .deck small { font-size: 12px; }
  main { width: 98vw; }
  .box { border-width: 2px; }
  dialog { padding: 20px; }
  dialog h2 { font-size: 28px; }
}

@media (orientation: landscape) and (max-height: 620px) {
  main { max-width: 135vh; padding: 2px 0; }
  .deck { padding: 5px 15px; }
  .deck small { display: none; }
  .box { border-width: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .combo.blazing, .wind.low { animation: none; }
  button { transition: none; }
}

/* the pad for the lane you must press next lights up */
.pads button.cue {
  outline: 3px solid #fff6d8;
  outline-offset: 2px;
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 0 24px #ffd16699, 0 3px 0 #a37238;
  animation: padcue .9s ease-in-out infinite;
}

@keyframes padcue {
  50% { outline-color: #ffe6a0; box-shadow: 0 0 34px #ffe08ac0, 0 3px 0 #a37238; }
}

/* the exact press window: the key chip on the pad lights up */
.pads button.now {
  outline: 3px solid #ffe6a0;
  outline-offset: 2px;
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 0 28px #ffd166cc, 0 3px 0 #a37238;
  animation: none;
  z-index: 1;
}

.pads button.now kbd {
  background: #ffe6a0;
  color: #213d35;
  border-color: #a37238;
  opacity: 1;
  box-shadow: 0 0 10px #ffd166cc;
  animation: keyglow .5s ease-in-out infinite alternate;
}

@keyframes keyglow {
  from { box-shadow: 0 0 4px #ffd16688; }
  to { box-shadow: 0 0 14px #ffe6a0dd; }
}

@media (prefers-reduced-motion: reduce) {
  .pads button.cue, .pads button.now kbd { animation: none; }
}

/* the title song button nudges while autoplay is still blocked */
#audioBtn.nudge {
  border-color: #ffd166;
  color: #ffe6a0;
  animation: nudge 2.6s ease-in-out infinite;
}

@keyframes nudge {
  0%, 100% { box-shadow: 0 0 0 0 #ffd16600; }
  45% { box-shadow: 0 0 0 3px #ffd16655, 0 0 18px #ffd16644; }
}

@media (max-width: 650px) {
  .audio-fab { width: 32px; height: 32px; font-size: 13px; }
}
