:root {
  --bg: #fff; --fg: #0f0f0f; --muted: #606060; --card: #f2f2f2; --line: #e5e5e5;
  --accent: #e5322d; --accent-fg: #fff; --chip: #f0f0f0; --chip-active: #0f0f0f; --chip-active-fg: #fff;
  --warn: #b26a00; --danger: #c62828; --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f0f0f; --fg: #f1f1f1; --muted: #aaa; --card: #212121; --line: #303030;
    --chip: #272727; --chip-active: #f1f1f1; --chip-active-fg: #0f0f0f; --warn: #ffb74d; --danger: #ef5350; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom); }
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line);
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; display: flex; gap: 10px; align-items: center; }
.logo { display: flex; align-items: center; gap: 6px; font-weight: 700; white-space: nowrap; }
.logo .mark { width: 28px; height: 20px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; }
.logo .mark::after { content: ""; border-left: 8px solid #fff; border-top: 5px solid transparent; border-bottom: 5px solid transparent; margin-left: 2px; }
.search { flex: 1; position: relative; }
.search input { width: 100%; padding: 9px 36px 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); outline: none; }
.search input:focus { border-color: var(--muted); }
.search .clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: none; padding: 6px 10px; color: var(--muted); cursor: pointer; }
.icon-btn { border: 0; background: none; padding: 8px; border-radius: 999px; cursor: pointer; color: var(--fg); display: grid; place-items: center; }
.icon-btn:hover { background: var(--card); }
.icon-btn svg { width: 22px; height: 22px; }
@media (max-width: 520px) { .logo .text { display: none; } }

/* Chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; background: var(--chip); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.chip.active { background: var(--chip-active); color: var(--chip-active-fg); }
.chip.small { padding: 3px 9px; font-size: 13px; border-radius: 6px; }

/* Usage meter */
.usage { padding: 0 12px 6px; font-size: 13px; color: var(--muted); }
.usage .bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.usage .bar > div { height: 100%; background: var(--muted); width: 0; transition: width .3s; }
.usage.warn { color: var(--warn); }
.usage.warn .bar > div { background: var(--warn); }
.usage.full { color: var(--danger); }
.usage.full .bar > div { background: var(--danger); }

/* Feed */
main { max-width: 1400px; margin: 0 auto; }
.feed { display: grid; gap: 4px 16px; grid-template-columns: 1fr; padding: 0 0 100px; }
@media (min-width: 640px) { .feed { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); padding: 8px 16px 100px; gap: 24px 16px; } }
.card { display: block; }
.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--card); overflow: hidden; }
@media (min-width: 640px) { .thumb { border-radius: var(--radius); } }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.thumb .dur { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.8); color: #fff; font-size: 12px; font-weight: 600; padding: 1px 5px; border-radius: 4px; }
.meta { padding: 10px 12px 14px; }
@media (min-width: 640px) { .meta { padding: 10px 2px 0; } }
.meta h3 { margin: 0 0 4px; font-size: 16px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta .sub { color: var(--muted); font-size: 13px; }
.meta .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.empty, .status-line { text-align: center; color: var(--muted); padding: 40px 20px; }
.sentinel { height: 1px; }

/* FAB */
.fab { position: fixed; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 20; background: var(--accent); color: var(--accent-fg);
  border-radius: 999px; padding: 14px 20px 14px 16px; display: flex; gap: 6px; align-items: center; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.fab svg { width: 22px; height: 22px; }

/* Forms / pages */
.page { max-width: 720px; margin: 0 auto; padding: 16px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.input { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); outline: none; }
.input:focus { border-color: var(--muted); }
.btn { border: 0; border-radius: 999px; padding: 12px 20px; font-weight: 600; cursor: pointer; background: var(--chip); }
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.msg { padding: 10px 14px; border-radius: 10px; margin: 12px 0; font-size: 14px; }
.msg.error { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.msg.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.msg.ok { background: color-mix(in srgb, #2e7d32 15%, transparent); }
.picker { display: grid; place-items: center; gap: 8px; border: 2px dashed var(--line); border-radius: var(--radius); padding: 32px 16px; text-align: center; cursor: pointer; color: var(--muted); }
.picker svg { width: 40px; height: 40px; }
.preview { width: 100%; border-radius: var(--radius); background: #000; max-height: 50vh; display: block; }
.thumb-preview { width: 160px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; background: var(--card); }
.tag-input { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.tag-input input { flex: 1; min-width: 120px; border: 0; background: none; outline: none; padding: 4px; }
.tag-input .chip { background: var(--bg); display: inline-flex; gap: 4px; align-items: center; }
.tag-input .chip button { border: 0; background: none; padding: 0 2px; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; }
.progress { height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.small { font-size: 13px; color: var(--muted); }

/* Watch */
.player-wrap { background: #000; position: sticky; top: 0; z-index: 5; }
@media (min-width: 900px) { .player-wrap { position: static; max-width: 1100px; margin: 16px auto 0; border-radius: var(--radius); overflow: hidden; } }
.player { width: 100%; max-height: 70vh; aspect-ratio: 16/9; display: block; background: #000; }
.watch-meta { max-width: 1100px; margin: 0 auto; padding: 12px 16px 60px; }
.watch-meta h1 { font-size: 20px; margin: 0 0 6px; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; }
.login .logo { justify-content: center; font-size: 22px; margin-bottom: 24px; }
.login .logo .mark { width: 40px; height: 28px; }
.center { text-align: center; }
.spacer { flex: 1; }
.usage.flush { padding: 0 0 12px; }
.chips.flush { padding: 10px 0; }
.thumb-row { align-items: center; margin: 12px 0; }
#retake { margin-top: 6px; padding: 6px 12px; }
@media (min-width: 640px) {
  .search { max-width: 640px; margin: 0 auto; }
  .chips, .usage { padding-left: 16px; padding-right: 16px; }
}
