/* AgentDex battle UI
   Color tokens follow the project's validated data-viz palette:
   status (good/warning/serious/critical) drives the HP meter and
   status-effect badges; a fixed categorical mapping drives type badges
   so each type always renders the same hue (identity, never color-alone —
   every badge also carries its text label). */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ee;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --gridline: #e1e0d9;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --type-fire: #eb6834;
  --type-water: #2a78d6;
  --type-electric: #eda100;
  --type-grass: #008300;
  --type-flying: #4a3aa7;
  --type-normal: #898781;
  --type-ground: #a9885f;

  --accent: #2a78d6;
  --accent-ink: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --gridline: #2c2c2a;

    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;

    --type-fire: #d95926;
    --type-water: #3987e5;
    --type-electric: #c98500;
    --type-grass: #008300;
    --type-flying: #9085e9;
    --type-normal: #c3c2b7;
    --type-ground: #c2a074;

    --accent: #3987e5;
    --accent-ink: #0b0b0b;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--gridline);
  background: var(--surface-1);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand-mark { font-size: 20px; }

.conn { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.dot.ok { background: var(--status-good); }
.dot.err { background: var(--status-critical); }

/* ---------- stage / panel ---------- */

.stage {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 24px 16px 40px;
}

.panel {
  width: 100%;
  max-width: 640px;
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: 16px;
  padding: 24px;
}

.title { margin: 0 0 4px; font-size: 22px; }
.subtitle { margin: 0 0 20px; color: var(--text-secondary); font-size: 14px; }

.form-grid { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }

input[type="text"], input[type="number"] {
  background: var(--surface-2);
  border: 1px solid var(--gridline);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-primary);
  font-family: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.species-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.species-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  border-radius: 10px;
  border: 2px solid var(--gridline);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
}
.species-card:hover { border-color: var(--accent); }
.species-card[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
}
.species-emoji { font-size: 26px; }
.species-name { font-weight: 600; text-transform: capitalize; }
.species-types { display: flex; gap: 3px; }

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

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-large { width: 100%; padding: 14px; font-size: 16px; margin-top: 22px; }

.btn-secondary { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--gridline); }
.btn-secondary:hover { border-color: var(--accent); }

.btn-link {
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  padding: 2px 4px;
}
.btn-link:hover { text-decoration: underline; }

.btn-back {
  display: inline-block;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  margin-bottom: 14px;
}
.btn-back:hover { color: var(--accent); }

/* ---------- mode select ---------- */

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 8px;
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  padding: 18px 16px;
  border-radius: 12px;
  border: 2px solid var(--gridline);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
}
.mode-card:hover { border-color: var(--accent); }
.mode-emoji { font-size: 26px; }
.mode-title { font-weight: 700; font-size: 15px; }
.mode-desc { font-size: 12px; color: var(--text-secondary); line-height: 1.4; }

@media (max-width: 480px) {
  .mode-grid { grid-template-columns: 1fr; }
}

/* ---------- battle scene ---------- */

.battle-panel { max-width: 720px; }

.field-scene { display: flex; flex-direction: column; gap: 10px; }

.combatant {
  background: var(--surface-2);
  border: 1px solid var(--gridline);
  border-radius: 12px;
  padding: 12px 14px;
}
.combatant-wild { align-self: flex-start; width: 82%; }
.combatant-player { align-self: flex-end; width: 82%; }

