/* Mobile-first. Desktop just gets a wider, centred column. */
:root {
  --bg: #0d1220;
  --bg-2: #141c30;
  --card: #1a2440;
  --card-2: #223057;
  --line: #2c3a63;
  --text: #eef2fb;
  --muted: #94a2c4;
  --accent: #ffd447;
  --accent-2: #4dd6ff;
  --good: #45d68a;
  --warn: #ffa943;
  --bad: #ff6b7a;
  --radius: 14px;
  --tabbar: 62px;
  --pad: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}

#app {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) var(--pad)
           calc(var(--tabbar) + env(safe-area-inset-bottom) + 18px);
  max-width: 720px;
  margin: 0 auto;
}
body.no-tabbar #app { padding-bottom: calc(env(safe-area-inset-bottom) + 18px); }

h1 { font-size: 21px; margin: 16px 0 4px; }
h2 { font-size: 17px; margin: 20px 0 8px; }
h3 { font-size: 15px; margin: 0 0 6px; }
p  { margin: 6px 0; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }

/* ── Controls ─────────────────────────────────────────────────────────────── */
button, input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  width: 100%;
}
button { cursor: pointer; touch-action: manipulation; }
button:active { transform: scale(0.985); }
button:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--accent); color: #17203a; border-color: var(--accent); font-weight: 650; }
.btn-ghost   { background: transparent; }
.btn-danger  { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1; }
.btn-sm { padding: 8px 10px; font-size: 13px; width: auto; }

label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

/* Checkbox rows: the global `width: 100%` on inputs would blow up the box. */
label.check-field { display: flex; align-items: center; gap: 10px; margin: 12px 0; cursor: pointer; }
label.check-field > input[type="checkbox"] { width: 18px; height: 18px; flex: none; padding: 0; accent-color: var(--accent); }
label.check-field > span { font-size: 14px; }

/* Hidden native file input driven by a styled button. */
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ── Layout blocks ────────────────────────────────────────────────────────── */
.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  margin: 12px 0;
}
.hero { text-align: center; padding: 26px 18px; }
.hero .logo { font-size: 42px; line-height: 1; }

.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

.sticky-search {
  position: sticky;
  top: 0;
  z-index: 5;
  background: linear-gradient(var(--bg) 72%, transparent);
  padding: 10px 0 12px;
}

