:root {
  --bg: #0d1014;
  --surface: #151a21;
  --surface-2: #1c232c;
  --border: #2a333f;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --gold: #d4af6a;
  --gold-dim: #8a7244;
  --green: #5fbf8a;
  --blue: #5aa2d8;
  --red: #d86a6a;
  --radius: 10px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f2ee;
    --surface: #ffffff;
    --surface-2: #f0ede7;
    --border: #ddd7cc;
    --text: #1d2229;
    --muted: #6b7380;
    --gold: #9a7630;
    --gold-dim: #c9b080;
    --green: #2f8f5b;
    --blue: #2b72a8;
    --red: #b44848;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

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(--gold); }
code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 .3em;
  font-size: .9em;
}
.muted { color: var(--muted); }
[hidden] { display: none !important; }

input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .7rem;
  min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
button {
  background: var(--gold);
  color: #16120a;
  border-color: var(--gold);
  font-weight: 600;
  cursor: pointer;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: .7rem 1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.brand svg { width: 28px; height: 28px; }

main { max-width: 1400px; margin: 0 auto; padding: 1.25rem 1rem 2rem; }

/* ---- Intro / Status ---- */
.intro { max-width: 720px; margin: 2rem auto; }
.intro h1 { font-size: 1.8rem; margin: 0 0 .5rem; }
.intro h2 { font-size: 1.1rem; margin-top: 2rem; color: var(--gold); }
.intro li { margin: .4rem 0; }
.intro .notice {
  padding: 1rem 1.25rem;
  border: 1px solid var(--gold);
  border-radius: 8px;
  color: var(--gold);
  font-weight: 600;
}

.status {
  max-width: 720px;
  margin: 3rem auto;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}
.status.error { border-color: var(--red); color: var(--red); }

/* ---- Summary ---- */
.summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem 2rem;
  align-items: center;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.player { display: flex; gap: 1rem; align-items: center; }
.player h1 { margin: 0; font-size: 1.5rem; word-break: break-all; }
.player p { margin: 0; font-size: .85rem; }
#refresh { margin-left: auto; white-space: nowrap; }
button:disabled { opacity: .6; cursor: wait; }
.mr-badge {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  flex: none;
  border: 2px solid var(--gold);
  border-radius: 50%;
  color: var(--gold);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
}
.mr-badge small { font-size: .6rem; letter-spacing: .1em; }
.stats { display: flex; gap: 2rem; justify-content: flex-end; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; }
.stat-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.summary .bar { grid-column: 1 / -1; }

.bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}
.bar > div { height: 100%; background: var(--gold); border-radius: inherit; transition: width .3s; }
.bar.big { height: 10px; }

/* ---- Group cards ---- */
.groups {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: .6rem;
  margin: 1rem 0;
}
.group {
  text-align: left;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .7rem .8rem;
  font-weight: 400;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.group:hover { border-color: var(--gold-dim); }
.group.active { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.group .g-head { display: flex; justify-content: space-between; gap: .5rem; font-weight: 600; }
.group .g-count { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 400; font-size: .85rem; }
.group.done .bar > div { background: var(--green); }

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
  margin: 1rem 0;
}
.toolbar input { flex: 1 1 220px; }
#resultCount { margin-left: auto; font-size: .85rem; }

/* ---- Items ---- */
.items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .6rem;
}
.item {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: .6rem;
  align-items: center;
  padding: .6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  min-width: 0;
  position: relative;
}
.item .wiki { color: inherit; text-decoration: none; }
.item .wiki::after { content: ''; position: absolute; inset: 0; }
.item .price {
  position: relative;
  z-index: 1;
  align-self: flex-start;
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
}
.item .price:hover { text-decoration: underline; }
.item:hover { border-color: var(--gold-dim); }
.item.mastered { border-left-color: var(--green); }
.item.progress { border-left-color: var(--blue); }
.item.zero { opacity: .75; }
.item img, .item .noimg {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 6px;
  background: var(--surface-2);
}
.item .info { min-width: 0; display: flex; flex-direction: column; gap: .25rem; }
.item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { display: flex; justify-content: space-between; gap: .4rem; font-size: .78rem; color: var(--muted); }
.item .rank { font-variant-numeric: tabular-nums; }
.item.mastered .rank { color: var(--green); font-weight: 600; }
.item.mastered .bar > div { background: var(--green); }
.item.progress .bar > div { background: var(--blue); }
.tag {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 .3em;
}

footer { text-align: center; padding: 2rem 1rem; font-size: .8rem; }

@media (max-width: 700px) {
  .summary { grid-template-columns: 1fr; }
  .stats { justify-content: space-between; gap: 1rem; }
  .items { grid-template-columns: 1fr; }
}