.combatant-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.combatant-emoji { font-size: 30px; }
.combatant-id { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.combatant-name { font-weight: 700; font-size: 15px; text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combatant-level { font-size: 12px; color: var(--text-muted); }

.type-badges { display: flex; gap: 4px; }
.type-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 3px 7px;
  border-radius: 999px;
  color: #ffffff;
  white-space: nowrap;
}

.hp-row { display: flex; align-items: center; gap: 8px; }
.hp-bar-track {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: var(--gridline);
  overflow: hidden;
}
.hp-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--status-good);
  transition: width 0.4s ease, background-color 0.4s ease;
  width: 100%;
}
.hp-bar-fill.warning { background: var(--status-warning); }
.hp-bar-fill.critical { background: var(--status-critical); }
.hp-text { font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; min-width: 62px; text-align: right; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  color: #ffffff;
}
.status-badge.burn { background: var(--status-serious); }
.status-badge.paralysis { background: var(--status-warning); color: #241a00; }

.vs-divider { text-align: center; font-size: 11px; font-weight: 700; color: var(--text-muted); letter-spacing: 0.1em; }

/* ---------- taunt / log ---------- */

.taunt-bubble {
  margin-top: 14px;
  background: var(--surface-2);
  border: 1px dashed var(--gridline);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
}
.taunt-source { font-weight: 700; margin-right: 6px; color: var(--text-secondary); }
.taunt-text { font-style: italic; }

.log-panel {
  margin-top: 14px;
  height: 160px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--gridline);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.log-turn-header { margin-top: 8px; font-weight: 700; color: var(--text-secondary); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.log-turn-header:first-child { margin-top: 0; }
.log-line { color: var(--text-primary); }

/* ---------- moves ---------- */

.moves-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.move-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid var(--gridline);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.move-btn:hover:not(:disabled) { border-color: var(--accent); }
.move-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.move-name { font-weight: 700; font-size: 13px; text-transform: capitalize; }
.move-meta { font-size: 11px; color: var(--text-muted); }

/* ---------- pvp setup (tabs / waiting room / open matches) ---------- */

.tab-row { display: flex; gap: 6px; margin-bottom: 18px; }
.tab-btn {
  flex: 1;
  border: 2px solid var(--gridline);
  background: var(--surface-2);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 10px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.tab-btn:hover { border-color: var(--accent); }
.tab-btn[aria-selected="true"] {
  border-color: var(--accent);
  color: var(--text-primary);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
}

.field-label-row { display: flex; align-items: center; justify-content: space-between; }

.open-matches-list { display: flex; flex-direction: column; gap: 8px; }
.empty-hint { margin: 0; font-size: 12px; color: var(--text-muted); }

.open-match-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--gridline);
  background: var(--surface-2);
  font-size: 13px;
}
.open-match-row .om-who { display: flex; align-items: center; gap: 8px; }
.open-match-row .om-emoji { font-size: 20px; }
.open-match-row .om-name { font-weight: 700; text-transform: capitalize; }
.open-match-row .om-id { font-size: 11px; color: var(--text-muted); }

.waiting-room {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 20px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px dashed var(--gridline);
}
.waiting-title { margin: 0; font-weight: 700; }
.waiting-desc { margin: 0; font-size: 12px; color: var(--text-secondary); max-width: 46ch; }

.match-id-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: 999px;
  padding: 6px 6px 6px 14px;
  font-size: 12px;
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--gridline);
  border-top-color: var(--accent);
  animation: pvp-spin 0.8s linear infinite;
}
@keyframes pvp-spin { to { transform: rotate(360deg); } }

/* ---------- pvp battle: match meta / turn status ---------- */

.match-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.match-meta code { color: var(--text-secondary); }

.turn-status {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--gridline);
  border-radius: 8px;
  padding: 8px 12px;
}
.turn-status .spinner { width: 14px; height: 14px; border-width: 2px; }
.turn-status .countdown { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }

/* ---------- error / end ---------- */

.error-banner {
  margin-top: 12px;
  background: color-mix(in srgb, var(--status-critical) 14%, var(--surface-1));
  border: 1px solid var(--status-critical);
  color: var(--status-critical);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}

.end-banner {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--gridline);
}
.end-title { font-size: 18px; font-weight: 800; }
.end-title.win { color: var(--status-good); }
.end-title.lose { color: var(--status-critical); }
.end-title.draw { color: var(--status-warning); }

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

.footer {
  padding: 10px 20px;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--gridline);
}

@media (max-width: 480px) {
  .moves-grid { grid-template-columns: 1fr; }
  .combatant-wild, .combatant-player { width: 100%; }
}
