/* ============================================================
   Catastrophe — the game
   Depends on css/styles.css for tokens and the button base,
   and css/board.css for the leaderboard panel.
   ============================================================ */

:root { --gold: #ffd88a; --warn: #ff9d9d; }
[hidden]{display:none!important}

.game-main { padding-top: calc(var(--header-h) + 52px); padding-bottom: 84px; }
.game-wrap { max-width: 960px; margin: 0 auto; padding: 0 24px; }
.game-head { margin-bottom: 22px; }
.game-head h1 {
  font-family: var(--font-head);
  font-size: clamp(1.8rem, 4.6vw, 2.5rem);
  line-height: 1.07; letter-spacing: -.025em; margin-bottom: 11px;
}
.game-head p { color: var(--text-dim); font-size: 1rem; max-width: 68ch; }
.hud{display:flex;align-items:flex-end;gap:20px;margin-bottom:9px;flex-wrap:wrap}
.stat{display:flex;flex-direction:column;gap:1px}
.stat span{font-family:var(--font-head);font-size:.6rem;letter-spacing:.14em;text-transform:uppercase;color:var(--text-faint)}
.stat strong{font-family:var(--font-head);font-size:1.4rem;font-weight:700;font-variant-numeric:tabular-nums;line-height:1}
.stat-chaos strong{color:var(--warn)}
.stat-total strong{color:var(--gold)}
.hud-spacer{flex:1}
.pips{display:flex;gap:5px;align-items:center;height:20px}
.pip{width:22px;height:6px;border-radius:99px;background:var(--surface-2)}
.pip.done{background:var(--gradient)}
.pip.now{background:var(--gold)}
.track{height:5px;background:var(--surface-2);border-radius:999px;overflow:hidden;margin-bottom:12px}
.fill{height:100%;width:0%;background:linear-gradient(120deg,#ffd88a,#ff9d9d);border-radius:999px;transition:width .1s linear}

/* The base rule only centres it; the two media queries below decide how wide
   it may be, measured from where the canvas actually starts (389px down on a
   tall window) rather than estimated. */
.stage-wrap{position:relative;margin:0 auto}
canvas#stage{display:block;width:100%;aspect-ratio:15/10;border:1px solid var(--border);border-radius:14px;
  background:#11162b;cursor:pointer;touch-action:manipulation;user-select:none;-webkit-user-select:none}
canvas#stage:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.overlay{position:absolute;inset:0;display:grid;place-items:center;padding:22px;border-radius:14px;
  background:rgba(10,13,24,.92);backdrop-filter:blur(5px);text-align:center;overflow-y:auto}
.overlay[hidden]{display:none}
.overlay h2{font-family:var(--font-head);font-size:clamp(1.25rem,3.6vw,1.8rem);letter-spacing:-.02em;margin-bottom:8px}
.overlay p{color:var(--text-dim);font-size:.9rem;max-width:46ch;margin:0 auto 16px}
/* An author display rule beats the UA's [hidden], so anything hidden by the
   attribute has to say so explicitly or it shows up on the start screen. */
[hidden]{display:none!important}
.score-row{display:flex;gap:22px;justify-content:center;margin-bottom:16px;flex-wrap:wrap}
.score-row div{display:flex;flex-direction:column;gap:1px}
.score-row span{font-family:var(--font-head);font-size:.58rem;letter-spacing:.14em;text-transform:uppercase;color:var(--text-faint)}
.score-row b{font-family:var(--font-head);font-size:1.5rem;font-weight:700;font-variant-numeric:tabular-nums;line-height:1}
.final{font-family:var(--font-head);font-size:2.9rem;font-weight:700;line-height:1;font-variant-numeric:tabular-nums;
  background:var(--gradient);-webkit-background-clip:text;background-clip:text;color:transparent;margin-bottom:2px}
.final-label{font-family:var(--font-head);font-size:.6rem;letter-spacing:.16em;text-transform:uppercase;color:var(--text-faint);margin-bottom:14px}
.btn{font-family:var(--font-head);font-size:.9rem;font-weight:600;padding:12px 26px;border-radius:999px;border:1px solid transparent;
  background:var(--gradient);color:#0a0d18;cursor:pointer;transition:transform .15s ease}
.btn:hover{transform:translateY(-2px)}
.btn-ghost{background:transparent;border-color:var(--border);color:var(--text)}
.btn:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.runs{display:grid;gap:3px;margin:0 auto 16px;max-width:300px;text-align:left}
.runs div{display:flex;justify-content:space-between;font-size:.84rem;color:var(--text-dim)}
.runs b{font-family:var(--font-head);font-weight:600;font-variant-numeric:tabular-nums;color:var(--text)}
.note{margin-top:20px;padding-left:16px;border-left:2px solid var(--border);color:var(--text-faint);font-size:.86rem;max-width:78ch}
.note b{color:var(--text-dim);font-weight:500}

/* Keep the whole board on screen, and let it go edge to edge on a phone. */
@media (min-width: 641px) {
  .stage-wrap { max-width: min(100%, max(430px, (100dvh - 404px) * 15 / 10)); margin: 0 auto; }
}
@media (min-width: 641px) and (max-height: 860px) {
  .game-main { padding-top: calc(var(--header-h) + 24px); padding-bottom: 52px; }
  .game-head { margin-bottom: 12px; }
  .game-head h1 { font-size: 1.7rem; margin-bottom: 0; }
  .game-head p { display: none; }
  .stage-wrap { max-width: min(100%, max(430px, (100dvh - 236px) * 15 / 10)); }
}
@media (max-width: 640px) {
  .game-main { padding-top: calc(var(--header-h) + 16px); padding-bottom: 44px; }
  .game-wrap { padding: 0 12px; }
  .game-head { margin-bottom: 12px; }
  .game-head h1 { font-size: 1.5rem; margin-bottom: 0; }
  .game-head .eyebrow { margin-bottom: 6px; }
  .game-head p { display: none; }
  .hud { gap: 14px; }
  .stat strong { font-size: 1.2rem; }
  .stage-wrap { margin: 0 -12px; max-width: none; }
  canvas#stage { aspect-ratio: 1.34; border-radius: 11px; }
  .note { margin-top: 18px; font-size: .82rem; }
}

/* ---------- free play ----------
   Unlocked after five levels: one room, no scoring, and the cat is dragged
   by hand. The two stats that mean nothing without a scored level are hidden
   rather than left showing the previous run's numbers. */
.hud-free .stat-pips, .hud-free .stat-total { display: none; }

.free-bar{display:flex;align-items:center;gap:16px;flex-wrap:wrap;
  margin:0 0 12px;padding:11px 15px;border:1px solid var(--gold);border-radius:12px;
  background:rgba(255,216,138,.06)}
.free-bar p{margin:0;flex:1;min-width:220px;color:var(--text-dim);font-size:.86rem}
.free-bar b{color:var(--gold);font-weight:600;font-family:var(--font-head)}
.free-actions{display:flex;gap:8px;flex-wrap:wrap}
.btn-sm{padding:8px 16px;font-size:.78rem}

/* Dragging must not scroll the page out from under the room on a touch
   screen, and the canvas should read as grabbable. */
canvas#stage.draggable{cursor:grab;touch-action:none}
body.dragging canvas#stage.draggable{cursor:grabbing}
body.dragging{user-select:none;-webkit-user-select:none}

.ov-actions{display:flex;gap:10px;justify-content:center;flex-wrap:wrap}

/* The free bar costs about 80px of vertical space, so the viewport cap that
   keeps the whole board on screen has to give that back. The bar precedes
   .stage-wrap in the markup, so the mode class on the hud can reach it. */
@media (min-width: 641px) {
  .hud-free ~ .stage-wrap { max-width: min(100%, max(400px, (100dvh - 486px) * 15 / 10)); }
}
@media (min-width: 641px) and (max-height: 860px) {
  .hud-free ~ .stage-wrap { max-width: min(100%, max(400px, (100dvh - 318px) * 15 / 10)); }
}

@media (max-width: 640px) {
  .free-bar{padding:10px 12px;gap:10px}
  .free-bar p{font-size:.8rem;min-width:0}
  .free-actions{width:100%}
  .free-actions .btn{flex:1}
}
/* On the smallest phones the bar's second sentence is the difference between
   the canvas fitting on screen and not, so it goes. */
@media (max-width: 420px) {
  .free-more{display:none}
  .free-bar{padding:9px 11px;gap:8px;margin-bottom:9px}
  .free-bar p{font-size:.78rem}
  .btn-sm{padding:7px 12px;font-size:.74rem}
}
