:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --border: #e4e3de;
  --text: #16161a;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #5b4bd5;
  --accent-soft: #ecebfb;
  --accent-text: #4436b8;
  --good: #0ca30c;
  --good-text: #067a06;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --series-1: #2a78d6;
  --grid: #e9e8e3;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #8b7ff0;
    --accent-soft: #2a2645;
    --accent-text: #b4abff;
    --good-text: #4cc94c;
    --series-1: #3987e5;
    --grid: #2a2a28;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #242422;
  --border: #2f2f2c;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8f8e86;
  --accent: #8b7ff0;
  --accent-soft: #2a2645;
  --accent-text: #b4abff;
  --good-text: #4cc94c;
  --series-1: #3987e5;
  --grid: #2a2a28;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent-text); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Shell: nav rail + main ---------- */
.shell { display: flex; min-height: 100vh; }
.rail {
  width: 76px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 2px; overflow-y: auto;
  position: sticky; top: 0; height: 100vh;
}
.logo { width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; margin-bottom: 14px; }
.rail a, .rail button {
  width: 62px; padding: 8px 0; border-radius: 10px; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-2); text-decoration: none; font-size: 11px;
}
.rail a:hover, .rail button:hover { background: var(--surface-2); }
.rail a.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.rail a[aria-disabled="true"] { opacity: .5; }
.rail svg { width: 20px; height: 20px; }
.rail .spacer { flex: 1; }
main { flex: 1; min-width: 0; padding: 20px 24px 48px; }

.proto-banner {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--accent-soft); color: var(--accent-text); border-radius: 10px;
  padding: 8px 12px; font-size: 12.5px; margin-bottom: 18px;
}

