:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #cde2fb;
  --other: #b5b3ab;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-soft: #184f95;
    --other: #7a7973;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-soft: #184f95;
  --other: #7a7973;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--accent-ink); }

.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }

header h1 { font-size: 22px; margin: 0; letter-spacing: 0.02em; }
header .meta { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

.filters {
  display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center;
  margin: 20px 0 16px;
}
.filter-label { font-size: 12px; color: var(--text-muted); margin-right: 6px; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button {
  font: inherit; font-size: 13px; border: 0; background: transparent; color: var(--text-secondary);
  padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--surface-2); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.kpi .label { font-size: 12px; color: var(--text-muted); }
.kpi .value { font-size: 26px; font-weight: 650; line-height: 1.25; overflow-wrap: anywhere; }
.kpi .value.small { font-size: 17px; padding-top: 5px; }
.kpi .sub { font-size: 12px; color: var(--text-secondary); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 4px; }
.card .note { font-size: 12px; color: var(--text-muted); margin: 0 0 12px; }

.badge {
  display: inline-block; font-size: 11px; line-height: 1; padding: 3px 6px; border-radius: 4px;
  background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border);
  vertical-align: 2px; margin-left: 6px; white-space: nowrap;
}

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { font-size: 12px; font-weight: 500; color: var(--text-muted); text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

.share-table tbody tr { cursor: pointer; }
.share-table tbody tr:hover { background: var(--surface-2); }
.share-table tbody tr[aria-selected="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.share-table .rank { color: var(--text-muted); width: 2em; }
.share-table .name { font-weight: 550; min-width: 9em; }
.type-cell { display: inline-flex; align-items: center; gap: 10px; }
.type-name { word-break: keep-all; overflow-wrap: anywhere; }
.thumbs {
  display: inline-flex; gap: 2px; flex: none; width: 64px; height: 40px; border-radius: 6px; overflow: hidden;
  background: var(--surface-2); border-bottom: 3px solid transparent;
}
.thumbs.large { width: 120px; height: 72px; border-bottom-width: 4px; }
.thumbs img { flex: 1 1 0; min-width: 0; height: 100%; object-fit: cover; display: block; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

.bar-cell { width: 34%; min-width: 120px; }
.bar { position: relative; height: 12px; }
.bar > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }

.more { margin-top: 8px; font: inherit; font-size: 13px; background: none; border: 0; color: var(--accent-ink); cursor: pointer; padding: 4px 0; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dim { opacity: 0.18; }
.chart .endlabel { font-size: 11px; fill: var(--text-secondary); }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 10px; font-size: 12px; color: var(--text-secondary); }
.legend span { cursor: default; white-space: nowrap; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); border-radius: 8px; padding: 8px 10px; font-size: 12px;
  min-width: 170px; z-index: 5; display: none;
}
.tooltip .t-head { color: var(--text-muted); margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.empty { color: var(--text-muted); font-size: 13px; padding: 24px 0; text-align: center; }

.detail-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin-bottom: 12px; }
.detail-head h2 { font-size: 20px; margin: 0; }
.detail-head .stats { color: var(--text-secondary); font-size: 13px; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; }
.subhead { font-size: 13px; font-weight: 600; margin: 0 0 8px; }

.recipe-group { margin-bottom: 10px; }
.recipe-group h4 { font-size: 12px; font-weight: 500; color: var(--text-muted); margin: 0 0 2px; display: flex; justify-content: space-between; }
.recipe-row { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; font-size: 14px; border-bottom: 1px dashed var(--grid); }
.recipe-row .count { font-variant-numeric: tabular-nums; font-weight: 600; }
.deckcode { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 12px; font-size: 13px; }
.deckcode code { font-size: 13px; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }
.deckcode button { font: inherit; font-size: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary); border-radius: 6px; padding: 2px 8px; cursor: pointer; }

.meter { position: relative; height: 8px; background: var(--surface-2); border-radius: 4px; min-width: 60px; }
.meter > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 4px; }
.cards-table td.name { min-width: 8em; }
.dist { display: inline-flex; gap: 2px; }
.dist span {
  width: 22px; height: 20px; border-radius: 3px; font-size: 10px; line-height: 20px; text-align: center;
  color: var(--text-secondary); background: var(--surface-2); font-variant-numeric: tabular-nums;
}
.dist span.hot { color: #fff; }
.zone-row td { font-size: 12px; color: var(--text-muted); background: var(--surface-2); padding: 3px 8px; }

.samples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.samples a { font-size: 12px; text-decoration: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; color: var(--text-secondary); }
.samples a b { color: var(--text-primary); font-weight: 600; margin-right: 4px; }

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

@media (max-width: 760px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .bar-cell { min-width: 70px; width: 28%; }
  .thumbs { width: 48px; height: 30px; }
  .type-cell { gap: 8px; }
  .hide-sm { display: none; }
}

/* ---- detail modal ---- */
body.no-scroll { overflow: hidden; }
.modal { position: fixed; inset: 0; z-index: 20; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.modal-panel {
  position: relative; margin: 3vh auto; width: min(1000px, calc(100% - 32px)); max-height: 94vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px 20px 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
}
.modal-close {
  position: sticky; top: 0; float: right; z-index: 2; width: 36px; height: 36px; margin: -6px -6px 0 8px;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); }
.modal-panel section { margin-top: 22px; }
.modal-panel .detail-head { display: block; margin: 0; }
.modal-panel .detail-head h2 { font-size: 22px; margin: 0 0 8px; }
.detail-head .stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--text-secondary); }
.placings { display: inline-flex; flex-wrap: wrap; gap: 4px 10px; }
.placings b { margin-left: 3px; color: var(--text-primary); font-variant-numeric: tabular-nums; }

