:root {
  color-scheme: light;
  --gold: #F7C948;
  --gold-dark: #DFAF2B;
  --gold-ink: #3a2a00;
  --outline: #A67C00;
  --ink: #2B2B2B;
  --ink-soft: #5b5750;
  --ink-faint: #8a847a;
  --bg: #FBF8F1;
  --surface: #FFFFFF;
  --surface-soft: #FFF7E4;
  --surface-sunk: #F4F0E6;
  --border: rgba(43, 43, 43, 0.10);
  --grid: rgba(43, 43, 43, 0.08);
  --good: #1c7a41;   --good-bg: rgba(46, 204, 113, 0.14);
  --warn: #8a5a00;   --warn-bg: rgba(237, 161, 0, 0.16);
  --bad: #b3232a;    --bad-bg: rgba(229, 72, 77, 0.13);
  --info: #1f4fbf;   --info-bg: rgba(58, 125, 255, 0.11);
  /* Categorical chart slots — dataviz reference palette, fixed order. */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --s9: #0a9fb3; /* 9th slot added for Reveal's mode group (2026-09-30) */
  --seq-0: #f0efec; --seq-1: #cde2fb; --seq-2: #86b6ef; --seq-3: #3987e5; --seq-4: #1c5cab; --seq-5: #0d366b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 6px 18px rgba(43, 43, 43, 0.07);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #F5F0E6;
    --ink-soft: #C9C2B4;
    --ink-faint: #9a9384;
    --bg: #14120E;
    --surface: #1E1A14;
    --surface-soft: #262016;
    --surface-sunk: #191611;
    --border: rgba(247, 201, 72, 0.13);
    --grid: rgba(245, 240, 230, 0.08);
    --good: #5fd08f; --warn: #f0b940; --bad: #ff8589; --info: #8db2ff;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --s9: #24b9cc;
    --seq-0: #2a2823; --seq-1: #104281; --seq-2: #1c5cab; --seq-3: #3987e5; --seq-4: #86b6ef; --seq-5: #cde2fb;
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45;
}
[hidden] { display: none !important; }
a { color: var(--outline); }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 228px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--gold); color: var(--gold-ink);
  display: grid; place-items: center; font-size: 20px; font-weight: 800;
}
.brand-name { font-weight: 800; }
.brand-sub { font-size: 11.5px; color: var(--ink-faint); }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); padding: 14px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--ink-soft); text-decoration: none; font-weight: 600; font-size: 13.5px;
}
.nav-link:hover { background: var(--surface-soft); color: var(--ink); }
.nav-link.active { background: var(--surface-soft); color: var(--ink); box-shadow: inset 3px 0 0 var(--gold); }
.nav-link .ico { width: 18px; text-align: center; }
.nav-badge { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 18px; font-weight: 800; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.freshness { font-size: 12.5px; color: var(--ink-faint); }
.freshness.stale { color: var(--warn); }
.account { font-size: 12.5px; color: var(--ink-soft); display: flex; gap: 8px; align-items: center; }
.icon-btn.nav-toggle { display: none; }
.progress { position: relative; height: 26px; background: var(--surface-sunk); border-bottom: 1px solid var(--border); font-size: 12px; }
.progress-bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--gold); opacity: .45; transition: width .2s; }
.progress span { position: relative; padding: 0 24px; line-height: 26px; color: var(--ink-soft); }
.view { padding: 22px 24px 60px; max-width: 1480px; width: 100%; }

@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 50; left: -240px; transition: left .2s; box-shadow: var(--shadow); }
  .sidebar.open { left: 0; }
  .icon-btn.nav-toggle { display: inline-flex; }
  .view { padding: 16px; }
  .topbar { padding: 10px 16px; }
}

