:root {
  --bg: #0e1116;
  --surface: #151a21;
  --surface-2: #1b2129;
  --border: #232a33;
  --text: #d5dae2;
  --strong: #eef1f5;
  --muted: #8a93a1;
  --faint: #5e6774;
  --accent: #d6a54a;
  --accent-ink: #1b1405;
  --bar: #b89148;
  --track: #222932;
  --rushed: #d9706b;
  --good: #5fae84;
  --gold: #d9b552;
  --elixir: #c071cc;
  --dark: #8f86e0;
  --radius: 14px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f4f5f8;
    --border: #e4e7ec;
    --text: #2a313b;
    --strong: #12171e;
    --muted: #6a7482;
    --faint: #9aa3af;
    --accent: #c48a1c;
    --accent-ink: #ffffff;
    --bar: #d0a24c;
    --track: #eceef2;
    --rushed: #c9534d;
    --good: #3b8f62;
    --gold: #b8901a;
    --elixir: #a647b5;
    --dark: #6a5fd0;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
img { display: block; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { width: 100%; max-width: 1120px; margin-inline: auto; padding-inline: 20px; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 14px 8px; flex-wrap: wrap; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.th-badge {
  width: 40px; height: 40px; border-radius: 10px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font: 20px/1 'Lilita One', Inter, sans-serif;
}
.who-name { font-size: 17px; font-weight: 600; color: var(--strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-meta { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.lens { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.lens select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 10px; color: var(--text);
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 13px; border-radius: 9px; font-weight: 500;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--faint); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.spin svg { animation: spin 1s linear infinite; }
#btn-live.on::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--good); }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 6px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: 0; padding: 10px 12px 12px; white-space: nowrap;
  color: var(--muted); font-weight: 500; position: relative;
}
.tab:hover, .tab[aria-selected="true"] { color: var(--strong); }
.tab[aria-selected="true"]::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent);
}
.tab .count { margin-left: 5px; font-size: 11px; color: var(--faint); }

main.wrap { padding-block: 24px 32px; }
#banner:empty { display: none; }
.banner {
  margin-top: 16px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.banner b { color: var(--text); font-weight: 600; }

/* Layout */
.stack { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); align-items: start; }
.grid > * { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--strong); }
.card-head .sub { color: var(--faint); font-size: 12.5px; }
.pad { margin: 4px 0; }

/* Summary */
.summary { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: center; }
.ring { position: relative; width: 116px; height: 116px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .val { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring .val b { font-size: 26px; font-weight: 600; color: var(--strong); display: block; line-height: 1.1; }
.ring .val small { color: var(--faint); font-size: 11.5px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.kpi { padding: 4px 16px; border-left: 1px solid var(--border); min-width: 0; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 22px; font-weight: 600; color: var(--strong); margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .value .faint { font-size: 15px; font-weight: 500; }
.kpi .note { color: var(--faint); font-size: 12px; }

/* Area strip */
.areas { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px 20px; padding: 14px 20px; }
.area {
  display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 8px;
  background: none; border: 0; padding: 6px 0; text-align: left; color: inherit;
}
.area .label { color: var(--muted); font-size: 12.5px; }
.area .value { font-weight: 600; color: var(--strong); font-variant-numeric: tabular-nums; }
.area .bar { grid-column: 1 / -1; margin-top: 6px; }
.area:hover .label { color: var(--text); }

/* Rows */
.list { display: grid; }
.row {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 14px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--border);
}
.list > .row:first-child { border-top: 0; }
.row .ic { width: 40px; height: 40px; object-fit: contain; }
.row .ic.ph { border-radius: 10px; background: var(--surface-2); }
.title { display: flex; align-items: center; gap: 7px; font-weight: 500; color: var(--strong); }
.meta { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.gap { font-size: 16px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; min-width: 36px; text-align: right; }
.gap.done { color: var(--good); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--rushed); flex: none; }
.legend { display: inline-flex; align-items: center; gap: 6px; }

.bar { position: relative; height: 4px; border-radius: 4px; background: var(--track); margin-top: 7px; overflow: hidden; }
.bar > span { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--bar); }
.row .bar { max-width: 520px; }

.more {
  margin-top: 6px; width: 100%; background: none; border: 0; border-top: 1px solid var(--border);
  color: var(--muted); padding: 10px 0 0; font-size: 12.5px;
}
.more:hover { color: var(--text); }

details.maxed { margin-top: 6px; border-top: 1px solid var(--border); padding-top: 4px; }
details.maxed summary {
  list-style: none; cursor: pointer; color: var(--muted); font-size: 12.5px;
  padding: 8px 0; display: flex; align-items: center; gap: 6px;
}
details.maxed summary::-webkit-details-marker { display: none; }
details.maxed summary::before { content: "›"; font-size: 15px; line-height: 1; transition: transform .15s; }
details.maxed[open] summary::before { transform: rotate(90deg); }
details.maxed summary:hover { color: var(--text); }
.maxed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 4px 12px; padding-bottom: 6px; }
.maxed-grid .m { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding: 4px 0; }
.maxed-grid img { width: 26px; height: 26px; object-fit: contain; }

/* Tab toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 6px; color: var(--muted); font-size: 12.5px; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--strong); }
.stats { display: flex; flex-wrap: wrap; gap: 10px 32px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-weight: 600; font-size: 17px; color: var(--strong); font-variant-numeric: tabular-nums; }
.stat .value .faint { font-weight: 500; font-size: 14px; }
.res { display: inline-flex; align-items: center; gap: 5px; margin-right: 10px; white-space: nowrap; }
.res::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.res.G::before { background: var(--gold); }
.res.E::before { background: var(--elixir); }
.res.D::before { background: var(--dark); }
.res.GE::before { background: linear-gradient(90deg, var(--gold) 50%, var(--elixir) 50%); }

/* Upgrades */
.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 24px; }
.job { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px 0; }
.job .ic { width: 32px; height: 32px; object-fit: contain; }
.job .title { font-size: 13.5px; }
.eta { color: var(--muted); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Walls */
.wall-rows { display: grid; gap: 10px; }
.wall-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) 40px; gap: 12px; align-items: center; font-size: 13px; }
.wall-row .bar { margin: 0; height: 8px; }
.wall-row.max .bar > span { background: var(--good); }
.wall-row .n { text-align: right; color: var(--strong); font-variant-numeric: tabular-nums; }
.wall-row .l { color: var(--muted); }
.mile { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.list > .mile:first-child { border-top: 0; }
.mile .cost { font-weight: 600; color: var(--strong); font-variant-numeric: tabular-nums; }

/* History */
.spark { width: 100%; height: 80px; display: block; margin-bottom: 12px; }
.th-prog { display: grid; gap: 10px; }
.th-prog .r { display: grid; grid-template-columns: 48px minmax(0, 1fr) 70px; gap: 12px; align-items: center; font-size: 13px; }
.th-prog .r .bar { margin: 0; }
.th-prog .r > .small { text-align: right; color: var(--strong); }
.hist-list { display: grid; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 6px; }
.hist-item { display: grid; grid-template-columns: 1fr 60px 50px; gap: 12px; padding: 7px 0; background: none; border: 0; text-align: left; font-size: 13px; color: var(--text); }
.hist-item > :last-child { text-align: right; }
.hist-item:hover .muted { color: var(--text); }

/* Empty state */
.empty { text-align: center; padding: 72px 16px; }
.empty img { width: 88px; height: 88px; margin: 0 auto 16px; object-fit: contain; }
.empty h2 { font-size: 22px; font-weight: 600; color: var(--strong); margin: 0 0 8px; }
.empty p { color: var(--muted); max-width: 440px; margin: 0 auto 20px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }

/* Dialog */
dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--surface); color: var(--text);
  width: min(620px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
dialog::backdrop { background: rgba(5, 8, 12, .6); backdrop-filter: blur(3px); }
.dlg { padding: 20px; display: grid; gap: 12px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head h2 { margin: 0; font-size: 17px; font-weight: 600; color: var(--strong); }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.hint b { color: var(--text); font-weight: 600; }
textarea {
  width: 100%; min-height: 200px; resize: vertical; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; }
.field small { color: var(--faint); font-weight: 400; }
.field input { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; }
textarea:focus, .field input:focus, .lens select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 1px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dlg-error { margin: 0; color: var(--rushed); font-size: 13px; }

.foot { color: var(--faint); font-size: 12px; padding-bottom: 32px; }

@media (max-width: 860px) {
  .summary { grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 20px; }
  .kpis { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 0; }
  .kpi:nth-child(odd) { border-left: 0; }
}
@media (max-width: 560px) {
  .wrap { padding-inline: 16px; }
  .top-inner { gap: 10px; }
  .top-actions { width: 100%; }
  .lens { flex: 1; }
  .lens span { display: none; }
  .lens select { width: 100%; }
  .btn#btn-live span { display: none; }
  .card { padding: 16px; }
  .kpi { padding: 4px 12px; }
  .kpi .value { font-size: 19px; }
  .row { gap: 12px; }
  .stats { gap: 10px 24px; }
}
