/* =====================================================================
   Downside — fixed "upside-down tower" theme.
   Same cabinet frame as Grapple Grove and Abyss (full-height shell, frosted
   top bar, chunky buttons, hard-shadow 16:9 stage, overlay-scrolled modal)
   with a dusk palette: plum voids, amber edges, mint hero, coral hazards.
   Deliberately ignores the center's light/dark mode; no glass.css loaded.
   ===================================================================== */
:root {
  --ds-void: #0b0710;    /* page bottom */
  --ds-deep: #171020;    /* app body */
  --ds-warm: #ffc774;    /* amber edges + telemetry */
  --ds-glow: #ffe0a8;    /* lit edges */
  --ds-mint: #a8f0c2;    /* the hero */
  --ds-coral: #ff7a63;   /* danger */
  --ds-ink: #fff2e0;     /* main text */
  --ds-dim: rgba(255, 236, 214, .62);
  --ds-line: rgba(255, 199, 116, .34);
}

html, body { height: 100%; }
body.ds-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(72% 46% at 18% 0%, rgba(255, 170, 96, .16), transparent 62%),
    radial-gradient(62% 42% at 86% 8%, rgba(168, 240, 194, .07), transparent 66%),
    linear-gradient(180deg, #2a1a33 0%, #171020 46%, var(--ds-void) 100%);
  color: var(--ds-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.ds-page *,
body.ds-page *::before,
body.ds-page *::after { box-sizing: border-box; }

/* ---------- App frame ---------- */
.c-app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.c-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(14, 8, 20, .64);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--ds-line);
  z-index: 20;
}
.c-bar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-bar__brand svg { filter: drop-shadow(0 0 7px rgba(255, 199, 116, .4)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 26px);
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  white-space: nowrap;
  color: #fff6e8;
  text-shadow: 0 0 14px rgba(255, 199, 116, .35), 0 0 30px rgba(150, 90, 40, .3);
}
.c-bar__stats { display: flex; align-items: center; gap: 8px 16px; margin-left: auto; }
.c-bar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stat { font-size: 14px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; color: var(--ds-dim); }
.stat b { color: var(--ds-glow); font-size: 16px; text-shadow: 0 0 8px rgba(255, 224, 168, .3); }
#room { color: var(--ds-warm); }
#timer { color: var(--ds-glow); font-variant-numeric: tabular-nums; }
#sparks { color: var(--ds-mint); }
#best { color: #ffd9a1; }

/* ---------- Buttons ---------- */
.c-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 12px;
  border: 2px solid var(--ds-line);
  background: rgba(28, 17, 34, .85);
  color: var(--ds-ink);
  box-shadow: 0 3px 0 rgba(6, 3, 9, .7);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.c-btn:hover { background: rgba(44, 27, 52, .95); border-color: var(--ds-warm); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(6, 3, 9, .7); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(255, 199, 116, .45); }
/* .c-btn sets display:inline-block, which would beat the UA's [hidden] rule. */
.c-btn[hidden] { display: none; }
.c-btn--primary {
  background: linear-gradient(140deg, #d2ffdf, #6fdd9f);
  border-color: rgba(226, 255, 234, .7);
  color: #08240f;
  text-shadow: none;
  box-shadow: 0 3px 0 rgba(8, 51, 25, .6);
}
.c-btn--primary:hover { background: linear-gradient(140deg, #e6ffed, #8fecb4); border-color: #f4fff8; }
.c-btn--icon { padding: 8px 11px; }
.c-btn--icon svg { display: block; }
/* Sound icon: waves hide when muted, slash hides when live. */
.ds-slash { display: none; }
body.ds-muted .ds-wave { opacity: 0; }
body.ds-muted .ds-slash { display: block; }

/* ---------- Table / stage column ---------- */
.c-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2.4vh, 22px);
}
.ds-board {
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* 16:9 landscape; capped by viewport height minus bar + caption. */
  width: min(96vw, calc((100vh - 178px) * 1.7778));
  width: min(96vw, calc((100dvh - 178px) * 1.7778));
}
.ds-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background: var(--ds-void);
  border: 3px solid rgba(255, 199, 116, .24);
  box-shadow: 0 10px 0 rgba(6, 3, 9, .5), 0 22px 48px rgba(6, 3, 9, .65), 0 0 42px rgba(255, 199, 116, .12);
  touch-action: none;
  cursor: pointer;
}
#board {
  display: block;
  width: 100%; height: 100%;
  touch-action: none;                  /* capture taps without page scroll */
  -webkit-user-select: none; user-select: none;
}

