/* =====================================================================
   Pivot — fixed "blueprint chamber" theme.
   Same cabinet frame as Downside / Grapple Grove (full-height shell,
   frosted top bar, chunky buttons, hard-shadow square stage, overlay-
   scrolled modal) with a draftsman's palette: midnight paper, bone
   walls, brass frame, vermilion hero, coral spikes, teal signals.
   Deliberately ignores the center's light/dark mode; no glass.css.
   ===================================================================== */
:root {
  --pv-void: #060b15;    /* page bottom */
  --pv-deep: #0b1424;    /* app body */
  --pv-brass: #e9b95f;   /* frame + edges */
  --pv-glow: #ffe2a6;    /* lit edges */
  --pv-mint: #7ef0d0;    /* signals / open door */
  --pv-coral: #ff8a70;   /* danger */
  --pv-red: #ff6b57;     /* the hero */
  --pv-ink: #e8f0ff;     /* main text */
  --pv-dim: rgba(214, 228, 255, .62);
  --pv-line: rgba(233, 185, 95, .34);
}

html, body { height: 100%; }
body.pv-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(70% 44% at 16% 0%, rgba(233, 185, 95, .15), transparent 62%),
    radial-gradient(58% 40% at 88% 6%, rgba(126, 240, 208, .07), transparent 66%),
    linear-gradient(180deg, #16233c 0%, #0b1424 48%, var(--pv-void) 100%);
  color: var(--pv-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.pv-page *,
body.pv-page *::before,
body.pv-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(8, 15, 27, .66);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--pv-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(233, 185, 95, .35)); }
.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: #f6fbff;
  text-shadow: 0 0 14px rgba(233, 185, 95, .32), 0 0 30px rgba(40, 90, 150, .35);
}
.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(--pv-dim); }
.stat b { color: var(--pv-glow); font-size: 16px; text-shadow: 0 0 8px rgba(255, 226, 166, .3); }
#pvRoom { color: var(--pv-brass); }
#pvTurns { color: var(--pv-glow); font-variant-numeric: tabular-nums; }
#pvKeys { color: var(--pv-mint); font-variant-numeric: tabular-nums; }

/* ---------- 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(--pv-line);
  background: rgba(13, 23, 40, .88);
  color: var(--pv-ink);
  box-shadow: 0 3px 0 rgba(3, 8, 16, .7);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.c-btn:hover { background: rgba(23, 38, 62, .96); border-color: var(--pv-brass); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(3, 8, 16, .7); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(233, 185, 95, .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, #a9f7e2, #47cba9);
  border-color: rgba(214, 255, 246, .72);
  color: #04241c;
  text-shadow: none;
  box-shadow: 0 3px 0 rgba(4, 51, 40, .6);
}
.c-btn--primary:hover { background: linear-gradient(140deg, #c4fbec, #67dcbc); border-color: #f0fffb; }
.c-btn--icon { padding: 8px 11px; }
.c-btn--icon svg { display: block; }
/* Sound icon: waves hide when muted, slash hides when live. */
.pv-slash { display: none; }
body.pv-muted .pv-wave { opacity: 0; }
body.pv-muted .pv-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(8px, 2vh, 20px);
}
.pv-board {
  display: flex;
  flex-direction: column;
  gap: 9px;
  /* square; capped by the viewport height minus bar + caption */
  width: min(94vw, calc(100vh - 190px));
  width: min(94vw, calc(100dvh - 190px));
}
.pv-stage {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  overflow: hidden;
  background: var(--pv-void);
  border: 3px solid rgba(233, 185, 95, .26);
  box-shadow: 0 10px 0 rgba(3, 8, 16, .5), 0 22px 48px rgba(3, 8, 16, .65), 0 0 42px rgba(233, 185, 95, .13);
  touch-action: none;
  cursor: default;
}
#pvBoard {
  display: block;
  width: 100%; height: 100%;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}

/* ---------- Caption ---------- */
.pv-caption {
  flex: none;
  margin: 0;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.8;
  color: var(--pv-dim);
}
.pv-card kbd, .c-modal kbd, .pv-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(--pv-ink);
  background: rgba(9, 18, 32, .94);
  border: 1px solid var(--pv-line);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(3, 8, 16, .6);
}

