/* Shared chrome for all minigame pages: HUD, toast, overlay,
   legend chips, leaderboard. Game-specific canvas/color rules stay in each
   game's own stylesheet (e.g. degen-pong.css, gains-stacker.css). */

.game-body { background: var(--bg); }

.game-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 50px 6vw 90px;
  text-align: center;
}

.game-title {
  font-size: clamp(2.2rem, 8vw, 3.4rem);
  margin-bottom: 14px;
}
.game-title .hl {
  background: linear-gradient(90deg, var(--amber), var(--red));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.game-switcher {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 auto 24px;
}
.game-switch-tab {
  font-weight: 800;
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--muted);
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.game-switch-tab:hover { color: var(--text); border-color: var(--amber); }
.game-switch-tab.is-active {
  background: var(--amber);
  color: #1a1200;
  border-color: #000;
  box-shadow: 3px 3px 0 #000;
}

.game-sub {
  color: var(--muted);
  font-size: 15px;
  max-width: 440px;
  margin: 0 auto 30px;
  line-height: 1.6;
}


.game-hud {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.hud-stat {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px 22px;
  min-width: 100px;
}
.hud-label {
  display: block;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.hud-value {
  display: block;
  font-family: 'Anton', sans-serif;
  font-size: 26px;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}

.game-stage {
  position: relative;
  max-width: 500px;
  margin: 0 auto;
  border-radius: 20px;
  overflow: hidden;
  border: 3px solid #000;
  box-shadow: var(--shadow-hard);
  touch-action: none;
}

.game-toast {
  position: absolute;
  top: 14%;
  left: 50%;
  transform: translate(-50%, -10px);
  font-family: 'Anton', sans-serif;
  font-size: clamp(1.4rem, 6vw, 2.2rem);
  color: #fff;
  text-shadow: 0 3px 0 #000, 0 0 20px rgba(0,0,0,0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.3s ease;
  white-space: nowrap;
}
.game-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 8, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.game-overlay[hidden] { display: none; }
.overlay-card {
  background: var(--panel);
  border: 3px solid #000;
  border-radius: 18px;
  box-shadow: var(--shadow-hard);
  padding: 32px 28px;
  text-align: center;
  max-width: 320px;
}
.overlay-card h2 {
  font-family: 'Anton', sans-serif;
  font-size: 1.8rem;
  color: var(--amber);
  margin: 0 0 12px;
}
.overlay-card p {
  color: var(--text);
  font-size: 15px;
  margin: 6px 0;
}
#overlay-best { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
#btn-replay { margin-top: 8px; }

.game-hint {
  color: var(--muted);
  font-size: 12.5px;
  max-width: 420px;
  margin: 22px auto 0;
  line-height: 1.6;
}

.game-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 20px auto 0;
  max-width: 480px;
}
.legend-chip {
  font-size: 11px;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--muted);
  letter-spacing: 0.3px;
}
.legend-moon { color: #6fb98f; border-color: #6fb98f; }
.legend-10x { color: #f0a94e; border-color: #f0a94e; }
.legend-diamond { color: #5ec4c9; border-color: #5ec4c9; }
.legend-paper { color: #d9c3a3; border-color: #d9c3a3; }
.legend-rekt { color: #d9634f; border-color: #d9634f; }
.legend-rug { color: #b3735f; border-color: #b3735f; }

.leaderboard {
  margin: 30px auto 0;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 18px 20px;
  text-align: left;
}
.leaderboard-title {
  font-family: 'Anton', sans-serif;
  font-size: 16px;
  letter-spacing: 0.5px;
  color: var(--amber);
  margin: 0 0 10px;
  text-align: center;
}
.leaderboard-sub {
  font-family: inherit;
  font-weight: 600;
  font-size: 11px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}
.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: rank;
}
.leaderboard-list li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--panel-border);
  font-size: 13.5px;
}
.leaderboard-list li:last-child { border-bottom: none; }
/* Your own row, so you can find yourself on a board of twenty-five. */
.leaderboard-list li.is-you {
  background: rgba(255, 183, 3, 0.08);
  border-radius: 8px;
  padding-left: 6px;
  padding-right: 6px;
  margin: 0 -6px;
}
.leaderboard-list li.is-you .lb-addr { color: var(--amber); }
.leaderboard-list li.is-you::before { color: var(--amber); }
.leaderboard-list li::before {
  content: counter(rank);
  font-family: 'Anton', sans-serif;
  font-size: 13px;
  color: var(--muted);
  width: 18px;
  flex-shrink: 0;
  text-align: center;
}
.leaderboard-list .lb-addr {
  flex: 1;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.leaderboard-list .lb-score {
  font-family: 'Anton', sans-serif;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}
.leaderboard-list .lb-meta {
  font-size: 11px;
  color: var(--muted);
}
.leaderboard-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  margin: 4px 0 0;
}

.game-footnote {
  color: var(--muted);
  font-size: 12px;
  max-width: 440px;
  margin: 26px auto 0;
  line-height: 1.6;
}

/* ---- Rails ----
   Wrappers that exist purely so the desktop grid below has something to put
   in its side columns. `display: contents` makes them invisible to layout
   everywhere else, so a phone lays the page out exactly as if they were
   never in the markup. */
.game-rail { display: contents; }

/* ---- Desktop ---------------------------------------------------------
   One narrow centred column is right for a phone and wrong for a monitor:
   the board lands below the fold with a thousand pixels of dead black on
   either side of it, so you scroll to play and lose sight of your score.
   Wide viewports get the arcade-cabinet treatment instead -- the board
   sized off the viewport's HEIGHT so the whole thing is visible at once,
   flanked by a score panel on the left and the rules and leaderboard on
   the right. */
@media (min-width: 1040px) {
  .game-page:not(.tycoon-page) {
    max-width: 1280px;
    padding: 30px 36px 46px;
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr) 280px;
    /* Rows 1-3 hug their content and row 4 soaks up whatever height the
       board has left over, so the score panel sits directly under the
       blurb instead of being pushed halfway down the board's shadow. */
    grid-template-rows: auto auto auto 1fr;
    column-gap: 36px;
    justify-content: center;
    align-items: start;
  }

  /* Only the title and the game tabs run across the top; the blurb drops
     into the left rail, because every line of centred prose above the
     board is a line the board itself does not get. */
  .game-page:not(.tycoon-page) .game-head { display: contents; }
  :not(.tycoon-page) > .game-head > .game-title { grid-column: 1 / -1; grid-row: 1; }
  .game-page:not(.tycoon-page) .game-switcher { grid-column: 1 / -1; grid-row: 2; margin-bottom: 22px; }
  .game-page:not(.tycoon-page) .game-sub {
    grid-column: 1;
    grid-row: 3;
    max-width: none;
    margin: 0 0 18px;
    text-align: left;
    font-size: 14px;
  }

  .game-rail {
    display: flex;
    flex-direction: column;
    gap: 20px;
    text-align: left;
  }
  .game-rail-left { grid-column: 1; grid-row: 4; }
  .game-stage { grid-column: 2; grid-row: 3 / 5; }
  .game-rail-right { grid-column: 3; grid-row: 3 / 5; }

  /* A row of chips becomes a scoreboard: one line per stat, label left,
     number right, tabular figures already keeping the digits from
     jittering as they count up. */
  .game-rail-left .game-hud {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 0;
  }
  .game-rail-left .hud-stat {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    width: 100%;
    padding: 11px 18px;
  }
  .game-rail-left .hud-label { font-size: 11.5px; }
  .game-rail-left .hud-value { font-size: 27px; line-height: 1; }

  .game-rail-right .game-hint,
  .game-rail-right .game-footnote {
    max-width: none;
    margin: 0;
    text-align: left;
  }
  .game-rail-right .game-legend {
    max-width: none;
    margin: 0;
    justify-content: flex-start;
  }
  .game-rail-right .leaderboard { max-width: none; margin: 0; }
  /* "this browser, for now" trails the title on a wide page; in a 280px
     rail it wraps into the middle of it, so give it its own line. */
  .game-rail-right .leaderboard-sub { display: block; margin-top: 3px; }

  /* The canvases are a fixed 5:7 portrait, so the board is sized by picking
     a width and letting the aspect ratio derive the height. The three terms
     are the three things that can limit it: the column it sits in, its own
     native 500px, and the viewport height (converted through the 5:7), which
     is the one that actually keeps the whole board above the fold. The
     max() floor stops a very short window shrinking it to nothing -- there,
     a little page scroll is the better trade. */
  .game-stage {
    justify-self: center;
    max-width: none;
    width: min(100%, 500px, max(300px, calc((100vh - 268px) * 5 / 7)));
    aspect-ratio: 5 / 7;
    height: auto;
    margin: 0;
  }
  .game-stage canvas {
    width: 100%;
    height: 100%;
  }
}
