/* DrawTube: calm, paper-like, phone first. Colours as tokens; dark mode follows the system. */
:root {
  --bg: #f6f3ee; --card: #fffdf9; --ink: #23262b; --muted: #6b6f76; --line: #e4ded4;
  --accent: #3b6e8f; --accent-ink: #fff; --done: #3f8a5a; --warn: #b4562f; --chip: #ece6dc;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 2px 8px rgba(40, 30, 10, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c; --card: #1f2227; --ink: #e8e6e1; --muted: #9a9ea6; --line: #2e3238;
    --accent: #7fb0d0; --accent-ink: #0d1a22; --done: #6cc28d; --warn: #e48a62; --chip: #2a2e34;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); } .tiny { font-size: 13px; } .pad { padding: 0 16px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2.sub { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 16px 8px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; min-height: 46px;
}
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 600 15px system-ui; min-height: 46px;
  padding: 0 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); width: 100%; margin-top: 16px; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--warn); border-color: var(--warn); background: transparent; margin-top: 14px; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn:disabled { opacity: .55; }
.linklike { background: none; border: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; padding: 8px 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form { margin: 0 16px; padding: 4px 16px 16px; }
.err { color: var(--warn); min-height: 1.4em; margin: 10px 0 0; }
.msg { min-height: 1.4em; margin: 10px 0 0; font-size: 14px; }

/* login */
#login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card h1 { margin-top: 10px; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(12px + env(safe-area-inset-top)) 16px 10px; display: flex; flex-direction: column; gap: 10px; }
.top.slim { flex-direction: row; align-items: center; gap: 8px; padding-bottom: 6px; }
.icon-btn { font-size: 30px; line-height: 1; width: 44px; height: 44px; border: 0; background: transparent; color: var(--ink); cursor: pointer; border-radius: 10px; }

/* category chips: horizontal scroll */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; background: var(--chip); color: var(--ink); font: 600 14px system-ui; padding: 9px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap; min-height: 38px; }
.chip.on { background: var(--ink); color: var(--bg); }
.chip small { font-weight: 500; opacity: .7; margin-left: 4px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 2px 16px 8px; }
.seg { display: inline-flex; background: var(--chip); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: 600 13px system-ui; padding: 7px 12px; border-radius: 8px; cursor: pointer; min-height: 34px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* library sections + cards */
.section-h { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 16px 8px; }
.section-h h2 { font-size: 17px; margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; padding: 0 16px; }
@media (max-width: 420px) { .grid { grid-template-columns: 1fr 1fr; gap: 10px; } }
.vcard { position: relative; text-align: left; border: 0; padding: 0; background: transparent; color: inherit; cursor: pointer; font: inherit; }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: var(--chip); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0, 0, 0, .72); color: #fff; font: 600 11.5px system-ui; padding: 2px 6px; border-radius: 5px; font-variant-numeric: tabular-nums; }
.badge-done { position: absolute; left: 6px; top: 6px; background: var(--done); color: #fff; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.state { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .5); color: #fff; font: 600 13px system-ui; text-align: center; padding: 6px; }
.state.failed { background: rgba(120, 30, 10, .6); }
.resume { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--warn); }
.vtitle { font: 600 14px/1.3 system-ui; margin: 7px 0 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.vchan { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order { display: flex; gap: 6px; margin-top: 6px; }
.order button { flex: 1; min-height: 36px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; font-size: 16px; cursor: pointer; }
.order button:disabled { opacity: .35; }
.empty { margin: 32px 16px; text-align: center; color: var(--muted); }

/* queue */
.qitem { margin: 0 16px 10px; padding: 12px 14px; }
.qitem .t { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qitem .meta { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; }
.bar { height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .5s; }
.qitem.failed .meta { color: var(--warn); }
.qitem .btn { margin-top: 8px; }

/* player */
#player video { width: 100%; max-height: 56vh; background: #000; display: block; }
.title { font-size: 19px; margin-top: 14px; }
.done-btn { width: 100%; margin-top: 12px; }
.done-btn[aria-pressed="true"] { background: var(--done); border-color: var(--done); color: #fff; }
.more { margin: 18px 0 30px; }
.more summary { cursor: pointer; color: var(--muted); padding: 8px 0; }
.more a { display: inline-block; margin: 6px 0; color: var(--accent); }
.more .btn { width: 100%; }

/* categories */
.row-form { display: flex; gap: 8px; align-items: center; padding: 12px; }
.row-form .btn.primary { width: auto; margin: 0; }
.cat-list { list-style: none; margin: 14px 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cat-item { padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: center; }
.cat-item input { min-height: 40px; padding: 8px 10px; }
.cat-item .ctl { display: flex; gap: 4px; }
.cat-item .ctl button { width: 40px; height: 40px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; cursor: pointer; font-size: 15px; }
.cat-item .ctl button:disabled { opacity: .35; }
.cat-item .ctl .del { color: var(--warn); }
.cat-item .count { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }
.cat-item .moveto { grid-column: 1 / -1; display: flex; gap: 8px; }
.cat-item .moveto select { min-height: 40px; padding: 6px 8px; }

/* bottom tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 0 9px; color: var(--muted); text-decoration: none; font: 600 12px system-ui; min-height: 56px; }
.tabs a span { font-size: 19px; line-height: 1.2; }
.tabs a.on { color: var(--accent); }

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

@media (min-width: 900px) {
  #app { max-width: 1100px; margin: 0 auto; }
  .form, .qitem { max-width: 640px; }
  #player video { max-height: 64vh; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