/* ---------- Title / pause / clear overlays ---------- */
.pv-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(4, 9, 17, .66);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  cursor: default;
}
.pv-overlay[hidden] { display: none; }
.pv-card {
  position: relative;
  margin: auto;                        /* centers AND lets a tall card scroll in */
  width: min(100%, 380px);
  text-align: center;
  padding: 20px 24px 18px;
  border-radius: 16px;
  background:
    radial-gradient(120% 90% at 50% -20%, rgba(233, 185, 95, .13), transparent 62%),
    linear-gradient(160deg, #16233a, #080e1a);
  border: 2px solid var(--pv-line);
  box-shadow: 0 8px 0 rgba(3, 8, 16, .45), 0 22px 50px rgba(3, 8, 16, .65), 0 0 30px rgba(233, 185, 95, .12);
  color: var(--pv-ink);
  animation: pvPop .28s ease;
}
@keyframes pvPop { from { transform: scale(.9); opacity: 0; } }
.pv-mark { display: flex; justify-content: center; margin-bottom: 2px; filter: drop-shadow(0 0 10px rgba(233, 185, 95, .28)); }
.pv-card h2 {
  margin: 4px 0 6px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #f6fbff;
  text-shadow: 0 0 14px rgba(233, 185, 95, .3);
}
.pv-card__blurb { margin: 0 0 12px; color: var(--pv-dim); font-size: 13.5px; line-height: 1.55; }
.pv-card__blurb b { color: var(--pv-brass); }
.pv-card__bestline {
  margin: -4px 0 12px;
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(233, 185, 95, .1);
  border: 1px solid rgba(233, 185, 95, .3);
  color: var(--pv-glow);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .05em;
}
.pv-card__bestline[hidden] { display: none; }

/* Result stats: compact pair */
.pv-res {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin: 0 0 12px;
}
.pv-res[hidden] { display: none; }
.pv-res__item {
  padding: 6px 4px 7px;
  border-radius: 10px;
  background: rgba(4, 10, 19, .5);
  border: 1px solid rgba(233, 185, 95, .16);
}
.pv-res__item span {
  display: block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--pv-dim);
}
.pv-res__item b { font-size: 18px; color: var(--pv-glow); font-variant-numeric: tabular-nums; }
.pv-res__item:nth-child(2) b { color: var(--pv-mint); }

/* Card buttons: full-width stacked blocks */
.pv-card .c-btn { display: block; width: 100%; margin-top: 8px; font-size: 14px; }
.pv-card .c-btn[hidden] { display: none; }
.pv-card__hint {
  margin: 12px 0 0;
  font-size: 11.5px;
  line-height: 1.8;
  color: var(--pv-dim);
}
.pv-card__hint kbd { font-size: 11px; }

