:root {
  --paper: #f5f1e8;
  --surface: #fffdf8;
  --surface-2: #efe9dc;
  --ink: #141210;
  --ink-2: #3d3a35;
  --muted: #6e685d;
  --line: #ddd5c4;
  --accent: #e63946;
  --en: #2457c5;
  --jp: #d62839;
  --up: #17804a;
  --down: #b4471b;
  --mast-bg: #141210;
  --mast-ink: #f5f1e8;
  --shadow: 0 1px 2px rgb(20 18 16 / 6%), 0 4px 16px rgb(20 18 16 / 6%);
  --radius: 10px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  --display: 'Anton', Impact, 'Arial Narrow', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #0f0e0d;
    --surface: #1a1917;
    --surface-2: #24221f;
    --ink: #f3efe6;
    --ink-2: #d4cfc4;
    --muted: #9b9488;
    --line: #2f2c28;
    --en: #7aa2ff;
    --jp: #ff6b78;
    --up: #4cc38a;
    --down: #f08a5d;
    --mast-bg: #000;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --paper: #0f0e0d;
  --surface: #1a1917;
  --surface-2: #24221f;
  --ink: #f3efe6;
  --ink-2: #d4cfc4;
  --muted: #9b9488;
  --line: #2f2c28;
  --en: #7aa2ff;
  --jp: #ff6b78;
  --up: #4cc38a;
  --down: #f08a5d;
  --mast-bg: #000;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  overflow-x: hidden;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { width: min(1240px, 100% - 32px); margin-inline: auto; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------- Masthead ---------- */
.masthead {
  background-color: var(--mast-bg);
  background-image: radial-gradient(rgb(255 255 255 / 9%) 1px, transparent 1.4px);
  background-size: 7px 7px;
  color: var(--mast-ink);
  border-bottom: 4px solid var(--accent);
}
.masthead-inner {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 16px 32px; padding: 32px 0 24px;
}
.kicker { margin: 0 0 4px; font-size: 12px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: #bdb5a6; }
h1 { margin: 0; font: 400 clamp(38px, 7vw, 64px)/0.95 var(--display); text-transform: uppercase; letter-spacing: 0.01em; }
h1 span { color: var(--accent); }
.sub { margin: 8px 0 0; color: #cfc8ba; }
.meta { display: grid; grid-template-columns: auto auto; gap: 2px 14px; margin: 0; font-size: 13px; color: #cfc8ba; }
.meta dt { color: #8f887b; }
.meta dd { margin: 0; text-align: right; font-family: var(--mono); color: var(--mast-ink); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 24px 0 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.stat .label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stat .value { font: 600 22px/1.25 var(--mono); margin-top: 4px; }
.stat .detail { font-size: 13px; color: var(--ink-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat button.detail { all: unset; cursor: pointer; display: block; font-size: 13px; color: var(--ink-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.stat button.detail:hover { text-decoration: underline; }

/* ---------- Controls ---------- */
.controls {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 10px 0; background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.search { flex: 1 1 240px; position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 11px; width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input {
  width: 100%; height: 38px; padding: 0 12px 0 36px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.search input:focus, .select select:focus, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button {
  border: 0; background: transparent; padding: 0 12px; height: 32px; border-radius: 6px;
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.select { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.select select {
  height: 38px; padding: 0 28px 0 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 8px center / 12px;
  appearance: none; color: var(--ink); max-width: 200px;
}
.result-count { margin: 14px 0 10px; font-size: 13px; color: var(--muted); }

/* ---------- Grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(216px, 1fr)); gap: 16px; }
.tile {
  display: flex; flex-direction: column; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer; padding: 0;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--ink-2); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.art {
  position: relative; aspect-ratio: 5 / 6; background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden;
}
.art img { width: 100%; height: 100%; object-fit: contain; padding: 12px 12px 0; }
.art .noimg { font: 600 13px var(--mono); color: var(--muted); }
.badges { position: absolute; top: 8px; left: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.badge {
  font: 700 10px/1 var(--sans); letter-spacing: 0.06em; text-transform: uppercase;
  padding: 4px 6px; border-radius: 4px; background: var(--ink); color: var(--paper);
}
.badge.red { background: var(--accent); color: #fff; }
.badge.prb { background: #c99a2e; color: #1a1408; }
.badge.lead { background: #5b4bb7; color: #fff; }
.tile-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.tile-title { font-weight: 700; font-size: 15px; line-height: 1.25; }
.tile-sub { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0 8px; }
.tile-sub .num { color: var(--ink-2); }
.ja { font-size: 12px; color: var(--muted); }
.prices { display: grid; gap: 6px; margin-top: auto; padding-top: 8px; border-top: 1px dashed var(--line); }
.prow { display: grid; grid-template-columns: 26px 1fr auto; align-items: baseline; gap: 6px; }
.flag {
  font: 700 10px/1 var(--sans); letter-spacing: 0.04em; padding: 3px 0; width: 26px; text-align: center;
  border-radius: 3px; color: #fff; align-self: center;
}
.flag.en { background: var(--en); }
.flag.jp { background: var(--jp); }
.pval { font: 600 16px/1.2 var(--mono); font-variant-numeric: tabular-nums; }
.pval small { font: 500 11px var(--sans); color: var(--muted); margin-left: 4px; }
.psub { grid-column: 2 / -1; font-size: 11.5px; color: var(--muted); margin-top: -3px; }
.chg { font: 600 12px var(--mono); white-space: nowrap; }
.chg.up { color: var(--up); }
.chg.down { color: var(--down); }
.chg.flat { color: var(--muted); }
.na { color: var(--muted); font: 500 13px var(--sans); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 860px; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); white-space: nowrap; }
td.r, th.r { text-align: right; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
.tcard { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.tcard img { width: 34px; height: 47px; object-fit: cover; border-radius: 3px; background: var(--surface-2); }
.tcard b { display: block; }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* ---------- Notes / footer ---------- */
.notes { margin: 48px 0 16px; padding-top: 24px; border-top: 2px solid var(--ink); }
.notes h2 { font: 400 26px/1 var(--display); text-transform: uppercase; margin: 0 0 16px; }
.notes-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; }
.notes h3 { font-size: 14px; margin: 0 0 6px; display: flex; gap: 8px; align-items: center; }
.notes p { margin: 0 0 8px; font-size: 13.5px; color: var(--ink-2); }
.footer { padding: 16px 0 40px; font-size: 12px; color: var(--muted); }

/* ---------- Detail dialog ---------- */
dialog {
  width: min(980px, 100% - 24px); max-height: calc(100% - 24px); padding: 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / 35%);
}
dialog::backdrop { background: rgb(10 9 8 / 60%); backdrop-filter: blur(2px); }
.d-inner { padding: 22px; }
.d-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.d-head h2 { margin: 0; font: 400 30px/1.05 var(--display); text-transform: uppercase; }
.d-head .tile-sub { font-size: 13px; margin-top: 6px; }
.close {
  flex: none; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-2); cursor: pointer; font-size: 20px; line-height: 1;
}
.d-grid { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 22px; }
.d-images { display: grid; gap: 10px; align-content: start; }
.d-images figure { margin: 0; background: var(--surface-2); border-radius: 10px; padding: 10px; }
.d-images img { width: 100%; aspect-ratio: 5/7; object-fit: contain; }
.d-images figcaption { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 6px; align-items: center; }
.d-images .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pcards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pcard { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.pcard h3 { margin: 0 0 8px; font-size: 13px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.pcard h3 a { font-weight: 500; font-size: 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.kv dd.big { font-size: 18px; font-weight: 600; }
.premium { margin: 12px 0 0; font-size: 13px; color: var(--ink-2); }
.chart-box { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.chart-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.chart-head h3 { margin: 0; font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font: 11px var(--mono); }
.chart .tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--paper);
  font: 12px/1.45 var(--mono); padding: 6px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -100%);
}
.chart-note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

@media (max-width: 760px) {
  .d-grid { grid-template-columns: 1fr; }
  .d-images { grid-template-columns: 1fr 1fr; }
  .d-images .pair { display: contents; }
  .pcards { grid-template-columns: 1fr; }
  .d-inner { padding: 16px; }
  .controls { position: static; }
  .meta { grid-template-columns: auto 1fr; width: 100%; }
}
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile-body { padding: 10px; }
  .pval { font-size: 14px; min-width: 0; }
  .pval small { display: block; margin-left: 0; }
  .select select { max-width: 150px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
}
