/* =====================================================================
   Tower Stacker — fixed "golden-hour dusk" theme.
   Same page frame as Flappy Bird / Timberman (full-height app shell,
   frosted top bar, chunky arcade buttons, hard-shadow stage, card
   overlays, colored rules modal) but with this game's own palette, taken
   straight from its canvas: dusk purple sky, warm horizon glow, sunset-
   coral primary buttons, deep-plum ink. Deliberately ignores the center's
   light/dark mode; no glass.css loaded.
   ===================================================================== */
:root {
  --ts-dusk:   #3b2d63;   /* page + sky top */
  --ts-violet: #7b4a8f;   /* sky mid */
  --ts-ember:  #ff9e5e;   /* horizon glow */
  --ts-gold:   #f6c445;   /* perfect / highlight */
  --ts-coral:  #ff7a4d;   /* primary button base */
  --ts-coraldk:#c2410c;
  --ts-cream:  #fdeecb;   /* card surface */
  --ts-plum:   #2a1f42;   /* modal "inside a brick" */
  --ts-ink:    #241a34;   /* outline ink — main text color */
  --ts-line:   rgba(36, 26, 52, .82);
}

html, body { height: 100%; }
body.ts-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, var(--ts-dusk) 0%, var(--ts-violet) 52%, var(--ts-ember) 100%);
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.ts-page *,
body.ts-page *::before,
body.ts-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(255, 255, 255, .16);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid rgba(255, 255, 255, .5);
  z-index: 20;
}
.c-bar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-bar__brand svg { filter: drop-shadow(0 2px 0 rgba(36, 26, 52, .35)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 26px);
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  white-space: nowrap;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(36, 26, 52, .35);
}
.c-bar__stats { display: flex; align-items: center; gap: 8px 18px; 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: .03em; white-space: nowrap; color: rgba(255, 255, 255, .82); }
.stat b { color: var(--ts-gold); font-size: 16px; }

/* ---------- Buttons (chunky arcade style, matches Flappy's frame) ------ */
.c-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 12px;
  border: 2px solid var(--ts-line);
  background: #fff;
  color: var(--ts-ink);
  box-shadow: 0 3px 0 rgba(36, 26, 52, .4);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
}
.c-btn:hover { background: #ffe9c9; border-color: var(--ts-coral); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(36, 26, 52, .4); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(255, 122, 77, .55); }
/* Primary = sunset coral, this game's stand-in for the pipe-green / shirt-red. */
.c-btn--primary {
  background: linear-gradient(140deg, #ff9a63, var(--ts-coral));
  border-color: var(--ts-line);
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .2);
}
.c-btn--primary:hover { background: linear-gradient(140deg, #ffa977, var(--ts-coral)); }

/* ---------- 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);
}
.ts-board {
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* 2:3 portrait; capped by viewport height minus chrome (bar + gauge +
     caption). Same sizing idea as Flappy / Timberman. */
  width: min(92vw, calc((100vh - 205px) * 0.6667), 420px);
  width: min(92vw, calc((100dvh - 205px) * 0.6667), 420px);
}
.ts-stage {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 14px;
  overflow: hidden;
  background: var(--ts-dusk);
  border: 3px solid var(--ts-line);
  box-shadow: 0 10px 0 rgba(36, 26, 52, .3), 0 22px 48px rgba(36, 26, 52, .45);
  touch-action: manipulation;
  cursor: pointer;
}
#board {
  display: block;
  width: 100%; height: 100%;
  touch-action: none;                  /* capture taps without page scroll */
  -webkit-user-select: none; user-select: none;
}

/* ---------- Height gauge ---------- */
/* Fills left→right as the tower climbs toward the sky-record benchmark;
   JS caps the read-out at 100% so a record run just stays pegged full. */
.gauge {
  flex: none;
  height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .28);
  border: 2px solid var(--ts-line);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(36, 26, 52, .25);
}
.gauge__fill {
  height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd35a, var(--ts-coral));
  transition: width .2s ease;
}