.chip-btn { font: inherit; font-size: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary); border-radius: 6px; padding: 2px 8px; cursor: pointer; }
.deck-image img { display: block; width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--border); }

.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.recipe-card { position: relative; margin: 0; }
.recipe-card img, .card-tile img { display: block; width: 100%; height: auto; border-radius: 5px; }
.count-badge {
  position: absolute; right: 4px; bottom: 4px; min-width: 24px; padding: 1px 6px; border-radius: 6px;
  background: rgba(11, 11, 11, 0.85); color: #fff; font-weight: 700; font-size: 14px; text-align: center; font-variant-numeric: tabular-nums;
}
.card-missing {
  display: flex; align-items: center; justify-content: center; aspect-ratio: 250 / 349; padding: 6px; border-radius: 5px;
  background: var(--surface-2); color: var(--text-secondary); font-size: 12px; text-align: center;
}

.zone-head { font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 14px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--grid); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 14px 12px; }
.card-tile { margin: 0; min-width: 0; }
.card-tile figcaption { margin-top: 6px; font-size: 12px; display: grid; gap: 4px; }
.card-name { font-weight: 600; font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
.card-stat { display: flex; justify-content: space-between; align-items: baseline; color: var(--text-secondary); }
.card-stat b { font-size: 15px; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.card-tile .meter { min-width: 0; height: 6px; }
.card-tile .dist span { width: auto; flex: 1; }
.card-tile .dist { display: flex; }

.samples-table td { font-size: 13px; }
.samples-table td.event { min-width: 14em; }
.rank-chip {
  display: inline-block; min-width: 4.2em; text-align: center; font-size: 12px; font-weight: 600; padding: 2px 6px; border-radius: 5px;
  background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border); white-space: nowrap;
}
.rank-chip.r1 { background: var(--accent); color: #fff; border-color: transparent; }
.rank-chip.r2 { background: var(--accent-soft); color: var(--text-primary); border-color: transparent; }

@media (max-width: 760px) {
  .modal-panel { margin: 0; width: 100%; max-height: 100%; height: 100%; border-radius: 0; padding: 14px 14px 32px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px 8px; }
  .recipe-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
}

/* ---- sub-type chooser ---- */
.chooser { display: grid; gap: 8px; }
.chooser-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; text-align: left;
  font: inherit; color: var(--text-primary); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; cursor: pointer;
}
.chooser-row:hover { background: var(--surface-2); }
.chooser-row .type-name { font-weight: 600; }
.chooser-stat { color: var(--text-secondary); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---- link to the win-rate site ---- */
.extlink { margin: 8px 0 0; font-size: 13px; }
.extlink:empty { display: none; }
.extlink a { font-weight: 600; }