/* ---------- Caption ---------- */
.ds-caption {
  flex: none;
  margin: 0;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.9;
  color: var(--ds-dim);
}
.ds-card kbd, .c-modal kbd, .ds-caption kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin: 0 1px;
  font: 700 12px/1.5 ui-monospace, "Segoe UI", monospace;
  text-align: center;
  color: var(--ds-ink);
  background: rgba(26, 15, 32, .92);
  border: 1px solid var(--ds-line);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(6, 3, 9, .6);
}

/* ---------- Title / pause / finish overlays ---------- */
.ds-overlay {
  touch-action: manipulation;
  position: absolute; inset: 0; z-index: 8;
  display: flex;
  overflow: auto;                      /* the overlay scrolls, never the card */
  padding: 16px;
  background: rgba(8, 4, 12, .64);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  cursor: default;
}
.ds-overlay[hidden] { display: none; }
.ds-card {
  position: relative;
  margin: auto;                        /* centers AND lets a tall card scroll in */
  width: min(100%, 388px);
  text-align: center;
  padding: 20px 24px 18px;
  border-radius: 16px;
  background:
    radial-gradient(120% 90% at 50% -20%, rgba(255, 199, 116, .14), transparent 62%),
    linear-gradient(160deg, #2a1a34, #120b18);
  border: 2px solid var(--ds-line);
  box-shadow: 0 8px 0 rgba(6, 3, 9, .45), 0 22px 50px rgba(6, 3, 9, .65), 0 0 30px rgba(255, 199, 116, .12);
  color: var(--ds-ink);
  animation: dsPop .28s ease;
}
@keyframes dsPop { from { transform: scale(.9); opacity: 0; } }
.ds-mark { display: flex; justify-content: center; margin-bottom: 2px; filter: drop-shadow(0 0 10px rgba(255, 199, 116, .3)); }
.ds-card h2 {
  margin: 4px 0 6px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #fff8ec;
  text-shadow: 0 0 14px rgba(255, 199, 116, .32);
}
.ds-card__blurb { margin: 0 0 12px; color: var(--ds-dim); font-size: 13.5px; line-height: 1.55; }
.ds-card__blurb b { color: var(--ds-warm); }
.ds-card__bestline {
  margin: -4px 0 12px;
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(255, 199, 116, .1);
  border: 1px solid rgba(255, 199, 116, .3);
  color: var(--ds-glow);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .05em;
}
.ds-card__bestline[hidden] { display: none; }

/* Result stats: compact 2 x 2 block */
.ds-res {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin: 0 0 12px;
}
.ds-res[hidden] { display: none; }
.ds-res__item {
  padding: 6px 4px 7px;
  border-radius: 10px;
  background: rgba(9, 5, 13, .45);
  border: 1px solid rgba(255, 199, 116, .16);
}
.ds-res__item span {
  display: block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ds-dim);
}
.ds-res__item b { font-size: 17px; color: var(--ds-glow); font-variant-numeric: tabular-nums; }
.ds-res__item:nth-child(2) b { color: #ffb2a4; }
.ds-res__item:nth-child(3) b { color: var(--ds-mint); }

/* Card buttons: full-width stacked blocks */
.ds-card .c-btn { display: block; width: 100%; margin-top: 8px; font-size: 14px; }
.ds-card .c-btn[hidden] { display: none; }
.ds-card__hint {
  margin: 12px 0 0;
  font-size: 11.5px;
  line-height: 1.8;
  color: var(--ds-dim);
}
.ds-card__hint kbd { font-size: 11px; }

/* ---------- Toast ---------- */
.ds-toast {
  position: absolute;
  left: 50%; top: 14px;
  z-index: 9;
  transform: translate(-50%, -6px);
  max-width: 92%;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(12, 6, 16, .92);
  border: 1px solid rgba(255, 199, 116, .4);
  box-shadow: 0 6px 20px rgba(6, 3, 9, .5);
  color: #fff2dc;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .05em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease, transform .18s ease;
}
.ds-toast[hidden] { display: none; }
.ds-toast.is-in { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Touch strip (coarse pointers / narrow screens) ---------- */
.ds-touch {
  display: none;
  grid-template-columns: 1fr 1fr 96px;
  gap: 8px;
  width: 100%;
  touch-action: none;
}
.ds-tbtn {
  appearance: none;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  width: 100%; height: 50px;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 14px;
  border: 2px solid rgba(255, 224, 168, .5);
  background: rgba(18, 10, 24, .78);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: var(--ds-glow);
  font: 800 8.5px/1 system-ui, sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
  box-shadow: 0 2px 0 rgba(6, 3, 9, .45);
  cursor: pointer;
}
.ds-tbtn:active, .ds-tbtn.is-down { transform: translateY(1px); background: rgba(52, 30, 60, .95); }
.ds-tbtn svg { pointer-events: none; }
.ds-tbtn--flip {
  height: 50px;
  border-color: rgba(168, 240, 194, .62);
  color: var(--ds-mint);
}
/* The strip sits under the stage, so the board reserves its height too. */
@media (hover: none), (pointer: coarse), (max-width: 820px) {
  .ds-touch { display: grid; }
  .ds-board { width: min(96vw, calc((100dvh - 240px) * 1.7778)); }
}

/* ---------- Room select ---------- */
.ds-rooms {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 4px 0 2px;
}
.ds-room {
  position: relative;
  appearance: none;
  cursor: pointer;
  padding: 8px 4px 7px;
  border-radius: 12px;
  border: 1px solid rgba(255, 199, 116, .26);
  background: rgba(12, 7, 17, .55);
  color: var(--ds-ink);
  font: inherit;
  text-align: center;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.ds-room:hover:not(:disabled) { background: rgba(46, 28, 54, .8); border-color: var(--ds-warm); }
.ds-room:active:not(:disabled) { transform: translateY(1px); }
.ds-room:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(255, 199, 116, .45); }
.ds-room b { display: block; font-size: 16px; font-weight: 800; letter-spacing: .04em; }
.ds-room small { display: block; margin-top: 1px; font-size: 9.5px; font-weight: 700; color: var(--ds-dim); }
.ds-room i {
  position: absolute; top: 6px; right: 7px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ds-warm);
  box-shadow: 0 0 7px rgba(255, 199, 116, .85);
}
.ds-room.is-current { border-color: var(--ds-mint); box-shadow: 0 0 0 1px rgba(168, 240, 194, .45) inset; }
.ds-room:disabled { opacity: .38; cursor: not-allowed; }
.ds-room:disabled b { color: var(--ds-dim); }

/* ---------- Rules modal (overlay scrolls; panel never does) ---------- */
.c-modal { position: fixed; inset: 0; z-index: 500; display: flex; overflow: auto; padding: 14px; }
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed; inset: 0;
  background: rgba(6, 3, 9, .7);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.c-modal__panel {
  position: relative;
  margin: auto;
  width: min(92vw, 500px);
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(255, 199, 116, .08), transparent 60%),
    linear-gradient(160deg, #2a1a34, #100a16);
  color: #f7ecdd;
  border-radius: 16px;
  border: 2px solid var(--ds-line);
  box-shadow: 0 8px 0 rgba(6, 3, 9, .45), 0 24px 60px rgba(6, 3, 9, .72), 0 0 34px rgba(255, 199, 116, .12);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 199, 116, .22);
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em;
  color: #fff8ec; text-shadow: 0 0 10px rgba(255, 199, 116, .32);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: #f7ecdd; font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--ds-warm); }
.c-modal__body { padding: 6px 20px 2px; font-size: 13.5px; line-height: 1.5; }
.c-modal__body h3 {
  margin: 12px 0 5px; font-size: 13px;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--ds-warm);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 2.5px 0; }