/* ---------- Toast ---------- */
.pv-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(6, 12, 22, .94);
  border: 1px solid rgba(233, 185, 95, .4);
  box-shadow: 0 6px 20px rgba(3, 8, 16, .5);
  color: #f4f8ff;
  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;
}
.pv-toast[hidden] { display: none; }
.pv-toast.is-in { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Touch strip (coarse pointers / narrow screens) ---------- */
.pv-touch {
  display: none;
  grid-template-columns: 1fr 1fr 1.15fr 1.2fr 1.2fr;
  gap: 7px;
  width: 100%;
  touch-action: none;
}
.pv-tbtn {
  appearance: none;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  width: 100%; height: 50px;
  padding: 0 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 14px;
  border: 2px solid rgba(255, 226, 166, .46);
  background: rgba(9, 18, 32, .8);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: var(--pv-glow);
  font: 800 8.5px/1 system-ui, sans-serif;
  letter-spacing: .07em;
  text-transform: uppercase;
  box-shadow: 0 2px 0 rgba(3, 8, 16, .45);
  cursor: pointer;
}
.pv-tbtn:active, .pv-tbtn.is-down { transform: translateY(1px); background: rgba(30, 48, 74, .96); }
.pv-tbtn svg { pointer-events: none; }
.pv-tbtn--jump { border-color: rgba(126, 240, 208, .58); color: var(--pv-mint); }
.pv-tbtn--turn {
  border-color: rgba(233, 185, 95, .66);
  color: var(--pv-brass);
  background: rgba(34, 26, 12, .55);
}
.pv-tbtn--turn:active, .pv-tbtn--turn.is-down { background: rgba(74, 55, 22, .9); }
/* The strip sits under the stage, so the board reserves its height too. */
@media (hover: none), (pointer: coarse), (max-width: 820px) {
  .pv-touch { display: grid; }
  .pv-board { width: min(94vw, calc(100dvh - 252px)); }
}

/* ---------- Chamber select ---------- */
.pv-rooms {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 4px 0 2px;
}
.pv-room {
  position: relative;
  appearance: none;
  cursor: pointer;
  padding: 8px 4px 7px;
  border-radius: 12px;
  border: 1px solid rgba(233, 185, 95, .26);
  background: rgba(5, 11, 21, .56);
  color: var(--pv-ink);
  font: inherit;
  text-align: center;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.pv-room:hover:not(:disabled) { background: rgba(26, 42, 66, .85); border-color: var(--pv-brass); }
.pv-room:active:not(:disabled) { transform: translateY(1px); }
.pv-room:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(233, 185, 95, .45); }
.pv-room b { display: block; font-size: 16px; font-weight: 800; letter-spacing: .04em; }
.pv-room small { display: block; margin-top: 1px; font-size: 9.5px; font-weight: 700; color: var(--pv-dim); }
.pv-room i {
  position: absolute; top: 6px; right: 7px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--pv-brass);
  box-shadow: 0 0 7px rgba(233, 185, 95, .85);
}
.pv-room.is-current { border-color: var(--pv-mint); box-shadow: 0 0 0 1px rgba(126, 240, 208, .45) inset; }
.pv-room:disabled { opacity: .38; cursor: not-allowed; }
.pv-room:disabled b { color: var(--pv-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(3, 8, 16, .72);
  -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(233, 185, 95, .08), transparent 60%),
    linear-gradient(160deg, #16233a, #070d18);
  color: #eef4ff;
  border-radius: 16px;
  border: 2px solid var(--pv-line);
  box-shadow: 0 8px 0 rgba(3, 8, 16, .45), 0 24px 60px rgba(3, 8, 16, .72), 0 0 34px rgba(233, 185, 95, .12);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(233, 185, 95, .22);
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em;
  color: #f6fbff; text-shadow: 0 0 10px rgba(233, 185, 95, .3);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: #eef4ff; font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--pv-brass); }
.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(--pv-brass);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 2.5px 0; }
.c-modal__body b { color: var(--pv-mint); }
.c-modal__lead { margin: 10px 0; }
.c-modal__note {
  margin: 12px 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(233, 185, 95, .07);
  border: 1px solid rgba(233, 185, 95, .24);
  font-size: 13px;
  color: #e2ebfa;
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }
.c-modal .c-btn { border-color: var(--pv-line); box-shadow: 0 3px 0 rgba(3, 8, 16, .6); }
.pv-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; }
  .pv-board { width: min(94vw, calc(100vh - 168px)); width: min(94vw, calc(100dvh - 168px)); }
}
/* Narrow screens: controls get their own full-width row, and the overlay
   leaves the tiny 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; }
  .pv-overlay { position: fixed; z-index: 40; padding: 12px; }
  .pv-card { width: min(100%, 360px); padding: 18px 20px 16px; }
  .pv-card h2 { font-size: 21px; }
  .pv-caption { display: none; }
  .pv-touch { gap: 5px; grid-template-columns: 1fr 1fr 1.1fr 1.25fr 1.25fr; }
  .pv-tbtn { height: 48px; font-size: 8px; }
  .pv-tbtn svg { width: 18px; height: 18px; }
  .pv-rooms { grid-template-columns: repeat(3, 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; }
  .pv-tbtn { height: 44px; }
  .pv-tbtn span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .pv-card, .pv-toast { transition: none; animation: none; }
}
