:root {
  --bg: #07090e;
  --bg-2: #0d1119;
  --panel: #0f141d;
  --panel-2: #151b27;
  --line: #222b3a;
  --text: #e8e3d6;
  --muted: #8b93a3;
  --faint: #5b6476;
  --gold: #d8b45a;
  --gold-2: #f3d891;
  --str: #e0583f;
  --agi: #45c06a;
  --int: #3d9ff0;
  --all: #c88cf0;
  --t-kill: #ff5d4f;
  --t-death: #a78bfa;
  --t-ally_nearby: #34d3a0;
  --t-enemy_nearby: #ffb443;
  --t-ability_cast: #4fa8ff;
  --t-other: #f472b6;
  --radius: 10px;
  --display: "Cinzel", "Trajan Pro", Georgia, serif;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--ui);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .dot { fill: currentColor; stroke: none; }

/* ---------- top bar ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0f1420, #0a0d14);
  flex-wrap: wrap;
  position: relative;
  z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 {
  font: 700 21px/1 var(--display);
  letter-spacing: .06em;
  margin: 0;
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand .sub { color: var(--muted); font-size: 12px; }
@media (max-width: 1720px) { .brand .sub { display: none; } }
@media (max-width: 1560px) { .chip .n { display: none; } }

.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 10px; color: var(--faint); pointer-events: none; }
.search input {
  width: 210px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 10px 7px 32px;
  font: inherit;
  outline: none;
}
.search input:focus { border-color: var(--gold); }
#suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 260px;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px #0009;
  display: none;
  max-height: 320px;
  overflow: auto;
}
#suggest.open { display: block; }
#suggest li { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
#suggest li[aria-selected="true"], #suggest li:hover { background: #ffffff10; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  --c: var(--gold);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: opacity .15s, background .15s;
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }
.chip[aria-pressed="false"] { opacity: .38; background: transparent; }
.chip .n { color: var(--muted); font-variant-numeric: tabular-nums; }

.actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 11px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: #3a465c; background: #1a2130; }
.btn[aria-pressed="true"] { border-color: var(--gold); color: var(--gold-2); box-shadow: 0 0 0 1px var(--gold) inset, 0 0 18px #d8b45a33; }
.btn.ghost { background: #0b0f17cc; backdrop-filter: blur(6px); }

.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 28px; height: 16px; border-radius: 99px; background: #2a3242; position: relative; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #cfd5df; transition: transform .15s; }
.switch input:checked + .track { background: var(--gold); }
.switch input:checked + .track::after { transform: translateX(12px); }
.switch input:focus-visible + .track { outline: 2px solid var(--gold-2); outline-offset: 2px; }

/* ---------- layout ---------- */
main { flex: 1; display: flex; min-height: 0; }
#stage {
  flex: 1;
  position: relative;
  min-width: 0;
  background:
    radial-gradient(circle at 50% 50%, #131a2a 0%, #0a0e16 45%, var(--bg) 75%);
  overflow: hidden;
}
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#back { position: absolute; top: 14px; left: 14px; z-index: 3; }
#loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  font: 600 16px var(--display); letter-spacing: .1em; color: var(--gold);
}

#tip {
  position: absolute;
  pointer-events: none;
  background: #0b0f17ee;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 4;
  box-shadow: 0 8px 24px #0008;
}
#tip b { font: 700 13px var(--display); letter-spacing: .03em; display: block; margin-bottom: 2px; }
#tip .m { color: var(--muted); }

#bubble {
  position: absolute;
  z-index: 4;
  max-width: 320px;
  background: #f5efdf;
  color: #1a1408;
  border-radius: 14px;
  padding: 10px 14px 9px;
  box-shadow: 0 10px 40px #000a, 0 0 0 1px #fff3 inset;
  font-size: 14px;
  line-height: 1.35;
  transform-origin: var(--ox, 50%) var(--oy, 100%);
  animation: pop .22s cubic-bezier(.2, 1.4, .4, 1);
  pointer-events: none;
}
#bubble .q { font-style: italic; }
#bubble .by { margin-top: 5px; font-size: 11px; color: #6b5d3d; font-style: normal; display: flex; gap: 6px; align-items: center; }
#bubble .by i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); display: inline-block; }
#bubble::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  background: #f5efdf;
  left: var(--ax, 24px);
  top: var(--ay, auto);
  bottom: var(--ab, -6px);
  transform: rotate(45deg);
  border-radius: 2px;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- side panel ---------- */
