/* ==========================================================================
   css/base.css — design tokens + reusable components for every page
   --------------------------------------------------------------------------
   Loaded by index.html and stats.html before layout.css / game.css.
   Owner: frontend-shell-agent. The game views (css/game.css) build on these
   tokens and utility classes, so names here are a contract — do not rename.

   Look: "a touch of" the Pokémon Scarlet/Violet menu — dark translucent navy
   panels floating on a soft landscape gradient, white text, a single muted
   Pokéball-red accent for the selected row / primary action (phase 2,
   DECISIONS.md 45 — the phase-1 yellow is gone), green rounded HP bars and
   type-coloured badges. Modern and readable, not a pixel-retro UI.
   ========================================================================== */

:root {
  /* Page background: soft green/blue landscape (sky -> meadow) */
  --bg-gradient: linear-gradient(165deg, #8fd3f4 0%, #a6dfd0 32%, #9bd68a 62%, #6fbf73 100%);

  /* Panels (SV menu: rgba navy, faint border, soft shadow) */
  --panel: rgba(18, 26, 44, 0.88);
  --panel-2: rgba(255, 255, 255, 0.06);
  --panel-3: rgba(255, 255, 255, 0.10);
  --panel-border: 1px solid rgba(255, 255, 255, 0.08);
  --panel-border-strong: 1px solid rgba(255, 255, 255, 0.16);
  --shadow: 0 10px 30px rgba(8, 12, 24, 0.35);
  --shadow-sm: 0 4px 12px rgba(8, 12, 24, 0.25);

  /* Text */
  --text: #f4f6fb;
  --muted: #a9b3c7;
  /* Height of the pinned game header. The shell reserves exactly this much, so the page can
     never sit under it or leave a gap below it (GAPS.md 50, DECISIONS.md 73). */
  --header-h: 52px;
  --font: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, Consolas, "Courier New", monospace;

  /* Accent + semantic colours (ARCHITECTURE.md 11.5: muted Pokéball red) */
  --accent: #d64545;          /* rings, borders, active markers */
  --accent-hover: #e25a5a;    /* hover state of accent surfaces */
  --accent-strong: #b83232;   /* primary buttons (white text) */
  --accent-soft: rgba(214, 69, 69, 0.16); /* selected rows, soft tags, active nav */
  --accent-light: #f08c8c;    /* accent-coloured text on dark panels (links, names, numbers) */
  --accent-text: #ffffff;
  --danger: #e5484d;
  --danger-hover: #f05a5f;
  --success: #4cd964;
  --info: #5aa9ff;
  --warning: #f5b400;

  /* HP bar colours (green > 50 %, yellow > 20 %, red below — like the games) */
  --hp: #4cd964;
  --hp-mid: #f5b400;
  --hp-low: #e74c3c;
  --hp-track: rgba(255, 255, 255, 0.14);

  /* Shape */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 5px;
  --focus: 0 0 0 3px rgba(214, 69, 69, 0.45);

  /* Standard Pokémon type palette (Bulbapedia colours) */
  --type-normal: #a8a77a;
  --type-fire: #ee8130;
  --type-water: #6390f0;
  --type-electric: #f7d02c;
  --type-grass: #7ac74c;
  --type-ice: #96d9d6;
  --type-fighting: #c22e28;
  --type-poison: #a33ea1;
  --type-ground: #e2bf65;
  --type-flying: #a98ff3;
  --type-psychic: #f95587;
  --type-bug: #a6b91a;
  --type-rock: #b6a136;
  --type-ghost: #735797;
  --type-dragon: #6f35fc;
  --type-dark: #705746;
  --type-steel: #b7b7ce;
  --type-fairy: #d685ad;

  /* Variant colours for text labels (sprite filters live in css/game.css) */
  --variant-shiny: #ffd86b;
  --variant-dark: #a78bfa;
  --variant-golden: #ffb020;
  --variant-frozen: #8fe3ff;   /* the Frozen form (DECISIONS 149) */
  --variant-shadow: #c9ccd6;   /* the Shadow form: silver, its black and white (DECISIONS 330) */
  --variant-crystal: #bfefff;   /* the Crystal form (Prism, task 8) */

  /* 统一管线：grayscale 抹掉物种色，sepia 建亮度底，再染色；各曲面只叠加自己的投影/光晕。 */
  --form-golden-tint: grayscale(1) sepia(1) saturate(2.9) hue-rotate(-9deg) brightness(1.04) contrast(1.18);
  --form-dark-tint: grayscale(1) sepia(1) saturate(1.7) hue-rotate(252deg) brightness(0.72) contrast(1.28);
  --form-dark-glow: drop-shadow(0 0 3px rgba(150, 90, 255, 0.45));
  --form-dark-scene-tint: grayscale(1) sepia(1) saturate(1.7) hue-rotate(252deg) brightness(0.85) contrast(1.15);
  --form-dark-scene-glow: drop-shadow(0 0 3px rgba(150, 90, 255, 0.45));
  --form-frozen-tint: grayscale(1) sepia(1) saturate(2.4) hue-rotate(160deg) brightness(1.2) contrast(1.02);
  --form-frozen-glow: drop-shadow(0 0 4px rgba(120, 220, 255, 0.7)) drop-shadow(0 0 9px rgba(80, 165, 255, 0.35));
  --form-frozen-scene-glow: drop-shadow(0 0 4px rgba(120, 220, 255, 0.7));
  --form-frozen-evo-glow: drop-shadow(0 0 9px rgba(80, 165, 255, 0.45));
  --form-shadow-tint: grayscale(1) brightness(1.24) contrast(1.06);
  --form-shadow-glow: drop-shadow(0 0 3px rgba(210, 220, 240, 0.55));
  --form-shadow-scene-tint: grayscale(1) brightness(1.18) contrast(1.04);
  --form-shadow-scene-glow: drop-shadow(0 0 3px rgba(210, 220, 240, 0.5));
  --form-shadow-evo-glow: drop-shadow(0 0 9px rgba(190, 205, 235, 0.55));
  --form-crystal-tint: grayscale(1) sepia(1) saturate(0.55) hue-rotate(285deg) brightness(1.16) contrast(1.02);
  --form-crystal-glow: drop-shadow(0 0 4px rgba(200, 240, 255, 0.8)) drop-shadow(0 0 10px rgba(150, 190, 255, 0.45));
  --form-crystal-scene-tint: grayscale(1) sepia(1) saturate(0.45) hue-rotate(285deg) brightness(1.12) contrast(1.02);
  --form-crystal-scene-glow: drop-shadow(0 0 3px rgba(190, 235, 255, 0.6));
  --form-crystal-evo-glow: drop-shadow(0 0 9px rgba(180, 230, 255, 0.55));
  --form-evo-shadow: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45));
}