/* ---------- Generic UI ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
a.btn { color: inherit; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn svg { width: 16px; height: 16px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 11px; cursor: pointer; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge.good { color: var(--good-text); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: 12.5px; color: var(--text-2); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); font-weight: 600; }
.icon { border-radius: 22%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; letter-spacing: -.02em; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13px;
  transition: .2s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- Screen 1: Market Explorer ---------- */
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.filters { padding: 14px; display: grid; gap: 12px; margin-bottom: 14px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.field input[type=search], .field select {
  height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 0 10px;
}
.field input[type=search] { width: min(340px, 100%); }
.field.grow { flex: 1; min-width: 200px; }
.field.grow input { width: 100%; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.results-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; color: var(--text-2); }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; min-width: 1180px; }
table.grid th, table.grid td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.grid th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; background: var(--surface); position: sticky; top: 0; }
table.grid td.r, table.grid th.r { text-align: right; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.title-cell { display: flex; flex-direction: column; }
.title-cell b { font-weight: 600; }
.title-cell small { color: var(--text-3); font-size: 11.5px; }
.trend-up { color: var(--good-text); font-weight: 600; }
.trend-down { color: var(--critical); font-weight: 600; }
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.status i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.app-card { padding: 14px; cursor: pointer; display: grid; gap: 12px; text-align: left; }
.app-card:hover { border-color: var(--accent); }
.app-card .top { display: flex; gap: 12px; align-items: center; }
.app-card .top div { min-width: 0; }
.app-card .top b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-card .badges { display: flex; flex-wrap: wrap; gap: 5px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.kpis div { background: var(--surface-2); border-radius: 8px; padding: 7px 8px; }
.kpis small { display: block; font-size: 10.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; }
.kpis b { font-size: 15px; }
.empty { padding: 40px; text-align: center; color: var(--text-2); }

/* ---------- Screen 2: App Detail ---------- */
.back { margin-bottom: 12px; }
.masthead { padding: 18px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.masthead .meta { flex: 1; min-width: 220px; }
.masthead h1 { font-size: 24px; }
.masthead .sub { color: var(--text-2); margin: 4px 0 6px; }
.masthead .short { margin: 0 0 8px; color: var(--text); }
.masthead .badges { display: flex; gap: 6px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 12px; align-items: start; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 8px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 12px 12px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs button[aria-selected="true"] { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-body { padding: 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
.section h3 { font-size: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.section p.note { margin: -4px 0 10px; color: var(--text-3); font-size: 12.5px; }
.textbox { background: var(--surface-2); border-radius: 10px; padding: 12px; white-space: pre-wrap; }
.limits { display: grid; gap: 10px; }
.limit { display: grid; grid-template-columns: 120px 1fr 92px; gap: 10px; align-items: center; }
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 4px; background: var(--series-1); }
.ngram table { width: 100%; border-collapse: collapse; }
.ngram th, .ngram td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.ngram th { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.ngram td.r, .ngram th.r { text-align: right; }
.bar-inline { display: inline-block; height: 6px; border-radius: 3px; background: var(--series-1); vertical-align: middle; margin-right: 6px; }

.shots { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 6px; }
.shot { flex: none; width: 150px; aspect-ratio: 9 / 19; border-radius: 14px; scroll-snap-align: start; padding: 14px 10px;
  color: #fff; display: flex; flex-direction: column; justify-content: space-between; font-weight: 700; font-size: 15px; line-height: 1.2; }
.shot.real { padding: 0; width: auto; height: 320px; aspect-ratio: auto; object-fit: contain; background: var(--surface-2); }
.proto-banner.live { background: #e3f4e3; color: var(--good-text); }
:root[data-theme="dark"] .proto-banner.live { background: #17301a; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .proto-banner.live { background: #17301a; } }
.live-box .checks { align-items: center; }
.lookup-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px; }
.lookup-item { display: flex; gap: 10px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 10px; color: inherit; text-decoration: none; min-width: 0; }
.lookup-item:hover { border-color: var(--accent); }
.lookup-item span { min-width: 0; }
.lookup-item b, .lookup-item small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lookup-item small { color: var(--text-3); font-size: 11.5px; }
.live-box a.chip { text-decoration: none; }
img.icon { object-fit: cover; }
.shot .phone { background: rgba(255, 255, 255, .22); border-radius: 10px; height: 55%; }

.ads { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.ad { overflow: hidden; display: flex; flex-direction: column; }
.poster { position: relative; aspect-ratio: 9 / 12; display: flex; align-items: end; padding: 12px; color: #fff; font-weight: 700; font-size: 15px; border: 0; cursor: pointer; text-align: left; }
.poster .play { position: absolute; inset: 0; margin: auto; width: 54px; height: 54px; border-radius: 50%; background: rgba(0,0,0,.45); display: grid; place-items: center; }
.poster .play svg { width: 22px; height: 22px; fill: #fff; }
.poster .dur { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,.55); padding: 2px 7px; border-radius: 6px; font-size: 11.5px; font-weight: 600; }
.player { aspect-ratio: 9 / 12; background: #000; color: #ddd; display: grid; place-items: center; padding: 16px; text-align: center; font-size: 12.5px; }
.player .progress { width: 80%; height: 4px; background: #333; border-radius: 2px; overflow: hidden; margin-top: 10px; }
.player .progress i { display: block; height: 100%; width: 0; background: #fff; animation: prog var(--d, 15s) linear forwards; }
@keyframes prog { to { width: 100%; } }
.ad .info { padding: 12px; display: grid; gap: 6px; font-size: 12.5px; }
.ad .row { display: flex; justify-content: space-between; gap: 8px; color: var(--text-2); }

.sdk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.sdk { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; }
.sdk .icon { width: 30px; height: 30px; font-size: 11px; background: var(--surface-2); color: var(--text-2); }
.sdk small { display: block; color: var(--text-3); font-size: 11px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.fact { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.fact small { display: block; color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.fact b { font-size: 17px; }
.perm { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); gap: 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* KPI side panel */
.panel { padding: 16px; display: grid; gap: 16px; position: sticky; top: 16px; }
.panel h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.panel dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; }
.panel dt { color: var(--text-2); }
.panel dd { margin: 0; font-weight: 600; text-align: right; }
.panel .group + .group { border-top: 1px solid var(--border); padding-top: 14px; }

/* Charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1); opacity: .08; }
.chart .hair { stroke: var(--text-3); stroke-width: 1; }
.chart .dotm { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,.12);
  border-radius: 8px; padding: 6px 10px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); }
.tip b { display: block; font-size: 14px; }
.tip span { color: var(--text-3); }
details.data-table summary { cursor: pointer; color: var(--text-3); font-size: 12px; margin-top: 6px; }
details.data-table .scroll { max-height: 200px; overflow: auto; }
details.data-table table { border-collapse: collapse; font-size: 12px; }
details.data-table td, details.data-table th { padding: 3px 10px; border-bottom: 1px solid var(--border); text-align: right; }
.milestone { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.milestone .big { font-size: 30px; font-weight: 700; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .detail { grid-template-columns: minmax(0, 1fr); }
  .panel { position: static; }
}
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .rail { width: 100%; height: auto; flex-direction: row; position: sticky; top: 0; z-index: 10; padding: 6px 10px; border-right: 0; border-bottom: 1px solid var(--border); justify-content: flex-start; overflow-x: auto; gap: 2px; }
  .logo { margin: 0; width: 32px; height: 32px; }
  .rail .spacer { display: none; }
  .rail a, .rail button { width: auto; padding: 6px 8px; flex: none; }
  main { padding: 14px 16px 40px; }
  .limit { grid-template-columns: 90px 1fr 74px; }
  .masthead h1 { font-size: 20px; }
}