/* ---------- Buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: none; border-radius: 999px;
  padding: 8px 16px; font: inherit; font-weight: 700; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: var(--gold-ink); }
.btn-primary:hover:not(:disabled) { background: var(--gold-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--outline); }
.btn-danger { background: #E5484D; color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 14px;
}
input[type=text], input[type=number], input[type=search], input[type=datetime-local], input[type=date], select, textarea {
  padding: 8px 10px; font: inherit; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--ink);
}
textarea { width: 100%; min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
label.field { display: block; margin-bottom: 12px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
label.field > input, label.field > select, label.field > textarea { display: block; width: 100%; margin-top: 5px; }
.hint { font-weight: 400; color: var(--ink-faint); font-size: 12px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }

/* ---------- Layout primitives ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head p { margin: 2px 0 0; color: var(--ink-soft); font-size: 13px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; min-width: 0;
}
.card + .card, .grid + .card, .card + .grid, .grid + .grid, .tiles + .grid, .tiles + .card { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card h2 { margin: 0 0 2px; font-size: 15px; }
.card .sub { margin: 0 0 12px; color: var(--ink-faint); font-size: 12.5px; }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 12px; color: var(--ink-faint); font-weight: 600; }
.tile .value { font-size: 24px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .delta { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.tile .delta.up { color: var(--good); }
.tile .delta.down { color: var(--bad); }
.tile .note { font-size: 11.5px; color: var(--ink-faint); margin-top: 4px; line-height: 1.35; }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 340px; }
.chart-box.short { height: 190px; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.muted { background: var(--surface-sunk); color: var(--ink-faint); }

.notice { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; }
.notice.info { background: var(--info-bg); color: var(--info); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.empty { padding: 36px 10px; text-align: center; color: var(--ink-faint); }
.muted { color: var(--ink-faint); }

/* ---------- Data table ---------- */
.dt-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.dt-toolbar .spacer { flex: 1; }
.dt-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table.dt { border-collapse: collapse; width: 100%; font-size: 13px; }
table.dt th {
  position: sticky; top: 0; background: var(--surface-soft); text-align: left; padding: 8px 10px;
  font-weight: 700; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none;
}
table.dt th.num, table.dt td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.dt th .arr { font-size: 10px; color: var(--ink-faint); margin-left: 3px; }
table.dt td { padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
table.dt tr:last-child td { border-bottom: none; }
table.dt tbody tr:hover { background: var(--surface-soft); }
table.dt tbody tr.clickable { cursor: pointer; }
table.dt td.wrap { white-space: normal; }
.dt-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; font-size: 12.5px; color: var(--ink-soft); }
.dt-cols { position: absolute; z-index: 30; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 8px; max-height: 360px; overflow: auto; }
.dt-cols label { display: flex; gap: 8px; padding: 4px 6px; font-size: 13px; cursor: pointer; white-space: nowrap; }

/* ---------- Modal / toast / menu ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; padding: 22px; }
.modal.wide { max-width: 820px; }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast-root { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 10px 14px; font-size: 13px; max-width: 380px; }
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
.ctx-menu { position: fixed; z-index: 120; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 5px; min-width: 180px; }
.ctx-menu button { display: block; width: 100%; text-align: left; background: none; border: none; font: inherit; font-size: 13px; padding: 7px 10px; border-radius: 6px; cursor: pointer; color: var(--ink); }
.ctx-menu button:hover:not(:disabled) { background: var(--surface-soft); }
.ctx-menu button:disabled { color: var(--ink-faint); cursor: not-allowed; }
.ctx-menu button.danger { color: var(--bad); }

/* ---------- Player page ---------- */
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 18px; }
.kv .k { font-size: 11.5px; color: var(--ink-faint); font-weight: 600; }
.kv .v { font-weight: 700; word-break: break-word; font-variant-numeric: tabular-nums; }
.player-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.avatar { width: 48px; height: 48px; border-radius: 14px; background: var(--gold); color: var(--gold-ink); display: grid; place-items: center; font-weight: 800; font-size: 20px; }
.pills-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pills-list span { font-size: 12px; background: var(--surface-sunk); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; }

/* Activity calendar (GitHub-style) */
.cal-wrap { overflow-x: auto; padding-bottom: 4px; }
.cal { display: grid; grid-auto-flow: column; grid-template-rows: 14px repeat(7, 13px); gap: 3px; font-size: 10px; color: var(--ink-faint); }
.cal .cell { width: 13px; height: 13px; border-radius: 3px; background: var(--seq-0); }
.cal .cell[data-l="1"] { background: var(--seq-1); }
.cal .cell[data-l="2"] { background: var(--seq-2); }
.cal .cell[data-l="3"] { background: var(--seq-3); }
.cal .cell[data-l="4"] { background: var(--seq-4); }
.cal .cell.future { background: transparent; }
.cal .mlabel { grid-row: 1; white-space: nowrap; overflow: visible; }
.cal-legend { display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--ink-faint); margin-top: 8px; }
.cal-legend .cell { width: 11px; height: 11px; border-radius: 3px; }