.c-modal__body b { color: var(--ds-mint); }
.c-modal__lead { margin: 10px 0; }
.c-modal__note {
  margin: 12px 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 199, 116, .07);
  border: 1px solid rgba(255, 199, 116, .24);
  font-size: 13px;
  color: #f0e2d2;
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }
.c-modal .c-btn { border-color: var(--ds-line); box-shadow: 0 3px 0 rgba(6, 3, 9, .6); }
.ds-rooms-panel { width: min(92vw, 472px); }

/* ---------- Responsive ---------- */
@media (max-width: 760px), (max-height: 560px) {
  .c-bar { gap: 5px 12px; padding: 7px clamp(10px, 3vw, 18px); padding-top: max(7px, env(safe-area-inset-top)); }
  .c-bar__brand { gap: 8px; }
  .c-bar__title { font-size: 16px; }
  .c-bar__stats { gap: 4px 11px; margin-left: auto; }
  .stat { font-size: 12px; }
  .stat b { font-size: 13px; }
  .c-btn { padding: 8px 10px; font-size: 12px; }
  .c-btn--icon { padding: 7px 9px; }
  .c-bar__controls { gap: 6px; }
  .c-bar__controls .c-btn { padding: 9px 10px; white-space: nowrap; }
  .ds-board { width: min(96vw, calc((100vh - 156px) * 1.7778)); width: min(96vw, calc((100dvh - 156px) * 1.7778)); }
}
/* Narrow screens: controls get their own full-width row, and the overlay
   leaves the tiny 16:9 stage so the card is readable. */
