:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --text: #171a22;
  --muted: #5d6372;
  --border: #d9dce4;
  --accent: #e3350d;
  --accent-2: #2a75bb;
  --focus: #2a75bb;

  --tier-S: #ff5a5f;
  --tier-A: #ff9f43;
  --tier-B: #f7cf46;
  --tier-C: #7bd66f;
  --tier-D: #6ab0ff;

  --t-grass: #3fa34d;
  --t-fire: #e8542f;
  --t-water: #2f86d6;
  --t-lightning: #e2b400;
  --t-psychic: #9b5ad1;
  --t-fighting: #b8662e;
  --t-darkness: #3e4a5c;
  --t-metal: #8a97a6;
  --t-dragon: #b39032;
  --t-colorless: #9ea3ab;
  --t-trainer: #5c6b7a;

  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #222634;
    --text: #eceef4;
    --muted: #9aa1b2;
    --border: #2d3242;
    --accent-2: #5aa5ec;
    --focus: #7ab8f5;
    --t-darkness: #6a7890;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-2: #222634;
  --text: #eceef4;
  --muted: #9aa1b2;
  --border: #2d3242;
  --accent-2: #5aa5ec;
  --focus: #7ab8f5;
  --t-darkness: #6a7890;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
a { color: var(--accent-2); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.5rem; color: var(--text); text-decoration: none; font-size: 1.1rem; white-space: nowrap; }
.brand b { color: var(--accent); }
.brand-mark {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(var(--accent) 0 46%, #222 46% 54%, #f2f2f2 54%);
  border: 2px solid #222; position: relative;
}
.brand-mark::after { content: ''; position: absolute; inset: 5px; border-radius: 50%; background: #fff; border: 2px solid #222; }
.nav { display: flex; gap: 0.25rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a {
  padding: 0.4rem 0.7rem; border-radius: 999px; text-decoration: none; color: var(--muted); white-space: nowrap; font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: #fff; background: var(--accent); }
.theme-toggle {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 1rem; flex: none;
}

main { max-width: 1180px; margin: 0 auto; padding: 1.25rem 16px 3rem; outline: none; }
.footer { max-width: 1180px; margin: 0 auto; padding: 1.5rem 16px 2.5rem; color: var(--muted); font-size: 0.8rem; border-top: 1px solid var(--border); }

/* ---------- generic pieces ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: 0.9rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.section { margin-top: 2rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.75rem; padding: 0.1rem 0.55rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.pill.new { background: #fde7e2; color: #a3240a; border-color: #f6c2b6; }
:root[data-theme='dark'] .pill.new { background: #3a1d17; color: #ffb59f; border-color: #5a2a20; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .pill.new { background: #3a1d17; color: #ffb59f; border-color: #5a2a20; } }
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 0.45rem 0.85rem; border-radius: 8px; font: inherit; font-weight: 500; text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* type chip */
.type {
  display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.72rem; font-weight: 600;
  padding: 0.05rem 0.5rem 0.05rem 0.3rem; border-radius: 999px; color: #fff; background: var(--tc, var(--t-colorless));
}
.type::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: rgb(255 255 255 / 0.85); }

/* ---------- toolbar / filters ---------- */
.tabs { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 0.4rem 0.9rem; cursor: pointer; font: inherit; font-weight: 600;
}
.tab[aria-pressed='true'] { background: var(--text); color: var(--bg); border-color: var(--text); }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 1rem; }
.toolbar input[type='search'], .toolbar select {
  font: inherit; padding: 0.45rem 0.7rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-width: 0;
}
.toolbar input[type='search'] { flex: 1 1 200px; }
.type-filter { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.type-filter button {
  border: 2px solid transparent; background: var(--tc); color: #fff; border-radius: 999px; font: inherit; font-size: 0.75rem; font-weight: 600;
  padding: 0.15rem 0.6rem; cursor: pointer; opacity: 0.45;
}
.type-filter button[aria-pressed='true'] { opacity: 1; border-color: var(--text); }
.mode-blurb { margin: -0.25rem 0 1rem; }

/* ---------- tier rows ---------- */
.tierlist { display: grid; gap: 6px; }
.tier-row { display: grid; grid-template-columns: 76px 1fr; min-height: 92px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tier-label {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  background: var(--tier-color); color: #1a1a1a; font-weight: 800; font-size: 1.9rem; padding: 0.4rem;
}
.tier-label small { font-size: 0.62rem; font-weight: 700; line-height: 1.1; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.02em; }
.tier-items { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; align-content: flex-start; }
.tier-empty { color: var(--muted); font-size: 0.85rem; padding: 0.6rem; }

.tile {
  position: relative; display: flex; flex-direction: column; gap: 0.25rem; width: 168px; padding: 0.55rem 0.65rem 0.6rem;
  border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); border-left: 5px solid var(--tc);
  text-decoration: none; color: var(--text); cursor: pointer; text-align: left; font: inherit;
}
.tile:hover { border-color: var(--muted); border-left-color: var(--tc); transform: translateY(-1px); }
.tile .name { font-weight: 700; font-size: 0.9rem; line-height: 1.2; }
.tile .sub { font-size: 0.75rem; color: var(--muted); line-height: 1.25; }
.tile .meta { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: auto; }
.tile .stat { font-size: 0.72rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.tile .stat b { color: var(--text); }
.tile.compact { width: 132px; }

/* ---------- deck detail ---------- */
.detail-head { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; }
.tier-badges { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.tier-badge { display: grid; grid-template-rows: auto auto; text-align: center; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); min-width: 88px; }
.tier-badge b { background: var(--tier-color); color: #1a1a1a; font-size: 1.4rem; padding: 0.15rem 0; }
.tier-badge span { font-size: 0.7rem; padding: 0.2rem 0.4rem; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.statbar { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.statbar div { display: flex; flex-direction: column; }
.statbar b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.statbar span { font-size: 0.75rem; color: var(--muted); }
.card-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.card-chips > span:not(.type):not(.pill) { padding: 0.2rem 0.6rem; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.85rem; }
ol.steps { margin: 0; padding-left: 1.2rem; display: grid; gap: 0.4rem; }
.matchups { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.matchups ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.matchups a { text-decoration: none; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rank { font-weight: 800; font-size: 1.2rem; color: var(--accent); }

.callout { border-left: 4px solid var(--accent-2); padding: 0.6rem 0.9rem; background: var(--surface); border-radius: 0 8px 8px 0; font-size: 0.9rem; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; row-gap: 0.4rem; }
  .nav { order: 3; flex-basis: 100%; }
  .tier-row { grid-template-columns: 54px 1fr; }
  .tier-label { font-size: 1.5rem; }
  .tier-label small { display: none; }
  .tile { width: calc(50% - 4px); }
  .tile.compact { width: calc(50% - 4px); }
}