#panel {
  width: 420px;
  flex: none;
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #2a3344 transparent;
}
.sec { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.sec h2 { font: 700 12px var(--display); letter-spacing: .14em; color: var(--gold); margin: 0 0 10px; text-transform: uppercase; }
.lede { color: var(--muted); margin: 0; }
.lede strong { color: var(--text); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.stat b { display: block; font: 700 19px var(--display); color: var(--text); font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); }

.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.rank li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.rank li:hover { background: #ffffff0a; }
.rank .bar { height: 4px; border-radius: 4px; background: var(--gold); opacity: .7; margin-top: 3px; }
.rank .v { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.rank .nm { font-weight: 500; }

.av { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: #1d2533; border: 2px solid var(--ac, #444); flex: none; }
.av.sm { width: 22px; height: 22px; border-width: 1.5px; }
.av.lg { width: 56px; height: 56px; border-width: 3px; }
.av-fallback { display: inline-grid; place-items: center; font: 700 11px var(--display); color: var(--muted); }

.hero-head { position: relative; padding: 0; border-bottom: 1px solid var(--line); }
.hero-head .banner { height: 132px; background-size: cover; background-position: center 30%; position: relative; }
.hero-head .banner::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, #0f141d00 20%, var(--panel) 100%); }
.hero-head .info { position: relative; margin-top: -44px; padding: 0 18px 14px; z-index: 1; }
.hero-head h2 { font: 700 26px/1.1 var(--display); margin: 0; letter-spacing: .03em; }
.attr { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin-top: 4px; }
.attr::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ac); }
.hero-head .nums { margin-top: 8px; color: var(--muted); font-size: 12.5px; }
.hero-head .nums b { color: var(--text); }
.unrel { display: inline-block; margin-left: 8px; font: 600 10px var(--ui); letter-spacing: .1em; padding: 2px 6px; border-radius: 4px; background: #c88cf033; color: var(--all); vertical-align: middle; }

.tabs { display: flex; gap: 4px; padding: 10px 18px 0; position: sticky; top: 0; background: var(--panel); z-index: 2; border-bottom: 1px solid var(--line); }
.tab { background: none; border: 0; padding: 8px 10px 9px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-size: 13px; }
.tab[aria-selected="true"] { color: var(--text); border-color: var(--gold); }
.tab .n { color: var(--faint); margin-left: 3px; }
.tabs .spacer { flex: 1; }
.tabs .link { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; }
.tabs .link:hover { color: var(--text); }

.cards { padding: 10px 12px 30px; display: grid; gap: 8px; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card > header { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer; }
.card > header:hover { background: #ffffff06; }
.card .who { flex: 1; min-width: 0; }
.card .who b { font-weight: 600; display: block; }
.card .who small { color: var(--muted); font-size: 11.5px; display: block; margin-bottom: 4px; }
.card .who b, .card .who small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .chev { color: var(--faint); transition: transform .15s; }
.card[open] .chev { transform: rotate(90deg); }
.card .body { display: none; padding: 0 10px 10px; }
.card[open] .body { display: block; }
.pills { display: flex; gap: 4px; flex-wrap: wrap; }
.pill { --c: var(--gold); font-size: 10.5px; padding: 1px 7px; border-radius: 99px; background: color-mix(in srgb, var(--c) 18%, transparent); color: color-mix(in srgb, var(--c) 80%, white); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); white-space: nowrap; }
.pill.cond { --c: #7c8597; }
.pill.voice { --c: var(--all); }
.pill.time { --c: #8fb3d9; }
.pill.ability { --c: var(--t-ability_cast); }
.pill.bug { --c: #ff6b6b; font-weight: 600; }
.pill.chance { --c: #9aa3b2; }

.rule { border-top: 1px dashed #2a3344; padding-top: 8px; margin-top: 8px; }
.rule:first-child { border-top: 0; margin-top: 2px; padding-top: 0; }
.rule .meta { margin-bottom: 6px; }
.rule .note { font-size: 11.5px; color: #ff9b9b; margin: 0 0 6px; }

.ln { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: center; padding: 4px 4px; border-radius: 7px; }
.ln:hover { background: #ffffff08; }
.ln .t { font-size: 13.5px; }
.ln .t.none { color: var(--faint); font-style: italic; }
.ln .d { color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.play {
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid #3a465c; background: #1b2232;
  display: grid; place-items: center; cursor: pointer; padding: 0;
  color: var(--gold-2);
}
.play:hover { border-color: var(--gold); background: #262f42; }
.play:disabled { opacity: .3; cursor: not-allowed; }
.play svg { width: 12px; height: 12px; fill: currentColor; stroke: none; }
.ln.playing { background: #d8b45a14; }
.ln.playing .play { background: var(--gold); color: #1a1408; border-color: var(--gold); }
.eq { display: none; gap: 2px; align-items: flex-end; height: 12px; }
.ln.playing .eq { display: flex; }
.ln.playing .play svg { display: none; }
.eq i { width: 2px; background: currentColor; animation: eq .8s infinite ease-in-out; }
.eq i:nth-child(2) { animation-delay: -.3s; }
.eq i:nth-child(3) { animation-delay: -.55s; }
@keyframes eq { 0%, 100% { height: 3px; } 50% { height: 12px; } }

.pair-head { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 20px 18px 14px; }
.pair-head .side { display: grid; justify-items: center; gap: 6px; text-align: center; cursor: pointer; }
.pair-head .side b { font: 700 15px var(--display); }
.pair-head .x { color: var(--gold); font: 700 22px var(--display); }
.dir-title { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 12.5px; color: var(--muted); }
.dir-title b { color: var(--text); }
.empty { color: var(--faint); font-style: italic; font-size: 13px; }

.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); margin: 4px 0; }
.legend-row i { width: 22px; height: 3px; border-radius: 2px; background: var(--c); box-shadow: 0 0 6px var(--c); }
.kbd { font: 600 11px var(--ui); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); }

.foot {
  flex: none;
  padding: 6px 18px;
  border-top: 1px solid var(--line);
  background: #0a0d14;
  color: var(--faint);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}
.foot a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.foot a:hover { color: var(--text); }

:focus-visible { outline: 2px solid var(--gold-2); outline-offset: 2px; }

@media (max-width: 980px) {
  body { overflow: auto; }
  main { flex: none; flex-direction: column; }
  #stage { flex: none; height: 68vh; }
  #panel { width: 100%; border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .actions { margin-left: 0; }
  .top { padding: 10px 16px; gap: 10px; }
  .search input { width: 100%; }
  .search { flex: 1; min-width: 160px; }
}
