/* Full-screen pages: Leaderboard and Arcade mode everywhere; the title and
   the end card too on compact screens (phones: max-width 720px or
   max-height 500px, see COMPACT_QUERY in game/game-ui.js).
   Every page is a Back bar, a body that scrolls on its own, and a footer
   pinned to the bottom, so nothing important can be pushed off screen. */
.menu-page {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: linear-gradient(rgba(6, 18, 34, 0.84), rgba(6, 18, 34, 0.94)), var(--page-art, none) center / cover no-repeat, #0b1a2a;
  color: #fff;
}
.page-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: rgba(4, 15, 26, 0.72); border-bottom: 2px solid rgba(255, 214, 92, 0.35); }
.page-back {
  min-height: 44px;
  padding: 0 16px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.page-back:active { transform: translateY(1px); }
.page-title { margin: 0; color: #ffdc6b; font-family: "Courier New", monospace; font-size: 20px; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase; }
.page-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.page-content { display: grid; gap: 12px; width: min(760px, 100%); margin: 0 auto; padding: 14px; box-sizing: border-box; }
.page-note { margin: 0; color: #c8ddeb; font-size: 14px; font-weight: 700; line-height: 1.4; text-align: center; }
.page-foot { display: grid; justify-items: center; gap: 8px; padding: 10px 14px 12px; background: rgba(4, 15, 26, 0.88); border-top: 2px solid rgba(255, 255, 255, 0.12); }
.page-foot > * { width: min(760px, 100%); box-sizing: border-box; }
.page-keys { margin: 0; color: #9fc0d6; font-size: 12px; font-weight: 700; text-align: center; }
.uses-touch .page-keys { display: none; }
.uses-touch .menu-page .page-foot:has(> .page-keys:only-child) { display: none; }

/* Arcade mode's Play / Clears tabs sit at the right of the Back bar. */
.page-bar { flex-wrap: wrap; row-gap: 8px; }
/* Centred in the bar (on its own centred row on narrow phones, below). */
.page-bar { position: relative; }
.arcade-tabs { position: absolute; left: 50%; top: 50%; display: flex; gap: 6px; transform: translate(-50%, -50%); }
.arcade-tab { min-height: 40px; padding: 0 18px; border: 2px solid rgba(255, 255, 255, 0.4); border-radius: 999px; background: transparent; color: #d7e9f5; font: inherit; font-size: 15px; font-weight: 900; letter-spacing: 0.04em; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.arcade-tab.is-active { background: #ffd65c; border-color: #ffd65c; color: #2a1d00; }
/* Clears: how far every player has got. */
.clears-status { margin: 0; color: #ffdc6b; font-size: 14px; font-weight: 900; text-align: center; }
.clears-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.clears-list li { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; grid-template-areas: "rank name stage" "rank pips pips"; column-gap: 10px; row-gap: 4px; align-items: center; padding: 8px 12px; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 10px; background: rgba(8, 24, 40, 0.8); color: #fff; }
.clears-list li.is-me { border-color: #ffd65c; box-shadow: 0 0 0 2px rgba(255, 214, 92, 0.3); }
.clears-list .rank { grid-area: rank; font-size: 16px; }
.clears-list .name { grid-area: name; font-size: 15px; font-weight: 700; }
.clears-stage { grid-area: stage; color: #ffdc6b; font-size: 13px; font-weight: 900; text-align: right; }
.clears-pips { grid-area: pips; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; }
.clears-pips i { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.16); }
.clears-pips i.is-lit { background: #ffd65c; }
.arcade-warning { justify-self: center; margin: 0; padding: 8px 14px; border: 2px solid #ffd65c; border-radius: 8px; background: rgba(255, 214, 92, 0.12); color: #ffdc6b; font-size: 14px; font-weight: 900; line-height: 1.35; text-align: center; }
.menu-page .leaderboard-card-menu { position: static; display: grid; grid-template-rows: auto auto auto auto; width: 100%; max-width: none; padding: 12px 14px; box-sizing: border-box; text-align: left; }
.menu-page .leaderboard-list li { font-size: 15px; }

/* Arcade: worlds as picture cards, then that world's stages, then Start. */
.world-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.world-card { position: relative; display: grid; grid-template-rows: auto auto; padding: 0; border: 3px solid rgba(255, 255, 255, 0.25); border-radius: 10px; overflow: hidden; background: #0b1a2a; color: #fff; font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; text-align: left; }
.world-card-art { aspect-ratio: 16 / 9; background: var(--world-art) center / cover no-repeat, #1c3a58; }
.world-card-name { display: grid; padding: 5px 8px 6px; font-size: 12px; font-weight: 700; line-height: 1.25; }
.world-card-number { color: #ffdc6b; font-size: 11px; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; }
.world-card.is-active { border-color: #ffd65c; box-shadow: 0 0 0 3px rgba(255, 214, 92, 0.35); }
.world-card.is-locked { cursor: default; opacity: 0.55; }
.world-card.is-locked .world-card-art { filter: grayscale(1) brightness(0.5); }
.world-card.is-locked::after { content: "\1F512"; position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%); font-size: 26px; }
.stage-tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.stage-tile { display: grid; gap: 2px; min-height: 50px; padding: 6px; border: 2px solid rgba(255, 255, 255, 0.25); border-radius: 8px; background: #102a43; color: #fff; font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.stage-tile-label { color: #ffdc6b; font-size: 11px; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; }
.stage-tile-name { font-size: 11px; font-weight: 700; line-height: 1.2; }
.stage-tile.is-boss { background: #3a1620; }
.stage-tile.is-active { border-color: #ffd65c; background: #ffd65c; color: #2a1d00; }
.stage-tile.is-active .stage-tile-label { color: #4f171c; }
.stage-tile.is-locked { opacity: 0.45; cursor: default; }
/* The Round Tower's floors (8-C): one tile per boss, under the stage row. */
.floor-tiles { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
.stage-tile.is-floor { background: #1d1433; border-color: rgba(232, 195, 90, 0.45); }
.stage-tile.is-floor.is-active { background: #e8c35a; border-color: #fff1b8; color: #1a1230; }
.arcade-start { min-height: 52px; padding: 8px 28px; font-size: 1.1rem; }
.arcade-actions { display: flex; justify-content: center; align-items: stretch; gap: 10px; }
/* Watch replays: bright and next to Start, so nobody misses it; greyed with a lock until the stage is cleared. */
.arcade-replays { min-height: 52px; padding: 8px 22px; font-size: 1.05rem; font-weight: 900; background: #56d6ff; color: #04263a; border: 2px solid #b8f0ff; box-shadow: 0 0 0 3px rgba(86, 214, 255, 0.25); }
.arcade-replays.has-replays { animation: replays-glow 1.8s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .arcade-replays.has-replays { animation: none; } }
@keyframes replays-glow { 0%, 100% { box-shadow: 0 0 0 3px rgba(86, 214, 255, 0.25); } 50% { box-shadow: 0 0 0 7px rgba(86, 214, 255, 0.45); } }
.arcade-replays:disabled { background: rgba(255, 255, 255, 0.1); color: rgba(255, 255, 255, 0.55); border-color: rgba(255, 255, 255, 0.25); box-shadow: none; animation: none; cursor: default; }
/* Replays: one row per player, fastest first, each with a Watch button. */
.replays-list li.is-active { border-color: #7fd3ff; }
.replay-watch { min-height: 38px; padding: 4px 16px; font-weight: 900; }
.replay-watch.is-active { background: #ffd65c; border-color: #ffd65c; color: #2a1d00; }

/* Compact title page: the painting fills the screen, sign on top, menu under. */
.title-screen.as-page {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 16px;
  overflow-y: auto;
  border-radius: 0;
  background-color: #0b1a2a;
  background-size: cover;
  background-position: center;
}
.title-screen.as-page .title-sign { width: min(440px, 92%); padding: 12px 18px; flex: 0 0 auto; }
.title-screen.as-page .title-sign h1 { font-size: 1.45rem; text-shadow: 3px 3px 0 #24364f; }
.title-screen.as-page .title-menu-slot { width: 100%; flex: 0 0 auto; }
.title-screen.as-page .title-menu { width: min(360px, 88%); gap: 12px; }
.title-screen.as-page .menu-item { min-height: 58px; font-size: 1.2rem; }

/* Compact end card: its own page with a big Continue. */
.overlay.end-card.as-page { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; border-radius: 0; overflow-y: auto; background: linear-gradient(rgba(6, 18, 34, 0.9), rgba(6, 18, 34, 0.97)), #0b1a2a; }
.overlay.end-card.as-page .overlay-card { margin: auto; width: min(420px, 92%); max-height: none; padding: 24px 18px; gap: 12px; }
.overlay.end-card.as-page .overlay-card h1 { font-size: 30px; }
.overlay.end-card.as-page .overlay-actions .btn { min-height: 54px; min-width: 200px; font-size: 1.1rem; }

@media (max-width: 720px) {
  .arcade-tab { min-height: 36px; padding: 0 14px; font-size: 14px; }
  .arcade-tabs { position: static; flex-basis: 100%; justify-content: center; transform: none; }
  .world-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .world-card-name { font-size: 11px; padding: 4px 6px 5px; }
  .stage-tiles { gap: 5px; }
  .floor-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .stage-tile { min-height: 46px; padding: 4px 2px; }
  .stage-tile-label { font-size: 10px; letter-spacing: 0.02em; }
  .stage-tile-name { display: none; }
  .page-title { font-size: 17px; }
  .arcade-warning { font-size: 13px; }
}
/* Sideways phones: slim bars, all 8 worlds in one row, stages and Start on
   one footer line, the title's sign beside its menu. */
@media (orientation: landscape) and (max-height: 500px) {
  .page-bar { padding: 6px 12px; }
  .arcade-tab { min-height: 34px; }
  .clears-list li { padding: 5px 10px; }
  .page-back { min-height: 38px; font-size: 14px; }
  .page-title { font-size: 16px; }
  .page-content { padding: 8px 12px; gap: 8px; }
  .page-note { display: none; }
  .arcade-warning { font-size: 12px; padding: 5px 10px; }
  .world-cards { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
  .world-card { border-width: 2px; }
  .world-card-name { display: none; }
  .world-card.is-locked::after { top: 50%; font-size: 18px; }
  .page-foot { grid-template-columns: minmax(0, 1fr) auto; align-items: center; padding: 6px 12px 8px; gap: 8px; }
  .page-foot > * { width: auto; }
  .page-foot .page-keys { grid-column: 1 / -1; }
  .stage-tile { min-height: 42px; }
  .stage-tile-name { display: none; }
  .arcade-start { min-height: 44px; padding: 4px 18px; font-size: 1rem; white-space: nowrap; }
  .arcade-replays { min-height: 44px; padding: 4px 14px; white-space: nowrap; }
  .title-screen.as-page { flex-direction: row; gap: 24px; padding: 12px 20px; }
  .title-screen.as-page .title-sign { width: min(360px, 46%); }
  .title-screen.as-page .title-sign h1 { font-size: 1.2rem; }
  .title-screen.as-page .title-menu-slot { width: min(320px, 44%); }
  .title-screen.as-page .title-menu { width: 100%; gap: 8px; }
  .title-screen.as-page .menu-item { min-height: 48px; font-size: 1.05rem; }
  .overlay.end-card.as-page .overlay-card { padding: 14px 18px; gap: 6px; }
  .overlay.end-card.as-page .overlay-card h1 { font-size: 24px; margin: 0; }
  .overlay.end-card.as-page .overlay-actions .btn { min-height: 46px; }
}

/* The ending: the painting fills the end screen, Circle's last word fades
   in across the top, and the result card rises at the bottom a moment
   later. Wide screens (inside the game picture) and phone pages alike. */
.ending-line { display: none; }
.overlay.end-card.is-won { align-items: end; background: linear-gradient(rgba(6, 18, 34, 0) 70%, rgba(6, 18, 34, 0.55)), var(--ending-art, none) center / cover no-repeat, #0b1a2a; }
.end-card.is-won .ending-line {
  position: absolute;
  top: 5%;
  left: 50%;
  display: grid;
  gap: 4px;
  width: min(640px, 90%);
  margin: 0;
  padding: 12px 18px;
  transform: translateX(-50%);
  border: 3px solid #14344f;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: #16111f;
  font-family: "Courier New", monospace;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.3;
  text-align: center;
  box-shadow: 5px 5px 0 rgba(20, 52, 79, 0.4);
  animation: endingLine 0.7s ease-out 0.6s both;
}
.ending-speaker { color: #3b3470; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; }
.end-card.is-won .overlay-card { margin-bottom: 4%; background: rgba(8, 24, 40, 0.88); animation: endingCard 0.6s ease-out 3s both; }
/* Wide screens: the card waits in the corner, clear of the brothers. */
.overlay.end-card.is-won:not(.as-page) { justify-items: end; }
.overlay.end-card.is-won:not(.as-page) .overlay-card { width: min(340px, 38%); margin: 0 3% 3% 0; padding: 14px 16px; gap: 6px; }
.overlay.end-card.is-won:not(.as-page) .overlay-card h1 { font-size: 24px; margin: 0; }
@keyframes endingLine { from { opacity: 0; transform: translate(-50%, -12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes endingCard { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
.overlay.end-card.as-page.is-won { justify-content: flex-end; padding-bottom: 12px; }
.overlay.end-card.as-page.is-won .overlay-card { margin: 0 auto; }
@media (max-width: 720px), (max-height: 500px) {
  .end-card.is-won .ending-line { font-size: 15px; padding: 8px 12px; top: 3%; }
  .end-card.is-won .overlay-card { padding: 12px 16px; gap: 6px; }
  .end-card.is-won .overlay-card h1 { font-size: 22px; margin: 0; }
}
@media (orientation: landscape) {
  .overlay.end-card.as-page.is-won { align-items: flex-end; padding: 0 3% 3% 0; }
  .overlay.end-card.as-page.is-won .overlay-card { width: min(320px, 42%); margin: 0; }
}
/* Upright phones: a slim card under the brothers (just the result and Continue). */
@media (orientation: portrait) and (max-width: 720px) {
  .overlay.end-card.as-page.is-won { padding-bottom: 8px; }
  .overlay.end-card.as-page.is-won .overlay-card { width: calc(100% - 16px); padding: 8px 12px; gap: 4px; }
  .end-card.is-won .overlay-card > .panel-title,
  .end-card.is-won .overlay-card > p:not(.overlay-rank) { display: none; }
  .overlay.end-card.as-page.is-won .overlay-actions .btn { min-height: 46px; }
}

/* Rewards page and the pop-up when one is paid (rewards-ui.js). */
.rewards-card { display: grid; gap: 10px; }
.rewards-status { margin: 0; color: #ffe08a; font-size: 15px; font-weight: 800; text-align: center; }
.rewards-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.rewards-list li { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; grid-template-areas: "mark name amount" "mark state state"; column-gap: 10px; row-gap: 2px; align-items: center; padding: 10px 12px; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 10px; background: rgba(8, 24, 40, 0.8); color: #fff; }
.rewards-list li.is-paid { border-color: #7be08f; background: rgba(18, 60, 38, 0.85); }
.rewards-list .reward-mark { grid-area: mark; font-size: 18px; color: #ffd65c; text-align: center; }
.rewards-list li.is-paid .reward-mark { color: #7be08f; }
.rewards-list .reward-name { grid-area: name; font-size: 15px; font-weight: 700; }
.rewards-list .reward-amount { grid-area: amount; font-size: 14px; font-weight: 800; color: #ffe08a; white-space: nowrap; }
.rewards-list .reward-state { grid-area: state; font-size: 12px; color: #b8d4e6; }
.reward-toast { position: fixed; left: 50%; top: 14px; z-index: 40; display: grid; gap: 2px; padding: 10px 18px; border: 2px solid #ffd65c; border-radius: 12px; background: rgba(10, 26, 44, 0.94); color: #fff; font-size: 14px; text-align: center; pointer-events: none; opacity: 0; transform: translate(-50%, -16px); transition: opacity 0.25s, transform 0.25s; }
.reward-toast strong { font-size: 18px; color: #ffe08a; }
.reward-toast.is-shown { opacity: 1; transform: translate(-50%, 0); }
/* Upright phones in play: the note sits in the empty space under the picture
   (above the stick and JUMP), never over the game. */
.uses-touch.is-playing.has-deck .reward-toast { top: calc(var(--deck-top, 0px) + 72px); width: max-content; max-width: calc(100% - 32px); }
/* Sideways phones in play have no empty band: a small one-line pill just
   under the score line instead, over the sky rather than the action. */
.uses-touch.is-playing:not(.has-deck) .reward-toast { top: calc(max(4px, env(safe-area-inset-top)) + 40px); grid-auto-flow: column; align-items: baseline; gap: 8px; padding: 3px 12px; border-width: 1px; border-radius: 999px; font-size: 11px; white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis; }
.uses-touch.is-playing:not(.has-deck) .reward-toast strong { font-size: 12px; }
/* Replay rows: comment count + Watch; a replay's comment thread. */
.replays-list li { grid-template-columns: 44px minmax(0, 1fr) auto auto; grid-template-areas: "rank name stage buttons"; }
.replay-buttons { grid-area: buttons; display: flex; gap: 6px; }
.replay-talk { min-height: 38px; padding: 4px 12px; font-weight: 900; }
.replay-comments { display: grid; gap: 10px; width: min(760px, 100%); margin: 0 auto; }
.comment-top { display: flex; justify-content: space-between; gap: 8px; }
.comment-watch { min-height: 44px; padding: 6px 20px; font-weight: 900; }
.comment-small { min-height: 34px; padding: 2px 12px; font-size: 13px; font-weight: 800; }
.replay-comments-heading { margin: 0; font-size: 16px; font-weight: 900; color: #fff; }
.comment-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.comment-list li { padding: 8px 12px; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 10px; background: rgba(8, 24, 40, 0.85); color: #fff; }
.comment-list li.is-me { border-color: #ffd65c; }
.comment-head { display: flex; gap: 8px; align-items: baseline; }
.comment-time { color: rgba(255, 255, 255, 0.55); font-size: 12px; }
.comment-text { margin: 4px 0 6px; font-size: 15px; line-height: 1.35; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }
.comment-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.comment-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.comment-reply-row { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; color: #7fd3ff; font-size: 13px; font-weight: 800; }
.comment-input { box-sizing: border-box; width: 100%; min-height: 48px; padding: 8px 10px; border: 2px solid rgba(255, 255, 255, 0.35); border-radius: 10px; background: rgba(4, 15, 26, 0.9); color: #fff; font: inherit; font-size: 16px; resize: vertical; user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }
.comment-post { min-height: 48px; padding: 6px 20px; font-weight: 900; }
@media (max-width: 520px) {
  .replays-list li { grid-template-columns: 36px minmax(0, 1fr) auto; grid-template-areas: "rank name buttons" "rank stage buttons"; }
  .replays-list .clears-stage { text-align: left; }
}

/* Replays: This version / Earlier versions (only when a stage changed). */
.replay-version-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 8px; }
.replay-version-tabs[hidden] { display: none; }
.replay-version-note { display: block; font-size: 11px; font-weight: 700; opacity: 0.7; letter-spacing: 0.02em; }
.leaderboard-list .replay-version-note { color: inherit; text-transform: none; overflow: hidden; text-overflow: ellipsis; }
.board-version-tabs { margin: 8px 0 0; }
.replay-retry, .clears-retry { justify-self: center; min-height: 38px; padding: 4px 18px; }
.replay-retry[hidden], .clears-retry[hidden] { display: none; }
