/* =====================================================================
   Taut — fixed "brass loom at night" theme.
   Same page frame as Timberman / Flappy (full-height app shell, frosted top
   bar, chunky arcade buttons, hard-shadow stage, overlay card, rules modal)
   with its own palette taken from the canvas: aubergine night, brass rail,
   teal strings, gold rope, pink filaments, saw silver.
   Deliberately ignores the center's light/dark mode; no glass.css loaded.
   ===================================================================== */
:root {
  --tw-night:   #0b0715;
  --tw-night-2: #1c1233;
  --tw-ink:     #f7e9cd;
  --tw-muted:   #b8a6cc;
  --tw-brass:   #c9973f;
  --tw-brass-hi:#f0c778;
  --tw-teal:    #4ce3cf;
  --tw-pink:    #ff6f9a;
  --tw-danger:  #ff5f76;
  --tw-wood:    #3a2410;
  --tw-line:    #4a3566;
  --tw-line-2:  #241738;
}

html, body { height: 100%; }
body.tw-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--tw-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(120, 72, 160, .35) 0%, transparent 62%),
    linear-gradient(180deg, var(--tw-night) 0%, var(--tw-night-2) 100%);
  /* The shared back chip reads these tokens, so it matches this page. */
  --gc-surface: #241738;
  --gc-text: #f7e9cd;
  --gc-border: #4a3566;
  --gc-shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 20px rgba(0,0,0,.45);
}
body.tw-page *,
body.tw-page *::before,
body.tw-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(18, 11, 32, .72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid rgba(201, 151, 63, .55);
  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 6px rgba(240, 199, 120, .35)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 26px);
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--tw-ink);
}
.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: var(--tw-muted); }
.stat b { color: var(--tw-brass-hi); font-size: 16px; font-variant-numeric: tabular-nums; }
.stat:last-child b { color: var(--tw-teal); }

/* ---------- 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(--tw-line);
  background: #221636;
  color: var(--tw-ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .45);
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.c-btn:hover { background: #2d1d45; border-color: var(--tw-brass); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .45); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(76, 227, 207, .45); }
.c-btn--primary {
  background: linear-gradient(140deg, var(--tw-brass-hi), var(--tw-brass));
  border-color: var(--tw-wood);
  color: #2a1a05;
  text-shadow: none;
}
.c-btn--primary:hover { background: linear-gradient(140deg, #ffd894, #d8a54a); }
.c-btn[aria-pressed="false"] { color: var(--tw-muted); }

/* ---------- 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);
}
.tw-board {
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* 16:10 stage, capped by the space the chrome leaves on short windows. */
  width: min(96vw, calc((100vh - 220px) * 1.6), 1120px);
  width: min(96vw, calc((100dvh - 220px) * 1.6), 1120px);
}
.tw-stage {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: 16px;
  overflow: hidden;
  background: var(--tw-night);
  border: 2px solid var(--tw-line);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .35), 0 24px 56px rgba(0, 0, 0, .6), inset 0 0 60px rgba(120, 72, 160, .2);
  touch-action: none;
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
#board {
  display: block;
  width: 100%; height: 100%;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}

/* ---------- Caption ---------- */
.tw-caption {
  flex: none;
  margin: 0;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .02em;
  line-height: 1.9;
  color: var(--tw-muted);
}
.tw-caption kbd, .tw-card kbd, .c-modal 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(--tw-ink);
  background: #221636;
  border: 1px solid var(--tw-line);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .4);
}

/* ---------- Ready / paused / game-over overlay ---------- */
/* The overlay scrolls, never the card: on Windows a max-height + overflow
   card always reserves a scrollbar gutter inside the panel. */