/* Heat table (retention / weekday-hour) */
table.heat { border-collapse: separate; border-spacing: 2px; font-size: 12px; }
table.heat th { font-weight: 600; color: var(--ink-faint); padding: 3px 6px; text-align: right; white-space: nowrap; }
table.heat.compact { width: 100%; table-layout: fixed; border-spacing: 1px; }
table.heat.compact th { padding: 2px; font-size: 10px; text-align: center; }
table.heat.compact th:first-child { width: 34px; text-align: right; }
table.heat.compact td { min-width: 0; padding: 0; height: 18px; }
table.heat td { padding: 5px 7px; text-align: center; border-radius: 4px; min-width: 42px; font-variant-numeric: tabular-nums; }

.tooltip-float { position: fixed; pointer-events: none; z-index: 300; background: var(--ink); color: var(--bg); padding: 5px 8px; border-radius: 6px; font-size: 12px; }

.support-msg { white-space: pre-wrap; background: var(--surface-sunk); border-radius: var(--radius-sm); padding: 12px; font-size: 13px; }

/* Ratings & reviews */
.review-filters { flex-wrap: wrap; gap: 8px; }
.review-filters .star-filter { display: inline-flex; gap: 4px; }
.review-filters input[type=search] { min-width: 180px; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); }
.review { border-top: 1px solid var(--border); padding: 14px 0; }
.review.low { box-shadow: inset 3px 0 0 var(--bad); padding-left: 12px; }
.review-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; font-size: 13px; }
.review-head .spacer { flex: 1; }
.review-stars { color: var(--gold-dark); letter-spacing: 1px; font-size: 15px; }
.review-stars.s1, .review-stars.s2 { color: var(--bad); }
.review-title { font-weight: 700; margin-top: 6px; }
.review-text { margin-top: 6px; white-space: pre-wrap; }
.review-translation { margin-top: 4px; font-size: 13px; color: var(--ink-soft); }
.review-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.review-reply { margin-top: 10px; padding: 8px 12px; background: var(--surface-soft); border-radius: var(--radius-sm); font-size: 13px; }
.review-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.review-actions a.btn { text-decoration: none; }
.review-compose { margin-top: 10px; }
.review-compose textarea, .tpl-row textarea { width: 100%; margin: 6px 0; }
.tpl-row { display: grid; grid-template-columns: 200px minmax(0, 1fr) auto; gap: 10px; align-items: start; margin: 10px 0; }
@media (max-width: 700px) { .tpl-row { grid-template-columns: minmax(0, 1fr); } }
details.card > summary { cursor: pointer; }

/* Growth overview */
ul.alerts { list-style: none; margin: 8px 0 0; padding: 0; }
ul.alerts li { padding: 8px 12px; border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 13px; }
ul.alerts li.warn { background: var(--warn-bg); }
ul.alerts li.bad { background: var(--bad-bg); }
ul.alerts li a { color: var(--ink); text-decoration: none; margin-right: 6px; }
.marker-key { display: inline-flex; align-items: center; gap: 4px; margin-left: 10px; font-size: 12px; }
.marker-key::before { content: ""; width: 0; height: 12px; border-left: 2px dashed var(--c); }
.funnel-row { display: grid; grid-template-columns: 260px minmax(0, 1fr) 130px; gap: 12px; align-items: center; padding: 5px 0; font-size: 13px; }
.funnel-bar { background: var(--surface-soft); border-radius: 6px; height: 18px; overflow: hidden; }
.funnel-bar span { display: block; height: 100%; background: var(--s1); border-radius: 6px; }
.funnel-n { text-align: right; }
@media (max-width: 800px) { .funnel-row { grid-template-columns: minmax(0, 1fr) 90px; } .funnel-bar { grid-column: 1 / -1; grid-row: 2; } }

/* Device filter bar (js/filters.js) */
.filter-bar { margin-bottom: 16px; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.filter-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.filter-selects select { max-width: 220px; }
.filter-selects select.active { border-color: var(--outline); background: var(--surface-soft); font-weight: 700; }
