/*
 * arcade.css - shared frame for the games added after the original nine.
 *
 * Loaded alongside styles.css, whose :root tokens (--primary-color, --bg-dark,
 * --accent-color) this builds on. It owns the chrome every game repeats - top
 * bar, HUD chips, buttons, modal - so each game file carries only the CSS that
 * is actually specific to that game.
 */

.arcade-body {
  margin: 0;
  min-height: 100vh;
  /*
   * The thing `user-scalable=no` was really buying these pages was "a fast
   * second tap is a tap, not a zoom". `touch-action: manipulation` buys that
   * on its own and leaves pinch-to-zoom working, which is what the viewport
   * meta was taking away from anyone who needs to magnify a board. Game
   * surfaces that must also swallow drags keep their own `touch-action: none`.
   */
  touch-action: manipulation;
  background:
    radial-gradient(circle at 20% 0%, rgba(157, 78, 221, 0.25), transparent 55%),
    radial-gradient(circle at 85% 100%, rgba(255, 158, 0, 0.15), transparent 50%),
    var(--bg-dark, #1a1a2e);
  color: var(--text-light, rgba(255, 255, 255, 0.9));
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 12px 32px;
  -webkit-tap-highlight-color: transparent;
}

/* Games are click/drag surfaces; text selection just gets in the way. */
.arcade-body.no-select {
  user-select: none;
  -webkit-user-select: none;
}

/*
 * styles.css styles every bare <button> as a 160px-wide pill with 25px of
 * horizontal padding. Games build grids and keyboards out of buttons, where
 * that minimum silently forces horizontal overflow on narrow screens - a
 * six-column grid of buttons cannot be narrower than 960px. Neutralise the two
 * offending properties here.
 *
 * :where() keeps this at zero specificity of its own, so it loses to any class
 * rule - both the .arcade-* controls below and each game's own button styles,
 * which are declared later in their own <style> block.
 */
.arcade-body :where(button) {
  min-width: 0;
  padding: 0;
}

.arcade-topbar {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.arcade-back {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(157, 78, 221, 0.15);
  border: 1px solid rgba(157, 78, 221, 0.35);
  transition: background 0.25s, transform 0.25s;
  white-space: nowrap;
}

.arcade-back:hover {
  background: rgba(157, 78, 221, 0.3);
  transform: translateY(-1px);
}

.arcade-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 0 18px rgba(157, 78, 221, 0.7);
  margin: 0;
}

.arcade-hud {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 14px;
}

.arcade-chip {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(157, 78, 221, 0.3);
  border-radius: 12px;
  padding: 6px 14px;
  min-width: 84px;
  text-align: center;
}

/*
 * 0.62rem is 9.9px, which is what every HUD label on every game rendered at -
 * SCORE, BEST, LIVES - and uppercase with 0.08em tracking is the least legible
 * shape small type can take. The tracking is what makes the caps readable at
 * all, so the size goes up instead of the tracking coming off.
 */
.arcade-chip .label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.72);
}

.arcade-chip .value {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-color, #ff9e00);
  font-variant-numeric: tabular-nums;
}

.arcade-stage {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(157, 78, 221, 0.3);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  position: relative;
}

.arcade-btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--primary-color, #9d4edd), var(--primary-dark, #7b2cbf));
  border: none;
  border-radius: 12px;
  padding: 11px 22px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
  box-shadow: 0 6px 18px rgba(123, 44, 191, 0.4);
}

.arcade-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.arcade-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.arcade-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(157, 78, 221, 0.4);
  box-shadow: none;
}

/* The rules text, and the one paragraph on the page a new player actually has
   to read. 0.8rem at 60% cleared AA on contrast but was still only 12.8px. */
.arcade-note {
  max-width: 560px;
  text-align: center;
  font-size: 0.86rem;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.72);
  margin-top: 16px;
}

/* Overlay used for start screens and game-over cards. */
.arcade-modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 24, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.arcade-modal[hidden] {
  display: none;
}

