/* =====================================================================
   Douser — fixed "papercut cellar" theme.
   Full-height app shell, frosted top bar, chunky arcade buttons and card
   overlays, same frame family as Flappy/Timberman, but this game's own
   palette: slate paper, ivory card stock, one amber lamp.
   Deliberately ignores the center's light/dark mode; no glass.css here.
   ===================================================================== */
:root {
  --ds-night:  #0a121b;   /* page gradient top */
  --ds-night2: #111e29;   /* page gradient bottom */
  --ds-slate:  #21333f;   /* floor */
  --ds-paper:  #e9e0cb;   /* ivory card stock */
  --ds-amber:  #ffb457;
  --ds-amberl: #ffe0a8;
  --ds-hot:    #ff7a4d;
  --ds-ink:    #0d1620;   /* outlines and main text */
  --ds-line:   rgba(233, 224, 203, .82);
}

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(120% 70% at 50% -10%, #1c2c3a 0%, transparent 60%),
    linear-gradient(180deg, var(--ds-night) 0%, var(--ds-night2) 100%);
  color: var(--ds-paper);
  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(9, 16, 23, .62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 180, 87, .32);
  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(255, 180, 87, .45)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 26px);
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ds-paper);
}
.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: .05em; white-space: nowrap; color: rgba(233, 224, 203, .66); }
.stat b { color: var(--ds-amberl); font-size: 16px; }

/* Chances: three little lamps, snuffed as you are caught */
.lamps { display: flex; align-items: center; gap: 5px; }
.lamp {
  position: relative;
  width: 12px; height: 16px;
  border: 1.6px solid var(--ds-amber);
  border-radius: 4px 4px 3px 3px;
  transition: opacity .25s ease, filter .25s ease;
}
.lamp::after {
  content: "";
  position: absolute;
  inset: 3px 2px 3px;
  border-radius: 2px;
  background: var(--ds-amberl);
}
.lamp.lost { opacity: .2; filter: grayscale(1); }

/* ---------- Buttons (chunky arcade style) ---------- */
.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: 11px;
  border: 2px solid rgba(233, 224, 203, .55);
  background: rgba(23, 36, 47, .92);
  color: var(--ds-paper);
  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: #1e2f3c; border-color: var(--ds-amber); }
.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(255, 180, 87, .55); }
.c-btn--primary {
  background: linear-gradient(150deg, #ffc470, var(--ds-amber));
  border-color: rgba(255, 224, 168, .8);
  color: #2a1a08;
  box-shadow: 0 3px 0 rgba(120, 62, 6, .55);
}
.c-btn--primary:hover { background: linear-gradient(150deg, #ffd08a, #ffbe6b); }

/* ---------- Table / stage column ---------- */
.c-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vh, 18px);
}
.ds-board {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* 560:620 room. The script's fitBoard() sets the final width from the space
     actually left under the bar, so this is only the pre-boot fallback. */
  width: min(94vw, 640px);
  max-width: 100%;
}

/* ---------- Lantern oil ---------- */
.ds-oil {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(233, 224, 203, .58);
}
.ds-oil__tag { flex: none; }
.ds-oil__track {
  flex: 1 1 auto;
  height: 12px;
  border-radius: 999px;
  border: 1.5px solid rgba(233, 224, 203, .38);
  background: rgba(9, 16, 23, .72);
  overflow: hidden;
}
.ds-oil__fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd08a, var(--ds-amber));
  box-shadow: 0 0 10px rgba(255, 180, 87, .5);
  transition: width .14s linear, background .3s ease;
}
.ds-oil__fill.low { background: linear-gradient(180deg, #ff9d6a, var(--ds-hot)); }
.ds-oil__count { flex: none; min-width: 34px; text-align: right; color: rgba(233, 224, 203, .78); }

/* ---------- The room ---------- */
.ds-stage {
  position: relative;
  aspect-ratio: 560 / 620;
  border-radius: 14px;
  overflow: hidden;
  background: var(--ds-night);
  border: 2px solid rgba(255, 180, 87, .38);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .35), 0 24px 54px rgba(0, 0, 0, .6);
  touch-action: none;
}
#board {
  display: block;
  width: 100%; height: 100%;
  touch-action: none;                 /* drag-to-walk, no page scroll */
  -webkit-user-select: none; user-select: none;
}

/* Round lamp toggle, sits in the corner of the room */
.ds-lamp {
  position: absolute;
  right: max(10px, 3%);
  bottom: max(10px, 3%);
  z-index: 4;
  appearance: none;
  cursor: pointer;
  width: clamp(54px, 9.5%, 68px);
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 180, 87, .7);
  background: rgba(13, 22, 32, .78);
  color: rgba(233, 224, 203, .72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .4);
  transition: background .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.ds-lamp svg { width: 24px; height: 24px; }
