/* 1024 BATTLE — popcorn-arcade styling (glossy pills, light-bordered panels,
   gold selection rings) floated over a full-screen photographic backdrop.
   Fonts are self-hosted, so there is no third-party runtime dependency. */

@font-face {
  font-family: 'Manrope';
  src: url('assets/manrope-var.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: 'Chakra Petch';
  src: url('assets/chakra-600.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: 'Chakra Petch';
  src: url('assets/chakra-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #0d0f16;
  --bg-deep: #080a10;

  --text: #f2f5fa;
  --text-dim: #a9b6c6;
  --text-faint: #7c8a9c;

  /* popcorn-arcade tokens, matched to arcade.bonmipang.com */
  --pill-blue: linear-gradient(#5cc3f2, #2e8fd6);
  --pill-blue-hi: linear-gradient(#77d0f6, #3a9be0);
  --pill-gold: linear-gradient(#ffd84a, #f5a31b);
  --pill-gold-hi: linear-gradient(#ffe272, #ffb02e);
  --pill-ghost: linear-gradient(#86a9bd, #5d8299);
  --pill-ghost-hi: linear-gradient(#9bbccf, #6c93aa);
  --pill-edge: rgba(255, 255, 255, 0.85);
  --pill-drop: 0 3px 0 rgba(0, 0, 0, 0.22), inset 0 2px 0 rgba(255, 255, 255, 0.35);
  --gold: #ffe14d;
  --gold-ink: #6b3b00;
  --gold-edge: #fff3c9;

  --panel: rgba(18, 40, 62, 0.66);
  --panel-solid: rgba(14, 32, 50, 0.94);
  --panel-opaque: #0e2032;
  --panel-edge: #7fcdee;

  --slot-bg: #e9f7ff;
  --slot-edge: #cfeaf8;
  --slot-ink: #134d77;

  --danger: #ff8a7a;

  /* one hue per seat */
  --p0: #e2593e;          /* ember */
  --p0-soft: #4a2a22;
  --p1: #3e7be2;          /* azure */
  --p1-soft: #22304a;
  --p2: #46b17b;          /* jade */
  --p2-soft: #1f3b2e;
  --p3: #b06fd6;          /* orchid */
  --p3-soft: #372642;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  --radius: 16px;
  --radius-sm: 12px;
  --tap: 46px;

  --cjk: 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', 'Hiragino Sans GB', sans-serif;
  --font-display: 'Chakra Petch', var(--cjk), 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Manrope', var(--cjk), 'Segoe UI', system-ui, sans-serif;

  --board-size: min(92vw, 56vh, 470px);
  --ease: cubic-bezier(0.32, 0.72, 0.29, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* the hidden attribute must always win over display rules below */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ---------------- full-screen cover photo as the backdrop ---------------- */

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background-image: url("assets/cover.jpg");
  background-image: image-set(
    url("assets/cover.webp") type("image/webp"),
    url("assets/cover.jpg") type("image/jpeg")
  );
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* a portrait crop for portrait viewports, where the landscape shot would be
   cropped down to almost nothing */
@media (orientation: portrait) {
  body::before {
    background-image: url("assets/cover-portrait.jpg");
    background-image: image-set(
      url("assets/cover-portrait.webp") type("image/webp"),
      url("assets/cover-portrait.jpg") type("image/jpeg")
    );
  }
}

/* Scrim + grain. Light on the lobby so the artwork carries the page; heavier in
   game, where the board has to be the thing your eye goes to. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  transition: background-color 0.4s var(--ease);
  background-color: rgba(8, 10, 16, 0.12);
  background-image:
    radial-gradient(120% 85% at 50% 45%, rgba(8, 10, 16, 0) 0%, rgba(8, 10, 16, 0.34) 62%, rgba(8, 10, 16, 0.66) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.24'/%3E%3C/svg%3E");
}

body[data-screen="game"]::after { background-color: rgba(8, 10, 16, 0.62); }

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s5) var(--s4) var(--s6);
  gap: var(--s4);
}

.screen {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s4);
}

.screen > * { animation: rise 0.45s var(--ease) backwards; }
.screen > *:nth-child(2) { animation-delay: 0.06s; }
.screen > *:nth-child(3) { animation-delay: 0.12s; }
.screen > *:nth-child(4) { animation-delay: 0.18s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------ wordmark */

.brand { text-align: center; }

.brand h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(40px, 14vw, 62px);
  line-height: 1;
  letter-spacing: 0.01em;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.3em;
  /* chunky arcade lettering: hard dark edge plus a drop, like moulded plastic */
  color: #fff;
  text-shadow:
    0 2px 0 #0a2438,
    0 -2px 0 #0a2438,
    2px 0 0 #0a2438,
    -2px 0 0 #0a2438,
    0 6px 0 rgba(4, 16, 26, 0.85),
    0 10px 22px rgba(0, 0, 0, 0.7);
}

.brand h1 span {
  color: var(--gold);
  font-weight: 700;
  font-size: 0.5em;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  margin-right: -0.26em; /* tracking pads the right edge; pull it back */
  text-shadow:
    0 2px 0 #5a3200,
    0 -2px 0 #5a3200,
    2px 0 0 #5a3200,
    -2px 0 0 #5a3200,
    0 5px 0 rgba(50, 26, 0, 0.8),
    0 10px 20px rgba(0, 0, 0, 0.65);
}

.tagline {
  color: #dfe8f2;
  font-size: 13.5px;
  font-weight: 700;
  margin-top: var(--s2);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9);
}

/* ------------------------------------------------ panels */

.card {
  background: var(--panel);
  backdrop-filter: blur(5px);
  border: 3px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: var(--s4);
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.card.center { align-items: center; text-align: center; }

.field { display: flex; flex-direction: column; gap: var(--s2); }

.field > span {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #bcd8ea;
}

input[type="text"] {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 3px solid var(--slot-edge);
  background: var(--slot-bg);
  color: var(--slot-ink);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 700;
  min-height: var(--tap);
  outline: none;
  width: 100%;
  transition: box-shadow 0.15s, border-color 0.15s;
}

input[type="text"]::placeholder { color: #7fa8c4; opacity: 1; }

input[type="text"]:hover { border-color: #b6dcf2; }

input[type="text"]:focus-visible {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 225, 77, 0.5);
}

#code-input {
  text-transform: uppercase;
  letter-spacing: 0.38em;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  padding-left: 0.38em;
}

/* ------------------------------------------------ pill buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 15px;
  color: #fff;
  cursor: pointer;
  border: 3px solid var(--pill-edge);
  border-radius: 999px;
  padding: 10px 18px;
  min-height: var(--tap);
  background: var(--pill-blue);
  box-shadow: var(--pill-drop);
  transition: transform 0.05s, filter 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.btn svg { flex: none; }

.btn:hover { background: var(--pill-blue-hi); }

/* physical press: the button travels down onto its own shadow */
.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.22), inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(255, 225, 77, 0.75), var(--pill-drop);
}

.btn.primary {
  background: var(--pill-gold);
  border-color: var(--gold-edge);
  color: var(--gold-ink);
  text-shadow: 0 1px 0 #ffe9a8;
  font-size: 17px;
}

.btn.primary:hover { background: var(--pill-gold-hi); }

.btn.subtle {
  background: var(--pill-ghost);
  font-size: 13px;
  min-height: 44px; /* the touch-target floor (UI-DESIGN-STANDARD) */
  padding: 8px 14px;
  border-width: 2px;
}

.btn.subtle:hover { background: var(--pill-ghost-hi); }

.btn[disabled] {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
  transform: none;
}

.btn[disabled]:hover { background: var(--pill-ghost); }

/* one tap from abandoning a live game */
.btn.armed {
  background: linear-gradient(#ff8f7d, #d94a34);
  border-color: #ffd9d2;
  color: #fff;
}

.divider {
  display: flex;
  align-items: center;
  gap: var(--s3);
  color: #b9d4e6;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 2px;
  border-radius: 2px;
  background: rgba(127, 205, 238, 0.35);
}

.join-row { display: flex; gap: var(--s2); }
.join-row input { flex: 1; min-width: 0; }
.join-row .btn { flex: none; }

.cpu-row { display: flex; gap: var(--s2); align-items: stretch; }
.cpu-row .seg { flex: 1; }
.cpu-row .btn { flex: none; }

.error {
  color: #fff;
  background: linear-gradient(#e2604a, #bf3a26);
  border: 2px solid #ffd9d2;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

/* ------------------------------------------------ segmented controls */

.seg {
  display: flex;
  gap: var(--s2);
  min-height: var(--tap);
}

.seg-btn {
  flex: 1;
  background: #eaf6ff;
  border: 3px solid var(--slot-edge);
  border-radius: 999px;
  color: #1c6aa3;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  padding: 8px 6px;
  transition: transform 0.05s, box-shadow 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.seg-btn:hover:not(.is-on) { background: #fff; }
.seg-btn:active { transform: translateY(1px); }

.seg-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(255, 225, 77, 0.75);
}

/* selected: the arcade's gold ring, unmistakable at a glance */
.seg-btn.is-on {
  background: var(--pill-gold);
  border-color: var(--gold-edge);
  color: var(--gold-ink);
  text-shadow: 0 1px 0 #ffe9a8;
  box-shadow: 0 0 0 3px var(--gold), 0 3px 0 rgba(0, 0, 0, 0.18);
}

/* ------------------------------------------------ rules disclosure */

.rules-card {
  max-width: 420px;
  max-height: calc(100vh - var(--s6));
  overflow-y: auto;
  background: var(--panel-opaque);
  gap: var(--s4);
}

.rules-card h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
  text-align: center;
  text-shadow: 0 2px 0 #5a3200;
}

.rules-list {
  padding-left: var(--s4);
  display: grid;
  gap: var(--s3);
  font-size: 13.5px;
  color: #d6e5f1;
  font-weight: 500;
  line-height: 1.6;
}

.rules-list li::marker { color: var(--panel-edge); }
.rules-list strong { color: var(--gold); font-weight: 800; }
.rules-list em { color: #fff; font-style: normal; font-weight: 700; }

/* language switch, parked in the corner like the arcade's */
.lang-btn {
  position: fixed;
  top: var(--s3);
  /* 讓開園區那一排。--park-dock-w 是 shared/client/social.js 掛載時公布的實際寬度
     （收合 40px、展開會變寬，而且隨語言與 extra 按鈕變動），所以這裡不能寫死數字。
     沒載到 social.js 時 fallback 0px，版面跟以前一樣。 */
  right: calc(var(--park-dock-w, 0px) + var(--s3) + 8px);
  z-index: 80;
  min-width: 56px;
  font-weight: 800;
}

/* ------------------------------------------------ waiting */

.waiting-label {
  color: #bcd8ea;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.room-code {
  font-family: var(--font-display);
  font-size: clamp(42px, 15vw, 58px);
  font-weight: 700;
  letter-spacing: 0.2em;
  padding-left: 0.2em;
  color: var(--gold);
  text-shadow: 0 2px 0 #5a3200, 0 4px 0 rgba(50, 26, 0, 0.7), 0 0 30px rgba(255, 225, 77, 0.35);
}

.waiting-hint {
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: #cfe0ee;
  font-size: 13px;
  font-weight: 700;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px var(--gold);
  animation: pulse 1.5s ease-in-out infinite;
  flex: none;
}

@keyframes pulse { 0%, 100% { opacity: 0.2; } 50% { opacity: 1; } }

.waiting-roster {
  list-style: none;
  display: grid;
  gap: var(--s2);
  width: 100%;
  font-size: 13.5px;
}

.waiting-roster li {
  background: rgba(233, 247, 255, 0.92);
  border: 2px solid var(--slot-edge);
  border-radius: 999px;
  padding: 9px 16px;
  font-weight: 800;
  color: var(--slot-ink);
}

.waiting-roster .seat-open {
  background: rgba(255, 255, 255, 0.08);
  border-style: dashed;
  border-color: rgba(127, 205, 238, 0.5);
  color: #a9c4d6;
  font-weight: 600;
  font-style: italic;
}

/* ------------------------------------------------ game hud */

.hud {
  width: var(--board-size);
  display: flex;
  align-items: stretch;
  gap: var(--s2);
}

.player-cards {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(66px, 1fr));
  gap: var(--s2);
  min-width: 0;
}

.player-card {
  background: var(--panel-solid);
  border: 2px solid rgba(127, 205, 238, 0.55);
  border-radius: var(--radius-sm);
  padding: var(--s2) var(--s2) var(--s2) 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  min-width: 0;
  overflow: hidden;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s var(--ease);
}

/* seat colour as a left rail — survives any card width */
.player-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
}

.player-card.seat0::before { background: var(--p0); }
.player-card.seat1::before { background: var(--p1); }
.player-card.seat2::before { background: var(--p2); }
.player-card.seat3::before { background: var(--p3); }

/* whose turn it is: the arcade's gold ring, breathing gently */
.player-card.active {
  border-color: var(--gold-edge);
  box-shadow: 0 0 0 3px var(--gold), 0 4px 14px -4px rgba(255, 225, 77, 0.6);
  transform: translateY(-2px);
  animation: breathe 2s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 3px var(--gold), 0 4px 14px -4px rgba(255, 225, 77, 0.45); }
  50% { box-shadow: 0 0 0 3px var(--gold), 0 4px 22px -2px rgba(255, 225, 77, 0.85); }
}

.player-card.leader {
  border-color: var(--gold-edge);
  background: linear-gradient(180deg, rgba(90, 62, 10, 0.95) 0%, rgba(40, 28, 6, 0.95) 100%);
}

.player-name {
  font-size: 11px;
  color: #b9cddc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
  padding-right: var(--s2);
}

.player-score {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  transition: color 0.2s;
}

/* a scoring move should be felt, not just read */
.player-score.bump { animation: bump 0.45s var(--ease); }

@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.35); color: var(--gold); }
  100% { transform: scale(1); }
}

/* losing a tile costs you its value, so a falling score is worth seeing too */
.player-score.drop { animation: drop 0.45s var(--ease); }

@keyframes drop {
  0% { transform: scale(1); }
  35% { transform: scale(0.82); color: var(--danger); }
  100% { transform: scale(1); }
}

.conn-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6fdc6f;
  box-shadow: 0 0 6px rgba(111, 220, 111, 0.9);
}

.conn-dot.off { background: transparent; border: 2px solid #9aa9b8; box-shadow: none; } /* hollow: not colour alone */

.hud-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  flex: none;
}

.goal {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-ink);
  background: var(--pill-gold);
  border: 2px solid var(--gold-edge);
  border-radius: 999px;
  padding: 3px 10px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

.turn-banner {
  font-size: 11px;
  color: #cfe0ee;
  white-space: nowrap;
  font-weight: 800;
  max-width: 13ch;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.turn-banner.mine { color: var(--gold); }

/* ------------------------------------------------ board */

#board-wrap { touch-action: none; }

#board {
  width: var(--board-size);
  height: var(--board-size);
  /* opaque on purpose: the backdrop's own numerals would ghost through empty
     cells and read as faint tiles */
  background: var(--panel-solid);
  backdrop-filter: blur(8px);
  border: 3px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: var(--s2);
  display: grid;
  /* --grid is set by client.js from the board size */
  grid-template-columns: repeat(var(--grid, 4), 1fr);
  grid-template-rows: repeat(var(--grid, 4), 1fr);
  gap: var(--s2);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), inset 0 2px 0 rgba(255, 255, 255, 0.12);
  transition: box-shadow 0.2s;
}

#board.replaying {
  border-color: var(--gold-edge);
  box-shadow: 0 0 0 3px var(--gold), 0 10px 28px rgba(0, 0, 0, 0.5);
}

#board.shake { animation: shake 0.25s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.cell {
  background: rgba(233, 247, 255, 0.07);
  border: 1px solid rgba(127, 205, 238, 0.14);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile {
  position: relative;
  width: 100%;
  height: 100%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: calc(var(--board-size) / (var(--grid, 4) * 2.3));
  color: #fff;
  /* candy gloss: hard bottom edge, bright top lip */
  box-shadow:
    0 3px 0 rgba(0, 0, 0, 0.28),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

/* top-half sheen, the popcorn tiles' signature */
.tile::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 52%;
  background: linear-gradient(rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.tile.small { font-size: calc(var(--board-size) / (var(--grid, 4) * 3)); }

.tile.pop { animation: pop 0.2s var(--ease); }

@keyframes pop {
  0% { transform: scale(0.5); opacity: 0.35; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

/* owner colours, brightness scales with tile tier */
.tile.o0 { background: color-mix(in srgb, var(--p0) var(--tier), var(--p0-soft)); }
.tile.o1 { background: color-mix(in srgb, var(--p1) var(--tier), var(--p1-soft)); }
.tile.o2 { background: color-mix(in srgb, var(--p2) var(--tier), var(--p2-soft)); }
.tile.o3 { background: color-mix(in srgb, var(--p3) var(--tier), var(--p3-soft)); }

.tile.win {
  border-color: var(--gold-edge);
  box-shadow:
    0 0 0 3px var(--gold),
    0 0 30px 4px rgba(255, 225, 77, 0.65),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

/* ------------------------------------------------ game footer */

.game-foot {
  width: var(--board-size);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}

.foot-actions { display: flex; gap: var(--s2); }

.controls-hint {
  color: #b9cddc;
  font-size: 11.5px;
  font-weight: 700;
  text-align: right;
  line-height: 1.35;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

/* ------------------------------------------------ overlay + toast */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(6, 14, 22, 0.86);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
  animation: fade 0.25s var(--ease) backwards;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.overlay .card {
  max-width: 360px;
  animation: rise 0.35s var(--ease) backwards;
  background: var(--panel-opaque);
}

.overlay h2 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 2px 0 #5a3200, 0 4px 0 rgba(50, 26, 0, 0.6);
}

#over-detail { color: #cfe0ee; font-size: 13.5px; font-weight: 600; }

.over-actions {
  display: flex;
  gap: var(--s2);
  flex-wrap: wrap;
  justify-content: center;
}

/* connection state bar: persistent while the socket is not online */
.conn-bar {
  position: fixed;
  top: calc(var(--s3) + 52px);
  /* centred without a transform: left:50% would cap its width at half the screen */
  left: 16px;
  right: 16px;
  margin: 0 auto;
  width: max-content;
  z-index: 75;
  display: flex;
  align-items: center;
  gap: var(--s2);
  max-width: calc(100vw - 32px);
  padding: 6px 8px 6px 14px;
  background: var(--panel-solid);
  border: 2px solid var(--panel-edge);
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
.conn-bar[hidden] { display: none; }
.conn-bar .btn { min-height: 36px; padding: 4px 12px; flex: none; }
.conn-bar .btn[hidden] { display: none; }
.conn-bar-spin { flex: none; animation: conn-spin 0.9s linear infinite; }
.conn-bar-warn { flex: none; color: var(--gold); display: none; }
.conn-bar[data-state="lost"] .conn-bar-spin,
.conn-bar[data-state="replaced"] .conn-bar-spin { display: none; }
.conn-bar[data-state="lost"] .conn-bar-warn,
.conn-bar[data-state="replaced"] .conn-bar-warn { display: block; }
.conn-bar[data-state="lost"],
.conn-bar[data-state="replaced"] { padding-right: 6px; }
.conn-bar[data-state="connecting"],
.conn-bar[data-state="reconnecting"] { padding-right: 16px; }
@keyframes conn-spin { to { transform: rotate(360deg); } }
/* wide screens: the top row has room between the title area and the dock, so
   the bar sits there instead of over the in-game score cards */
@media (min-width: 760px) {
  .conn-bar { top: var(--s3); max-width: calc(100vw - 2 * (var(--park-dock-w, 0px) + 140px)); }
}

/* the shared invite panel on the waiting card */
.share-panel { width: 100%; margin: var(--s2) 0; }
.share-panel[hidden] { display: none; }

.toast {
  position: fixed;
  bottom: var(--s5);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-solid);
  border: 2px solid var(--panel-edge);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 700;
  z-index: 70;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.28s var(--ease) both;
  max-width: calc(100vw - var(--s6));
  text-align: center;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ------------------------------------------------ responsive */

@media (max-width: 430px) {
  #app { padding: var(--s4) var(--s3) var(--s5); }
  .hud { flex-direction: column; gap: var(--s2); }
  .hud-mid { flex-direction: row; gap: var(--s3); justify-content: center; }
  .turn-banner { max-width: none; }
  .game-foot { flex-direction: column-reverse; align-items: stretch; gap: var(--s2); }
  .controls-hint { text-align: center; }
  .foot-actions .btn { flex: 1; }
  /* 手機上語言鈕與園區那一排同一條橫帶, 標題要從它下面開始, 否則 EN 壓在 BATTLE 上 */
  .brand { padding-top: 40px; }
  /* 展開的園區那一排幾乎佔滿 390px 的寬, 跟著 --park-dock-w 讓開會被推出畫面(x<0)。
     手機上改讀收合寬度, 展開時退到那一排底下被它蓋住, 收起來就回來。 */
  .lang-btn { right: calc(var(--park-dock-rest-w, 0px) + var(--s3) + 8px); z-index: 59; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
