:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #efefea;
  --text: #17181c;
  --muted: #676a72;
  --line: #e2e2dc;
  --accent: #e8492a;
  --accent-ink: #ffffff;
  --good: #1f8a4c;
  --warn: #b7791f;
  --bad: #c23a3a;
  --live: #e0245e;
  --chip: #ecebe5;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 2px 8px rgb(0 0 0 / .04);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d23;
    --surface-2: #22262e;
    --text: #eceef2;
    --muted: #979ca8;
    --line: #2b3039;
    --accent: #ff6a47;
    --accent-ink: #1a0d08;
    --good: #46c27c;
    --warn: #e0a840;
    --bad: #ef6b6b;
    --live: #ff4f86;
    --chip: #262a33;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.01em; }
.brand img { width: 26px; height: 26px; }
.top select { max-width: 52%; }

main { max-width: 860px; margin: 0 auto; padding: 16px; }

/* ---------- bottom tabs ---------- */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; text-decoration: none; color: var(--muted); font-size: 11px;
}
.tabs a[aria-current="page"] { color: var(--accent); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge {
  position: absolute; top: 4px; left: calc(50% + 6px);
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: 10.5px; line-height: 17px; text-align: center;
}
.badge.live { background: var(--live); color: #fff; }
.badge:empty { display: none; }

@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 92px; }
  .tabs { inset: 0 auto 0 0; width: 92px; grid-template-columns: 1fr; grid-auto-rows: 72px; align-content: start; padding-top: 70px; border-top: 0; border-right: 1px solid var(--line); }
}

/* ---------- building blocks ---------- */
h1 { font-size: 22px; letter-spacing: -.02em; margin: 4px 0 12px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.grow { flex: 1; min-width: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px;
}
.card.unread { border-left: 3px solid var(--accent); }
.card h3 { font-size: 16px; margin: 0 0 4px; line-height: 1.3; overflow-wrap: anywhere; }
.card p { margin: 6px 0 0; overflow-wrap: anywhere; }
.list { display: grid; gap: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; background: var(--chip); font-size: 12px; white-space: nowrap;
}
.chip.good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.chip.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.chip.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.chip.live { background: var(--live); color: #fff; }
.chip.accent { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); cursor: pointer; text-decoration: none; font-weight: 550; font-size: 14px;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }

input[type=text], input[type=url], input[type=number], input[type=password], input[type=date], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
}
.top select { width: auto; min-height: 34px; padding: 4px 8px; }
textarea { min-height: 70px; resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }

.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.seg button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 6px 0 4px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; letter-spacing: -.02em; }
.stat span { font-size: 12px; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }

.stream-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; }
.rank { font-weight: 700; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.viewers { font-variant-numeric: tabular-nums; font-weight: 650; text-align: right; }
.trend-up { color: var(--good); font-size: 12px; }
.trend-down { color: var(--bad); font-size: 12px; }
.ellip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat { margin-top: 8px; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.chat div { overflow-wrap: anywhere; }
.chat b { color: var(--muted); font-weight: 600; }

.score { font-size: 22px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.good { background: var(--good); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }

dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 24px)); max-height: 88vh; padding: 0; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { padding: 18px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

#toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.login { max-width: 360px; margin: 12vh auto 0; }

/* ---------- clips ---------- */
.draft-row { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.thumb { width: 64px; aspect-ratio: 9 / 16; object-fit: cover; border-radius: 8px; background: var(--surface-2); flex: none; }
.thumb.ph { display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.draft-layout { display: grid; gap: 16px; margin-top: 12px; }
.player video, .player-ph { width: 100%; max-width: 360px; aspect-ratio: 9 / 16; display: block; margin: 0 auto; border-radius: 14px; background: #000; }
.player-ph { display: grid; place-items: center; text-align: center; color: #ddd; padding: 20px; }
details summary { cursor: pointer; margin: 4px 0; }
@media (min-width: 760px) { .draft-layout { grid-template-columns: 360px 1fr; align-items: start; } }
