/* ============ DigiSurvivor — Digivice-style interface ============
 * "Everything is the Digivice" (docs/GAME_DESIGN.md "UI identity"). Base look A1, LCD
 * glass: dark glass panels with a 1px cyan rim and a faint dot texture, flat, square.
 * Colour roles: cyan lit = selected and main actions, yellow = gains and rewards,
 * red = alerts; gold and the Digimon logo's orange-on-blue are retired.
 * Body text: Pixelify Sans (OFL); titles: Pixel Digivolve by Pixel Sagas (OFL);
 * labels and numbers: DotGothic16 (OFL) via --font-lcd; run timer: Micro 5 (OFL).
 */
/* Pixel Digivolve has one weight: map every weight to it so headings are never faux-bold. */
@font-face {
  font-family: 'Digivolve';
  src: url('../assets/fonts/PixelDigivolve.otf') format('opentype');
  font-weight: 100 900;
  font-display: swap;
}
/* Pixelify Sans with the digits redrawn so they can't be confused (tools/make_font.py). */
@font-face {
  font-family: 'Pixelify';
  src: url('../assets/fonts/PixelifyPS-400.ttf') format('truetype');
  font-weight: 400 550;
  font-display: block;
}
@font-face {
  font-family: 'Pixelify';
  src: url('../assets/fonts/PixelifyPS-700.ttf') format('truetype');
  font-weight: 551 900;
  font-display: block;
}
/* LCD faces (OFL): DotGothic16 cut down to Latin and symbols (tools/make_lcd_font.py) for
   labels and numbers, Micro 5 for the run timer. Pixelify stands in while they load. */