@media (max-width: 700px) {
  /* Three rows: brand, telemetry, controls. Nothing spills off the edge. */
  .c-bar { gap: 6px 10px; }
  .c-bar__brand { flex: 1 1 100%; }
  .c-bar__stats { flex: 1 1 100%; margin-left: 0; justify-content: space-between; }
  .c-bar__controls { flex: 1 1 100%; flex-wrap: nowrap; }
  .c-bar__controls .c-btn { flex: 1 1 auto; min-width: 0; padding: 9px 6px; overflow: hidden; text-overflow: ellipsis; }
  .c-table { padding: 10px 8px; }
  .ds-overlay { position: fixed; z-index: 40; padding: 12px; }
  .ds-card { width: min(100%, 360px); padding: 18px 20px 16px; }
  .ds-card h2 { font-size: 21px; }
  .ds-caption { display: none; }
  .ds-touch { gap: 6px; grid-template-columns: 1fr 1fr 88px; }
  .ds-rooms { grid-template-columns: repeat(4, 1fr); gap: 6px; }
}
/* Smallest phones: labels scale down instead of stacking. */
@media (max-width: 380px) {
  .c-bar { gap: 5px 8px; }
  .c-bar__title { font-size: 15px; }
  .stat { font-size: 11px; }
  .stat b { font-size: 12px; }
  .c-bar__controls { gap: 4px; }
  .c-bar__controls .c-btn { font-size: clamp(10px, 3.2vw, 12px); padding: 9px 4px; letter-spacing: .01em; }
  .ds-touch { grid-template-columns: 1fr 1fr 78px; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .ds-card, .ds-toast { transition: none; animation: none; }
}
