:root {
  --bg: #fbf7f0; --surface: #ffffff; --surface-2: #f4efe6; --text: #231f1a; --muted: #6b6258;
  --line: #e6dfd2; --primary: #0f766e; --primary-text: #ffffff; --primary-soft: #d6efec;
  --danger: #b42318; --danger-soft: #fde8e6; --warn-soft: #fff1cc; --ok: #1a7f4b;
  --radius: 14px; --shadow: 0 1px 2px rgba(35, 31, 26, .06), 0 4px 14px rgba(35, 31, 26, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16130f; --surface: #1f1b16; --surface-2: #2a251e; --text: #f3ede3; --muted: #a79d8f;
    --line: #38322a; --primary: #3bb5a8; --primary-text: #08201d; --primary-soft: #143a36;
    --danger: #ff8a7a; --danger-soft: #3d1a16; --warn-soft: #3b2f10; --ok: #5fd08f;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: .55rem .95rem; border-radius: 10px; min-height: 44px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .875rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.field { display: grid; gap: .25rem; margin-bottom: .85rem; }
.field label { font-weight: 600; font-size: .9rem; }
.field input, .field select { padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); min-height: 44px; width: 100%; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; }
.row > .field { flex: 1 1 140px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.chip { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--primary-soft); color: var(--primary); }
.chip.paused { background: var(--danger-soft); color: var(--danger); }
.chip.warn { background: var(--warn-soft); }
.notice { padding: .65rem .85rem; border-radius: 10px; background: var(--warn-soft); margin-bottom: .85rem; }
.notice.error { background: var(--danger-soft); color: var(--danger); }

/* auth */
.auth { max-width: 420px; margin: 8vh auto; padding: 0 16px; }
.auth h1 { text-align: center; font-size: 1.8rem; }
.auth .sub { text-align: center; margin-bottom: 1.25rem; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--surface-2); padding: 4px;
  border-radius: 12px; margin-bottom: 1rem; }
.seg button { border: 0; background: transparent; padding: .5rem; border-radius: 9px; min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--surface); font-weight: 600; box-shadow: var(--shadow); }

/* app shell */
.topbar { display: flex; align-items: center; gap: .75rem; padding: .7rem 16px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 800; font-size: 1.1rem; margin-right: auto; }
.layout { display: grid; grid-template-columns: 260px 1fr; gap: 1rem; max-width: 1100px; margin: 0 auto; padding: 16px; }
.sidebar .child { display: flex; width: 100%; text-align: left; align-items: center; gap: .6rem; padding: .7rem .8rem;
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; margin-bottom: .5rem; min-height: 52px; }
.sidebar .child[aria-current="true"] { border-color: var(--primary); background: var(--primary-soft); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: var(--primary-text);
  display: grid; place-items: center; font-weight: 700; flex: none; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: .65rem 1rem; border-bottom: 3px solid transparent; min-height: 44px; }
.tabs button[aria-selected="true"] { border-color: var(--primary); font-weight: 700; }
.head { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.head h1 { margin: 0; margin-right: auto; }

.bar { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: .4rem 0; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.bar.high > span { background: var(--danger); }
.code { font: 700 2.2rem/1.2 ui-monospace, Menlo, monospace; letter-spacing: .2em; padding: .5rem 0; }

.chlist { display: grid; gap: .6rem; }
.channel { display: flex; align-items: center; gap: .8rem; }
.channel img, .channel .ph { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex: none; }
.channel .grow { flex: 1; min-width: 0; }
.channel .grow strong { display: block; overflow-wrap: anywhere; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .9rem; }
.video { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.video.blocked { opacity: .55; }
.video .thumb { position: relative; aspect-ratio: 16 / 9; background: var(--surface-2); }
.video .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video .dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0, 0, 0, .75); color: #fff; font-size: .75rem;
  padding: 0 .4rem; border-radius: 6px; }
.video .meta { padding: .6rem .7rem; display: grid; gap: .35rem; flex: 1; }
.video .title { font-weight: 600; font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; }
.stat { background: var(--surface-2); border-radius: 12px; padding: .8rem; }
.stat b { display: block; font-size: 1.6rem; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: .7rem 1.1rem; border-radius: 12px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; z-index: 20; }
#toast.show { opacity: 1; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: .4rem; }
  .topbar .muted { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout > * { min-width: 0; }
  .sidebar { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .25rem; }
  .sidebar .child { width: auto; flex: none; margin: 0; }
  .sidebar h2 { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.wdgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: .5rem; margin-bottom: .85rem; }
.wdgrid .field { margin: 0; }
.wdgrid input { padding: .5rem; text-align: center; }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.chart .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; }
.chart .b { width: 100%; max-width: 34px; background: var(--primary); border-radius: 8px 8px 0 0; }
.chart .b.empty { background: var(--line); }
.hrow { display: flex; align-items: center; gap: .9rem; margin-bottom: .6rem; padding: .7rem .9rem; flex-wrap: wrap; }
.hrow img, .hrow .ph { width: 96px; height: 54px; object-fit: cover; border-radius: 8px; background: var(--surface-2); flex: none; }
.hrow .grow { flex: 1; min-width: 160px; display: grid; }
.hrow strong { overflow-wrap: anywhere; }

footer.legal { max-width: 1100px; margin: 1.5rem auto 2rem; padding: 0 16px; text-align: center; color: var(--muted); font-size: .85rem; }
footer.legal a { color: var(--muted); }
.card a, .auth a { color: var(--primary); }
footer.legal a { white-space: nowrap; }

.layout > * { min-width: 0; }
