:root {
  color-scheme: light;
  --page: #f3f2f0;
  --surface: #ffffff;
  --ink: #18181b;
  --ink-2: #52525b;
  --muted: #8a8a93;
  --line: rgba(24, 24, 27, 0.13);
  --line-strong: rgba(24, 24, 27, 0.26);
  --you: #2563c9;
  --them: #d23f3f;
  --win: #1f9d55;
  --draw: #c98f00;
  --loss: #d23f3f;
  --forfeit: #6b6b74;
  --button: #18181b;
  --button-ink: #ffffff;
  --r: 3px;
  --sans: "Petrov Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #111113;
    --surface: #1b1b1f;
    --ink: #f1f1f3;
    --ink-2: #c3c3ca;
    --muted: #8a8a93;
    --line: rgba(255, 255, 255, 0.11);
    --line-strong: rgba(255, 255, 255, 0.22);
    --you: #5b8ff0;
    --them: #f06262;
    --win: #34c172;
    --draw: #e3b022;
    --loss: #f06262;
    --forfeit: #8a8a93;
    --button: #f1f1f3;
    --button-ink: #111113;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 380 15px/1.45 var(--sans);
  font-feature-settings: "tnum";
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a { color: inherit; }

header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
h1 { margin: 0; font-size: 28px; font-weight: 750; letter-spacing: -0.03em; }
h1::first-letter { color: var(--them); }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
h2 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }

button.icon {
  width: 34px; height: 34px; border-radius: var(--r);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 600;
}
button.primary {
  display: block; width: 100%; padding: 11px 16px; border: 0; border-radius: var(--r);
  background: var(--button); color: var(--button-ink); font-weight: 600;
}
button.primary:disabled { opacity: 0.35; cursor: default; }
button.secondary {
  display: block; width: 100%; margin-top: 8px; padding: 10px 16px; border-radius: var(--r);
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink); font-weight: 600;
}

.modes { display: flex; gap: 4px; margin: -6px 0 16px; padding: 3px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.modes a {
  flex: 1; padding: 6px 0; text-align: center; text-decoration: none; border-radius: 2px;
  font-size: 14px; font-weight: 600; color: var(--muted);
}
.modes a[aria-current="page"] { background: var(--button); color: var(--button-ink); }

.label, .kicker { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.kicker { margin: 0 0 10px; }

/* Power budget */
.power { margin-bottom: 14px; }
.power-row { display: flex; justify-content: space-between; align-items: baseline; }
.power-num b { font-size: 22px; font-weight: 700; }
.power-num small { color: var(--muted); font-size: 14px; }
.bar { height: 8px; margin: 6px 0 10px; background: var(--line); border-radius: var(--r); overflow: hidden; }
.bar .fill { height: 100%; width: 100%; background: var(--you); transition: width 0.5s ease; }
.pips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 0; padding: 0; list-style: none; }
.pips li {
  height: 30px; display: grid; place-items: center; border-radius: var(--r);
  border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 600;
}
.pips li.current { border-color: var(--ink); color: var(--ink); }
.pips li.win { background: var(--win); border-color: var(--win); color: #fff; }
.pips li.draw { background: var(--draw); border-color: var(--draw); color: #fff; }
.pips li.loss { background: var(--loss); border-color: var(--loss); color: #fff; }
.pips.lives { grid-template-columns: repeat(3, 1fr); }
.pips li.life { color: var(--them); border-color: var(--line-strong); font-size: 15px; }
.pips li.forfeit { background: var(--forfeit); border-color: var(--forfeit); color: #fff; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; margin-bottom: 14px;
}
.error { margin: 0 0 14px; padding: 10px 12px; border-radius: var(--r); border: 1px solid var(--loss); color: var(--loss); }

img.blank { visibility: hidden; }

/* Opponent */
.who { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.who img {
  width: 96px; height: 120px; object-fit: contain; flex: none;
  background: var(--page); border-radius: var(--r);
}
.origin { margin: 4px 0 8px; color: var(--ink-2); font-size: 14px; }
.tier { margin: 0; display: inline-block; padding: 3px 8px; border-radius: var(--r); background: var(--them); color: #fff; font-size: 14px; }
.tier b { font-weight: 700; }

form#pick-form .label { display: block; margin-bottom: 6px; }
.combo { position: relative; margin-bottom: 10px; }
.combo input {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--page); border: 1px solid var(--line-strong); border-radius: var(--r); outline: none;
}
.combo input:focus { border-color: var(--you); }
#suggestions {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none; max-height: 300px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}
#suggestions li { padding: 8px 10px; border-radius: var(--r); cursor: pointer; display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
#suggestions li small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#suggestions li.active { background: var(--page); }
#suggestions li.used { opacity: 0.45; cursor: default; }

/* Result */
.result { border-width: 2px; }
.result.win { border-color: var(--win); }
.result.draw { border-color: var(--draw); }
.result.loss { border-color: var(--loss); }
.result.forfeit { border-color: var(--forfeit); }
.versus { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: start; margin-bottom: 14px; }
.vs { align-self: center; font-weight: 800; color: var(--muted); font-size: 14px; }
.fighter { text-align: center; min-width: 0; }
.fighter img { width: 100%; max-width: 120px; height: 120px; object-fit: contain; background: var(--page); border-radius: var(--r); }
.fighter .side { margin: 6px 0 0; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.fighter.you .side { color: var(--you); }
.fighter.them .side { color: var(--them); }
.fighter .name { margin: 2px 0 4px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.fighter .stat { margin: 0; font-size: 13px; color: var(--ink-2); }
.verdict { margin: 0 0 4px; font-size: 16px; }
.result.win .verdict b { color: var(--win); }
.result.draw .verdict b { color: var(--draw); }
.result.loss .verdict b { color: var(--loss); }
.result.forfeit .verdict b { color: var(--forfeit); }
.cost { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.result:not(:has(button)) .cost { margin-bottom: 0; }

/* Summary */
.summary h2 { font-size: 26px; }
#spare { margin: 2px 0 12px; color: var(--ink-2); }
.recap { margin: 0 0 16px; padding: 0; list-style: none; font-size: 14px; }
.recap li { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-top: 1px solid var(--line); }
.recap .dot { flex: none; width: 10px; height: 10px; border-radius: 2px; transform: translateY(1px); }
.recap .win .dot { background: var(--win); }
.recap .draw .dot { background: var(--draw); }
.recap .loss .dot { background: var(--loss); }
.recap .forfeit .dot { background: var(--forfeit); }
.recap b { font-weight: 600; }
.next { margin: 10px 0 0; text-align: center; color: var(--muted); font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); margin: 0;
  padding: 8px 14px; border-radius: var(--r); background: var(--button); color: var(--button-ink);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

footer { margin-top: 24px; text-align: center; font-size: 12px; color: var(--muted); }

dialog {
  max-width: min(480px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--line-strong);
  border-radius: var(--r); background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog h2 { margin-bottom: 10px; }
dialog p, dialog li { font-size: 14px; }
dialog ul { padding-left: 18px; }
dialog li { margin-bottom: 6px; }
.ladder-title { margin-bottom: 4px; font-weight: 600; }
.ladder { margin-top: 0; color: var(--ink-2); font-size: 12px !important; line-height: 1.6; }