/* ---------- Caption under the stage ---------- */
.ts-caption {
  flex: none;
  margin: 0;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.9;
  color: rgba(255, 255, 255, .82);
}
.ts-card kbd, .c-modal kbd, .ts-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(--ts-ink);
  background: #fff;
  border: 1px solid var(--ts-line);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(36, 26, 52, .3);
}

/* ---------- Ready / game-over overlays ---------- */
.ts-overlay {
  touch-action: manipulation;
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(36, 26, 52, .38);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.ts-overlay[hidden] { display: none; }
.ts-card {
  touch-action: manipulation;
  max-width: 300px;
  text-align: center;
  padding: 22px 24px 20px;
  border-radius: 16px;
  background: linear-gradient(160deg, #fff6e0, var(--ts-cream));
  border: 2px solid var(--ts-line);
  box-shadow: 0 8px 0 rgba(36, 26, 52, .28), 0 22px 50px rgba(36, 26, 52, .45);
  color: var(--ts-ink);
  animation: tsPop .3s ease;
}
@keyframes tsPop { from { transform: scale(.88); opacity: 0; } }
.ts-card__big { font-size: 40px; line-height: 1.1; }
.ts-card__big svg {
  width: 80px;
  height: 80px;
  display: block;
  margin: 0 auto;
}
.ts-card h2 {
  margin: 6px 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--ts-ink);
  text-shadow: 2px 2px 0 rgba(255, 255, 255, .5);
}
.ts-card p { margin: 0 0 14px; color: #5b4a72; font-size: 13.5px; line-height: 1.55; }
.ts-card p b { color: var(--ts-coraldk); }
.ts-card .c-btn { font-size: 14px; }

/* ---------- Rules modal (overlay scrolls, never a boxed inner scrollbar) -- */
.c-modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; padding: 16px;
  overflow-y: auto;                 /* the overlay scrolls, not the card */
  overscroll-behavior: contain;
}
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed; inset: 0;
  background: rgba(36, 26, 52, .55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
/* Panel is "inside a brick": deep plum with cream text. margin:auto centres
   it AND lets a too-tall card scroll in from the top (no max-height/overflow). */
.c-modal__panel {
  position: relative; z-index: 1;
  margin: auto;
  width: min(92vw, 470px);
  background: linear-gradient(160deg, #453368, var(--ts-plum));
  color: #f3e9d6;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, .5);
  box-shadow: 0 8px 0 rgba(36, 26, 52, .35), 0 24px 60px rgba(36, 26, 52, .6);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, .24);
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em;
  color: #fff; text-shadow: 2px 2px 0 rgba(0, 0, 0, .25);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: #f3e9d6; font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--ts-gold); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.55; }
.c-modal__body h3 {
  margin: 16px 0 6px; font-size: 13px;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--ts-gold);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--ts-gold); }
.c-modal__lead { margin: 12px 0; }
.c-modal__note {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .3);
  font-size: 13px;
  color: #ece0c6;
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }
.c-modal .c-btn { border-color: rgba(255, 255, 255, .8); box-shadow: 0 3px 0 rgba(0, 0, 0, .3); }
.c-modal .c-btn--primary { border-color: var(--ts-line); }

/* ---------- Responsive (same breakpoints as the arcade frame) ---------- */
@media (max-width: 700px), (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 12px; margin-left: auto; }
  .stat { font-size: 12px; }
  .stat b { font-size: 13px; }
  .c-btn { padding: 8px 10px; font-size: 12px; }
  .c-bar__controls { gap: 6px; }
  .c-bar__controls .c-btn { padding: 9px 10px; white-space: nowrap; }
  .ts-board { width: min(94vw, calc((100vh - 180px) * 0.6667), 420px); width: min(94vw, calc((100dvh - 180px) * 0.6667), 420px); }
}
/* Narrow screens only: the buttons drop to a row of their own and split it
   evenly into full-width thumb targets. */
@media (max-width: 700px) {
  .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; }
}
/* Smallest phones: labels scale down with the viewport 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; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .ts-card, .gauge__fill { transition: none; animation: none; }
}