/* --------------------------------------------------------------------------
   Reset-ish
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

/* A game, not a document: dragging over the screen should not smear a blue selection over
   the UI (owner feedback). Only while the game shell is mounted — the login page and the
   stats page stay selectable — and never in a field you type in. */
body.shell, body.shell * { user-select: none; -webkit-user-select: none; }
body.shell input, body.shell textarea, body.shell select, body.shell [contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Scrolling with a finger yes, pinch-zoom no: the game is laid out for the screen it is
     on (owner, 22 September). `pan-x pan-y` leaves every scroller working. */
  touch-action: pan-x pan-y;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: #8fd3f4 var(--bg-gradient);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* Subtle repeating pattern + soft "hills" on top of the gradient (pure CSS,
   no image): rolling blobs like the Sword/Shield map illustration. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(ellipse 60% 45% at 15% 10%, rgba(255, 255, 255, 0.28), transparent 70%),
    radial-gradient(ellipse 50% 40% at 85% 25%, rgba(255, 255, 255, 0.18), transparent 70%),
    radial-gradient(ellipse 70% 40% at 30% 100%, rgba(38, 120, 78, 0.28), transparent 70%),
    radial-gradient(ellipse 50% 35% at 90% 90%, rgba(30, 100, 130, 0.25), transparent 70%),
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.16) 1px, transparent 1.5px);
  background-size: auto, auto, auto, auto, 22px 22px;
}

