:root {
  --bg: #f7f7f8; --surface: #fff; --surface-2: #f1f1f3; --text: #18181b; --muted: #71717a;
  --line: #e4e4e7; --accent: #5b4bdb; --accent-text: #fff; --danger: #dc2626;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f0f12; --surface: #18181c; --surface-2: #222228; --text: #f4f4f5; --muted: #a1a1aa;
    --line: #2a2a30; --accent: #7c6ff0; --danger: #f87171; --shadow: 0 8px 24px rgba(0,0,0,.4); }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: inherit; }
header { display: flex; align-items: center; gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; letter-spacing: -.02em; text-decoration: none; display: flex; gap: 8px; align-items: center; }
.brand img { width: 22px; height: 22px; display: block; }
.spacer { flex: 1; }
input[type=search], input[type=text], input[type=password] {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; outline: none; min-width: 0;
}
input:focus { border-color: var(--accent); }
button, .btn { font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
button:hover, .btn:hover { background: var(--surface-2); }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.primary:hover { background: var(--accent); filter: brightness(1.08); }
.danger { color: var(--danger); }
main { max-width: 1200px; margin: 0 auto; padding: 28px 24px 64px; }
h1 { font-size: 22px; letter-spacing: -.01em; margin: 0 0 20px; }
.muted { color: var(--muted); }

/* Library grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 24px; }
.card { position: relative; }
.thumb { display: block; position: relative; aspect-ratio: 16/9; border-radius: 12px; overflow: hidden; background: var(--surface-2); box-shadow: var(--shadow); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.thumb:hover img { transform: scale(1.02); }
.thumb .dur { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.75); color: #fff; font-size: 12px; padding: 1px 6px; border-radius: 5px; }
.thumb .badge { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.75); color: #fff; font-size: 12px; padding: 1px 8px; border-radius: 5px; }
.thumb .placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.card-body { display: flex; align-items: flex-start; gap: 8px; padding: 10px 2px 0; }
.card-title { font-weight: 600; text-decoration: none; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { font-size: 13px; color: var(--muted); }
.more { border: none; background: none; padding: 2px 8px; font-size: 18px; line-height: 1; border-radius: 6px; color: var(--muted); }
.menu { position: absolute; right: 0; top: 100%; z-index: 10; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; min-width: 170px; }
.menu button { display: block; width: 100%; text-align: left; border: none; background: none; padding: 8px 12px; border-radius: 6px; }
.menu button:hover { background: var(--surface-2); }
.empty { text-align: center; padding: 96px 24px; color: var(--muted); }
.empty h2 { color: var(--text); margin: 0 0 8px; font-size: 20px; }
kbd { font: 12px ui-monospace, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; }

/* Video page */
.video-layout { display: grid; grid-template-columns: 1fr 300px; gap: 28px; align-items: start; }
.player { background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 16/9; }
.player video { width: 100%; height: 100%; display: block; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
/* While the AI title is being generated, the title box gets a moving rainbow border. */
.title-wrap { border-radius: 10px; padding: 2px; }
.title-wrap.generating { background: linear-gradient(90deg, #ff5f6d, #ffc371, #47e891, #3fa9f5, #a66cff, #ff5f6d) 0 0 / 300% 100%; animation: rainbow 2.4s linear infinite; }
.title-wrap.generating .title-input { background: var(--bg) !important; border-color: transparent !important; }
@keyframes rainbow { to { background-position: 300% 0; } }
.generating-text { background: linear-gradient(90deg, #ff5f6d, #ffc371, #47e891, #3fa9f5, #a66cff, #ff5f6d) 0 0 / 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; animation: rainbow 2.4s linear infinite; font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .title-wrap.generating { animation: none; } }
.title-input { width: 100%; font-size: 20px !important; font-weight: 600; background: transparent !important; border-color: transparent !important; padding: 4px 8px !important; margin: 0; display: block; border-radius: 8px !important; }
.title-input:hover { border-color: var(--line) !important; }
.title-input:focus { border-color: var(--accent) !important; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; margin-bottom: 8px; }
.radio:has(input:checked) { border-color: var(--accent); }
.radio input { margin-top: 4px; accent-color: var(--accent); }
.radio small { display: block; color: var(--muted); }
.link-row { display: flex; gap: 8px; margin-top: 14px; }
.link-row input { flex: 1; width: 0; }
.stack { display: grid; gap: 8px; }

/* Modal */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; padding: 22px; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal input { width: 100%; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #18181b; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 60; }

/* Login */
.login { max-width: 360px; margin: 12vh auto; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login form { display: grid; gap: 12px; margin-top: 16px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.5em; }

@media (max-width: 800px) {
  .video-layout { grid-template-columns: 1fr; }
  header { padding: 12px 16px; flex-wrap: wrap; }
  main { padding: 20px 16px 48px; }
  header input[type=search] { order: 3; width: 100%; }
}
