:root {
  color-scheme: dark;
  --bg: #0b0815;
  --bg-deep: #120d22;
  --panel: rgba(27, 18, 47, 0.92);
  --panel-2: rgba(38, 26, 64, 0.88);
  --line: #3d2b61;
  --line-bright: #6c4ea7;
  --text: #f1ecff;
  --muted: #a99bbf;
  --accent: #b895ff;
  --steel: #8ee8db;
  --gold: #f3ca73;
  --have: #2f9e6a;
  --have-glow: rgba(47, 158, 106, 0.35);
  --miss: #8a2f45;
  --miss-glow: rgba(138, 47, 69, 0.28);
  --sticky-bg: #140e24;
  --row-h: 22px;
  --slot-w: 118px;
  --cell-w: 18px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(900px 500px at 50% -8%, #312052 0%, transparent 70%),
    radial-gradient(600px 500px at 92% 72%, #1b1232 0%, transparent 72%),
    var(--bg);
  color: var(--text);
}
a { color: var(--steel); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }

.app {
  max-width: 100%;
  margin: 0 auto;
  padding: 12px 14px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 2px 0 12px;
  border-bottom: 1px solid rgba(108, 78, 167, 0.35);
}
.brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0.045em; }
.brand .tag {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.nav { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.86rem; }
.nav a { color: var(--muted); }
.nav a.active { color: var(--text); font-weight: 700; }

.toolbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  margin: 12px 0 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(145deg, var(--panel-2), var(--panel));
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
}

.origin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.origin-tabs button {
  border: 1px solid #413062;
  border-radius: 999px;
  padding: 6px 11px;
  background: rgba(11, 8, 21, 0.45);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.origin-tabs button:hover {
  border-color: var(--line-bright);
  color: var(--text);
}
.origin-tabs button.active {
  border-color: var(--accent);
  background: rgba(184, 149, 255, 0.16);
  color: var(--text);
  font-weight: 700;
}
.origin-tabs button .code {
  color: var(--gold);
  font-weight: 700;
  margin-right: 4px;
}

.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  font-size: 0.82rem;
  color: var(--muted);
}
.counts strong { color: var(--text); font-variant-numeric: tabular-nums; }
.counts .sep { opacity: 0.45; }

.legend {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  font-size: 0.76rem;
  color: var(--muted);
}
.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  vertical-align: -2px;
  margin-right: 4px;
}
.swatch.have { background: var(--have); box-shadow: 0 0 0 1px var(--have-glow); }
.swatch.miss { background: var(--miss); box-shadow: 0 0 0 1px var(--miss-glow); }

.note {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.board-wrap {
  overflow: auto;
  max-height: calc(100vh - 168px);
  border: 1px solid var(--line-bright);
  border-radius: 14px;
  background: #181125;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.38), 0 0 0 4px rgba(65, 40, 104, 0.14);
}

table.grid {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-size: 0.68rem;
}

.grid th,
.grid td {
  border-right: 1px solid rgba(61, 43, 97, 0.55);
  border-bottom: 1px solid rgba(61, 43, 97, 0.55);
  padding: 0;
  text-align: center;
  vertical-align: middle;
}

/* Sticky corner + slot column */
.grid th.slot-head,
.grid td.slot-label {
  position: sticky;
  left: 0;
  z-index: 25;
  width: var(--slot-w);
  min-width: var(--slot-w);
  max-width: var(--slot-w);
  background: var(--sticky-bg);
  text-align: left;
  padding: 0 8px;
  box-shadow: 2px 0 0 rgba(108, 78, 167, 0.35);
}
.grid th.slot-head {
  top: 0;
  z-index: 35;
  height: 78px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.grid thead tr.char-row th {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #1c1430;
  height: 28px;
  color: var(--accent);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line-bright);
}
.grid thead tr.class-row th {
  position: sticky;
  top: 28px;
  z-index: 20;
  background: #1a122c;
  height: 24px;
  color: var(--muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.grid thead tr.view-row th {
  position: sticky;
  top: 52px;
  z-index: 20;
  background: #160f26;
  height: 26px;
  width: var(--cell-w);
  min-width: var(--cell-w);
  max-width: var(--cell-w);
  color: var(--steel);
  font-size: 0.62rem;
  font-weight: 700;
}
.grid thead tr.char-row th.slot-head { top: 0; z-index: 36; height: 28px; }
.grid thead tr.class-row th.slot-head { top: 28px; z-index: 36; height: 24px; }
.grid thead tr.view-row th.slot-head { top: 52px; z-index: 36; height: 26px; }

.grid tbody td.slot-label {
  z-index: 15;
  height: var(--row-h);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid tbody td.slot-label .n {
  display: inline-block;
  width: 1.4em;
  color: var(--gold);
  font-weight: 700;
}
.grid tbody td.slot-label .lbl {
  color: var(--muted);
  font-size: 0.62rem;
}

.grid tbody td.cell {
  width: var(--cell-w);
  min-width: var(--cell-w);
  max-width: var(--cell-w);
  height: var(--row-h);
}
.grid tbody td.cell.have {
  background: var(--have);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.grid tbody td.cell.miss {
  background: var(--miss);
  opacity: 0.92;
}

.grid tbody tr:hover td.slot-label {
  background: #1e1633;
}
.grid tbody tr:hover td.cell.have {
  filter: brightness(1.12);
}
.grid tbody tr:hover td.cell.miss {
  filter: brightness(1.18);
}

.char-group-end {
  border-right: 2px solid rgba(184, 149, 255, 0.35) !important;
}
.class-group-end {
  border-right: 1px solid rgba(142, 232, 219, 0.28) !important;
}

.status-line {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.74rem;
}
.status-line.error { color: #ff8fa3; }

.foot {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.76rem;
}

.refresh-btn {
  margin-left: auto;
  background: #3a2a55;
  color: #e8dff5;
  border: 1px solid #6a5090;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
}
.refresh-btn:hover { background: #4a3870; }