.arcade-card {
  background: linear-gradient(160deg, #241a3d, #16162b);
  border: 1px solid rgba(157, 78, 221, 0.45);
  border-radius: 20px;
  padding: 26px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  /* The mascot adds ~100px to every card; a long rules card on a short phone
     would otherwise push its buttons off the bottom with no way to reach them. */
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

/*
 * arcade.js injects one of these into every .arcade-card and re-rolls the photo
 * each time the modal opens, so a different michi greets and sees off every
 * run. Games do not add the markup themselves.
 */
.arcade-mascot {
  display: block;
  width: 96px;
  height: 96px;
  margin: 0 auto 14px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(157, 78, 221, 0.55);
  box-shadow: 0 0 26px rgba(157, 78, 221, 0.45);
}

.arcade-card h2 {
  margin: 0 0 10px;
  font-size: 1.4rem;
  color: #fff;
}

.arcade-card p {
  margin: 0 0 16px;
  font-size: 0.88rem;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.75);
}

.arcade-card .big-score {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent-color, #ff9e00);
  display: block;
  margin: 6px 0 4px;
  font-variant-numeric: tabular-nums;
}

.arcade-card .best-flag {
  color: #6ee7b7;
  font-weight: 700;
  font-size: 0.85rem;
}

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

@media (max-height: 620px) {
  .arcade-mascot { width: 64px; height: 64px; margin-bottom: 10px; }
}

@media (max-width: 520px) {
  .arcade-title { font-size: 0.95rem; }
  .arcade-chip { min-width: 70px; padding: 5px 10px; }
  .arcade-stage { padding: 10px; border-radius: 14px; }
}

/*
 * [hidden] has to win here. Several rules above give elements an explicit
 * display (.big-score is display:block), and a class rule beats the UA's
 * [hidden] { display: none }, so a hidden game-over score would stay on screen.
 */
.arcade-body [hidden],
.arcade-modal [hidden] {
  display: none !important;
}

/* ==========================================================================
 * Leaderboards.
 *
 * One set of styles for the three places a board appears: inside the game-over
 * card of the arcade games, inside the overlay the original nine open from a
 * trophy button, and in the grid on leaderboards.html.
 *
 * Everything here is a class selector on purpose. The nine older games load
 * styles.css without .arcade-body, so the bare `button { min-width: 160px }`
 * rule described above is live on those pages and would blow the rename and
 * close controls out to pill width - a class beats an element selector
 * regardless of load order, which is what keeps these small.
 * ========================================================================== */

.arcade-board {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(157, 78, 221, 0.3);
  text-align: left;   /* .arcade-card centres its children; a table must not be */
}

.arcade-board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.arcade-board-title {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  font-weight: 700;
}

.arcade-board-you {
  min-width: 0;
  padding: 3px 9px;
  font: inherit;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(157, 78, 221, 0.18);
  border: 1px solid rgba(157, 78, 221, 0.4);
  border-radius: 999px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arcade-board-you:hover {
  background: rgba(157, 78, 221, 0.32);
  color: #fff;
}

/* No name yet: the chip is the call to action, so it reads as one. */
.arcade-board-you.is-unnamed {
  color: #fff;
  background: rgba(255, 158, 0, 0.22);
  border-color: rgba(255, 158, 0, 0.6);
  font-weight: 700;
}

/* The registered mark. Accounts sign in through Cognito and post under a
   handle nobody else can take; a guest's name is whatever they typed. */
.arcade-board-tick {
  display: inline-block;
  margin-left: 5px;
  font-size: 0.72em;
  font-weight: 700;
  color: #6ee7b7;
  vertical-align: 1px;
}

.arcade-board-rename {
  display: flex;
  gap: 6px;
  flex: 1 1 100%;
}

.arcade-board-rename input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 5px 9px;
  font: inherit;
  font-size: 0.8rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(157, 78, 221, 0.5);
  border-radius: 8px;
}

.arcade-board-save {
  min-width: 0;
  padding: 5px 12px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  background: var(--primary-color, #9d4edd);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.arcade-board-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.arcade-board-row {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.03);
}

/* The player's own row, so a board of strangers still answers "where am I". */
.arcade-board-row.is-me {
  background: rgba(157, 78, 221, 0.28);
  box-shadow: inset 0 0 0 1px rgba(157, 78, 221, 0.55);
}

.arcade-board-rank {
  color: rgba(255, 255, 255, 0.62);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}

.arcade-board-row:nth-child(1) .arcade-board-rank { color: #ffd166; }
.arcade-board-row:nth-child(2) .arcade-board-rank { color: #d8d8e8; }
.arcade-board-row:nth-child(3) .arcade-board-rank { color: #e0925f; }

.arcade-board-name {
  color: rgba(255, 255, 255, 0.9);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arcade-board-score {
  color: var(--accent-color, #ff9e00);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
}

.arcade-board-empty {
  padding: 10px 8px;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.62);
  text-align: center;
}

.arcade-board-note {
  margin: 8px 0 0;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.55);
  text-align: center;
  min-height: 1em;   /* reserve the line so the card does not jump when it fills */
}

/* --- the overlay, for games with no .arcade-card to hang a board on ------- */

.arcade-trophy {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 900;
  min-width: 0;
  width: 46px;
  height: 46px;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  background: rgba(36, 26, 61, 0.92);
  border: 1px solid rgba(157, 78, 221, 0.6);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

.arcade-trophy:hover {
  background: rgba(157, 78, 221, 0.6);
}

.arcade-overlay {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 6, 18, 0.82);
  backdrop-filter: blur(3px);
}

.arcade-overlay-panel {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  /* Top padding clears the absolutely positioned close button; without it the
     board's own header sits under the X and swallows the click. */
  padding: 44px 20px 22px;
  border-radius: 20px;
  color: rgba(255, 255, 255, 0.9);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, #241a3d, #16162b);
  border: 1px solid rgba(157, 78, 221, 0.45);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

/* The panel's board is the only thing in it, so it needs no separator rule. */
.arcade-overlay-panel .arcade-board {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.arcade-overlay-close {
  position: absolute;
  z-index: 2;
  top: 8px;
  right: 10px;
  min-width: 0;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.6);
  background: none;
  border: none;
  cursor: pointer;
}

.arcade-overlay-close:hover { color: #fff; }

/*
 * As with the rule above for .arcade-modal: the overlay and its own children
 * are given explicit display values, which beat the user agent's
 * [hidden] { display: none } on specificity alone.
 */
.arcade-overlay[hidden],
.arcade-overlay [hidden] {
  display: none !important;
}

/* --- the name gate --------------------------------------------------------
 * The card arcade.js raises the first time a run would go up with no name on
 * it. It borrows the overlay above; these rules only lay out the form.
 * ------------------------------------------------------------------------ */

.arcade-gate-panel {
  text-align: center;
  padding-top: 24px;
}

.arcade-gate-panel .arcade-mascot {
  width: 84px;
  height: 84px;
  margin-bottom: 10px;
}

.arcade-gate-title {
  margin: 0 0 8px;
  font-size: 1.3rem;
  color: #fff;
}

.arcade-gate-text,
.arcade-gate-alt,
.arcade-gate-fine {
  margin: 0 0 12px;
  font-size: 0.86rem;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.75);
}

.arcade-gate-held {
  margin: 0 0 12px;
  font-size: 0.86rem;
  font-weight: 700;
  color: #ffd166;
}

.arcade-gate-form {
  display: flex;
  gap: 8px;
  margin: 0 0 8px;
}

.arcade-gate-form input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  font: inherit;
  font-size: 1rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(157, 78, 221, 0.5);
  border-radius: 10px;
}

.arcade-gate-form input:focus {
  outline: 2px solid rgba(255, 158, 0, 0.8);
  outline-offset: 1px;
}

.arcade-gate-save {
  flex: 0 0 auto;
  min-width: 0;
  padding: 10px 16px;
  font-size: 0.86rem;
  white-space: nowrap;
}

.arcade-gate-error {
  margin: 0 0 8px;
  min-height: 1.2em;
  font-size: 0.8rem;
  color: #ff8a8a;
}

.arcade-gate-alt a,
.arcade-gate-fine a {
  color: #fff;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.35);
}

.arcade-gate-alt a:hover,
.arcade-gate-fine a:hover { border-bottom-color: #fff; }

.arcade-gate-fine {
  margin-bottom: 0;
  font-size: 0.74rem;
  color: rgba(255, 255, 255, 0.55);
}

@media (max-width: 400px) {
  .arcade-gate-form { flex-direction: column; }
}

/* --- pause ---------------------------------------------------------------
   The scrim reuses .arcade-overlay, so it inherits the z-index that already
   sits above every game's canvas and HUD. The chip is the third fixed circle
   in the bottom-right corner - the trophy owns bottom:14px and the floating
   mute chip owns bottom:70px - but neither is on every page, so the value here
   is only the full-stack fallback: positionPauseChip() in arcade.js counts the
   chips that actually exist and narrows it. Move any of the three and check the
   other two. */

.arcade-pause-panel {
  max-width: 340px;
  padding: 26px 20px 22px;
  text-align: center;
}

.arcade-pause-panel h2 {
  margin: 10px 0 6px;
  font-size: 1.5rem;
  color: #fff;
}

.arcade-pause-hint {
  margin: 0 0 18px;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.65);
}

.arcade-pause-chip {
  position: fixed;
  right: 14px;
  bottom: 126px;
  z-index: 900;
  min-width: 0;
  width: 46px;
  height: 46px;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  background: rgba(36, 26, 61, 0.92);
  border: 1px solid rgba(157, 78, 221, 0.6);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}

.arcade-pause-chip:hover {
  background: rgba(157, 78, 221, 0.6);
}

/* --- the daily challenge -------------------------------------------------
   The bar sits under .arcade-topbar and is the only thing telling a player
   that the run they are about to start was dealt rather than rolled. It is
   deliberately loud: a seeded run that looks like free play gives nobody a
   reason to care that everyone got the same pieces. */

.arcade-daily-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  max-width: 720px;
  margin: -6px 0 14px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.82);
  background: rgba(157, 78, 221, 0.16);
  border: 1px solid rgba(157, 78, 221, 0.45);
}

.arcade-daily-tag {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #16162b;
  background: #ffd166;
}

/* Pushed to the far end so it cannot be mistaken for part of the sentence. */
.arcade-daily-free {
  margin-left: auto;
  flex: none;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: underline;
}

.arcade-daily-free:hover { color: #e0b3ff; }

/* Inside the start and game-over cards, where the bar behind them cannot be
   seen. Its own element, because the games rewrite the title and the blurb. */
.arcade-daily-note {
  margin: 0 0 10px;
  font-size: 0.78rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.7);
}