h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.2; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; }
p { margin: 0 0 0.75em; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { vertical-align: middle; }
img { max-width: 100%; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

ul, ol { margin: 0; padding: 0; list-style: none; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: var(--panel-border); }
th { font-size: 11px; letter-spacing: 0.01em; color: var(--muted); font-weight: 700; }
tr:last-child td { border-bottom: 0; }
code, kbd { font-family: var(--font-mono); font-size: 0.9em; }

/* Keyboard focus ring: only for keyboard users (focus-visible) */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-xs); }

::selection { background: rgba(214, 69, 69, 0.45); color: #fff; }

/* Scrollbars inside dark panels. Thumb 0.25 -> 0.35 (owner, 26 September): chat, modals and the zoomed
   Town Map were too faint; the page scroller has its own clearer rule in css/layout.css (.view-scroll). */
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.35) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.35); border-radius: 999px; }
*::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------------------
   Panels + cards
   -------------------------------------------------------------------------- */
.panel {
  background: var(--panel);
  border: var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

/* "MAIN MENU" style header: small, bold, uppercase, letter-spaced */
.panel-title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;

  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-title .badge-count { margin-left: auto; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.panel-head .panel-title { margin: 0; }

.card {
  background: var(--panel-2);
  border: var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.card.clickable { cursor: pointer; transition: background-color 0.15s, transform 0.15s, border-color 0.15s; }
.card.clickable:hover { background: var(--panel-3); border-color: rgba(255, 255, 255, 0.18); transform: translateY(-1px); }
.card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.divider { height: 1px; background: rgba(255, 255, 255, 0.08); margin: 12px 0; border: 0; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.10);
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s, opacity 0.15s;
  user-select: none;
}
.btn:hover { background: rgba(255, 255, 255, 0.17); border-color: rgba(255, 255, 255, 0.25); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--accent-text);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }

.btn-success { background: var(--success); border-color: var(--success); color: #0f2b14; }
.btn-success:hover { background: #63e37a; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }

.btn-sm { padding: 4px 10px; min-height: 28px; font-size: 0.8rem; border-radius: 6px; }
.btn-sm svg { width: 14px; height: 14px; }
/* Extra-small icon buttons for compact rows (team rows, sidebar lists) */
.btn-xs { padding: 2px 6px; min-height: 24px; min-width: 24px; font-size: 0.72rem; border-radius: 5px; gap: 4px; }
.btn-xs svg { width: 13px; height: 13px; }
.btn-lg { padding: 12px 20px; min-height: 46px; font-size: 1rem; }
.btn-block { display: flex; width: 100%; }
.btn-icon { padding: 6px; min-width: 32px; min-height: 32px; }
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-primary.loading::after { border-color: rgba(255, 255, 255, 0.3); border-top-color: #fff; }

.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   HP bar (rounded track, colour switches at 50 % / 20 % like the games)
   -------------------------------------------------------------------------- */
.hpbar {
  height: 8px;
  background: var(--hp-track);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.hpbar.lg { height: 12px; }
.hpbar-fill {
  height: 100%;
  width: 0;
  background: var(--hp);
  border-radius: 999px;
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.3s;
}
.hpbar-fill.mid { background: var(--hp-mid); }
.hpbar-fill.low { background: var(--hp-low); }
.hp-text { font-variant-numeric: tabular-nums; }

/* Generic progress bar (Pokédex completion, EXP) */
.progress { height: 8px; background: var(--hp-track); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--info); border-radius: 999px; transition: width 0.45s ease; }
.progress-fill.accent { background: var(--accent); }

/* --------------------------------------------------------------------------
   Type badges
   -------------------------------------------------------------------------- */
.type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;

  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  background: #888;
  line-height: 1.5;
  vertical-align: middle;
}
.type-normal { background: var(--type-normal); }
.type-fire { background: var(--type-fire); }
.type-water { background: var(--type-water); }
.type-electric { background: var(--type-electric); color: #2b2400; text-shadow: none; }
.type-grass { background: var(--type-grass); }
.type-ice { background: var(--type-ice); color: #10333a; text-shadow: none; }
.type-fighting { background: var(--type-fighting); }
.type-poison { background: var(--type-poison); }
.type-ground { background: var(--type-ground); color: #33290a; text-shadow: none; }
.type-flying { background: var(--type-flying); }
.type-psychic { background: var(--type-psychic); }
.type-bug { background: var(--type-bug); }
.type-rock { background: var(--type-rock); }
.type-ghost { background: var(--type-ghost); }
.type-dragon { background: var(--type-dragon); }
.type-dark { background: var(--type-dark); }
.type-steel { background: var(--type-steel); color: #22232e; text-shadow: none; }
.type-fairy { background: var(--type-fairy); }

/* --------------------------------------------------------------------------
   Tags, badges, counters
   -------------------------------------------------------------------------- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  line-height: 1.5;
  white-space: nowrap;
}
.tag svg { width: 12px; height: 12px; }
.tag.ok { background: rgba(76, 217, 100, 0.18); color: #9df0ab; }
.tag.warn { background: rgba(245, 180, 0, 0.18); color: #ffd97a; }
.tag.danger { background: rgba(229, 72, 77, 0.2); color: #ff9a9d; }
.tag.info { background: rgba(90, 169, 255, 0.18); color: #a7cdff; }
.tag.accent { background: var(--accent-soft); color: var(--accent-light); box-shadow: inset 0 0 0 1px rgba(214, 69, 69, 0.45); }
.tag.soon { background: rgba(255, 255, 255, 0.08); color: var(--muted); font-size: 9px; padding: 0 5px; letter-spacing: 0.01em; }
.tag-variant-shiny { background: rgba(255, 216, 107, 0.2); color: var(--variant-shiny); }
.tag-variant-dark { background: rgba(167, 139, 250, 0.2); color: var(--variant-dark); }
.tag-variant-golden { background: rgba(255, 176, 32, 0.22); color: var(--variant-golden); }
.tag-variant-frozen { background: rgba(143, 227, 255, 0.2); color: var(--variant-frozen); }
.tag-variant-shadow { background: rgba(201, 204, 214, 0.16); color: var(--variant-shadow); }
.tag-variant-crystal { background: rgba(191, 239, 255, 0.18); color: var(--variant-crystal); }

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
}
.badge-count:empty, .badge-count[hidden] { display: none; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: var(--success); box-shadow: 0 0 0 3px rgba(76, 217, 100, 0.2); }
/* In a battle right now (trainer card, DECISIONS 257): the same amber as the trainer search. */
.dot.busy { background: var(--warning); box-shadow: 0 0 0 3px rgba(245, 180, 0, 0.2); }

/* --------------------------------------------------------------------------
   Layout utilities
   -------------------------------------------------------------------------- */
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.top { align-items: flex-start; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.tight { gap: 8px; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { text-align: center; }
.right { text-align: right; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.tiny { font-size: 0.72rem; }
.bold { font-weight: 700; }
.accent { color: var(--accent-light); }
.danger-text { color: #ff9a9d; }
.success-text { color: #9df0ab; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 20px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 20px; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (max-width: 600px) {
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
}

/* --------------------------------------------------------------------------
   Sprites + avatars
   -------------------------------------------------------------------------- */
.sprite {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  object-fit: contain;
}
.sprite.sm { width: 40px; height: 40px; }
.sprite.md { width: 64px; height: 64px; }
.sprite.lg { width: 96px; height: 96px; }
.sprite.xl { width: 128px; height: 128px; }
.sprite.fainted { filter: grayscale(1) brightness(0.6); }

.avatar {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: var(--panel-border);
  overflow: hidden;
  flex: none;
}
.avatar img { width: 100%; height: 100%; object-fit: contain; object-position: center bottom; image-rendering: pixelated; }
.avatar.sm { width: 28px; height: 28px; }
.avatar.md { width: 52px; height: 52px; }
.avatar.lg { width: 72px; height: 72px; }
.avatar.xl { width: 112px; height: 112px; }
.avatar.ring { box-shadow: 0 0 0 2px var(--accent); }

/* --------------------------------------------------------------------------
   Lists
   -------------------------------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 6px; }
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid transparent;
  transition: background-color 0.15s, border-color 0.15s;
  min-width: 0;
}
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover, .list-item.clickable:focus-visible { background: var(--panel-3); border-color: rgba(255, 255, 255, 0.14); }
.list-item.selected { border-color: var(--accent); background: var(--accent-soft); }
.list-item .grow { min-width: 0; }
.list-item .actions { display: flex; gap: 6px; flex: none; }
button.list-item { width: 100%; text-align: left; color: inherit; font: inherit; }

.empty {
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-sm);
}
.empty svg { width: 28px; height: 28px; opacity: 0.6; display: block; margin: 0 auto 6px; }

/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-sm);
}
.tab {
  flex: 1 1 0;
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.tab.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 0 0 0 1px rgba(214, 69, 69, 0.5); }
.tab .badge-count { min-width: 16px; height: 16px; font-size: 10px; }

/* --------------------------------------------------------------------------
   Forms (inputs on dark panels)
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label, .label { font-size: 0.8rem; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.field .hint { font-size: 0.75rem; color: var(--muted); }
.field .error { font-size: 0.78rem; color: #ff9a9d; min-height: 1em; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }

input[type="text"], input[type="password"], input[type="number"], input[type="search"],
input[type="email"], select, textarea, .input {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
  min-height: 38px;
}
input::placeholder, textarea::placeholder { color: rgba(169, 179, 199, 0.7); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}
input:disabled, select:disabled, textarea:disabled { opacity: 0.5; }
select option { background: #182238; color: var(--text); }
textarea { resize: vertical; min-height: 80px; }
input[type="number"] { width: auto; min-width: 80px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }

.input-group { display: flex; gap: 6px; }
.input-group input { flex: 1 1 auto; min-width: 0; }

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(6, 10, 20, 0.62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade-in 0.15s ease;
}
.modal {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: var(--panel-border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: pop-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  overflow: hidden;
}
.modal.wide { max-width: 720px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px 10px;
  border-bottom: var(--panel-border);
}
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 14px 16px; overflow: auto; min-height: 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 16px 14px;
  border-top: var(--panel-border);
}
.modal-close { color: var(--muted); }
.modal-close:hover { color: var(--text); }
/* A dialog opened with openModal({sheet: true}) - the move chooser after a battle (DECISIONS 462): on a
   phone it comes up from the bottom edge, full width, with a grab handle; above 600 px a normal dialog. */
.modal .sheet-grab { display: none; }
.sheet-note { margin: 8px 2px 0; font-size: 11px; color: var(--muted); text-align: center; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@media (max-width: 600px) {
  .modal-backdrop.as-sheet { align-items: flex-end; padding: 0; }
  .modal.sheet {
    max-width: none; max-height: calc(100dvh - 48px);
    border-radius: 16px 16px 0 0; border-bottom: 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    animation: sheet-up 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .modal.sheet .sheet-grab { display: block; flex: none; width: 40px; height: 4px; margin: 8px auto 0; border-radius: 99px; background: rgba(255, 255, 255, 0.25); }
  .modal.sheet .modal-head { padding: 8px 16px 10px; }
  .modal.sheet .modal-body { padding: 12px 14px 8px; }
  .modal.sheet .move-grid .move-btn { min-height: 64px; padding-right: 10px; }
  .modal.sheet .move-btn-meta { gap: 5px; font-size: 11px; }
  .modal.sheet .move-btn-meta .type-badge { padding: 1px 6px; font-size: 9px; }
  .modal.sheet .picker-actions { gap: 8px; margin-top: 12px; }
  .modal.sheet .picker-actions .btn { flex: 1 1 0; min-height: 46px; }
}

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: var(--panel-border-strong);
  border-left: 4px solid var(--info);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.9rem;
  pointer-events: auto;
  animation: toast-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.1);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--info); }
.toast .toast-icon { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.toast.ok .toast-icon { color: var(--success); }
.toast.err .toast-icon { color: var(--danger); }
.toast.info .toast-icon { color: var(--info); }
.toast .toast-text { flex: 1 1 auto; word-break: break-word; }
.toast .toast-close { flex: none; background: none; border: 0; color: var(--muted); padding: 0 2px; line-height: 1; }
.toast .toast-close:hover { color: var(--text); }
.toast.leaving { animation: toast-out 0.2s ease forwards; }

/* An invitation (battle challenge / trade offer, DECISIONS 205). Same quiet card, but it
   carries the accent edge, one short glow to catch the eye and a button you can hit with a
   thumb; on a phone the whole strip goes full width just above the safe area, because there
   the corner toast was easy to miss entirely. */
.toast.invite {
  border-left-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 1px rgba(214, 69, 69, 0.28);
  animation: toast-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.1), toast-invite-glow 1.1s ease-out 2;
}
.toast.invite .toast-icon { color: var(--accent-light); }
.toast.invite .toast-text { font-weight: 600; }
@keyframes toast-invite-glow {
  0%, 100% { box-shadow: var(--shadow), 0 0 0 1px rgba(214, 69, 69, 0.28); }
  45% { box-shadow: var(--shadow), 0 0 0 3px rgba(214, 69, 69, 0.34); }
}
@media (max-width: 640px) {
  .toast-container { left: 12px; right: 12px; max-width: none; gap: 6px; }
  /* Compact on a phone (idea #86, DECISIONS 602): five full ones covered a quarter of the screen. */
  .toast { padding: 7px 10px; font-size: 0.82rem; gap: 8px; }
  .toast.invite { flex-wrap: wrap; padding: 9px 10px; font-size: 0.88rem; }
  .toast.invite .toast-action { flex: 1 1 100%; margin: 4px 0 0; padding: 8px 12px; font-size: 0.88rem; }
}

/* --------------------------------------------------------------------------
   Loading / skeleton
   -------------------------------------------------------------------------- */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
/*
 * The loading screen of every page (owner, 25 September: "it has to be clear the page is loading").
 * A Poké Ball that rocks the way it shakes during a catch, the page's own line in bold under it
 * ("Loading the league…") and a sliding bar - js/util.js loadingBlock(), the plain `.view-loading`
 * lines (their ball and bar are ::before / ::after), stats.html and the boot splash of index.html.
 * It fades in after 0.15 s, so a page that answers at once never flashes it.
 */
.loading-block, .view-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  min-height: 180px; padding: 28px 16px; text-align: center;
  color: var(--text); font-weight: 700; font-size: 0.95rem; letter-spacing: 0.01em;
  animation: loading-in 0.25s ease 0.15s both;
}
/* One element each: the ball is two gradients (red top, white bottom, the black band and button). */
.loader-ball, .view-loading::before {
  content: '';
  flex: none;
  width: 46px; height: 46px; border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #f4f6fa 0 12%, #1b2233 13% 21%, transparent 22%),
    linear-gradient(to bottom, #e04848 0 44%, #1b2233 44% 56%, #f4f6fa 56% 100%);
  box-shadow: inset 0 0 0 2.5px #1b2233, inset -5px -7px 0 rgba(0, 0, 0, 0.14), 0 8px 14px -6px rgba(0, 0, 0, 0.55);
  transform-origin: 50% 88%;
  /* A little see-through: it says "loading" without taking over the page (owner, 25 September). */
  opacity: 0.7;
  animation: loader-shake 1.5s ease-in-out infinite;
}
/* An indeterminate bar: a red streak sliding over a faint track. */
.loading-bar, .view-loading::after {
  content: '';
  display: block; flex: none;
  width: 150px; height: 4px; border-radius: 4px;
  background:
    linear-gradient(90deg, transparent, var(--accent) 30%, var(--accent-light, #ff8a80) 50%, var(--accent) 70%, transparent) no-repeat,
    rgba(255, 255, 255, 0.12);
  background-size: 45% 100%, 100% 100%;
  /* Left to right at one steady speed, then again from the left - it says "busy", not how far
     (owner, 25 September: "gewoon een animatie van links naar rechts, ongeacht hoever het laden is,
     en dan loopen"). Was ease-in-out from far outside the track: the streak lingered out of sight
     at both ends and then shot through, which read as a jumpy bar, not a loop. */
  animation: loader-bar 1.3s linear infinite;
}
/* The small ones: a picker in a pop-up and the Bag drawer in a battle. */
.picker-list .view-loading, .battle-sub .view-loading, .loading-block.compact { min-height: 0; padding: 16px 12px; gap: 8px; font-size: 0.85rem; }
.picker-list .view-loading::before, .battle-sub .view-loading::before, .loading-block.compact .loader-ball { width: 30px; height: 30px; }
@keyframes loading-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
/* The capture shake: tip left, right, left, settle, rest. */
@keyframes loader-shake {
  0%, 55%, 100% { transform: rotate(0); }
  10% { transform: rotate(-20deg); }
  22% { transform: rotate(16deg); }
  34% { transform: rotate(-10deg); }
  45% { transform: rotate(5deg); }
}
/* -85% / 185%: the streak (45 % of the track) starts just outside the left edge and ends just
   outside the right one, so the track is hardly ever empty between two runs. */
@keyframes loader-bar { from { background-position: -85% 0, 0 0; } to { background-position: 185% 0, 0 0; } }
@media (prefers-reduced-motion: reduce) {
  .loader-ball, .view-loading::before { animation: none; }
  /* The ball stands still; the bar keeps its left-to-right run, only slower, because a bar that
     pulses in the middle reads as "half loaded" (owner, 25 September). */
  .loading-bar, .view-loading::after { animation: loader-bar 2.4s linear infinite; }
}
@keyframes loader-pulse { 50% { opacity: 0.45; } }
.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.06) 25%, rgba(255,255,255,0.12) 50%, rgba(255,255,255,0.06) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-xs);
  min-height: 1em;
}
/* A placeholder card (DECISIONS 319, js/util.js skeletons()): the element keeps the real card's
   class, so it has exactly its size in the real grid; only the look is swapped for the shimmer.
   Its text and parts stay in place but invisible. !important because it is a state on top of
   every card class (.team-row, .move-btn, .pc-tile ...), which all set their own background.
   The shine runs over the dark panel colour, so it also reads on the light page background.
   Reduced motion: still grey blocks, no shimmer (rule right below). */
.is-skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.07) 25%, rgba(255,255,255,0.15) 50%, rgba(255,255,255,0.07) 75%), var(--panel) !important;
  background-size: 200% 100% !important;
  animation: shimmer 1.4s linear infinite !important;
  border-color: rgba(255, 255, 255, 0.06) !important;
  box-shadow: none !important;
  color: transparent !important;
  pointer-events: none;
  cursor: default;
}
.is-skeleton > * { visibility: hidden; }
/* Its own line: the !important shorthand above outranks the global reduced-motion rule (a class
   beats *), so the shimmer is switched off here by name. */
@media (prefers-reduced-motion: reduce) { .is-skeleton { animation: none !important; } }

/* --------------------------------------------------------------------------
   Animations
   -------------------------------------------------------------------------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes pulse-dot { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.5); opacity: 0.55; } }

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