.tw-overlay {
  position: absolute; inset: 0; z-index: 6;
  display: flex;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: radial-gradient(120% 100% at 50% 0%, rgba(38, 20, 62, .72), rgba(8, 5, 16, .88));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  cursor: default;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 151, 63, .4) transparent;
}
.tw-overlay::-webkit-scrollbar { width: 8px; }
.tw-overlay::-webkit-scrollbar-track { background: transparent; }
.tw-overlay::-webkit-scrollbar-thumb { background: rgba(201, 151, 63, .35); border-radius: 8px; }
.tw-overlay[hidden] { display: none; }
.tw-card {
  /* margin auto centres AND lets an over-tall card scroll in from the top;
     flex none stops the flex container from shrinking it into clip instead */
  flex: 0 0 auto;
  margin: auto;
  width: min(400px, 100%);
  text-align: center;
  padding: 18px 22px 20px;
  border-radius: 18px;
  background: linear-gradient(165deg, #241738, #170e26);
  border: 2px solid rgba(201, 151, 63, .5);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .35), 0 26px 60px rgba(0, 0, 0, .65);
  animation: twPop .28s ease;
}
@keyframes twPop { from { transform: scale(.92); opacity: 0; } }
.tw-card__art { margin-bottom: 2px; }
.tw-card__art svg { width: 132px; height: 97px; display: block; margin: 0 auto; }
.tw-card h2 {
  margin: 2px 0 8px;
  font-size: clamp(20px, 3.2vw, 24px);
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--tw-ink);
}
.tw-card p { margin: 0 0 14px; color: var(--tw-muted); font-size: 13.5px; line-height: 1.55; }
.tw-card p b { color: var(--tw-brass-hi); }
.tw-card__stats {
  margin: 0 0 14px !important;
  font-size: 14px !important;
  font-weight: 700;
  color: var(--tw-brass-hi) !important;
  font-variant-numeric: tabular-nums;
}
.tw-card__stats.is-best { color: var(--tw-teal) !important; letter-spacing: .04em; }
.tw-card__go { display: block; width: min(250px, 90%); margin: 2px auto 0; }
.tw-card__link {
  display: block;
  margin-top: 14px;
  color: var(--tw-muted);
  font-size: 12.5px;
  text-decoration: none;
  border-bottom: 1px dashed var(--tw-line);
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
  padding-bottom: 1px;
}
.tw-card__link:hover { color: var(--tw-ink); }

/* ---------- Rules modal ---------- */
.c-modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 151, 63, .4) transparent;
}
.c-modal::-webkit-scrollbar { width: 10px; }
.c-modal::-webkit-scrollbar-track { background: transparent; }
.c-modal::-webkit-scrollbar-thumb { background: rgba(201, 151, 63, .35); border-radius: 10px; }
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed; inset: 0;
  background: rgba(5, 3, 10, .72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.c-modal__panel {
  position: relative;
  z-index: 1;
  /* flex none: the panel keeps its natural height and the overlay scrolls
     instead of squeezing the footer out of the viewport */
  flex: 0 0 auto;
  margin: auto;
  width: min(92vw, 500px);
  background: linear-gradient(165deg, #241738, #150c22);
  color: var(--tw-ink);
  border-radius: 18px;
  border: 2px solid rgba(201, 151, 63, .55);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .35), 0 26px 70px rgba(0, 0, 0, .7);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(201, 151, 63, .3);
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--tw-ink);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: var(--tw-muted); font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--tw-brass-hi); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.55; }
.c-modal__body h3 {
  margin: 16px 0 6px; font-size: 12px;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--tw-teal);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 5px 0; color: var(--tw-muted); }
.c-modal__body b { color: var(--tw-brass-hi); }
.c-modal__lead { margin: 12px 0; color: var(--tw-muted); }
.c-modal__note {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(76, 227, 207, .08);
  border: 1px solid rgba(76, 227, 207, .25);
  font-size: 13px;
  color: var(--tw-muted);
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 820px), (max-height: 620px) {
  /* Narrow windows make the 16:10 board short, so the card drops its art and
     tightens up rather than scrolling inside the play area. */
  .tw-card__art { display: none; }
  .tw-card { padding: 16px 18px 18px; }
  .tw-card h2 { font-size: 19px; margin: 4px 0 6px; }
  .tw-card p { font-size: 12.5px; line-height: 1.5; margin-bottom: 11px; }
  .tw-card__go { padding: 11px 22px; font-size: 14px; }
  .tw-card__link { margin-top: 10px; }
}

@media (max-width: 760px), (max-height: 620px) {
  .c-bar { gap: 6px 12px; padding: 8px clamp(10px, 3vw, 18px); padding-top: max(8px, env(safe-area-inset-top)); }
  .c-bar__brand { gap: 8px; }
  .c-bar__title { font-size: 16px; letter-spacing: .12em; }
  .c-bar__stats { gap: 4px 12px; }
  .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; }
  .tw-board { width: min(96vw, calc((100dvh - 190px) * 1.6), 1120px); }
  .tw-caption { font-size: 11.5px; }
}
@media (max-width: 760px) {
  .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; }
  .tw-board { width: min(98vw, calc((100dvh - 200px) * 1.6), 1120px); }
  .tw-caption { line-height: 1.7; }
}
@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, .tw-card { transition: none; animation: none; }
}
