: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, a.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); }

/* Portraits fade in when they arrive rather than popping in. */
img.portrait { opacity: 0; transition: opacity 0.25s ease; background: var(--page); border-radius: var(--r); object-fit: contain; }
img.portrait.in { opacity: 1; }
img.portrait.blank { opacity: 1; }

/* Opponent */
.who { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.who img { width: 96px; height: 120px; flex: none; }
.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; }
.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; }

/* Daily: the two teams, a battle per row */
.power.over .power-num b, .power.over .label { color: var(--loss); }
.power.over .fill { background: var(--loss); }
.heads { display: grid; grid-template-columns: 1fr 22px 1fr; margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.heads .you { color: var(--you); grid-column: 1; }
.heads .them { color: var(--them); grid-column: 3; }
.lineup { margin: 0 0 14px; padding: 0; list-style: none; display: grid; gap: 8px; }
.row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 8px; }
.row.active { border-color: var(--you); }
.row.done { border-left-width: 4px; animation: land 0.35s ease; }
.row.win { border-color: var(--win); }
.row.draw { border-color: var(--draw); }
.row.loss { border-color: var(--loss); }
.row.forfeit { border-color: var(--forfeit); }
@keyframes land { from { transform: scale(0.98); opacity: 0.6; } }
.pair { display: grid; grid-template-columns: minmax(0, 1fr) 22px minmax(0, 1fr); align-items: center; }
.pair .vs { text-align: center; font-size: 11px; }
.side { position: relative; display: flex; gap: 8px; align-items: flex-start; min-width: 0; min-height: 60px; border-radius: var(--r); }
.side img { width: 46px; height: 58px; flex: none; }
.side .info { min-width: 0; }
.side .name { margin: 0; font-size: 13px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.side .origin { margin: 1px 0 4px; font-size: 11px; color: var(--muted); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side .speed { margin: 3px 0 0; font-size: 11px; color: var(--ink-2); line-height: 1.2; }
.chip { display: inline-block; padding: 1px 6px; border-radius: var(--r); font-size: 12px; color: #fff; white-space: nowrap; }
.chip small { font-size: 11px; opacity: 0.85; }
.side.them .chip { background: var(--them); }
.side.you .chip { background: var(--you); }
.side.you[role="button"] { cursor: pointer; }
.side.you:not(.empty) { padding-right: 18px; }
.side.you.empty {
  align-items: center; justify-content: center; text-align: center; padding: 6px;
  border: 1px dashed var(--line-strong); color: var(--muted); font-size: 13px; font-weight: 600;
}
.row.active .side.you.empty { border-color: var(--you); color: var(--you); }
.row.done .side.you.empty { border-style: solid; }
.remove {
  position: absolute; top: -4px; right: -4px; width: 26px; height: 26px; padding: 0;
  border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1;
}
.remove:hover { color: var(--loss); }
.row .verdict { margin: 8px 0 0; font-size: 13px; }
.row.win .verdict b { color: var(--win); }
.row.draw .verdict b { color: var(--draw); }
.row.loss .verdict b { color: var(--loss); }
.row.forfeit .verdict b { color: var(--forfeit); }
/* The hand */
.hand-wrap { margin: 0 0 14px; }
.hand-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.hand-head .label { color: var(--you); }
.hand-hint { font-size: 12px; color: var(--ink-2); text-align: right; }
.hand { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.hand-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; min-width: 0;
  background: var(--surface); color: var(--ink); text-align: center;
  border: 1px solid var(--line); border-radius: var(--r);
}
.hand-card:hover { border-color: var(--you); }
.hand-card img { width: 56px; height: 70px; }
.hand-card .info { min-width: 0; width: 100%; }
.hand-card .name { margin: 0; font-size: 12px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.hand-card .origin { margin: 1px 0 4px; font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hand-card .chip { background: var(--you); font-size: 11px; }
.hand-card .speed { margin: 3px 0 0; font-size: 10px; color: var(--ink-2); line-height: 1.2; }
.hand-card.placed { opacity: 0.45; border-style: dashed; }
.hand-card .placed-at { margin: 2px 0 0; font-size: 10px; font-weight: 600; color: var(--you); overflow-wrap: anywhere; }
.send .note { margin: 8px 0 14px; color: var(--ink-2); font-size: 13px; text-align: center; }
a.secondary { box-sizing: border-box; text-align: center; text-decoration: none; }
.spare { margin: 2px 0 12px; color: var(--ink-2); }

/* 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; }

/* Desktop: a wider column, bigger type and portraits. Phones keep the
   compact layout above. */
@media (min-width: 760px) {
  body { font-size: 18px; }
  main { max-width: 820px; padding-top: 36px; }
  h1 { font-size: 36px; }
  .sub { font-size: 15px; }
  .modes a { font-size: 16px; padding: 8px 0; }
  .label, .kicker, .heads { font-size: 14px; }
  .power-num b { font-size: 28px; }
  .power-num small { font-size: 16px; }
  .bar { height: 10px; }
  .lineup { gap: 10px; }
  .row { padding: 12px 14px; }
  .pair { grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr); }
  .heads { grid-template-columns: 1fr 40px 1fr; }
  .pair .vs { font-size: 13px; }
  .side { gap: 16px; min-height: 110px; }
  .side img { width: 88px; height: 110px; }
  .side .name { font-size: 20px; }
  .side .origin { font-size: 15px; margin: 2px 0 8px; }
  .side .speed { font-size: 15px; margin-top: 6px; }
  .chip { font-size: 16px; padding: 3px 9px; }
  .chip small { font-size: 14px; }
  .side.you.empty { font-size: 17px; }
  .side.you:not(.empty) { padding-right: 26px; }
  .remove { width: 32px; height: 32px; font-size: 22px; }
  .row .verdict { font-size: 17px; margin-top: 10px; }
  .combo input { font-size: 17px; padding: 12px 14px; }
  .hand { gap: 10px; }
  .hand-hint { font-size: 15px; }
  .hand-card { padding: 12px 8px; gap: 6px; }
  .hand-card img { width: 80px; height: 100px; }
  .hand-card .name { font-size: 16px; }
  .hand-card .origin { font-size: 13px; }
  .hand-card .chip { font-size: 14px; }
  .hand-card .speed, .hand-card .placed-at { font-size: 13px; }
  .suggestions li { font-size: 16px; }
  .suggestions li small { font-size: 13px; }
  button.primary, button.secondary, a.secondary { padding: 13px 18px; font-size: 17px; }
  .send .note { font-size: 16px; }
  .summary h2 { font-size: 32px; }
  .next, footer { font-size: 14px; }
  .who img { width: 128px; height: 160px; }
  .fighter img { max-width: 160px; height: 160px; }
  .fighter .stat, .cost { font-size: 15px; }
  .fighter .side { font-size: 12px; }
  .verdict { font-size: 18px; }
  .tier { font-size: 16px; }
  .origin { font-size: 16px; }
  .recap { font-size: 16px; }
  dialog { max-width: 560px; }
  dialog p, dialog li { font-size: 16px; }
  .ladder { font-size: 13px !important; }
}

/* Wide screens: the hand sits beside the line-up, so there's no scrolling
   between a slot and the cards. Once fought the hand goes, and the
   line-up has the width. */
@media (min-width: 1100px) {
  main:has(#hand-wrap:not([hidden])) { max-width: 1240px; }
  #daily-view {
    display: grid; column-gap: 28px; align-items: start;
    grid-template-columns: minmax(0, 1fr) 440px;
    grid-template-areas: "heads hand" "lineup hand" "send hand" "summary hand";
  }
  #daily-view:has(#hand-wrap[hidden]) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "heads" "lineup" "send" "summary";
    max-width: 820px; margin: 0 auto;
  }
  #daily-view .heads { grid-area: heads; }
  #lineup { grid-area: lineup; }
  #hand-wrap { grid-area: hand; position: sticky; top: 16px; margin: 0; }
  #send-wrap { grid-area: send; }
  #d-summary { grid-area: summary; }
  .hand-card img { width: 64px; height: 80px; }
  .hand-card .name { font-size: 14px; }
  .hand-card .origin { font-size: 12px; }
  .hand-card .chip { font-size: 13px; }
  .hand-card .speed, .hand-card .placed-at { font-size: 12px; }
  .hand-hint { font-size: 14px; }
}