/* ── Tag cards ────────────────────────────────────────────────────────────── */
.list { display: grid; gap: 8px; }
.tag {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.tag.has-thumb { grid-template-columns: auto 1fr auto; }
.tag.owned { border-color: #2f6b4d; background: #172a25; }
.tag.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tag .name { font-weight: 620; }
.tag .sub { font-size: 12px; color: var(--muted); }
.tag .stars { color: var(--accent); font-size: 12px; letter-spacing: 1px; }

/* Disc faces. Aspect ratio is the source art's (1048x833), so a face never
   distorts and a row keeps its height whether the image has loaded or not. */
.thumb {
  flex: none;
  width: 66px;
  aspect-ratio: 1048 / 833;
  object-fit: contain;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #0b1120;
}
.thumb.sm { display: block; width: 100%; margin: 0 auto 4px; border-radius: 7px; }
/* Inline, in the "send this one" line: the disc you have to physically grab. */
.thumb.xs { width: 38px; border-radius: 6px; vertical-align: middle; }

/* "À préciser": the candidates side by side, faces first. Scrolls sideways
   rather than wrapping, so the strip never pushes the sheet's buttons away. */
.choices { display: flex; gap: 6px; overflow-x: auto; margin-top: 8px; padding: 2px 0 4px; }
.choice {
  flex: none;
  width: 88px;
  display: block;
  text-align: center;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card-2);
  cursor: pointer;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.choice.off { opacity: .45; cursor: default; }
.ch-nm { display: block; font-size: 11px; font-weight: 620; margin-top: 3px; }
.ch-sub { display: block; font-size: 10px; color: var(--muted); }
/* No face on disk: a type-coloured monogram, so the row still reads. */
.thumb.none {
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 750; letter-spacing: .5px;
  color: #0f1626; text-transform: uppercase;
}
/* The "ignore this one" tile has no type to borrow a colour from. */
.thumb.none.skip { background: var(--card); color: var(--muted); font-size: 15px; }

.pills { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.type { color: #0f1626; font-weight: 640; border: 0; }
.pill.mech { background: #3a2a5e; border-color: #574089; }
.pill.ok   { background: #1d4033; border-color: #2f6b4d; color: #9de9c2; }
.pill.warn { background: #4a3413; border-color: #7a5720; color: #ffd08a; }
/* The yellow "Special" banner printed on promo discs, so the badge reads like the disc. */
.pill.special {
  background: linear-gradient(180deg, #ffd85e, #e8a71b);
  border-color: #b87f10;
  color: #3a2600;
  font-weight: 720;
  font-style: italic;
  letter-spacing: .3px;
}

/* Battle-type picker: the first choice of a battle, so it is a target, not a dropdown. */
.seg { display: flex; gap: 8px; margin: 8px 0 4px; }
.seg-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  padding: 10px 12px;
  min-height: 56px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  color: inherit;
}
.seg-btn.on { border-color: var(--accent); background: var(--card-2); box-shadow: 0 0 0 1px var(--accent) inset; }
.seg-label { font-weight: 640; font-size: 14px; }
.seg-hint { font-size: 11px; color: var(--muted); line-height: 1.25; }
@media (max-width: 380px) { .seg { flex-direction: column; } }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 8px; font-size: 11px; color: var(--muted); margin-top: 6px; }

/* 18 Pokémon types, so a matchup reads at a glance without reading the label. */
.t-Normal{background:#a8a878}.t-Fire{background:#f08030}.t-Water{background:#6890f0}
.t-Electric{background:#f8d030}.t-Grass{background:#78c850}.t-Ice{background:#98d8d8}
.t-Fighting{background:#c03028;color:#fff!important}.t-Poison{background:#a040a0;color:#fff!important}
.t-Ground{background:#e0c068}.t-Flying{background:#a890f0}.t-Psychic{background:#f85888}
.t-Bug{background:#a8b820}.t-Rock{background:#b8a038}.t-Ghost{background:#705898;color:#fff!important}
.t-Dragon{background:#7038f8;color:#fff!important}.t-Dark{background:#705848;color:#fff!important}
.t-Steel{background:#b8b8d0}.t-Fairy{background:#ee99ac}

/* ── Battle results ───────────────────────────────────────────────────────── */
.team { background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin: 10px 0; }
.team.best { border-color: var(--accent); }
.team-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.team-head .rank { font-size: 18px; font-weight: 700; }
.team-head .score { margin-left: auto; font-size: 12px; color: var(--muted); }
.team-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.slot { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.slot .nm { font-size: 12px; font-weight: 620; overflow-wrap: anywhere; }
.slot .st { font-size: 10px; color: var(--accent); }

.matchup { margin-top: 10px; display: grid; gap: 6px; }
.mu { background: var(--card); border-radius: 12px; padding: 9px 11px; border-left: 3px solid var(--line); }
.mu.v-devastating, .mu.v-super-effective { border-left-color: var(--good); }
.mu.v-neutral { border-left-color: var(--muted); }
.mu.v-risky, .mu.v-resisted { border-left-color: var(--warn); }
.mu.v-no-effect { border-left-color: var(--bad); }
.mu .line { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.mult { font-weight: 700; }
.mult.up { color: var(--good); }
.mult.down { color: var(--warn); }
.mult.zero { color: var(--bad); }

.why { margin-top: 6px; font-size: 11px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
details.explain > summary { font-size: 12px; color: var(--accent-2); cursor: pointer; margin-top: 8px; }

/* ── Opponent slots ───────────────────────────────────────────────────────── */
.opps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.opp {
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 10px 6px;
  min-height: 78px;
  text-align: center;
  font-size: 12px;
}
.opp.filled { border-style: solid; border-color: var(--accent-2); }
.opp .x { font-size: 11px; color: var(--muted); }

/* ── Sheet / modal ────────────────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; background: #000a; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg-2);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  width: 100%; max-width: 720px;
  max-height: 88dvh;
  display: flex; flex-direction: column;
  padding: 12px var(--pad) calc(env(safe-area-inset-bottom) + 14px);
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: .6; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 2px auto 10px; }
.sheet-body { overflow: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding-top: 10px; }

/* ── Tab bar ──────────────────────────────────────────────────────────────── */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: #0f1728ee;
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar .tab {
  background: none; border: 0; border-radius: 0;
  padding: 8px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted);
}
#tabbar .tab .ico { font-size: 19px; }
#tabbar .tab[aria-current="page"] { color: var(--accent); }

/* ── Toasts / status ──────────────────────────────────────────────────────── */
#toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 12px);
  z-index: 60; display: grid; gap: 6px; width: min(92vw, 520px);
}
.toast {
  background: #223057; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 13px; font-size: 13px; box-shadow: 0 8px 24px #0007;
  animation: rise .16s ease-out;
}
.toast.err { background: #43202a; border-color: #7a3140; }
.toast.ok  { background: #17352a; border-color: #2f6b4d; }

.spinner {
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite; display: inline-block; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.busy { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 26px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px 14px; }

.preview { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); display: block; }

@media (min-width: 720px) {
  :root { --pad: 20px; }
  .team-slots { grid-template-columns: repeat(3, 1fr); }
}
