@import url('./ui-theme.css');

/* Conversion Tower: solid slate surfaces, ivory chess, tactile amber actions.
   Loaded only by the game document; archive and informational pages keep their
   own layouts. State and animation geometry remain owned by styles.css. */
:root {
  --bg-high: #0b1826;
  --bg-deep: #071018;
  --panel-strong: #1d2d3e;
}

body {
  background: radial-gradient(ellipse at 80% 0, #172a3e, transparent 60%), var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}
body::before, body::after { display: none; }
h1, h2, h3 { font-family: var(--font-ui); font-weight: 800; letter-spacing: -.035em; }
.label, .eyebrow { font-size: .875rem; letter-spacing: .045em; font-weight: 700; }
a { text-underline-offset: 4px; }
:where(button, a, select, input, summary):focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 4px;
}

/* Raised controls are reserved for actions; information surfaces stay flat. */
.primary, .secondary, .audio-toggle, a[data-challenge-return-link]:not([hidden]) {
  min-height: 52px;
  padding: 13px 20px;
  font-size: 1rem;
  font-weight: 750;
  line-height: 1.25;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}
.primary, #cancel-surrender, #cancel-restart, #surrender-run {
  min-height: 58px;
  font-size: 1.125rem;
}
#cancel-surrender, #cancel-restart, #surrender-run {
  border-color: var(--button-primary-border);
  background: var(--button-primary-background);
  color: var(--button-primary-ink);
  box-shadow: var(--button-primary-shadow);
}
.primary:hover:not(:disabled), .secondary:hover:not(:disabled), .audio-toggle:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.primary:active:not(:disabled), #surrender-run:active:not(:disabled), .secondary:active:not(:disabled), .audio-toggle:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: inset 0 1px 0 #ffffff16, 0 1px 0 #0b1522;
}
button:disabled { opacity: .5; filter: saturate(.4); box-shadow: none; }
.secondary.danger { background: #302836; border-color: #9c626a; color: #ffd5d5; }
#restart-run { background: var(--button-secondary-background); border-color: var(--button-secondary-border); color: var(--ink); }
.confirm-dialog-actions .secondary {
  background: linear-gradient(#26394c, #1d2d3e);
  border-color: var(--accent);
  color: var(--accent-strong);
}
.confirm-dialog-actions { display:grid; grid-template-columns:repeat(2, minmax(0, 1fr)); gap:12px; }
.confirm-dialog-actions button { border-radius:12px; font-weight:750; min-height:58px; }
@media (max-width:400px) {
  .confirm-dialog-actions { grid-template-columns:1fr; }
}
.audio-toggle { width: 48px; min-width: 48px; height: 48px; min-height: 48px; padding: 12px; border-radius: 12px; }
.audio-toggle-glyph { width: 24px; height: 24px; }

/* Lobby: the game and its action come before supporting explanations. */
.shell { grid-template-columns: minmax(0, 1fr); gap: 20px; width: min(1240px, calc(100% - 32px)); }
.lobby-scene {
  min-height: 620px;
  padding: 28px 36px 36px;
  gap: 24px;
  border-radius: 24px;
  border-color: var(--border);
  background: var(--panel);
  box-shadow: 0 18px 50px #0004;
}
.lobby-scene::before { display: none; }
.lobby-scene::after {
  inset: 90px 12px 0 55%;
  background-image: url('/tower-ascent-v2.webp');
  background-position: center bottom;
  background-size: contain;
  opacity: 1;
  filter: none;
  transform: none;
  mask-image: linear-gradient(90deg, transparent, #000 22%), linear-gradient(180deg, transparent, #000 12%, #000 85%, transparent);
  mask-composite: intersect;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 22%), linear-gradient(180deg, transparent, #000 12%, #000 85%, transparent);
  -webkit-mask-composite: source-in;
}
.landing-header { justify-content: space-between; align-items: center; gap: 20px; }
.lobby-screen, .lobby-scene, .landing-header, .landing-navigation { min-width: 0; }
.landing-navigation-toggle { display: none; }
.game-brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 1.25rem; font-weight: 800; white-space: nowrap; }
.game-brand img { width: 48px; height: 48px; border-radius: 12px; }
.landing-nav { gap: 8px 16px; font-size: .9375rem; }
.landing-nav > a { display: inline-flex; align-items: center; min-height: 48px; }
.locale-nav { gap: 2px; padding: 0; }
.locale-nav a { display: inline-grid; place-items: center; min-width: 42px; min-height: 44px; border-radius: 8px; }
.lobby-badge { background: none; border: none; border-radius: 0; padding: 0; color: var(--muted); font-size: .9375rem; }
.lobby-copy { max-width: 57%; gap: 16px; }
.lobby-copy > .eyebrow { display: none; }
.lobby-copy h1 { max-width: 16ch; font-size: clamp(2.5rem, 4vw, 3.6rem); line-height: 1.08; }
.landing-thesis { color: var(--muted); font-size: 1rem; font-weight: 500; line-height: 1.5; }
.lobby-copy .lede { color: var(--muted); font-size: 1rem; line-height: 1.55; }
.lobby-controls { display: grid; grid-template-columns: 1fr; gap: 20px; align-items: stretch; margin: 4px 0 0; }
.difficulty-picker { position: relative; width: 100%; min-width: 0; margin: 0; padding: 0; border: 0; }
.difficulty-picker .label { margin-bottom: 10px; padding: 0; color: var(--ink); font-size: 1rem; letter-spacing: 0; text-transform: none; }
.difficulty-select { min-height: 52px; border-radius: 12px; background: #203145; }
.difficulty-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.difficulty-choices[hidden], .difficulty-select[hidden] { display: none; }
.difficulty-choice {
  position: relative;
  display: grid;
  gap: 3px;
  min-height: 72px;
  padding: 10px 38px 10px 14px;
  border: 1px solid #496078;
  border-radius: 12px;
  background: linear-gradient(#26394c, #1d2d3e);
  box-shadow: inset 0 1px 0 #ffffff12, 0 3px 0 #0b1522;
  cursor: pointer;
}
.difficulty-choice input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.difficulty-choice-title { font-size: 1.0625rem; font-weight: 750; line-height: 1.3; }
.difficulty-choice-rating { color: var(--muted); font-size: .875rem; line-height: 1.3; }
.difficulty-choice:has(input:checked) { border-color: var(--accent-strong); background: #34404a; box-shadow: inset 0 0 0 1px var(--accent-strong), 0 3px 0 #0b1522; }
.difficulty-choice:has(input:checked)::after { content: '✓'; position: absolute; right: 12px; top: 12px; color: var(--accent-strong); font-size: 1.25rem; font-weight: 800; pointer-events: none; }
.difficulty-choice:has(input:focus-visible) { outline: 3px solid var(--accent-strong); outline-offset: 4px; }
.difficulty-choice:has(input:disabled) { opacity: .5; cursor: not-allowed; }
.difficulty-choice:has(input:disabled) input { cursor: not-allowed; }
.lobby-start-button { width: 100%; border-radius: 12px; }
.lobby-start-button::before { content: '▶'; margin-right: 12px; font-size: .875em; }
body[data-screen='lobby'] .game-stage { opacity: .8; filter: none; transform: none; }
body[data-screen='lobby'] .battle-menu { display: none; }
body[data-screen='lobby'] .board-header { display: none; }
.site-footer { font-size: .9375rem; padding: 12px 4px; }
.site-footer nav { flex-wrap: wrap; }
.site-footer nav a { min-height: 44px; display: inline-flex; align-items: center; }

/* Game: compact heading, broad board, readable status and flat information. */
.match-hud, .board-panel, .battle-menu { border-color: var(--border); background: var(--panel); border-radius: 18px; box-shadow: 0 12px 32px #0003; }
.match-hud::before, .board-panel::before, .battle-menu::before { display: none; }
.match-hud { padding: 16px 22px; gap: 10px; }
.match-copy .eyebrow { padding: 0; border: 0; background: none; color: var(--accent-strong); font-size: .9375rem; letter-spacing: .02em; }
.match-copy h2 { margin-top: 2px; font-size: clamp(1.8rem, 3vw, 2.5rem); line-height: 1.1; }
.challenge-subtitle { color: var(--muted); font-size: 1rem; line-height: 1.4; margin-top: 6px; }
.hud-chip { border: 0; background: none; border-radius: 0; padding: 4px 0; font-size: .9375rem; }
.hud-chip-label { font-size: .875rem; letter-spacing: 0; text-transform: none; }
.hud-chip-lives { gap: 12px; }
.hud-lives-track { gap: 7px; }
.hud-life, .floor-result-lives-track .hud-life { width: 22px; height: 22px; }

.clock-box { min-height: 52px; min-width: 118px; padding: 8px 14px; border-radius: 10px; background: var(--ink); color: var(--bg); border: 1px solid #fff4dc; box-shadow: none; }
#clock { color: inherit; font-family: var(--font-ui); font-weight: 800; font-size: 2.2rem; line-height: 1; letter-spacing: -.04em; }
.clock-box[data-state='warning'], .clock-box[data-state='expired'] { background: #3d202b; border-color: #e88185; color: #ffe1e1; }
.board-shell { padding: 6px; border-radius: 12px; border-color: #486078; background: #203145; box-shadow: 0 6px 18px #0004; }
.cm-chessboard.chess-club .board .square.white { fill: #e6dfc9; }
.cm-chessboard.chess-club .board .square.black { fill: #70859d; }
.cm-chessboard.chess-club .coordinates .coordinate { font-family: var(--font-ui); font-size: 8px; font-weight: 750; }
.cm-chessboard.chess-club .coordinates .coordinate.white { fill: #34475b; }
.cm-chessboard.chess-club .coordinates .coordinate.black { fill: #fff4dc; }
.board-status { color: var(--ink); font-size: 1rem; font-weight: 650; line-height: 1.4; letter-spacing: 0; text-transform: none; }
.feedback-banner { font-size: 1rem; border-radius: 10px; }
.battle-menu-summary { min-height: 56px; background: #203145; border-bottom: 1px solid var(--border); font-size: 1rem; }
.battle-menu-summary span:first-child { font-weight: 750; }
.battle-menu-note { font-size: .875rem; text-transform: none; letter-spacing: 0; }
.battle-menu-body { padding-top: 14px; }
.battle-card, .run-summary-stat { background: #192938; border-color: var(--border); border-radius: 12px; box-shadow: none; }
.battle-stat-value { font-size: 1.5rem; line-height: 1.2; }
.context-headline { font-size: 1.125rem; font-weight: 700; }
.context-meta, .context-players, .context-opening, .difficulty-meta, .tower-caption { font-size: 1rem; line-height: 1.5; }
.move-log { font-size: 1rem; }
.game-action-dock button { min-height: 52px; }

/* One-off challenges share the game context and live log, without tower progress. */
body[data-game-mode='shared'] .battle-menu .tower-card,
body[data-game-mode='shared'] .battle-card:has(#engine-move),
body[data-game-mode='shared'] .difficulty-meta { display: none; }
body[data-game-mode='shared'] .battle-menu .battle-card { grid-column: 1 / -1; }

@media (min-width: 1180px) {
  body[data-screen='game'][data-game-mode='shared'] .game-stage {
    grid-template-rows: auto min-content 1fr;
  }
}
.run-summary { position: static; width: 100%; background: var(--panel-strong); border-radius: 16px; backdrop-filter: none; }
.run-summary-stat-label { font-size: .875rem; letter-spacing: 0; text-transform: none; }
.run-summary-message { font-size: 1rem; }

/* Briefings and results share the same visual grammar as the main game. */
.takeover-dialog-card, .floor-result-card, .shared-challenge-card, .confirm-dialog-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 24px 70px #0007;
}
.takeover-dialog-card::before, .takeover-dialog-card::after { display: none; }
.takeover-event-badge, .takeover-player-badge-side { font-size: .9375rem; letter-spacing: 0; }
.takeover-player-badge-name { font-size: 1.125rem; line-height: 1.3; }
.takeover-objective-label { font-size: .9375rem; letter-spacing: .02em; }
.takeover-objective-value { font-size: clamp(2rem, 6vw, 3rem); line-height: 1.15; }
.takeover-dialog-actions .takeover-dialog-dismiss { min-height: 58px; font-size: 1.125rem; }
.floor-result-copy h2 { font-size: clamp(2rem, 6vw, 3rem); line-height: 1.1; }
.floor-result-objective, .floor-result-note { font-size: 1rem; line-height: 1.5; }
.floor-result-stat span { font-size: .9375rem; letter-spacing: 0; text-transform: none; }
.floor-result-stat strong { font-size: 1.75rem; }
.floor-result-actions { gap: 12px; }
.floor-result-actions button { min-height: 52px; }
.floor-result-actions .primary { min-height: 58px; }
.floor-result-close { width: 48px; height: 48px; border-radius: 12px; background: #203145; color: var(--ink); }
.floor-result-dialog[data-tone='loss'] .floor-result-card { background: #20232f; border-color: #9c626a; }

/* A small, one-shot reward. Effects never cover or intercept result actions. */
.result-heading { display:flex; align-items:center; gap:16px; }
.result-heading h2 { min-width:0; overflow-wrap:anywhere; }
.result-reward { position:relative; display:grid; place-items:center; flex:0 0 48px; width:48px; height:58px; color:#f0c276; pointer-events:none; isolation:isolate; }
.result-reward::before { content:''; position:absolute; inset:-14px; border-radius:50%; background:radial-gradient(circle, #efba5d38, #efba5d00 70%); z-index:-1; }
.result-reward-piece { display:block; width:42px; height:50px; filter:drop-shadow(0 3px 0 #866027); transform-origin:50% 90%; }
.result-spark { position:absolute; left:50%; top:50%; width:4px; height:6px; border-radius:1px; background:#f5ce85; opacity:0; }
.result-reward[data-animate='true'] .result-reward-piece { animation:reward-hop 650ms cubic-bezier(.2,.7,.3,1) both; }
.result-reward[data-animate='true']::before { animation:reward-glow 900ms ease-out both; }
.result-reward[data-animate='true'] .result-spark { animation:reward-spark 850ms 90ms ease-out both; }
@keyframes reward-hop {
  0% { transform:translateY(0) scale(.9,1.05); }
  24% { transform:translateY(-12px) rotate(-5deg); }
  55% { transform:translateY(0) scale(1.1,.9); }
  76% { transform:translateY(-3px); }
  100% { transform:translateY(0); }
}
@keyframes reward-glow { 0% { opacity:0; transform:scale(.6); } 35% { opacity:1; transform:scale(1.35); } 100% { opacity:1; transform:scale(1); } }
@keyframes reward-spark { 0% { opacity:0; transform:translate(-50%,-50%) scale(.3); } 20% { opacity:1; } 100% { opacity:0; transform:translate(var(--spark-x),var(--spark-y)) rotate(var(--spark-turn)) scale(.4); } }
.result-reward[data-tone='loss'] { color:#8292a2; }
.result-reward[data-tone='loss'] .result-reward-piece { transform:translateY(3px) rotate(12deg); filter:drop-shadow(0 2px 0 #263342); }
.result-reward[data-tone='loss']::before { opacity:0; background:radial-gradient(circle, #df819530, transparent 70%); }
.result-reward[data-tone='loss'][data-animate='true'] .result-reward-piece { animation:result-setback 800ms ease-out both; }
.result-reward[data-tone='loss'][data-animate='true']::before { animation:result-glow-out 800ms ease-out both; }
.result-life-lost { animation:result-heart-out 850ms ease-out both; }
@keyframes result-setback {
  0%, 15% { color:#f0c276; transform:translateY(0) rotate(0); }
  40% { transform:translateY(2px) rotate(-6deg); }
  70% { transform:translateY(4px) rotate(16deg); }
  100% { color:#8292a2; transform:translateY(3px) rotate(12deg); }
}
@keyframes result-glow-out { 0%, 20% { opacity:1; } 100% { opacity:0; } }
@keyframes result-heart-out {
  0%, 20% { transform:scale(1.12); }
  45% { transform:scale(.92); }
  100% { transform:scale(1); }
}
/* Completing the entire run earns a longer, one-shot gold celebration. */
.floor-result-dialog[data-run-complete='true'] .floor-result-card {
  border-color:#ae884a;
  background:radial-gradient(ellipse at 12% 0%, #e8b65b18, transparent 55%), #14212d;
}
.floor-result-dialog[data-run-complete='true'] .result-reward[data-animate='true'] .result-reward-piece { animation:crown-arrive 1100ms cubic-bezier(.2,.7,.3,1) both; }
.floor-result-dialog[data-run-complete='true'] .result-reward[data-animate='true']::before { animation:reward-glow 1600ms ease-out both; }
.tower-confetti { position:absolute; inset:0; overflow:hidden; border-radius:inherit; pointer-events:none; z-index:2; }
.tower-confetti-piece { position:absolute; top:-16px; left:var(--x); width:8px; height:100%; opacity:0; animation:tower-confetti-fall var(--duration) var(--delay) linear both; }
.tower-confetti-piece::before { content:''; display:block; width:6px; height:11px; border-radius:1px; background:#edbc68; animation:tower-confetti-turn var(--duration) var(--delay) ease-in-out both; }
.tower-confetti-piece:nth-child(3n)::before { background:#fff0ce; width:5px; height:7px; }
.tower-confetti-piece:nth-child(4n)::before { background:#b98639; width:4px; height:12px; }
@keyframes crown-arrive {
  0% { opacity:0; transform:translateY(-24px) scale(.7) rotate(-12deg); }
  45% { opacity:1; transform:translateY(2px) scale(1.12) rotate(3deg); }
  70% { transform:translateY(-4px) scale(1.04) rotate(-2deg); }
  100% { transform:translateY(0) scale(1) rotate(0); }
}
@keyframes tower-confetti-fall { 0% { opacity:0; transform:translate(0,-2%); } 8% { opacity:.85; } 75% { opacity:.7; } 100% { opacity:0; transform:translate(var(--drift),105%); } }
@keyframes tower-confetti-turn { from { transform:rotate(0) rotateY(0); } to { transform:rotate(var(--turn)) rotateY(540deg); } }
.floor-result-dialog[data-run-lost='true'] .result-reward-piece { transform-origin:50% 50%; transform:translate(3px,8px) rotate(75deg) scale(.85); color:#73808f; filter:drop-shadow(0 2px 0 #263342); }
.floor-result-dialog[data-run-lost='true'] .result-reward[data-animate='true'] .result-reward-piece { animation:final-tower-fall 1400ms ease-in-out both; }
.floor-result-dialog[data-run-lost='true'] .result-reward[data-animate='true']::before { animation:result-glow-out 1400ms ease-out both; }
.floor-result-dialog[data-run-lost='true'] .result-life-lost { animation:result-heart-out 1400ms ease-out both; }
@keyframes final-tower-fall {
  0%, 15% { color:#f0c276; transform:translate(0,0) rotate(0); }
  30% { transform:translate(0,0) rotate(-8deg); }
  65% { color:#8292a2; transform:translate(3px,8px) rotate(80deg) scale(.85); }
  82% { transform:translate(3px,6px) rotate(70deg) scale(.85); }
  100% { color:#73808f; transform:translate(3px,8px) rotate(75deg) scale(.85); }
}
@media (max-width:600px) {
  .result-heading { gap:12px; }
  .result-reward { flex-basis:36px; width:36px; height:46px; }
  .result-reward-piece { width:32px; height:40px; }
  .result-heading h2 { font-size:clamp(1.85rem, 9vw, 2.7rem); line-height:1.06; }
}
@media (prefers-reduced-motion:reduce) {
  .floor-result-dialog[data-run-lost='true'] .result-reward[data-animate='true'] .result-reward-piece,
  .floor-result-dialog[data-run-lost='true'] .result-reward[data-animate='true']::before,
  .floor-result-dialog[data-run-lost='true'] .result-life-lost { animation:none; }
  .tower-confetti { display:none; }
  .floor-result-dialog[data-run-complete='true'] .result-reward[data-animate='true'] .result-reward-piece,
  .floor-result-dialog[data-run-complete='true'] .result-reward[data-animate='true']::before { animation:none; }
  .result-reward[data-animate]::before, .result-reward[data-animate] .result-reward-piece, .result-reward[data-animate] .result-spark { animation:none; }
  .result-reward[data-tone='loss'][data-animate='true']::before, .result-reward[data-tone='loss'][data-animate='true'] .result-reward-piece, .result-life-lost { animation:none; }
}
.shared-challenge-content h2, .confirm-dialog-title { line-height: 1.15; }
.shared-challenge-content > .shared-challenge-difficulty { font-size: .9375rem; letter-spacing: 0; border-radius: 8px; }

/* The existing ascent animation now travels through a slate-and-brass scene. */
.tower-frame {
  background-image: linear-gradient(90deg, #071018d9 0%, #07101870 42%, #07101814 100%), url('/tower-ascent-v2.webp');
  background-color: #0c1927;
  background-repeat: no-repeat;
  background-position: center, right center;
  background-size: cover, cover;
}

.tower-step-run[data-state='cleared'], .tower-step-run[data-state='champion'] {
  --tower-step-accent: #d9a85b;
  --tower-step-node-ring: #d9a85b99;
  --tower-step-node-core: #d9a85b;
  --tower-step-connector: #d9a85b55;
  --tower-step-chip-border: #d9a85b55;
  --tower-step-chip-bg: #243446;
  --tower-step-chip-ink: #f0c276;
  --tower-step-caption-ink: #b5c3d2;
  --tower-step-icon-ink: #f0c276;
}
.tower-list::before { background: linear-gradient(#f0c276, #a47c40); }
.tower-check::before { background: none; }
.feedback-banner[data-tone='win'] { color: #f3ecdf; border-color: #d9a85b77; background: #253345; }
body[data-run-status='won'] .run-summary { background: var(--panel-strong); border-color: var(--accent); }
body[data-run-status='won'] .board-shell { box-shadow: 0 0 0 1px #d9a85b77, 0 6px 18px #0004; }
.tower-hud-step[data-state='cleared'], .tower-hud-step[data-state='champion'] { background: #d9a85b55; border-color: #d9a85b77; }
@keyframes arenaFlashWin {
  0%, 100% { box-shadow: 0 12px 32px #0003; }
  40% { box-shadow: 0 0 0 1px #d9a85b99, 0 0 40px #d9a85b33; }
}

@media (max-width: 899px) {
  .landing-header { flex-direction: column; align-items: stretch; gap: 8px; }
  .landing-nav { justify-content: flex-start; }
  .lobby-copy { max-width: 100%; }
  .lobby-scene::after { opacity: .18; inset: 120px 0 0 40%; }
}

@media (max-width: 699px) {
  .shell { width: calc(100% - 16px); gap: 12px; padding-top: 8px; }
  .lobby-scene { min-height: auto; padding: 16px; gap: 12px; border-radius: 18px; }
  .lobby-scene::after { display: none; }
  /* Raise the whole header above its sibling hero and controls. A high z-index
     inside navigation alone cannot escape the header's stacking context. */
  .lobby-scene > .landing-header { flex-direction: row; align-items: center; gap: 12px; z-index: 20; }
  .landing-navigation { position: static; flex-shrink: 0; }
  .landing-navigation-toggle { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 8px 12px; background: #203145; border: 1px solid #496078; border-radius: 10px; box-shadow: 0 3px 0 #0b1522; font-weight: 700; font-size: .9375rem; cursor: pointer; list-style: none; }
  .landing-navigation-toggle::-webkit-details-marker { display: none; }
  .landing-navigation[open] .landing-nav { position: absolute; z-index: 10; top: calc(100% + 10px); right: 0; display: flex; flex-wrap: wrap; width: min(340px, 100%); padding: 16px; gap: 4px 16px; border: 1px solid #496078; border-radius: 12px; background: #14202d; box-shadow: 0 16px 28px #0008; }
  .landing-navigation[open] .landing-nav > a { flex: 1 1 100%; white-space: normal; }
  .game-brand { font-size: 1.0625rem; white-space: normal; line-height: 1.2; }
  .game-brand img { width: 40px; height: 40px; }
  .landing-nav { min-width: 0; justify-content: flex-start; }
  .landing-nav > a, .locale-nav { flex-shrink: 0; }
  .landing-nav > a { font-size: .9375rem; }
  .lobby-utility-row { flex-wrap: nowrap; }
  .lobby-copy { gap: 12px; }
  .lobby-copy h1 { max-width: 18ch; font-size: clamp(1.9rem, 8vw, 2.6rem); line-height: 1.12; }
  .landing-thesis { font-size: .9375rem; line-height: 1.4; }
  .lobby-controls { grid-template-columns: 1fr; gap: 16px; margin-top: 2px; }
  .lobby-start-button { order: initial; min-height: 58px; font-size: 1.125rem; }
  .difficulty-choice { min-height: 66px; padding: 9px 30px 9px 12px; }
  .difficulty-choices { gap: 8px; }
  .difficulty-choice:has(input:checked)::after { right: 9px; }
  .lobby-copy .lede { font-size: .9375rem; }
  .game-stage { gap: 10px; }
  .match-hud { display: contents; }
  .match-hud-main { padding: 4px 6px; gap: 12px; }
  .match-copy h2 { font-size: clamp(1.6rem, 6.5vw, 2rem); line-height: 1.15; }
  .challenge-subtitle { font-size: .9375rem; margin-top: 4px; }
  .match-hud-sidecar { margin: 0; }
  .board-panel, body[data-screen='game'] .board-panel { padding: 10px 6px; gap: 10px; border-radius: 14px; }
  .board-header { padding: 0 4px; gap: 12px; margin: 0; }
  .board-header .hud-chip-lives { min-height: 44px; padding: 0; }
  .clock-box { min-height: 50px; padding: 7px 12px; min-width: 112px; border-radius: 10px; }
  #clock { font-size: 2rem; line-height: 1; }
  .board-shell { padding: 3px; border-radius: 8px; }
  .board-status { font-size: 1rem; }
  body[data-screen='game'] { padding-bottom: calc(154px + env(safe-area-inset-bottom)); }
  body[data-screen='game'] .game-action-dock {
    width: min(calc(100vw - 16px), 560px);
    bottom: calc(8px + env(safe-area-inset-bottom));
    padding: 10px 10px 14px;
    gap: 10px;
    border-color: var(--border);
    border-radius: 16px;
    background: #14202d;
    backdrop-filter: none;
    box-shadow: 0 -8px 28px #0005;
  }
  .battle-menu { border-radius: 14px; }
  .battle-menu-summary { padding: 14px; }
  .battle-card { padding: 14px; border-radius: 10px; }
  .takeover-dialog-card { padding: 18px; }
  .takeover-player-badge-name { font-size: 1rem; }
  .takeover-dialog-actions { display: flex; }
  .takeover-objective { padding: 20px 0; }
  .takeover-objective-value { font-size: 2.25rem; }
  .floor-result-card { padding: 24px 18px 20px; gap: 16px; border-radius: 18px; }
  .floor-result-copy h2 { font-size: clamp(1.85rem, 8vw, 2.4rem); }
  .floor-result-actions { grid-template-columns: 1fr; }
}

.analysis-dialog { --review-good: #91b2dc; }
@media (max-width: 760px) {
  .analysis-surface { padding-bottom: calc(max(180px, var(--analysis-controls-height, 180px)) + 24px); }
}

@media (prefers-reduced-motion: reduce) {
  .primary, .secondary, .audio-toggle { transition: none; }
}

/* Compact pre-game card. The source position stays fully concealed. */
.takeover-dialog::backdrop { background: #071018; backdrop-filter: none; }
.takeover-dialog { width: min(calc(100vw - 24px), 480px); border-radius: 24px; }
.takeover-dialog-card { padding: 28px; gap: 22px; border-radius: 24px; grid-template-rows: auto; background: #14202d; }
.takeover-dialog-copy { gap: 28px; grid-template-rows: auto; }
.takeover-dialog-rail { padding: 0; gap: 12px; }
.takeover-dialog-floor { border: 0; padding: 0; font-size: .9375rem; letter-spacing: .04em; }
.takeover-lives { display: flex; gap: 6px; font-size: 1.4rem; line-height: 1; }
.takeover-objective { padding: 0; gap: 8px; justify-items: start; text-align: left; }
.takeover-objective-label { text-transform: none; letter-spacing: 0; color: #a6b4c4; }
.takeover-objective-value { font: 800 clamp(2.25rem, 8vw, 3rem)/1.1 var(--font-ui); text-transform: none; letter-spacing: -.035em; }
.takeover-player-row { display: block; min-height: 0; padding: 0; border: 0; }
.takeover-player-badge-hero[data-side] { grid-column: auto; grid-row: auto; display: block; }
.takeover-player-badge-swatch { width: 24px; height: 28px; flex: 0 0 24px; border-radius: 0; }
.takeover-player-badge-swatch[data-side] { background:transparent; border:0; box-shadow:none; }
.takeover-player-badge-swatch[data-side]::after { display:none; }
.takeover-simple-piece { display:block; width:100%; height:100%; padding:0; }
.takeover-objective .takeover-eval { width:82%; margin:4px 0 0; }
.takeover-objective .takeover-eval-bar { height:6px; min-height:0; border:0; border-radius:3px; box-shadow:none; }
.takeover-objective #takeover-eval-hero { background:#f0c276; }
.takeover-objective #takeover-eval-opponent { background:#3c4c5c; }
.takeover-mission { margin:0; font-size:1.125rem; font-weight:600; line-height:1.4; color:#f3ecdf; }
.takeover-mission strong { color:#f0c276; white-space:nowrap; }
.takeover-player-badge-details { gap: 10px; }
.takeover-player-lead { color:#a6b4c4; font-size:1rem; line-height:1.4; }
.takeover-player-badge-side { font-size: .9375rem; font-weight: 400; text-transform: none; letter-spacing: 0; color: #a6b4c4; line-height: 1.35; }
.takeover-player-badge-name { margin:0; font-size: clamp(1.65rem, 6.8vw, 2rem); font-weight: 800; line-height:1.16; letter-spacing:-.025em; color:#f3ecdf; text-wrap:balance; }
.takeover-facts { display: grid; margin: -4px 0 -8px; padding: 0; border:0; font-size: .9375rem; }
.takeover-facts > div { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.takeover-facts dt { color: #a6b4c4; }
.takeover-facts dd { margin: 0; display:flex; align-items:center; gap:8px; font-weight:400; color:#a6b4c4; }
.takeover-clock { width:14px; height:14px; border:1.5px solid currentColor; border-radius:50%; position:relative; }
.takeover-clock::after { content:''; position:absolute; width:4px; height:4px; left:5px; top:2px; border-left:1.5px solid currentColor; border-bottom:1.5px solid currentColor; }
.takeover-dialog-actions { display: flex; margin: 0; }
.takeover-dialog-actions button { width: 100%; }
.takeover-source { border-top: 1px solid #334657; padding-top: 16px; color: #a6b4c4; font-size: .875rem; line-height: 1.5; }
.takeover-source > span { font-weight: 650; }
.takeover-source p { margin: 4px 0 0; overflow-wrap: anywhere; }
.takeover-source-move { display:block; }
.takeover-source .takeover-dialog-badge { max-width: none; font-size: .875rem; font-weight: 400; color: #a6b4c4; letter-spacing: 0; text-shadow: none; line-height: 1.5; }
.takeover-dialog [hidden] { display: none !important; }
@media (max-width: 600px) {
  .takeover-dialog-card { padding: 24px; gap: 22px; }
  .takeover-dialog-copy { gap: 26px; }
}

/* The landing footer is part of the same public-facing navigation. */
body[data-screen='lobby'] .site-footer { border-top: 1px solid var(--border); padding: 24px 4px; gap: 20px; }
.site-footer-copy { max-width: 70ch; gap: 10px; }
.site-footer nav { gap: 8px 20px; }
.site-footer a { text-decoration-thickness: 1px; }
body[data-screen='lobby'] .landing-thesis { padding-left: 16px; border-left: 3px solid var(--accent); color: var(--ink); }

/* One scroll surface per dialog, including short windows and browser toolbars. */
.primary[hidden], .secondary[hidden], .audio-toggle[hidden] { display: none; }

.confirm-dialog, .takeover-dialog, .floor-result-dialog, .shared-challenge-dialog {
  max-height: calc(100svh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 12px;
}
.takeover-dialog-card, .shared-challenge-card {
  max-height: none;
  overflow: visible;
}

@media (max-width: 699px) {
  /* Reserve the phone's height for the board; live turn/status text stays below it. */
  body[data-screen='game'] .challenge-subtitle { display: none; }
  body[data-screen='game'] .board-panel { padding-block: 8px; gap: 8px; }
  body[data-screen='game'] .clock-box { min-height: 42px; min-width: 100px; padding: 5px 10px; }
  body[data-screen='game'] #clock { font-size: 1.8rem; }
  body[data-screen='game'] { padding-bottom: calc(94px + env(safe-area-inset-bottom)); }
  body[data-screen='game'][data-game-mode='shared'] {
    padding-bottom: calc(var(--challenge-dock-height, 160px) + 16px + env(safe-area-inset-bottom));
  }
  body[data-screen='game'] .game-action-dock {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 8px 8px 12px;
    gap: 8px;
  }
  body[data-screen='game'] .game-action-dock button {
    min-height: 52px;
    padding: 9px 8px;
    font-size: 1rem;
  }
  body[data-screen='game'] .game-action-dock [data-challenge-return-link] { grid-column: 1 / -1; }
  body[data-screen='game'] .board-shell {
    --board-shell-size: var(--mobile-board-size, calc(100svh - 350px));
  }
  .shared-challenge-invite-layout { gap: 12px; padding: 16px; }
  .shared-challenge-board-column { width: min(100%, 260px, max(120px, calc(100svh - 380px))); }
  .shared-challenge-board-frame { width: 100%; }
  .shared-challenge-content > .shared-challenge-difficulty { margin-top: 12px; }
  .shared-challenge-actions { margin-top: 16px; }
}

/* Very short windows need document scrolling instead of a dock over the board. */
@media (max-width: 699px) and (max-height: 550px) {
  body[data-screen='game'] { padding-bottom: env(safe-area-inset-bottom); }
  body[data-screen='game'] .game-action-dock {
    position: static;
    transform: none;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  body[data-screen='game'] .board-shell { --board-shell-size: min(100%, max(160px, calc(100svh - 220px))); }
}

@media (min-width: 700px) and (max-height: 600px) {
  body[data-screen='game'] { --board-shell-size: 320px; }
}

/* Result actions: playing and reviewing lead; exporting stays a quiet utility. */
.shared-challenge-result-card .shared-challenge-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
#shared-result-start-tower, .result-sharing-actions,
.shared-challenge-result-card [data-challenge-return-link] { grid-column: 1 / -1; }
.shared-challenge-result-card .shared-challenge-actions > button { min-width: 0; padding-inline: 12px; }
.result-sharing-actions { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; }
.result-utility-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 130px;
  min-width: 0;
  min-height: 44px;
  padding: 8px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: 600 .875rem/1.4 var(--font-ui);
  cursor: pointer;
}
.result-utility-action:hover:not(:disabled) { color: var(--ink); background: #ffffff08; }
.result-utility-action[hidden] { display: none; }
.result-utility-action .share-icon { flex-shrink: 0; width: 18px; height: 18px; }

.share-action[aria-busy='true'] { opacity: 1; }
.share-action[aria-busy='true'] svg { display: none; }
.share-action[aria-busy='true']::before {
  content: '';
  flex: 0 0 15px;
  width: 15px;
  height: 15px;
  border: 2px solid #9daaba40;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: result-gif-spin .8s linear infinite;
}
@keyframes result-gif-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .share-action[aria-busy='true']::before { animation: none; }
}

/* Keep action feedback clear of the last result button. */
.shared-challenge-content > .share-feedback { margin: 12px 0 0; line-height: 1.4; }

/* Shared artwork for home, briefing, board HUD, tower and result lives.
   Keep this in the existing game stylesheet: running servers can still serve
   an older HTML shell without links to newly added stylesheets. */
.life-heart {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  vertical-align: middle;
}

/* Default for briefing hearts; existing context sizes take precedence. */
:where(.life-heart) { width: 1em; height: 1em; }

.life-heart::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url('/life-heart.svg?v=20261008b') center / contain no-repeat;
  filter: drop-shadow(0 2px 1px #0005);
}

.life-heart[data-state='lost']::before {
  filter: grayscale(1) brightness(.55) drop-shadow(0 1px 1px #0004);
  opacity: .65;
}

.result-life-lost::before { animation: life-heart-fade 850ms ease-out both; }
.floor-result-dialog[data-run-lost='true'] .result-life-lost::before { animation-duration: 1400ms; }

@keyframes life-heart-fade {
  0%, 20% { filter: drop-shadow(0 2px 1px #0005); opacity: 1; }
  100% { filter: grayscale(1) brightness(.55) drop-shadow(0 1px 1px #0004); opacity: .65; }
}

@media (prefers-reduced-motion: reduce) {
  .result-life-lost::before,
  .floor-result-dialog[data-run-lost='true'] .result-life-lost::before { animation: none; }
}
