:root {
    --bg: #fbfaf8;
    --surface: #ffffff;
    --surface-2: #f2f0ec;
    --border: #e4e0d8;
    --text: #1c1a17;
    --text-soft: #6b665d;
    --accent: #3f7d5a;
    --accent-soft: #e7f0ea;
    --danger: #b5442f;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.05);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14140f;
        --surface: #1c1c17;
        --surface-2: #24241d;
        --border: #33322a;
        --text: #ece9e2;
        --text-soft: #9a958a;
        --accent: #6bbd8c;
        --accent-soft: #1a2a20;
        --danger: #e0785f;
        --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
    }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }

/* ── top bar ── */
#topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 22px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky; top: 0; z-index: 20;
}
.brand {
    font-weight: 800; font-size: 1.15rem; letter-spacing: -.02em;
    color: var(--accent);
}
#crumbs { display: flex; align-items: center; gap: 8px; color: var(--text-soft); font-size: .92rem; min-width: 0; }
#crumbs a { color: var(--text-soft); }
#crumbs a:hover { color: var(--text); }
#crumbs .sep { opacity: .5; }
#crumbs .here { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
#usermenu { display: flex; align-items: center; gap: 12px; font-size: .9rem; }
#usermenu .name { font-weight: 600; cursor: pointer; }
#usermenu .name:hover { color: var(--accent); }
.badge-admin { font-size: .62rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
    color: var(--accent); background: var(--accent-soft); padding: 2px 6px; border-radius: 5px; }

/* ── layout ── */
#app { max-width: 1080px; margin: 0 auto; padding: 26px 22px 80px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.page-head .spacer { flex: 1; }
.muted { color: var(--text-soft); }
.empty { text-align: center; color: var(--text-soft); padding: 60px 20px; }
.section { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
    color: var(--text-soft); margin: 22px 0 10px; }
.section:first-child { margin-top: 4px; }

/* ── buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 8px 15px; border-radius: 9px; border: 1px solid var(--border);
    background: var(--surface); cursor: pointer; font-weight: 600; font-size: .9rem;
    transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn.danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn.small { padding: 4px 10px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: default; }

/* ── cards / grids ── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden; cursor: pointer; transition: transform .1s, box-shadow .1s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,.06), 0 12px 30px rgba(0,0,0,.09); }
.folder-card { display: flex; align-items: center; gap: 14px; padding: 18px; }
.folder-ico { font-size: 1.6rem; }
.folder-card .meta { min-width: 0; }
.folder-card .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-card .sub { color: var(--text-soft); font-size: .82rem; }

.thumb {
    aspect-ratio: 16/9; background: var(--surface-2) center/cover no-repeat;
    display: flex; align-items: center; justify-content: center; color: var(--text-soft);
    font-size: .8rem; position: relative;
}
.thumb .dur {
    position: absolute; right: 7px; bottom: 7px; background: rgba(0,0,0,.75); color: #fff;
    font: 600 .72rem/1 var(--mono); padding: 3px 5px; border-radius: 4px;
}
.thumb .state { font-weight: 600; text-transform: uppercase; letter-spacing: .06em; font-size: .68rem; }
.thumb .state.failed { color: var(--danger); }
.vid-card .body { padding: 12px 14px; }
.vid-card .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vid-card .sub { color: var(--text-soft); font-size: .8rem; margin-top: 2px; }

/* ── forms / login ── */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: .8rem; font-weight: 600; color: var(--text-soft); }
.input {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px;
    background: var(--bg);
}
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 72px; }