@font-face {
  font-family: 'DotGothic16';
  src: url('../assets/fonts/DotGothicDS-400.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Micro 5';
  src: url('../assets/fonts/Micro5-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  --ink: #f4fbff;
  --muted: #a3c6d2;
  --box1: #10283a;
  --box2: #07131d;
  --edge: #dce6ee;
  --edge-in: #2fb6c9;
  --edge-out: #03080d;
  --lit: #8ff6ff;                       /* selected, main actions, focus */
  --lit-ink: #04131b;                   /* text on a lit fill */
  --lit-soft: rgba(143,246,255,.14);    /* lit background tint */
  --lit-line: rgba(143,246,255,.24);    /* quiet rim for rows inside a panel */
  --gain: #ffe45c;                      /* Bits, rewards, claims, grown offers */
  --red: #ff5f6d;
  --green: #5fe08a;
  --shadow: #02070b;
  --glass: rgba(6,17,26,.96);
  --dots: radial-gradient(rgba(143,246,255,.10) 1px, transparent 1.4px) 0 0 / 4px 4px;
  --screen: #06111a;
  --grid: rgba(90,220,240,.06);
  --silver1: #eef3f7; --silver2: #9aa8b5; --silver3: #6b7a88;
  --lcd-off: rgba(110,226,242,.42); --lcd-on: #8ff6ff;
  --r1: #9fb1c9; --r2: #5fe08a; --r3: #4fb4ff; --r4: #c47bff; --r5: #ffcb3d;
  --font: 'Pixelify', 'Segoe UI', system-ui, sans-serif;
  --font-title: 'Digivolve', 'Pixelify', 'Segoe UI', system-ui, sans-serif;
  /* LCD dot-matrix face for labels and numbers; Micro 5 for the run timer (HUD, step 2). */
  --font-lcd: 'DotGothic16', 'Pixelify', 'Segoe UI', system-ui, monospace;
  --font-seg: 'Micro 5', 'DotGothic16', 'Pixelify', monospace;
  /* Faint 16px digital grid, layered over panel backgrounds. */
  --grid-bg:
    repeating-linear-gradient(0deg, var(--grid) 0 1px, transparent 1px 16px),
    repeating-linear-gradient(90deg, var(--grid) 0 1px, transparent 1px 16px);
}

* { box-sizing: border-box; }
.hidden { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: #03080d;
  color: var(--ink);
  font: 16px/1.35 var(--font);
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: none;
}
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
/* position: fixed + inset: 0 instead of 100vw / 100vh: on iPhone (especially
   when opened from the home screen) the vh units didn't match the window and
   the game looked stretched. */
#game { display: block; position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; }
button { font: inherit; color: inherit; }
input { font: inherit; }

/* ---------- screen layers ---------- */
.scr {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade .2s ease-out;
}
.scr.hidden { display: none; }
/* Screens that open with the top bar visible: they start below it. */
@media (min-height: 521px) {
  #scr-goals, #scr-dex, #scr-upgrades, #scr-gacha, #scr-friends, #scr-rank, #scr-lobby, #scr-profile { padding-top: 66px; }
}
.scr.dim { background: var(--grid-bg), radial-gradient(circle at 50% 40%, rgba(8,40,52,.55), rgba(2,7,11,.9)); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- A1 panel: LCD glass, 1px cyan rim, dot texture, cyan corner brackets ---------- */
.box {
  position: relative;
  border: 1px solid var(--edge-in);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 0 14px rgba(47,182,201,.25), 0 18px 50px rgba(0,0,0,.6);
  padding: 22px 24px;
  text-shadow: 1px 1px 0 var(--shadow);
  animation: pop .22s ease-out;
  max-height: 100%;
  overflow: auto;
  /* Corner brackets: two lit L-shapes as backgrounds (they stay on the corners while the panel scrolls). */
  background:
    linear-gradient(var(--lit), var(--lit)) left top / 12px 2px no-repeat,
    linear-gradient(var(--lit), var(--lit)) left top / 2px 12px no-repeat,
    linear-gradient(var(--lit), var(--lit)) right bottom / 12px 2px no-repeat,
    linear-gradient(var(--lit), var(--lit)) right bottom / 2px 12px no-repeat,
    var(--dots), var(--glass);
}
.box h1, .box h2, .box h3 { margin: 0 0 6px; font-family: var(--font-title); font-weight: 400; letter-spacing: 1px; }
.box h2 { font-size: 26px; color: var(--lit); text-shadow: 0 0 8px rgba(143,246,255,.45), 1px 1px 0 var(--shadow); }
.box h3 { font-size: 18px; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: 15px; }
.gold { color: var(--gain); }
.center { text-align: center; }

/* ---------- buttons ---------- */
/* A1 button: cyan outline on dark glass. */
.btn {
  appearance: none; cursor: pointer;
  padding: 10px 20px;
  border: 1px solid var(--edge-in);
  border-radius: 2px;
  background: rgba(4,19,27,.7);
  box-shadow: 0 0 0 1px rgba(0,0,0,.55);
  color: var(--lit);
  font-size: 17px; font-weight: 700;
  text-shadow: 1px 1px 0 var(--shadow);
  transition: transform .06s, background .12s, border-color .12s;
}
.btn:hover { background: var(--lit-soft); border-color: var(--lit); }
.btn:active { transform: translateY(1px); }
.btn:disabled { color: rgba(143,246,255,.35); border-color: rgba(143,246,255,.2); background: rgba(4,19,27,.5); box-shadow: none; cursor: not-allowed; transform: none; }
/* Main action: lit cyan (class name kept from PokéSurvivor so the markup and scripts stay). */
.btn.gold {
  background: var(--lit); color: var(--lit-ink); text-shadow: none;
  border-color: var(--lit);
  box-shadow: 0 0 0 1px rgba(0,0,0,.55), 0 0 10px rgba(143,246,255,.55);
}
.btn.gold:hover { background: #c4fbff; border-color: #c4fbff; }
.btn.gold:disabled { background: rgba(143,246,255,.25); color: rgba(4,19,27,.7); border-color: transparent; box-shadow: none; }
.btn.ghost { background: transparent; box-shadow: none; border-color: rgba(143,246,255,.3); color: var(--ink); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }


/* ---------- forms ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab {
  flex: 1; padding: 8px; cursor: pointer; border-radius: 2px;
  background: rgba(0,0,0,.25); border: 1px solid var(--lit-line);
  text-align: center; font-family: var(--font-lcd); letter-spacing: .04em;
}
.tab.on { border-color: var(--lit); background: var(--lit-soft); color: var(--lit); box-shadow: inset 0 -2px 0 var(--lit); }
label { display: block; font-size: 14px; color: var(--muted); margin: 8px 0 4px; }
.field {
  width: 100%; padding: 10px 12px;
  background: var(--screen); color: #fff;
  border: 1px solid rgba(47,182,201,.55); border-radius: 2px;
  font-size: 17px; outline: none;
}
.field:focus { border-color: var(--lit); box-shadow: 0 0 0 2px rgba(143,246,255,.25); }
.err { color: #ffb0b8; min-height: 20px; font-size: 14px; margin: 8px 0 0; }
.note { color: var(--muted); font-size: 13px; margin-top: 14px; }

/* ---------- start screen ---------- */
/* Title in DigiSurvivor's own colours (docs/START_SCREEN.md): white-to-cyan fill, silver
   outline like the Digivice casing, dark drop — not the Digimon logo's orange and blue.
   The outline is stacked drop-shadows because text-shadow would show through the clipped fill. */
.dv-title {
  margin: 0; font-family: var(--font-title); font-size: 46px; font-weight: 400; line-height: 1.1; letter-spacing: 1px;
  color: #bff6ff; background: linear-gradient(180deg, #ffffff 20%, #bff6ff 50%, #3fd3ea 85%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; text-shadow: none;
  filter: drop-shadow(2px 0 0 var(--silver2)) drop-shadow(-2px 0 0 var(--silver2))
    drop-shadow(0 2px 0 var(--silver2)) drop-shadow(0 -2px 0 var(--silver2))
    drop-shadow(4px 4px 0 var(--shadow)); }

.stage {
  display: block; margin: 8px auto 6px;
  /* PMD-style box: dark background and a border in the type's colour (--stage-c). */
  background:
    radial-gradient(ellipse at 50% 88%, rgba(90,220,240,.2), transparent 60%),
    var(--grid-bg),
    linear-gradient(180deg, rgba(14,40,56,.9), rgba(5,14,22,.94));
  border: 3px solid var(--stage-c, #2fb6c9);
  border-radius: 8px;
  box-shadow: 0 0 0 3px var(--edge-out), 0 10px 30px rgba(0,0,0,.45), inset 0 0 0 2px rgba(255,255,255,.06);
}

/* ---------- Pokémon grid ---------- */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px; max-height: 56vh; overflow-y: auto; padding: 4px;
}
.cell {
  position: relative; cursor: pointer; text-align: center;
  background: rgba(0,0,0,.25); border: 1px solid var(--lit-line); border-radius: 2px;
  padding: 4px 2px 6px; transition: transform .08s, border-color .12s, background .12s;
}
.cell:hover { transform: translateY(-2px); border-color: var(--edge-in); background: rgba(47,182,201,.12); }
.cell.on { border-color: var(--lit); background: var(--lit-soft); }
.cell.locked { cursor: default; opacity: .75; }
.cell.locked:hover { transform: none; border-color: rgba(244,248,255,.18); }
/* Scan data (systems/scan.js): a thin LCD bar under an unregistered silhouette. */
.scanbar { display: block; height: 4px; margin: 3px 8px 0; background: rgba(110,226,242,.15);
  box-shadow: 0 0 0 1px rgba(110,226,242,.35); }
.scanbar > i { display: block; height: 100%; background: var(--lcd-on); }
.scanbar.big { height: 6px; margin: 6px auto; max-width: 180px; }
.cell canvas { display: block; margin: 0 auto; }
.cell b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .no { position: absolute; top: 3px; left: 6px; font-size: 11px; color: var(--muted); }
.cell .stars { font-size: 10px; letter-spacing: -1px; }
.cell .partner { position: absolute; top: 3px; right: 5px; font-size: 12px; }

.wide { width: min(980px, 100%); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; }
.panel {
  background: rgba(0,0,0,.25); border: 1px solid var(--lit-line); border-radius: 2px; padding: 14px;
}
.stat { display: grid; grid-template-columns: 90px 1fr 34px; gap: 8px; align-items: center; font-size: 14px; margin: 5px 0; }
.stat .bar { height: 8px; background: repeating-linear-gradient(90deg, rgba(143,246,255,.13) 0 7px, transparent 7px 9px); overflow: hidden; }
.stat .bar i { display: block; height: 100%; background: repeating-linear-gradient(90deg, var(--lit) 0 7px, transparent 7px 9px); }
.stat > span:first-child { font: 12px var(--font-lcd); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* ---------- Digidex as the Digimon Analyzer ("UI identity" step 7) ----------
   Left: LCD rows (menu.js dexCell). Right: a title strip and the readout as fields. */
.grid.dex-rows { display: flex; flex-direction: column; gap: 4px; }
.dex-row {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 2px 12px 2px 2px; text-align: left; border-left: 3px solid transparent;
}
.dex-row:hover { transform: translateX(2px); }
.dex-row.locked:hover { transform: none; }
.dex-row.on { border-left-color: var(--lit); }
.dex-row canvas { margin: 0; }
/* Small dark silhouettes vanish on the glass: a faint cyan outline keeps the shape readable. */
.dex-row.locked canvas { filter: drop-shadow(1px 0 0 rgba(143,246,255,.45)) drop-shadow(-1px 0 0 rgba(143,246,255,.45)) drop-shadow(0 1px 0 rgba(143,246,255,.45)) drop-shadow(0 -1px 0 rgba(143,246,255,.45)); }
.dex-row b { font-size: 14px; }
.dex-row b img { vertical-align: -1px; }
.dex-row small { display: block; font: 11px/1.4 var(--font-lcd); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.dex-row .scanbar { margin: 3px 0 0; max-width: 160px; }
.an-head {
  margin: -14px -14px 10px; padding: 4px 12px;
  font: 12px/1.5 var(--font-lcd); letter-spacing: .22em; text-transform: uppercase; text-shadow: none;
  color: var(--lit-ink); background: var(--lit);
}
.an-fields { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 5px 10px; margin: 10px 0 12px; font-size: 14px; }
.an-fields dt { font: 11px/1.9 var(--font-lcd); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.an-fields dd { margin: 0; align-self: center; }
.an-fields .type { margin: 0 4px 2px 0; }
.type {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700;
  color: #10131a; text-shadow: none; margin-right: 4px;
}
.type .type-ico { vertical-align: -2px; margin: 0 3px 0 -4px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.dex-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.dex-tools input, .dex-tools select { background: rgba(0,0,0,.3); color: inherit; border: 2px solid rgba(244,248,255,.3); border-radius: 8px; padding: 4px 10px; font: inherit; font-size: 14px; }
.dex-tools input { flex: 1 1 180px; min-width: 0; }
.dex-tools select option { background: var(--box1); }
.dex-sort { align-items: center; margin-top: -4px; }
.dex-more { grid-column: 1 / -1; height: 1px; }
.fit-low { display: block; color: #ffb37a; font-size: 12px; margin-top: 2px; }
/* Pause with the run summary (run-ui.js, pauseSummary). */
.pause-box { width: min(720px, 100%); max-height: calc(100dvh - 24px); overflow-y: auto; }
.pause-sum { text-align: left; margin: 4px 0 10px; }
.pause-sum h3 { color: var(--lit); font-size: 16px; margin: 10px 0 6px; font-family: var(--font-title); font-weight: 400; }
.sum-moves { width: 100%; border-collapse: collapse; font-size: 14px; }
.sum-moves td, .sum-moves th { padding: 3px 4px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sum-moves th { font-size: 12px; color: var(--muted); font-weight: 400; }
.sum-moves .num { text-align: right; white-space: nowrap; }
.sum-moves img { vertical-align: -4px; }
.sum-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 14px; font-size: 14px; }
.sum-stats div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid rgba(255,255,255,.08); padding: 2px 0; }
.sum-stats span { color: var(--muted); }
.sum-stats small { color: var(--muted); font-weight: 400; }
.dex-sort .sub { margin: 0 2px 0 0; font-size: 13px; }
.chip {
  appearance: none; cursor: pointer; padding: 4px 10px; border-radius: 2px;
  background: rgba(0,0,0,.25); border: 1px solid var(--lit-line); font-size: 13px;
  font-family: var(--font-lcd); text-shadow: 1px 1px 0 var(--shadow);
}
.chip.on { border-color: var(--lit); color: var(--lit); background: var(--lit-soft); }

/* Coins and Digi-Egg data on the left; account, Save, News, Sound and Fullscreen on the right. */
.topbar {
  position: fixed; top: 14px; left: 16px; right: 16px; z-index: 25;
  display: flex; gap: 10px; align-items: center; justify-content: flex-end; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.tb-left { display: flex; gap: 10px; align-items: center; margin-right: auto; }
.pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 2px;
  background: var(--dots), var(--glass); border: 1px solid var(--edge-in);
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 0 10px rgba(47,182,201,.2);
  font-family: var(--font-lcd); text-shadow: 1px 1px 0 var(--shadow);
}
.coin {
  display: inline-block; width: 18px; height: 18px; vertical-align: -3px;
  background: var(--ico-coin) no-repeat center / contain; image-rendering: pixelated;
}
.credits-line {
  position: fixed; left: 14px; bottom: 10px; z-index: 25; font-size: 12px; color: rgba(163,198,210,.75);
  text-shadow: 1px 1px 0 #000;
}

/* ---------- upgrades ---------- */
.upg { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.upg-item { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; }
.upg-item .ic { font-size: 26px; text-align: center; }
.pips { display: flex; gap: 3px; margin-top: 4px; }
.pips i { width: 12px; height: 6px; border-radius: 2px; background: rgba(0,0,0,.4); }
.pips i.on { background: var(--lit); }

/* ---------- gacha ---------- */
/* Hatchery: the featured eggs' partners on an inner LCD (was a violet banner card). */
.banner {
  position: relative; border-radius: 2px; overflow: hidden;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 1px, transparent 1px 3px), var(--dots),
    radial-gradient(ellipse at 50% 70%, #0d2633, var(--screen) 75%);
  border: 1px solid var(--edge-in);
  box-shadow: inset 0 0 24px rgba(0,0,0,.6);
  padding: 18px;
}
.banner h3 { font-family: var(--font-title); font-weight: 400; font-size: 28px; color: var(--lit); text-shadow: 0 0 8px rgba(143,246,255,.45), 2px 2px 0 var(--shadow); }
.banner .feat {
  /* Below the text, never over it: legendaries at ×2 are big. */
  display: flex; align-items: flex-end; justify-content: center; gap: 6px;
  margin: 8px -10px -18px; height: 190px; overflow: hidden;
}
/* The three partners shrink together on narrow screens instead of widening the column. */
.banner .feat canvas { flex: 0 1 auto; min-width: 0; max-width: 33%; height: auto; }
.rates { font-size: 14px; }
.rates div { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed rgba(244,248,255,.15); }

#pull-fx {
  position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column;
  align-items: center; gap: 18px; padding: 14px 10px;
  /* If the 10 cards don't fit (mobile in landscape) it can scroll, and
     "Continue" always stays visible at the bottom (it used to end up off-screen
     and there was no way to close without reloading the page). */
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--grid-bg), radial-gradient(circle at 50% 45%, #0f3a4a, #02070b 70%);
}
/* Vertical centring that doesn't clip the top when it doesn't fit. */
#pull-fx::before, #pull-fx::after { content: ''; margin: auto; }
#pull-close { position: sticky; bottom: 8px; z-index: 2; flex-shrink: 0; box-shadow: 0 4px 18px rgba(0,0,0,.6); }
@media (max-height: 520px) {
  #pull-fx { gap: 10px; }
  .pull-results { gap: 6px; }
  .pcard { width: 100px; padding: 5px 3px; border-radius: 10px; }
  .pcard canvas { width: 84px; height: auto; }
  .pcard b { font-size: 12px; }
  .pcard .tag { font-size: 10px; }
  .pcard .stars { font-size: 11px; }
}
#pull-fx.hidden { display: none; }
.ball {
  width: 120px; height: 120px; border-radius: 50%; position: relative;
  background: linear-gradient(180deg, #ff4d4d 0 47%, #1a1a1a 47% 53%, #f4f4f4 53% 100%);
  border: 5px solid #1a1a1a;
  box-shadow: 0 0 0 0 var(--glow, #fff);
}
.ball::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 30px; height: 30px;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: #f4f4f4; border: 5px solid #1a1a1a;
}
.ball.drop { animation: drop .55s cubic-bezier(.3,1.6,.6,1) both; }
.ball.shake { animation: shake .45s ease-in-out 3; }
.ball.burst { animation: burst .45s ease-out forwards; }
@keyframes drop { from { transform: translateY(-60vh) rotate(-200deg); } to { transform: none; } }
@keyframes shake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-18deg); } 75% { transform: rotate(18deg); } }
@keyframes burst {
  0% { box-shadow: 0 0 0 0 var(--glow); }
  60% { box-shadow: 0 0 80px 40px var(--glow); transform: scale(1.15); }
  100% { box-shadow: 0 0 200px 120px transparent; transform: scale(0); opacity: 0; }
}
.pull-results { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 900px; }
.pcard {
  width: 150px; padding: 10px 6px; text-align: center; border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,.1), rgba(0,0,0,.3));
  border: 3px solid var(--rc, #fff);
  box-shadow: 0 0 22px var(--rc, #fff);
  animation: pop .3s ease-out both;
  text-shadow: 2px 2px 0 var(--shadow);
}
.pcard .stars { color: var(--rc); font-size: 14px; }
.pcard b { display: block; font-size: 16px; }
.pcard .tag { font-size: 12px; margin-top: 2px; }
.pcard .new { color: var(--gain); font-weight: 700; }
.pcard.r5 { animation: pop .3s ease-out both, legend 1.4s ease-in-out infinite alternate; }
@keyframes legend { to { box-shadow: 0 0 40px var(--rc), 0 0 80px var(--rc); } }

/* ---------- picker rows (level-up, item, Data Fusion), laid out like a Digimon card ----------
   --c (set per row) = the colour band on the left, the icon's tint and the Lv chip;
   .keep = the strip along the bottom with what carries over (run-ui.js cardEl). */
.cards { display: flex; flex-direction: column; gap: 10px; width: min(560px, 100%); }
.card {
  --c: var(--r1);
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 14px; text-align: left; cursor: pointer;
  background: rgba(0,0,0,.28); border: 1px solid var(--lit-line); border-radius: 2px;
  padding: 12px 14px 12px 24px; transition: transform .08s, background .12s, border-color .12s;
}
.card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 10px; background: var(--c); }
.card:hover { background: var(--lit-soft); border-color: var(--lit); transform: translateX(3px); }
.card .ico {
  flex: 0 0 46px; height: 46px; border-radius: 2px; display: grid; place-items: center; font-size: 24px;
  background: rgba(0,0,0,.3); background: color-mix(in srgb, var(--c) 20%, transparent);
  border: 1px dashed color-mix(in srgb, var(--c) 45%, transparent);
}
.card .txt { flex: 1; min-width: 0; }
.card .nm { font-weight: 700; font-size: 18px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card .lv {
  font: 12px/1.3 var(--font-lcd); letter-spacing: .04em; text-transform: uppercase; text-shadow: none;
  color: var(--lit-ink); background: var(--c); padding: 0 6px; border-radius: 1px;
}
.card .ds { color: var(--muted); font-size: 14px; }
.card .keep {
  margin-top: 6px; padding-top: 4px; border-top: 1px dashed var(--lit-line);
  font: 11px/1.35 var(--font-lcd); letter-spacing: .06em; text-transform: uppercase; color: var(--c);
}
.card .key { font-size: 13px; font-family: var(--font-lcd); color: var(--lit); border: 1px solid var(--edge-in); border-radius: 2px; padding: 2px 8px; }
@media (max-width: 520px) {
  .card { gap: 10px; padding: 10px 10px 10px 18px; }
  .card::before { width: 8px; }
  .card .ico { flex-basis: 40px; height: 40px; }
  .card .nm { font-size: 16px; }
  .card .ds { font-size: 13px; }
}
.tag-chip { font-size: 11px; padding: 2px 7px; border-radius: 2px; color: #10131a; text-shadow: none; font-family: var(--font-lcd); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 18px; }
.stats > div { background: rgba(0,0,0,.22); border-radius: 9px; padding: 8px 10px; }
.stats > div > span:first-child { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; }
.stats b { font-size: 22px; }

kbd {
  display: inline-block; padding: 0 6px; border: 1px solid var(--edge-in);
  border-radius: 2px; font: inherit; font-family: var(--font-lcd); font-size: 13px; color: var(--lit); text-shadow: none;
}

.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 60;
  padding: 10px 18px; border-radius: 2px;
  background: var(--dots), var(--glass); border: 1px solid var(--edge-in);
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 0 14px rgba(47,182,201,.3);
  text-shadow: 1px 1px 0 var(--shadow); animation: pop .2s ease-out;
}

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: rgba(47,182,201,.45); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 760px) and (min-height: 521px) {
  .split { grid-template-columns: 1fr; }
}

/* ============ pixel art icons ============ */
img.pix { image-rendering: pixelated; image-rendering: crisp-edges; vertical-align: middle; }
.stars-row { display: inline-flex; gap: 1px; vertical-align: middle; }
.cell .stars-row { display: flex; justify-content: center; margin-top: 2px; }
.badge-r { position: absolute; top: 3px; right: 4px; }
.move-icons { display: flex; flex-wrap: wrap; gap: 3px; margin: 0 0 10px; }
.card .ico img { display: block; }
.upg-item .ic { display: flex; justify-content: center; }

/* ============ generation tabs ============ */
.gen-tabs { display: flex; gap: 5px; overflow-x: auto; padding: 4px 2px 8px; margin-top: 6px; }
.gen-tab {
  appearance: none; cursor: pointer; flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; line-height: 1.1;
  padding: 6px 12px; border-radius: 2px;
  background: rgba(0,0,0,.25); border: 1px solid var(--lit-line);
  text-shadow: 1px 1px 0 var(--shadow);
}
.gen-tab b { font-size: 15px; }
.gen-tab small { font: 11px var(--font-lcd); color: var(--muted); }
.gen-tab:hover { border-color: var(--edge-in); }
.gen-tab.on { border-color: var(--lit); background: var(--lit-soft); }
.gen-tab.on b { color: var(--lit); }

/* ============ run results: registered Digimon ============ */
.caught > span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; }
.caught-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }
.caught-row > div { text-align: center; }
.caught-row small { display: block; font-size: 12px; color: #c9f3ff; }

/* ============ sound ============ */
.sound-panel { position: fixed; top: 62px; right: 16px; z-index: 30; width: 270px; padding: 14px 16px; }
.sound-inline { margin: 6px auto 16px; max-width: 320px; }
.snd-row { display: grid; grid-template-columns: 20px 64px 1fr; gap: 8px; align-items: center; margin-bottom: 10px; font-size: 14px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 8px; border-radius: 8px;
  background: rgba(0,0,0,.4); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 4px;
  background: var(--lit); border: 2px solid #e6fdff; cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 4px; background: var(--lit); border: 2px solid #e6fdff; }
#btn-sound { padding: 5px 9px; display: flex; }

/* ============ cloud, legal notice ============ */
.sync { display: inline-block; width: 9px; height: 9px; margin-left: 8px; border-radius: 2px;
  box-shadow: 0 0 0 2px var(--edge-out); vertical-align: 1px; }
.sync.ok { background: #5fe08a; }
.sync.syncing, .sync.pending { background: var(--gain); }
.sync.offline { background: #ff5f6d; }
.sync.local { background: #9fb1c9; }
.sync.guest { display: none; }
.legal-link { color: var(--muted); }
.legal-link:hover { color: #fff; }
.credits-line a { color: inherit; }
.legal h3 { margin: 14px 0 4px; color: var(--lit); font-size: 17px; font-family: var(--font-title); font-weight: 400; }
.legal p { margin: 0 0 8px; font-size: 14px; line-height: 1.45; }
.legal a { color: #9fd4ff; }
#scr-legal { z-index: 65; }   /* in front of Settings and Support (60) */
.boot { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center;
  background: #03080d; color: var(--muted); font-size: 18px; }

/* ---------- friends, room, invitations and leaderboard ---------- */
.fr-list { display: flex; flex-direction: column; gap: 6px; max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.fr-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 2px;
  background: rgba(0,0,0,.25); border: 1px solid var(--lit-line);
}
.fr-row b { font-size: 17px; }
.fr-row .st { color: var(--muted); font: 11px var(--font-lcd); letter-spacing: .06em; text-transform: uppercase; }
/* Square LCD status dots, each with a dark rim like a lit V-Pet segment. */
.dot { width: 10px; height: 10px; border-radius: 0; background: #6b7a94; flex: 0 0 10px; box-shadow: 0 0 0 1px rgba(0,0,0,.6); }
.dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.play { background: var(--gain); }
.dot.pend { background: var(--r4); }
#fr-add { margin: 10px 0 0; }
#fr-add .field { min-width: 180px; }

.lobby-members { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 10px; }
.lob-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px;
  border-radius: 2px; background: var(--dots), rgba(0,0,0,.3); border: 2px solid var(--pc, var(--lit-line));
  box-shadow: inset 0 0 18px rgba(0,0,0,.5);
  min-height: 170px; justify-content: center; text-align: center;
}
.lob-card b { font-size: 17px; color: var(--pc); }
.lob-card small { color: var(--muted); font-size: 12px; }
.lob-card .conn { font: 11px var(--font-lcd); letter-spacing: .06em; text-transform: uppercase; color: var(--green); }
.lob-card .conn.wait { color: var(--gain); }
.lob-card.empty { border: 1px dashed var(--lit-line); color: var(--muted); font-family: var(--font-lcd); text-transform: uppercase; letter-spacing: .1em; }

.invite-pop {
  position: fixed; right: 18px; bottom: 54px; z-index: 70; width: min(340px, calc(100% - 32px));
  padding: 14px 16px; animation: pop .2s ease-out;
}
.invite-pop img { vertical-align: middle; }

.rk-tools { gap: 8px; margin-bottom: 8px; }
.rk-tools .field { width: 220px; padding: 6px 10px; font-size: 15px; }
.rk-list { display: flex; flex-direction: column; gap: 4px; max-height: 46vh; overflow-y: auto; padding-right: 4px; }
/* V-Pet battle record: LCD ordinals, the top 3 lit, your own row lit (ranking-ui.js). */
.rk-row {
  display: grid; grid-template-columns: 54px auto 1fr auto 26px; gap: 10px; align-items: center;
  padding: 4px 12px; border-radius: 2px; background: rgba(0,0,0,.25); border: 1px solid var(--lit-line);
}
.rk-row .pos { font: 16px var(--font-lcd); letter-spacing: .06em; color: var(--muted); }
.rk-row.top1 .pos, .rk-row.top2 .pos, .rk-row.top3 .pos { color: var(--lit); text-shadow: 0 0 8px rgba(143,246,255,.5); }
.rk-row.top1, .rk-row.top2, .rk-row.top3 { border-color: rgba(143,246,255,.4); }
.rk-row .mons { display: flex; }
.rk-row .who { display: flex; flex-direction: column; min-width: 0; }
.rk-row .who b { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-row .who small { color: var(--muted); font: 11px var(--font-lcd); letter-spacing: .04em; }
.rk-row .time { font: 32px/1 var(--font-seg); color: var(--lit); }
.rk-row.mine { border-color: var(--lit); background: var(--lit-soft); }
.rk-rep { background: none; border: 0; padding: 4px; cursor: pointer; opacity: .35; line-height: 0; }
.rk-rep:hover { opacity: 1; }
.rk-rep.sent { opacity: .12; cursor: default; }
.rk-row.mod-row { grid-template-columns: 54px 1fr auto; }
.rk-row.mod-row.rep { grid-template-columns: 54px auto 1fr auto auto; }
.mod-warn { color: #ff8a96 !important; }
.mod-acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.rk-me { margin-top: 10px; padding: 10px 12px; border-radius: 2px; background: rgba(0,0,0,.25); border: 1px solid var(--lit-line); font-size: 15px; min-height: 20px; }

.cards.done .card { pointer-events: none; opacity: .45; }
/* Just appeared: a moment where they can't be picked (see guard() in run-ui.js). */
.cards.guard .card { opacity: .5; filter: saturate(.6); }
.cards .card { transition: transform .08s, background .12s, border-color .12s, opacity .2s, filter .2s; }
.cards.done .card.picked { opacity: 1; border-color: var(--lit); }
#lvl-wait { color: var(--lit); font-size: 15px; }

@media (max-width: 760px) {
  .lobby-members { grid-template-columns: repeat(2, 1fr); }
  .rk-row { grid-template-columns: 40px auto 1fr auto 22px; gap: 6px; }
}

/* ---------- tickets and per-Pokémon upgrades ---------- */
.tickets-line img, #tickets-pill img, #cost-1 img, #cost-10 img { vertical-align: middle; }
.upg-head { display: flex; gap: 14px; align-items: center; margin: 6px 0 12px; }
.upg-head .stage { width: 120px; height: 96px; flex: 0 0 120px; }
select.field { font-family: var(--font); }

/* ---------- gacha slot machine ---------- */
#slot { width: min(528px, 92vw, 66vh); height: auto; image-rendering: pixelated; cursor: pointer;
  filter: drop-shadow(0 0 30px rgba(255,90,90,.35)); animation: pop .25s ease-out both; }

/* ---------- missions, achievements, profile and items ---------- */
.goals-body { max-height: 62vh; overflow-y: auto; padding-right: 6px; }
.goals-h { margin: 6px 0 4px; }
.goals-h h3 { margin: 0; }
.mission {
  display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center;
  padding: 10px 12px; margin-bottom: 6px; border-radius: 2px;
  background: rgba(0,0,0,.25); border: 1px solid var(--lit-line);
}
.mission.ready { border-color: var(--gain); background: rgba(255,228,92,.1); }
.mission.claimed { opacity: .55; }
.mission small, .ach small { color: var(--muted); font-size: 12px; }
.mission .bar, .ach .bar { height: 7px; background: repeating-linear-gradient(90deg, rgba(143,246,255,.13) 0 7px, transparent 7px 9px); overflow: hidden; margin: 4px 0 2px; }
.mission .bar i, .ach .bar i { display: block; height: 100%; background: repeating-linear-gradient(90deg, var(--lit) 0 7px, transparent 7px 9px); }
.m-rw, .a-rw { font-size: 13px; color: var(--ink); }
.m-rw img, .a-rw img, .tag-chip img { vertical-align: middle; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }
.ach {
  display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 2px;
  background: rgba(0,0,0,.25); border: 1px solid var(--lit-line);
}
.ach.ok { border-color: rgba(255,228,92,.6); }
.ach .a-txt { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.leg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.leg-cell { display: flex; flex-direction: column; align-items: center; padding: 4px; border-radius: 2px; background: rgba(0,0,0,.25); border: 1px solid var(--lit-line); }
.leg-cell.ok { border-color: rgba(255,228,92,.5); }
.leg-cell small { font-size: 10px; color: var(--muted); text-align: center; }
.fav-slots { display: flex; gap: 12px; flex-wrap: wrap; margin: 6px 0; }
.fav-slot {
  width: 140px; min-height: 140px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 2px; background: rgba(0,0,0,.28); border: 1px dashed var(--lit-line); cursor: pointer; text-align: center;
}
.fav-slots.view .fav-slot { cursor: default; border-style: solid; border-color: rgba(143,246,255,.55); }
.fav-slot b { font-size: 14px; }
.profile-box { width: min(640px, 100%); max-height: 90vh; overflow-y: auto; }
.prof-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-top: -10px; }
.prof-head h2 { margin: 0; }
.prof-title { color: var(--gain); font-size: 15px; border: 1px solid var(--gain); border-radius: 2px; padding: 1px 8px; }
.prof-marks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
.prof-marks div { background: rgba(0,0,0,.25); border: 1px solid var(--lit-line); border-radius: 2px; padding: 6px 8px; display: flex; flex-direction: column; }
.prof-marks span { color: var(--muted); font: 11px var(--font-lcd); letter-spacing: .06em; text-transform: uppercase; }
.prof-marks b { font-size: 18px; }
.prof-medals { display: flex; flex-wrap: wrap; gap: 8px; }
.prof-medals .pm { width: 84px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.prof-medals small { font-size: 10px; color: var(--muted); }
a.plink { color: inherit; text-decoration: none; border-bottom: 1px dotted rgba(244,248,255,.4); }
a.plink:hover { color: var(--lit); }
#user-pill { cursor: pointer; }
.ach-pop {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 80;
  display: flex; gap: 10px; align-items: center; padding: 10px 16px; animation: pop .2s ease-out;
  border-color: var(--gain) !important;
}
.ach-pop b { display: block; color: var(--gain); }
.ach-pop small { color: var(--muted); }
.card.evo { border-color: var(--gain); background: linear-gradient(90deg, rgba(255,228,92,.16), rgba(255,228,92,.03)); }
.card.evo .nm { color: var(--gain); }
/* Bond (the legendaries' reward): pink */
.bond-title { color: #ff8ad8; }
.card.bond { border-color: #ff8ad8; background: linear-gradient(90deg, rgba(255,138,216,.18), rgba(255,138,216,.04)); }
.card.bond .nm { color: #ff8ad8; }
@media (max-height: 520px) {
  #scr-bond .bond-hint { display: none; }
  #scr-bond .box { width: min(820px, 100%); }
  #bond-cards { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
}
@media (max-width: 760px) { .mission { grid-template-columns: 1fr; } .prof-marks { grid-template-columns: repeat(2, 1fr); } }


/* ================= mobile and touch ================= */
html, body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
body { touch-action: manipulation; }
/* iPhone: without this, holding a finger on the joystick brought up "Copy / Select
   all" (Safari only honours the -webkit- version and doesn't inherit it properly). */
body, body * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
/* Key hints make no sense with touch. */
body.touch kbd, body.touch .card .key, body.touch .kbd-hint { display: none !important; }
#rotate {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5, 10, 30, .94);
}
#rotate.hidden { display: none; }
#rotate .box { max-width: 320px; }
#rotate-ico { animation: rot-hint 1.6s steps(4) infinite; display: inline-block; }
@keyframes rot-hint { 0%, 30% { transform: rotate(0deg); } 60%, 100% { transform: rotate(90deg); } }

/* ---------- settings ---------- */
#scr-settings { z-index: 60; }
/* Button placement (layout-ui.js): in front of Settings */
#scr-layout { z-index: 66; display: block; background: var(--dots), radial-gradient(circle at 50% 40%, #0d2633, #03080d); touch-action: none; }
#scr-layout.hidden { display: none; }
.lay-thing { position: absolute; z-index: 2; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.lay-thing.held { cursor: grabbing; filter: drop-shadow(0 0 8px rgba(143,246,255,.8)); }
.lay-thing.hidden { display: none; }
.lay-bar { display: flex; gap: 9px; }
.lay-slot { position: relative; width: 54px; height: 54px; flex: none; border-radius: 2px; background: rgba(6,17,26,.84); border: 1px solid rgba(143,246,255,.28); }
.lay-slot.on { border: 2.5px solid var(--lit); }
.lay-slot.item { margin-right: 9px; background: rgba(10,16,28,.55); }
.lay-slot i { position: absolute; left: 4px; top: 2px; font-style: normal; font-size: 10px; color: rgba(180,200,230,.7); }
.lay-tag { position: absolute; left: 50%; top: -18px; transform: translateX(-50%); font-size: 11px; color: var(--lit); white-space: nowrap; pointer-events: none; }
.lay-pause { border-radius: 2px; background: rgba(6,17,26,.84); border: 1px solid var(--edge-in); box-sizing: border-box; }
.lay-pause b { position: absolute; top: 9px; width: 5px; height: 18px; background: var(--lit); }
.lay-pause b:first-child { left: 11px; } .lay-pause b:last-child { left: 20px; }
.lay-stick { border-radius: 50%; background: rgba(6,17,26,.4); border: 2px solid rgba(143,246,255,.5); box-sizing: border-box; }
.lay-stick .knob { position: absolute; left: 50%; top: 50%; width: 42%; height: 42%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(143,246,255,.85); border: 3px solid var(--edge-in); box-sizing: border-box; }
.lay-panel { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); width: min(340px, calc(100% - 32px)); padding: 10px 14px; text-align: center; opacity: .95; }
.lay-panel h3 { margin: 0 0 6px; font-size: 14px; }
#lay-mode { justify-content: center; align-items: center; gap: 6px; margin: 0; }
.lay-help { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.lay-turn { color: var(--lit); font-size: 13px; margin: 4px 0; }
.lay-btns { justify-content: center; gap: 8px; margin-top: 6px; }
.box.settings { width: min(640px, 100%); max-height: calc(100dvh - 24px); display: flex; flex-direction: column; }
.set-body { overflow-y: auto; padding-right: 4px; min-height: 0; }
#set-tabs { flex-wrap: wrap; }
#set-tabs .gen-tab { padding: 6px 12px; }
.set-h { color: var(--lit); font-size: 17px; margin: 14px 0 6px; }
.set-h:first-child { margin-top: 4px; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.set-row b { display: block; }
.set-row small { display: block; color: var(--muted); font-size: 12px; }
.set-row .switch { min-width: 58px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.set-chips { margin: 6px 0 10px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; align-items: center; font-size: 14px; }
.keys span { color: var(--muted); }
.padkey { display: inline-block; padding: 0 7px; border: 2px solid rgba(244,248,255,.4); border-radius: 9px; font-size: 13px; color: var(--text, #f4f8ff) !important; text-shadow: none; }
/* What's selected with the gamepad (gamepad.js). */
.pad-focus { outline: 3px solid var(--lit) !important; outline-offset: 3px; box-shadow: 0 0 0 6px rgba(143,246,255,.25) !important; }
.credits { margin: 4px 0 12px; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.credits b { color: var(--ink); }
.about-logo { text-align: center; font-family: var(--font-title); font-size: 34px; font-weight: 400; color: var(--lit); text-shadow: 0 0 10px rgba(143,246,255,.5), 3px 3px 0 var(--shadow); margin-top: 6px; }
.btn.danger { background: #8a1f2e; border-color: #ff8a96; }
.row.wrap { flex-wrap: wrap; }
.touch-hint { display: none; }
body.touch .touch-hint { display: block; }
#pause-sound + .row, #scr-pause .row { flex-wrap: wrap; }
a.btn { text-decoration: none; display: inline-block; color: var(--ink); }

/* ================= short screens (mobile in landscape) =================
 * Everything more compact: the top bar makes room, the menu goes in two
 * columns and the credits line is hidden (it's in Settings → About). */
@media (max-height: 520px) {
  .scr { padding: 50px 10px 6px; }
  /* No top bar above: no need to leave room for it. */
  #scr-login, #scr-nick, #scr-levelup, #scr-pause,
  #scr-over, #scr-item, #scr-settings, #scr-legal, #scr-profile { padding: 6px 10px; }
  .split { grid-template-columns: 1fr; }
  .box { padding: 10px 14px; border-radius: 2px; }
  .box h2 { font-size: 20px; }
  .box h3 { font-size: 16px; }
  .sub { font-size: 13px; margin-bottom: 8px; }
  .note { margin-top: 8px; font-size: 12px; }
  .btn { padding: 7px 14px; }
  .btn.small { padding: 4px 9px; font-size: 13px; }
  .topbar { top: 5px; left: 6px; right: 6px; gap: 5px; }
  .tb-left { gap: 5px; }
  .pill { padding: 2px 8px; font-size: 13px; gap: 5px; }
  #user-pill { max-width: 130px; overflow: hidden; white-space: nowrap; }
  .topbar .btn.small { padding: 2px 6px; }
  .credits-line { display: none !important; }
  .sound-panel { top: 40px; }
  .ach-pop { top: auto; bottom: 8px; }
  .box.settings { max-height: calc(100dvh - 12px); }
}

/* ---------- loading screen (the first thing you see and what Google reads) ---------- */
/* Maintenance and noscript messages (js/main.js) still use .boot-in. */
.boot-in { text-align: center; padding: 20px; max-width: 640px; }
.boot-in h1 { margin: 0 0 8px; font-size: clamp(38px, 8vw, 64px); color: #bff6ff; text-shadow: 3px 3px 0 var(--silver2), 6px 6px 0 var(--shadow); font-weight: 400; font-family: var(--font-title); }
.boot-in p { margin: 6px 0; color: var(--muted); }
.boot-in a { color: #9fd4ff; }
.boot.noscript { z-index: 90; }
/* "Press to start": on top of everything, with the world visible behind. */
.tapstart { position: fixed; inset: 0; z-index: 80; cursor: pointer;
  background: radial-gradient(ellipse at center, rgba(5,9,20,.35), rgba(5,9,20,.8)); animation: fade .4s; }
.tap-blink { animation: blink 1.1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .tap-blink { animation: none; } }

/* Upgrades: buttons and veto */
.upg-btns { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.ban-picker { grid-column: 1 / -1; }
.bind-panel { grid-column: 1 / -1; }
.bind-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bind-slot { display: flex; align-items: center; gap: 6px; margin: 0; }
.bind-slot span { font-weight: 700; color: var(--lit); min-width: 14px; }
.bind-slot select { width: 100%; min-width: 0; }
@media (max-width: 760px) { .bind-slots { grid-template-columns: repeat(2, 1fr); } }
.ban-moves { display: flex; flex-wrap: wrap; gap: 6px; }
.ban-moves .chip { display: inline-flex; align-items: center; gap: 5px; }
.ban-moves .chip.ban { background: rgba(255,95,109,.25); border-color: #ff5f6d; color: #ffd3d8; text-decoration: line-through; }
/* What's new */
.news-btn { position: relative; }
.news-btn .dot { display: none; position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; background: #ff5f6d; box-shadow: 0 0 0 2px var(--shadow); }
.news-btn.new .dot { display: block; }
.box.news-box { width: min(640px, 100%); max-height: calc(100dvh - 90px); display: flex; flex-direction: column; }
.news-body { overflow-y: auto; padding-right: 4px; }
.news-day { padding-bottom: 6px; border-bottom: 1px solid rgba(255,255,255,.1); }
.news-day:last-child { border-bottom: 0; }
.news-day h3 { color: var(--lit); margin: 14px 0 6px; font-size: 18px; }
.news-day h3 small { display: block; color: var(--muted); font: 12px var(--font-lcd); letter-spacing: .12em; text-transform: uppercase; margin-top: 2px; }
.news-part { margin: 6px 0 8px; }
.news-tag { display: inline-block; font: 12px var(--font-lcd); letter-spacing: .1em; text-transform: uppercase; padding: 1px 8px; border-radius: 1px; color: var(--lit-ink); text-shadow: none; }
.news-tag.new { background: var(--green); } .news-tag.chg { background: var(--lit); } .news-tag.fix { background: var(--gain); }
.news-day ul { margin: 0; padding-left: 20px; }
.news-day li { margin: 4px 0; line-height: 1.35; font-size: 15px; }
@media (max-width: 760px) { .news-btn span { display: none; } }
/* Save button (top bar). */
.save-btn { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
#savenote-body p { line-height: 1.4; }
/* ============ Pokémon on mobile in landscape ============
 * The list on the left and the detail card (with "Choose as partner") on the right,
 * always visible: the card used to sit below the list and you had to
 * scroll to the edge to find the button. */
@media (max-height: 520px) {
  #scr-dex .box { height: 100%; display: flex; flex-direction: column; padding: 8px 10px; }
  #scr-dex .gen-tabs { margin-top: 2px; padding-bottom: 4px; flex: 0 0 auto; }
  #scr-dex .split { grid-template-columns: 1fr minmax(190px, 36%); gap: 8px; flex: 1; min-height: 0; margin-top: 2px !important; }
  #scr-dex .split > div:first-child { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
  #scr-dex .gen-tabs, #scr-dex .filters { scrollbar-width: none; }
  #scr-dex .gen-tabs::-webkit-scrollbar, #scr-dex .filters::-webkit-scrollbar { display: none; }
  #scr-dex .filters { flex-wrap: nowrap; overflow-x: auto; margin-bottom: 4px; flex: 0 0 auto; }
  #scr-dex .dex-tools { margin-bottom: 4px; gap: 6px; }
  /* Settings: the tabs in a row that scrolls sideways. */
  #set-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  #set-tabs::-webkit-scrollbar { display: none; }
  #set-tabs .gen-tab { flex: 0 0 auto; }
  #scr-dex .dex-tools input, #scr-dex .dex-tools select { padding: 2px 8px; font-size: 12px; }
  #scr-dex .chip { flex: 0 0 auto; padding: 2px 8px; font-size: 12px; }
  #scr-dex .grid { max-height: none; flex: 1; min-height: 0; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 5px; }
  #scr-dex .cell canvas { width: 69px; height: 60px; }
  #scr-dex .cell b { font-size: 11px; }
  #dex-detail { min-height: 0; overflow-y: auto; padding: 6px 8px; display: flex; flex-direction: column; }
  #dex-detail .stage { width: 132px; height: 114px; margin: 2px auto 4px; }
  #dex-detail h3 { margin: 0; }
  #dex-detail .stat { grid-template-columns: 62px 1fr 34px; gap: 4px; font-size: 12px; margin: 2px 0; }
  #dex-detail p { margin: 4px 0 !important; font-size: 12px !important; }
  #dex-detail .move-icons { margin-bottom: 4px; }
  /* The choose button, stuck to the bottom of the card: visible even if the card doesn't fit. */
  #dex-detail .btn { position: sticky; bottom: 0; order: 9; margin-top: auto; padding: 8px 6px; font-size: 15px;
    box-shadow: 0 -6px 10px rgba(3,10,16,.6); }
}

/* ============ Digivice: the start screen (docs/START_SCREEN.md, js/ui/digivice.js) ============
 * Loading, "Press to start", the egg picker and the main menu are the same device, centred
 * and sized to the screen height. --u is 1% of the device height; everything scales with it. */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dv-scr {
  --h: min(560px, calc(100dvh - 140px), calc((100vw - 32px) / 1.15));
  --u: calc(var(--h) / 100);
  padding: 0 !important; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.dv-scr.hidden { display: none !important; }
.dv-title {
  position: absolute; left: 0; right: 0; text-align: center; pointer-events: none;
  font-size: clamp(18px, calc((100dvh - var(--h)) / 4), 44px);
  top: calc((100dvh - var(--h)) / 4); transform: translateY(-50%);
}
.dv-tag {
  position: absolute; left: 16px; right: 16px; bottom: calc((100dvh - var(--h)) / 4); transform: translateY(50%);
  margin: 0; text-align: center; color: var(--muted); font-size: 14px; text-shadow: 1px 1px 0 var(--shadow);
}

/* The casing: an Adventure-style Digivice (wide pale-blue body with a waist, antenna stub,
   a ring around a square screen, one big key left and two right). Body and ring are one SVG
   (viewBox 230 x 200, so the ring's centre is the box's centre and its radius 45% of --h);
   the ring carries our own 8 icons and dots, never Digimoji. */
.dv {
  position: relative; height: var(--h); width: calc(var(--h) * 1.15);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 230 200'%3E%3Cdefs%3E%3ClinearGradient id='b' x1='0' y1='0' x2='.35' y2='1'%3E%3Cstop offset='0' stop-color='%23eef5fc'/%3E%3Cstop offset='.45' stop-color='%23c3d6ec'/%3E%3Cstop offset='1' stop-color='%238ba8ca'/%3E%3C/linearGradient%3E%3CradialGradient id='r' cx='.5' cy='.4' r='.62'%3E%3Cstop offset='0' stop-color='%23f4f8fd'/%3E%3Cstop offset='1' stop-color='%23bccfe6'/%3E%3C/radialGradient%3E%3C/defs%3E%3Cpath d='M40 6H190C213 6 225 19 225 41C225 57 215 65 215 79V121C215 135 225 143 225 159C225 181 213 194 190 194H40C17 194 5 181 5 159C5 143 15 135 15 121V79C15 65 5 57 5 41C5 19 17 6 40 6Z' fill='url%28%23b%29' stroke='%233f5878' stroke-width='2.5'/%3E%3Cpath d='M40 6H190C213 6 225 19 225 41C225 57 215 65 215 79V121C215 135 225 143 225 159C225 181 213 194 190 194H40C17 194 5 181 5 159C5 143 15 135 15 121V79C15 65 5 57 5 41C5 19 17 6 40 6Z' fill='none' stroke='%23fff' stroke-opacity='.7' stroke-width='1.4' transform='translate%28115 100%29 scale%28.955%29 translate%28-115 -100%29'/%3E%3Cpath d='M97 6v4h7v-4M126 6v4h7v-4' fill='%233f5878'/%3E%3Ccircle cx='115' cy='100' r='90' fill='url%28%23r%29' stroke='%235b789c' stroke-width='2'/%3E%3Ccircle cx='115' cy='100' r='87' fill='none' stroke='%23fff' stroke-opacity='.75' stroke-width='1.2'/%3E%3Ccircle cx='115' cy='100' r='77' fill='none' stroke='%237f99b9' stroke-width='3' stroke-dasharray='1.6 5.3'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  filter: drop-shadow(0 calc(var(--h) * .03) calc(var(--h) * .05) rgba(0,0,0,.6));
}
/* Antenna stub, top left. */
.dv::before {
  content: ''; position: absolute; left: 11%; top: calc(var(--h) * -.07); z-index: -1;
  width: calc(var(--h) * .05); height: calc(var(--h) * .12); border-radius: 30% 30% 15% 15%;
  transform: rotate(-20deg); transform-origin: 50% 100%;
  background: repeating-linear-gradient(180deg, transparent 0 18%, rgba(255,255,255,.12) 18% 24%),
    linear-gradient(90deg, #1b2027, #4b5560 50%, #1b2027);
}
/* The square screen in the middle of the ring. */
.dv-bezel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: calc(var(--h) * .5); height: calc(var(--h) * .5); min-height: 0;
  display: flex; flex-direction: column;
  padding: calc(var(--h) * .006) calc(var(--h) * .018) calc(var(--h) * .018);
  border-radius: calc(var(--h) * .04);
  background: linear-gradient(180deg, #2a3440, #141b23);
  box-shadow: 0 0 0 2px #3f5878, 0 0 0 calc(var(--h) * .008) #dbe7f4, inset 0 2px 0 rgba(255,255,255,.08), inset 0 -2px 0 rgba(0,0,0,.4);
}
.dv-brand {
  font-family: var(--font-title); text-align: center; text-transform: uppercase; letter-spacing: .14em;
  font-size: max(9px, calc(var(--h) * .022)); line-height: 1.6; color: #bff6ff;
  text-shadow: 1px 1px 0 #000, 0 0 8px rgba(63,211,234,.35);
}
/* The LCD: dark glass, faint grid and static scanlines. */
.dv-screen {
  position: relative; flex: 1; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; gap: calc(var(--u) * .6); padding: calc(var(--u) * 1.1);
  border-radius: calc(var(--u) * 1.2);
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.2) 0 1px, transparent 1px 3px), var(--grid-bg),
    radial-gradient(ellipse at 50% 45%, #0d2633, var(--screen) 75%);
  box-shadow: inset 0 0 0 2px rgba(63,211,234,.25), inset 0 0 24px rgba(0,0,0,.7);
  text-shadow: 1px 1px 0 var(--shadow);
}

/* Our 8 icons printed on the ring: 4 on the top arc, 4 on the bottom (V-Pet order, left to right).
   Dark when off, an LCD-cyan plate when highlighted, orange with a dot when something waits. */
.dv-icons { display: contents; }
.dv-ico {
  --r: calc(var(--h) * .385);
  position: absolute; left: calc(50% + cos(var(--a)) * var(--r)); top: calc(50% + sin(var(--a)) * var(--r));
  transform: translate(-50%, -50%);
  appearance: none; border: 0; padding: 0; cursor: pointer;
  width: max(44px, calc(var(--h) * .1)); height: max(44px, calc(var(--h) * .1));
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
  color: #34506f; background: radial-gradient(circle, #dce8f5 0 58%, transparent 60%);
  transition: color .1s, background .1s;
}
#dv-top .dv-ico:nth-child(1) { --a: -129deg; } #dv-top .dv-ico:nth-child(2) { --a: -103deg; }
#dv-top .dv-ico:nth-child(3) { --a: -77deg; }  #dv-top .dv-ico:nth-child(4) { --a: -51deg; }
#dv-bot .dv-ico:nth-child(1) { --a: 129deg; }  #dv-bot .dv-ico:nth-child(2) { --a: 103deg; }
#dv-bot .dv-ico:nth-child(3) { --a: 77deg; }   #dv-bot .dv-ico:nth-child(4) { --a: 51deg; }
.dv-ico svg { width: max(22px, calc(var(--h) * .056)); height: max(22px, calc(var(--h) * .056)); }
.dv-ico:hover { color: #0f2a4a; }
.dv-ico.sel { color: var(--lcd-on); background: radial-gradient(circle, #1d3a63 0 62%, #0f2440 63% 66%, transparent 68%); }
.dv-ico.sel svg { filter: drop-shadow(0 0 4px rgba(143,246,255,.7)); }
/* Lit like the V-Pet's call icon: blinks a few times (under 5 s), then stays orange. */
.dv-ico.lit { color: #c2410c; animation: dv-call 1.2s steps(2) 4; }
.dv-ico.sel.lit { color: var(--gain); }
.dv-ico.lit::after {
  content: ''; position: absolute; top: 10%; right: 12%; width: max(7px, calc(var(--h) * .016)); height: max(7px, calc(var(--h) * .016));
  border-radius: 50%; background: var(--gain); box-shadow: 0 0 0 1.5px #5a2a00;
}
@keyframes dv-call { 50% { color: #34506f; } }
.dv-ico:focus-visible, .dv-key:focus-visible, .dv-ico.pad-focus, .dv-key.pad-focus { outline: 3px solid #0d2340; outline-offset: 1px; }
.dv-egg:focus-visible, .dv-egg.pad-focus { outline: 2px solid #fff; outline-offset: 2px; }

.dv-mid { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.dv-partner, .dv-sil { display: block; width: 100%; height: 100%; object-fit: contain; }
.dv-hop { animation: dv-hop .45s ease-out; }
@keyframes dv-hop { 30% { transform: translateY(-8%); } 60% { transform: none; } 78% { transform: translateY(-2%); } }
.dv-guest { position: absolute; top: 0; left: 0; margin: -4px -6px; padding: 4px 6px; font-size: max(11px, calc(var(--u) * 2.2)); color: #ffb0b8;
  appearance: none; border: 0; background: transparent; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.dv-guest:hover { color: #fff; }
.dv-guest:disabled { cursor: default; text-decoration: none; }
.dv-guest:focus-visible, .dv-guest.pad-focus { outline: 2px solid #fff; outline-offset: 0; }
.dv-name {
  margin: 0; text-align: center; color: #fff; line-height: 1.2; min-height: 1.2em;
  font-family: var(--font-title); font-size: max(14px, calc(var(--u) * 3.6)); letter-spacing: 1px;
}
.dv-hint {
  margin: 0; min-height: 1.5em; padding-top: calc(var(--u) * .6); border-top: 1px solid rgba(63,211,234,.22);
  text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: max(12px, calc(var(--u) * 2.5)); color: var(--muted);
}
.dv-hint b { color: var(--lcd-on); }
.dv-hint.gold span { color: var(--gain); }

/* Casing keys, blue like the Adventure Digivice's: the big one on the left is OK (its label,
   the highlighted icon's name, is printed under it); the two on the right are previous / next. */
.dv-keys { display: contents; }
.dv-key {
  position: absolute; transform: translate(-50%, -50%);
  appearance: none; border: 0; padding: 0; cursor: pointer; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #eaf2ff;
  background: radial-gradient(ellipse at 40% 30%, #8fb4ff, #2d63de 45%, #173f9f 80%);
  box-shadow: 0 0 0 2px #0f255c, 0 calc(var(--h) * .008) 0 #0f255c,
    inset 0 0 0 calc(var(--h) * .009) rgba(255,255,255,.14), inset 0 2px 0 rgba(255,255,255,.5);
  transition: transform .06s;
}
.dv-key:active { transform: translate(-50%, calc(-50% + var(--h) * .006)); box-shadow: 0 0 0 2px #0f255c, 0 calc(var(--h) * .002) 0 #0f255c, inset 0 0 0 calc(var(--h) * .009) rgba(255,255,255,.14); }
.dv-side { left: 91.3%; width: max(48px, calc(var(--h) * .15)); height: max(44px, calc(var(--h) * .12)); }
.dv-keys > .dv-side:first-child { top: 37%; }
.dv-keys > .dv-side:last-child { top: 63%; }
.dv-side svg { width: 30%; height: 38%; filter: drop-shadow(0 1px 0 rgba(0,0,0,.35)); }
.dv-ok { left: 8.7%; top: 50%; width: max(46px, calc(var(--h) * .17)); height: max(52px, calc(var(--h) * .2)); }
.dv-ok > span {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(100% + var(--h) * .02); white-space: nowrap;
  font-family: var(--font-title); font-size: max(10px, calc(var(--h) * .026)); letter-spacing: .06em;
  color: #1c3658; text-shadow: 0 1px 0 rgba(255,255,255,.6);
}
.dv-ok:disabled { filter: grayscale(.7) brightness(.85); cursor: default; }
span.dv-key { cursor: inherit; }

/* Screen off (loading, "Press to start"), and the power-on sweep when the menu first shows. */
.dv-off .dv-screen { background: #050c12; align-items: center; justify-content: center; }
.boot-ld { margin: 0 0 calc(var(--u) * 2); color: var(--lcd-off); font-size: max(12px, calc(var(--u) * 2.6)); }
.dv-load { width: 60%; height: max(8px, calc(var(--u) * 1.8)); padding: 1px; border: 1px solid var(--lcd-off); }
.dv-load i { display: block; height: 100%; width: 40%; background: var(--lcd-off); animation: dv-load 1.4s ease-in-out infinite alternate; }
@keyframes dv-load { to { margin-left: 60%; } }
.dv-power > * { animation: dv-fadein .45s .25s both; }
.dv-power::after {
  content: ''; position: absolute; left: 0; right: 0; top: -20%; height: 18%; pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(143,246,255,.35), transparent);
  animation: dv-sweep .7s ease-out forwards;
}
@keyframes dv-sweep { to { top: 105%; } }
@keyframes dv-fadein { from { opacity: 0; } }

/* Egg picker and hatch on the LCD. */
.dv-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: calc(var(--u) * .8); }
.dv-pane .dv-hint { border-top: 0; border-bottom: 1px solid rgba(63,211,234,.22); padding: 0 0 calc(var(--u) * .6); }
.dv-eggs { display: flex; justify-content: center; gap: calc(var(--u) * 2); }
.dv-egg {
  appearance: none; border: 0; background: transparent; cursor: pointer; min-width: 44px; min-height: 44px;
  padding: calc(var(--u) * .8); border-radius: calc(var(--u) * 1.2);
}
.dv-egg canvas { display: block; width: max(36px, calc(var(--u) * 9)); height: max(45px, calc(var(--u) * 11.25)); }
.dv-egg.sel { background: rgba(143,246,255,.12); box-shadow: inset 0 0 0 2px #e8fdff; }
.dv-sil { filter: invert(1) opacity(.7) drop-shadow(0 0 6px rgba(143,246,255,.5)); }
.dv-hatch { display: block; height: 100%; width: 100%; object-fit: contain; }

@media (prefers-reduced-motion: reduce) {
  .dv-ico.lit, .dv-power > *, .dv-power::after, .dv-hop { animation: none; }
  .dv-load i { animation: none; width: 50%; }
}

/* Small landscape phones: the device fills the height under the top bar; the brand line and the
   egg picker's hint make room on the small screen. */
@media (max-height: 520px) {
  .dv-scr { --h: min(calc(100dvh - 88px), calc((100vw - 24px) / 1.15)); --u: calc(var(--h) / 80); }
  .dv-brand, #egg-pick > .dv-hint { display: none; }
  .dv-bezel { padding: calc(var(--h) * .014); }
  .dv-tag { display: none; }
  .dv-ok > span { left: 0; transform: none; }
}

/* ============ The Digital Gate: sign-in (docs/SIGN_IN_SCREEN.md, js/ui/login.js) ============
 * A glowing screen-shaped portal drawn on #gate-cv (grid tunnel, Native Forest far away,
 * data spilling out). The doors and forms sit in front of it. */
.gate { padding: 16px 16px 48px; flex-direction: column; gap: 1.6vh; background: #02060b; overflow: hidden; animation: none; }
.gate-cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: auto; }
.gate-title { position: relative; top: auto; transform: none; font-size: clamp(30px, 7.5vh, 58px); transition: opacity .35s; }
/* The clear part of the Gate between the title and the doors, where Native Forest shows. */
.gate-view { flex: 0 1 clamp(70px, 24vh, 240px); min-height: 40px; }
.gate.form-open .gate-view { display: none; }
.gate-ui { position: relative; width: min(560px, 100%); display: flex; justify-content: center; transition: opacity .35s; }
.gate-pane { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.gate-doors { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; }
.gate-door {
  appearance: none; cursor: pointer; min-height: 96px; padding: 14px 12px; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: var(--ink); text-shadow: 2px 2px 0 var(--shadow);
  background: linear-gradient(180deg, rgba(14,58,74,.92), rgba(4,20,30,.94));
  border: 2px solid rgba(143,246,255,.75);
  box-shadow: 0 0 0 2px var(--edge-out), inset 0 0 0 1px rgba(143,246,255,.25), inset 0 0 22px rgba(63,211,234,.18), 0 0 24px rgba(63,211,234,.18);
  transition: transform .06s, border-color .12s, background .12s;
}
.gate-door b { font-family: var(--font-title); font-weight: 400; font-size: clamp(17px, 2.6vw, 23px); letter-spacing: 1px; color: #fff; }
.gate-door small { font-size: 14px; color: var(--muted); }
.gate-door:hover { border-color: #fff; background: linear-gradient(180deg, rgba(20,82,102,.95), rgba(6,30,44,.95)); }
.gate-door:active { transform: translateY(2px); }
.gate-guest, .gate-link {
  appearance: none; border: 0; background: transparent; cursor: pointer; min-height: 44px; padding: 8px 12px;
  color: #bff6ff; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; text-shadow: 1px 1px 0 var(--shadow);
}
.gate-guest span { color: #ffb0b8; }
.gate-guest:hover, .gate-link:hover { color: #fff; }
.gate-door:focus-visible, .gate-guest:focus-visible, .gate-link:focus-visible, .gate-eye:focus-visible, .gsi:focus-visible, .gate .btn:focus-visible,
.gate-door.pad-focus, .gate-guest.pad-focus, .gate-link.pad-focus, .gate-eye.pad-focus, .gsi.pad-focus, .gate .btn.pad-focus,
.gate .field.pad-focus { outline: 3px solid #fff; outline-offset: 2px; }
.gate-warn { margin: 0; max-width: 46ch; text-align: center; font-size: 14px; color: var(--gain); text-shadow: 1px 1px 0 var(--shadow); }
.gate-warn::before { content: '⚠ '; }

.gate-form, .gate-clash {
  width: min(400px, 100%); align-items: stretch; gap: 0; padding: 18px 22px;
  border-radius: 8px; border: 2px solid rgba(143,246,255,.7);
  background: var(--grid-bg), linear-gradient(180deg, rgba(10,40,54,.96), rgba(3,12,20,.97));
  box-shadow: 0 0 0 2px var(--edge-out), inset 0 0 24px rgba(63,211,234,.14), 0 0 40px rgba(63,211,234,.2);
  text-shadow: 1px 1px 0 var(--shadow);
}
.gate-h { margin: 0 0 2px; text-align: center; font-family: var(--font-title); font-weight: 400; font-size: 22px; letter-spacing: 1px; color: #fff; }
.gate-carry { margin: 0 0 4px; text-align: center; font-size: 14px; color: var(--lcd-on); }
.gate-form label { margin: 10px 0 4px; }
.gate-hint { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.gate-pass { position: relative; }
.gate-pass .field { padding-right: 50px; }
.gate-eye {
  position: absolute; top: 0; right: 0; bottom: 0; width: 46px; appearance: none; border: 0; background: transparent;
  cursor: pointer; color: var(--muted); display: flex; align-items: center; justify-content: center; border-radius: 5px;
}
.gate-eye svg { width: 22px; height: 22px; }
.gate-eye[aria-pressed="true"] { color: var(--lcd-on); }
.gate-submit { margin-top: 16px; width: 100%; }
.gate-err { min-height: 0; margin: 8px 0 0; text-align: center; }
.gate-err:empty { display: none; }
.gate-err::before { content: '✖ '; }
.field[aria-invalid="true"] { border-color: #ff8a96; }
.gate-forgot { text-align: center; }
.gate-forgot .gate-link { font-size: 14px; }
.gate-note { margin: 0 0 4px; font-size: 13px; line-height: 1.45; color: var(--ink); text-align: left;
  padding: 8px 10px; border-radius: 5px; background: rgba(0,0,0,.3); border-left: 3px solid var(--lcd-on); }
.gate-back { align-self: center; margin-top: 4px; font-size: 14px; }
.gate-clash { align-items: center; gap: 14px; text-align: center; }
.gate-clash p { margin: 0; line-height: 1.45; }
.gate-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* Google's own sign-in button (light theme, standard "G"): not restyled to match the game. */
.gsi {
  appearance: none; cursor: pointer; align-self: center; margin-top: 12px; min-height: 44px; padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; color: #1f1f1f; border: 1px solid #747775; border-radius: 4px;
  font: 500 14px/1 Roboto, Arial, sans-serif; letter-spacing: .25px; text-shadow: none; -webkit-font-smoothing: antialiased;
}
.gsi svg { width: 18px; height: 18px; }
.gsi:hover { background: #f2f2f2; }
.gsi:disabled { opacity: .6; cursor: default; }
.gsi.pulse { animation: gsi-pulse 1.4s ease-in-out 3; }
@keyframes gsi-pulse { 50% { box-shadow: 0 0 0 4px rgba(143,246,255,.8); } }

.gate-foot { position: absolute; left: 16px; right: 16px; bottom: 10px; margin: 0; text-align: center; font-size: 13px;
  color: var(--muted); text-shadow: 1px 1px 0 var(--shadow); transition: opacity .35s; }
.gate-foot a { color: var(--muted); }
.gate-foot a:hover { color: #fff; }

/* The off Digivice (NO TAMER) that breaks into the Gate's data. */
.gate-dv { position: absolute; inset: 0; pointer-events: none; }
.gate-dv .dv { transition: opacity .25s; }
.gate-dv.gone .dv { opacity: 0; }
.gate-notamer { margin: 0; font-family: var(--font-title); color: var(--lcd-on); letter-spacing: .1em;
  font-size: max(14px, calc(var(--u) * 4)); text-shadow: 0 0 8px rgba(143,246,255,.6); animation: blink .5s steps(2) 2; }
/* While the Gate builds itself or you dive in, the doors and text are out of the way. */
.gate.intro .gate-title, .gate.intro .gate-ui, .gate.intro .gate-foot,
.gate.diving .gate-title, .gate.diving .gate-ui, .gate.diving .gate-foot { opacity: 0; pointer-events: none; }
.gate.diving .gate-title, .gate.diving .gate-ui, .gate.diving .gate-foot { transition-duration: .2s; }
.gate.intro .gate-title, .gate.intro .gate-ui, .gate.intro .gate-foot { transition: none; }

@media (prefers-reduced-motion: reduce) {
  .gate-notamer, .gsi.pulse { animation: none; }
  .gsi.pulse { box-shadow: 0 0 0 4px rgba(143,246,255,.8); }
}

/* Small landscape phones: doors stay side by side; with a form open the title moves to a
   corner and the footer hides, so the fields and button stay above the keyboard. */
@media (max-height: 520px) {
  .gate { padding: 8px 12px 28px; gap: 8px; }
  .gate-title { font-size: clamp(24px, 9vh, 38px); }
  .gate-door { min-height: 72px; padding: 8px; }
  .gate-door small { font-size: 13px; }
  .gate-pane { gap: 4px; }
  .gate.form-open { justify-content: flex-start; padding-top: 6px; }
  .gate.form-open .gate-title { position: absolute; top: 8px; left: 10px; right: auto; text-align: left; font-size: 14px; }
  .gate.form-open .gate-ui { width: min(400px, calc(100% - 2 * 140px)); min-width: min(360px, 100%); }
  .gate.form-open .gate-foot { display: none; }
  .gate-form, .gate-clash { padding: 8px 14px; max-height: calc(100dvh - 12px); overflow-y: auto; }
  .gate-h { font-size: 18px; }
  .gate-form label { margin: 6px 0 2px; }
  .gate-form .field { padding: 7px 10px; font-size: 16px; }
  .gate-submit { margin-top: 10px; }
  .gsi { margin-top: 6px; min-height: 40px; }
  .gate-link, .gate-guest { min-height: 36px; padding: 4px 10px; }
}

/* ---------- A2: Digivice casing around pause, results and the hatchery ("UI identity") ----------
   Same pale-blue shell, dark-blue outline and blue keys as the start screen's Adventure
   Digivice (.dv): the big OK key on the left presses the screen's main button (ui.js), the two
   keys on the right are only the casing. --cw (inline) caps the casing's width per screen. */
.case {
  position: relative; display: grid; grid-template-columns: 74px minmax(0, 1fr) 46px; align-items: center; gap: 12px;
  width: min(var(--cw, 820px), 100%); max-height: 100%; padding: 16px 14px;
  border-radius: 40px;
  background: radial-gradient(ellipse at 50% 35%, rgba(255,255,255,.35), transparent 60%),
    linear-gradient(160deg, #eef5fc, #c3d6ec 45%, #8ba8ca);
  box-shadow: 0 0 0 2.5px #3f5878, inset 0 0 0 3px rgba(255,255,255,.7), 0 18px 50px rgba(0,0,0,.6);
  animation: pop .22s ease-out;
}
/* Antenna stub, top left, as on the start screen's Digivice. */
.case::before {
  content: ''; position: absolute; left: 7%; top: -26px; z-index: -1; width: 18px; height: 40px;
  border-radius: 30% 30% 15% 15%; transform: rotate(-20deg); transform-origin: 50% 100%;
  background: repeating-linear-gradient(180deg, transparent 0 18%, rgba(255,255,255,.12) 18% 24%),
    linear-gradient(90deg, #1b2027, #4b5560 50%, #1b2027);
}
/* The screen: the A1 panel set into a dark bezel. */
.case > .box {
  width: auto; max-height: calc(100dvh - 72px); animation: none;
  box-shadow: 0 0 0 2px #3f5878, 0 0 0 6px #dbe7f4, 0 0 0 8px #3f5878, inset 0 0 24px rgba(0,0,0,.5);
}
.case-ok {
  position: relative; justify-self: center; width: 62px; height: 72px; border: 0; padding: 0; cursor: pointer;
  border-radius: 50%; color: #eaf2ff;
  background: radial-gradient(ellipse at 40% 30%, #8fb4ff, #2d63de 45%, #173f9f 80%);
  box-shadow: 0 0 0 2px #0f255c, 0 5px 0 #0f255c, inset 0 0 0 6px rgba(255,255,255,.14), inset 0 2px 0 rgba(255,255,255,.5);
  transition: transform .06s;
}
.case-ok:active { transform: translateY(4px); box-shadow: 0 0 0 2px #0f255c, 0 1px 0 #0f255c, inset 0 0 0 6px rgba(255,255,255,.14); }
.case-ok:focus-visible { outline: 3px solid var(--lit); outline-offset: 4px; }
/* Its label is printed on the casing under it, like the start screen's OK key. */
.case-ok > span {
  position: absolute; left: 50%; top: calc(100% + 10px); transform: translateX(-50%);
  font: 11px/1 var(--font-lcd); letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
  color: #3f5878; text-shadow: none;
}
.case-side { display: flex; flex-direction: column; gap: 22px; align-items: center; }
.case-side i {
  width: 40px; height: 34px; border-radius: 50%;
  background: radial-gradient(ellipse at 40% 30%, #8fb4ff, #2d63de 45%, #173f9f 80%);
  box-shadow: 0 0 0 2px #0f255c, 0 4px 0 #0f255c, inset 0 2px 0 rgba(255,255,255,.5);
}
/* Phones: the screen takes the width, the keys sit in a row under it. */
@media (max-width: 620px) {
  .case { grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 10px 8px 34px; border-radius: 24px; }
  .case > .box { order: 1; max-height: calc(100dvh - 220px); }   /* room for the top bar, the OK key and the credits line */
  .case-ok { order: 2; width: 52px; height: 52px; }
  .case-ok > span { top: calc(100% + 6px); }
  .case-side { display: none; }
  .case::before { top: -18px; height: 30px; width: 14px; }
}
@media (prefers-reduced-motion: reduce) { .case { animation: none; } }