.ds-lamp__label { font: 800 8.5px/1 system-ui, sans-serif; letter-spacing: .1em; text-transform: uppercase; }
.ds-lamp[aria-pressed="true"] {
  color: #2a1a08;
  background: radial-gradient(circle at 50% 40%, #ffe0a8, var(--ds-amber));
  border-color: #fff1d2;
  box-shadow: 0 0 18px rgba(255, 180, 87, .65), 0 3px 0 rgba(120, 62, 6, .5);
}
.ds-lamp:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(255, 180, 87, .6); }

/* ---------- Ready / results overlay ---------- */
.ds-overlay {
  touch-action: manipulation;
  position: absolute; inset: 0; z-index: 6;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(7, 12, 18, .55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.ds-overlay[hidden] { display: none; }
.ds-card {
  touch-action: manipulation;
  max-width: 306px;
  text-align: center;
  padding: 20px 24px 20px;
  border-radius: 16px;
  background: linear-gradient(160deg, #f3ecd9, var(--ds-paper));
  border: 2px solid var(--ds-ink);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .35), 0 22px 50px rgba(0, 0, 0, .55);
  color: var(--ds-ink);
  animation: dsPop .3s ease;
}
@keyframes dsPop { from { transform: scale(.9); opacity: 0; } }
.ds-card__big svg {
  width: 78px; height: 78px;
  display: block;
  margin: 0 auto 4px;
  filter: drop-shadow(0 0 10px rgba(255, 180, 87, .55));
}
.ds-card h2 {
  margin: 4px 0 6px;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ds-ink);
}
.ds-card p { margin: 0 0 14px; color: #4e5b63; font-size: 13.5px; line-height: 1.55; }
/* quiet second choice under the primary button ("start a fresh run") */
.ds-card__alt {
  display: block;
  margin: 9px auto 0;
  padding: 2px 6px;
  appearance: none;
  background: none;
  border: 0;
  cursor: pointer;
  font: 700 12px/1.5 system-ui, sans-serif;
  letter-spacing: .04em;
  color: #6b7780;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ds-card__alt:hover { color: var(--ds-ink); }
.ds-card__alt:focus-visible { outline: none; color: var(--ds-ink); box-shadow: 0 0 0 3px rgba(255, 180, 87, .55); border-radius: 6px; }
.ds-card__alt[hidden] { display: none; }

/* ---------- Caption under the room ---------- */
.ds-caption {
  flex: none;
  margin: 0;
  min-height: 1.9em;            /* one line at any caption wording */
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.9;
  color: rgba(233, 224, 203, .55);
}
.ds-caption kbd, .ds-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(--ds-paper);
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(233, 224, 203, .35);
  border-radius: 6px;
}
.ds-card kbd { color: var(--ds-ink); background: #fff; border-color: rgba(13, 22, 32, .5); }

/* ---------- Rules modal ----------
   The full-screen overlay scrolls, never the card: an inner scrollbar
   always reserves a gutter on Windows. Panel centres with margin:auto so
   a too-tall card can still be scrolled in from its top. */
.c-modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 8, 12, .72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.c-modal__panel {
  position: relative;
  z-index: 1;
  margin: auto;
  width: min(94vw, 470px);
  background: linear-gradient(165deg, #17252f, #0d1720);
  color: var(--ds-paper);
  border-radius: 16px;
  border: 1px solid rgba(255, 180, 87, .4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 24px 60px rgba(0, 0, 0, .65);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 180, 87, .22);
}
.c-modal__head h2 {
  margin: 0; font-size: 17px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--ds-paper);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: var(--ds-paper); font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--ds-amber); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.6; }
.c-modal__body h3 {
  margin: 16px 0 6px; font-size: 12px;
  text-transform: uppercase; letter-spacing: .14em;
  color: var(--ds-amber);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--ds-amberl); }
.c-modal__lead { margin: 12px 0; }
.c-modal__note {
  margin: 16px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 180, 87, .08);
  border: 1px solid rgba(255, 180, 87, .28);
  font-size: 13px;
  color: rgba(233, 224, 203, .82);
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }

/* ---------- Responsive ---------- */
@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__brand svg { width: 20px; height: 20px; }
  .c-bar__title { font-size: 16px; letter-spacing: .1em; }
  .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; }
  .ds-board { width: min(96vw, 640px); }
  .c-table { padding: 8px; }      /* reclaim the margins the room can use */
  .ds-lamp { width: 48px; height: 48px; }
  .ds-lamp svg { width: 21px; height: 21px; }
}
@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; }
}
@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: .02em; }
  .ds-caption { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .ds-card, .ds-oil__fill, .lamp { transition: none; animation: none; }
}