.login-wrap { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login-wrap .brand { font-size: 2rem; display: block; margin-bottom: 4px; }
.login-wrap .tag { color: var(--text-soft); margin-bottom: 26px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 24px; text-align: left; }
.err { color: var(--danger); font-size: .85rem; margin-top: 8px; min-height: 1.2em; }

/* ── player + comments ── */
.watch { display: grid; grid-template-columns: 1fr 360px; gap: 22px; align-items: start; }
@media (max-width: 860px) { .watch { grid-template-columns: 1fr; } }
video { width: 100%; border-radius: var(--radius); background: #000; display: block; box-shadow: var(--shadow); }
.watch-title { font-size: 1.3rem; font-weight: 800; margin: 14px 0 4px; }

/* comment timeline (scrubbable marker bar under the video) */
.vtl {
    position: relative; height: 30px; margin-top: 10px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 8px; cursor: pointer; overflow: hidden;
}
.vtl-progress { position: absolute; left: 0; top: 0; bottom: 0; width: 0;
    background: color-mix(in srgb, var(--accent) 20%, transparent); }
.vtl-playhead { position: absolute; top: 0; bottom: 0; width: 2px; left: 0;
    background: var(--accent); pointer-events: none; z-index: 3; }
.vtl-markers { position: absolute; inset: 0; }
.vtl-marker {
    position: absolute; top: 50%; width: 13px; height: 13px; margin-left: -6.5px;
    transform: translateY(-50%); background: var(--accent); border: 2px solid var(--surface);
    border-radius: 50%; cursor: pointer; z-index: 2; transition: transform .1s;
}
.vtl-marker:hover { transform: translateY(-50%) scale(1.35); z-index: 4; }
@keyframes cflash { from { background: var(--accent-soft); } to { background: transparent; } }
.comment.flash { animation: cflash 1.3s ease; border-radius: 6px; }

.comments { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: calc(100vh - 120px); }
.comments h3 { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: .95rem; }
.comment-list { padding: 10px 12px; overflow-y: auto; flex: 1; }
.composer { border-top: 1px solid var(--border); padding: 12px; }
.composer .row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.ts-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--text-soft); cursor: pointer; }
.ts-chip {
    font: 600 .78rem/1 var(--mono); color: var(--accent); background: var(--accent-soft);
    padding: 3px 7px; border-radius: 6px; border: none; cursor: pointer;
}
.ts-chip:hover { filter: brightness(.95); }

.comment { padding: 8px 0; }
.comment + .comment { border-top: 1px solid var(--border); }
.comment .head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.comment .author { font-weight: 700; font-size: .9rem; }
.comment .when { color: var(--text-soft); font-size: .74rem; }
.comment .body { margin-top: 3px; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment .actions { margin-top: 4px; display: flex; gap: 12px; }
.comment .actions button { background: none; border: none; color: var(--text-soft); font-size: .78rem; cursor: pointer; padding: 0; }
.comment .actions button:hover { color: var(--text); }
.replies { margin-left: 16px; padding-left: 12px; border-left: 2px solid var(--border); margin-top: 6px; }
.reply-box { margin: 8px 0 4px; }

/* ── modal ── */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex;
    align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
    width: 100%; max-width: 460px; max-height: 85vh; overflow-y: auto; padding: 22px; }
.modal h2 { font-size: 1.15rem; margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.check-row:last-child { border-bottom: none; }
.check-row .who { flex: 1; }
.who .dn { font-weight: 600; }
.who .un { color: var(--text-soft); font-size: .8rem; }

/* ── drag & drop overlay ── */
.dropzone {
    position: fixed; inset: 0; z-index: 200; display: none;
    align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--accent) 22%, rgba(0,0,0,.55));
    backdrop-filter: blur(2px);
    pointer-events: none;  /* let drag events reach the page, not the overlay */
}
.dropzone.show { display: flex; }
.dz-inner {
    border: 3px dashed #fff; border-radius: 18px; padding: 46px 70px;
    color: #fff; font-size: 1.3rem; font-weight: 700; text-align: center;
    background: rgba(0,0,0,.25); pointer-events: none;
}
.dz-ico { font-size: 2.4rem; margin-bottom: 8px; }

/* ── toast ── */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
    background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px;
    font-size: .9rem; box-shadow: var(--shadow); z-index: 100; }

.userlist { display: flex; flex-direction: column; gap: 0; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.user-row .who { flex: 1; }
.spin { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
