:root {
  --ink: #1d2433;
  --muted: #6b7280;
  --paper: #f6f3ec;
  --card: #ffffff;
  --line: #e4ded1;
  --navy: #1f2b45;
  --navy-2: #2c3b5e;
  --gold: #b8892f;
  --gold-soft: #f3e7cc;
  --ok: #2f7d4f;
  --bad: #b3362f;
  --warn: #b7791f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 25, 40, .06), 0 4px 14px rgba(20, 25, 40, .05);
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 15px/1.5 var(--sans); color: var(--ink); background: var(--paper); }
a { color: var(--navy-2); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.8rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
code { background: #eee8da; padding: 1px 5px; border-radius: 4px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 40px; min-height: 70vh; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .nowrap { white-space: nowrap; }
.ok { color: var(--ok); font-weight: 700; } .bad { color: var(--bad); font-weight: 700; }
.row { display: flex; align-items: center; flex-wrap: wrap; } .gap { gap: 10px; } .grow { flex: 1; min-width: 0; }
.inline { display: inline; margin: 0; }

/* top bar */
.topbar { background: var(--navy); color: #fff; border-bottom: 3px solid var(--gold); }
.topbar-inner { display: flex; align-items: center; gap: 20px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-family: var(--serif); font-size: 1.2rem; }
.brand svg { color: var(--gold); }
.mainnav { display: flex; align-items: center; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.mainnav a, .mainnav .linklike { color: #d9def0; text-decoration: none; padding: 8px 12px; border-radius: 6px; font-size: .95rem; }
.mainnav a:hover, .mainnav .linklike:hover { background: var(--navy-2); color: #fff; }
.mainnav a.active { background: var(--navy-2); color: #fff; box-shadow: inset 0 -2px 0 var(--gold); }
.nav-sep { width: 1px; height: 22px; background: #44507a; margin: 0 6px; }
.linklike { background: none; border: 0; cursor: pointer; font: inherit; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid #44507a; color: #fff; font-size: 1.2rem; border-radius: 6px; padding: 4px 10px; }
@media (max-width: 820px) {
  .nav-toggle { display: block; }
  .mainnav { display: none; width: 100%; flex-direction: column; align-items: stretch; padding-bottom: 10px; }
  .nav-open .mainnav { display: flex; }
  .topbar-inner { flex-wrap: wrap; }
  .nav-sep { display: none; }
}

/* buttons & forms */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 8px; font: inherit; font-size: .92rem; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { border-color: #c9bfa9; background: #fbf9f4; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); border-color: var(--navy-2); }
.btn-danger { color: var(--bad); border-color: #e6c3c0; }
.btn-danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: .85rem; } .btn-xs { padding: 2px 8px; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; padding: 11px; }
.btn.toggle.on { background: var(--gold-soft); border-color: var(--gold); }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: -1px; border-color: var(--gold); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--navy); }
label { display: block; font-weight: 500; font-size: .92rem; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 6px 0; }
.inline-label { display: flex; align-items: center; gap: 6px; font-weight: 400; }
.inline-label input { width: auto; margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 0; }
legend { font-weight: 600; padding: 0 6px; }
.stack > * + * { margin-top: 14px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two-col.top { align-items: start; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

/* layout pieces */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form-card { padding: 20px; margin-bottom: 18px; }
.form-card h2 { margin-bottom: 12px; }
details.form-card summary { cursor: pointer; }
details.form-card[open] summary { margin-bottom: 14px; }
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert-success { background: #eaf5ee; border-color: #bfe0cb; color: #1f5a37; }
.alert-error { background: #fbecea; border-color: #efc5c1; color: #8a2a24; }
.alert-info { background: #edf1fa; border-color: #c9d3ec; color: #2b3d68; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.pill { display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: 99px; background: #ece7db; color: #4b5161; font-weight: 600; letter-spacing: .02em; vertical-align: middle; }
.pill.gold { background: var(--gold); color: #fff; }
.pill.audio { background: #e3ecf8; color: #2c4f86; } .pill.video { background: #f6e6d8; color: #8a4a17; }
.pill.ok-pill { background: #e2f1e7; color: var(--ok); }
.foot { color: var(--muted); font-size: .82rem; padding: 20px 16px 30px; text-align: center; }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.filters input[type=search] { flex: 1 1 220px; width: auto; }
.filters select { width: auto; }

/* library grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.media-card { display: flex; flex-direction: column; overflow: hidden; }
.thumb { position: relative; display: grid; place-items: center; height: 120px; color: #fff; text-decoration: none; }
.thumb-audio { background: linear-gradient(135deg, #2c3b5e, #4a5d8c); }
.thumb-video { background: linear-gradient(135deg, #5b3a1e, #b8892f); }
.thumb svg { opacity: .9; transition: transform .15s; }
a.thumb:hover svg { transform: scale(1.12); }
.thumb .pill { position: absolute; top: 10px; left: 10px; background: rgba(255,255,255,.88); }
.card-body { padding: 12px 14px 4px; flex: 1; }
.card-body h3 { margin-bottom: 4px; overflow-wrap: anywhere; }
.card-body p { margin: 2px 0; }
.card-actions { display: flex; gap: 8px; padding: 10px 14px 14px; }
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
.pager a, .pager span { padding: 6px 11px; border-radius: 6px; border: 1px solid var(--line); background: #fff; text-decoration: none; color: var(--ink); }
.pager .current { background: var(--navy); color: #fff; border-color: var(--navy); }

/* watch page & player */
.watch { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .watch { grid-template-columns: 1fr; } }
.player-box { background: #10141f; border-radius: var(--radius); overflow: hidden; }
.player-box video { display: block; width: 100%; max-height: 70vh; background: #000; }
.player-box audio { display: block; width: calc(100% - 24px); margin: 0 12px 14px; }
.audio-art { display: grid; place-items: center; height: 220px; color: var(--gold); background: radial-gradient(circle at 50% 40%, #2c3b5e, #10141f 70%); }
.watch-info .desc { white-space: normal; }
.danger-zone { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-color: #efc5c1; }

.pl-player { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .pl-player { grid-template-columns: 1fr; } }
.now { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 4px; flex-wrap: wrap; }
.now h2 { margin: 2px 0; }
.controls { display: flex; gap: 6px; }
.controls .btn { font-size: 1.05rem; padding: 8px 12px; }
.tracklist { list-style: none; margin: 0; padding: 6px; max-height: 70vh; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); counter-reset: t; }
.tracklist li { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; cursor: pointer; counter-increment: t; }
.tracklist li::before { content: counter(t); color: var(--muted); width: 1.6em; text-align: right; font-size: .85rem; }
.tracklist li:hover { background: #f7f3ea; }
.tracklist li.playing { background: var(--gold-soft); }
.tracklist li.playing::before { content: "▶"; color: var(--gold); }
.tracklist .t-title { font-weight: 500; }

/* playlist editor */
.list { display: flex; flex-direction: column; gap: 12px; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 18px; flex-wrap: wrap; }
.list-row h3 { margin: 0 0 2px; } .list-row p { margin: 2px 0; }
.list-actions { display: flex; gap: 8px; align-items: center; }
.sortable { list-style: none; padding: 0; margin: 0 0 14px; counter-reset: s; }
.sortable li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: #fff; counter-increment: s; }
.sortable li::before { content: counter(s) "."; color: var(--muted); font-size: .85rem; width: 1.8em; }
.sortable li.dragging { opacity: .4; }
.sortable li.over { border-color: var(--gold); box-shadow: 0 -2px 0 var(--gold); }
.handle { cursor: grab; color: #a59c88; user-select: none; letter-spacing: -2px; }
.picklist { max-height: 460px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.pick { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid #f0ebe0; font-weight: 400; cursor: pointer; }
.pick:hover { background: #faf7f0; }
.pick:last-child { border-bottom: 0; }

/* upload */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 30px; border: 2px dashed #cfc5ae; border-radius: var(--radius); text-align: center; cursor: pointer; background: #fcfaf5; font-weight: 400; }
.dropzone.drag { border-color: var(--gold); background: var(--gold-soft); }
.dropzone input { max-width: 340px; }
.progress { position: relative; height: 22px; background: #eee8da; border-radius: 99px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--navy), var(--gold)); transition: width .2s; }
.progress .pct { position: absolute; inset: 0; display: grid; place-items: center; font-size: .8rem; font-weight: 600; color: #fff; text-shadow: 0 0 3px rgba(0,0,0,.5); }

/* tables & logs */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid #efe9dc; text-align: left; vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #faf7f0; }
.table.compact td { padding: 6px 8px; }
.table tr.inactive td { opacity: .55; }
.tag { display: inline-block; font-family: ui-monospace, Consolas, monospace; font-size: .78rem; padding: 2px 7px; border-radius: 5px; background: #eef0f4; color: #3a4256; white-space: nowrap; }
.tag.bad { background: #fbe4e1; color: var(--bad); } .tag.warn { background: #fbefd9; color: #8a5a10; }
.tag.good { background: #e2f1e7; color: var(--ok); } .tag.auth { background: #e3e9f8; color: #2c4f86; }
.details { max-width: 460px; }
.kv { display: inline-block; margin: 0 8px 2px 0; overflow-wrap: anywhere; }
.kv b { color: var(--muted); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; border-top: 3px solid var(--navy); }
.stat.warn { border-top-color: var(--bad); }
.stat-v { font-family: var(--serif); font-size: 1.4rem; font-weight: 600; }
.stat-l { color: var(--muted); font-size: .82rem; }

/* login */
body.bare { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(circle at 50% 0%, #2c3b5e, #1a2238 70%); }
body.bare main.wrap { min-height: 0; padding: 20px 16px; width: 100%; }
body.bare .foot { color: #9aa4c4; }
.login-card { background: #fff; max-width: 400px; margin: 0 auto; padding: 32px; border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.3); border-top: 4px solid var(--gold); }
.login-card.wide { max-width: 640px; }
.login-mark { color: var(--gold); text-align: center; }
.login-card h1 { text-align: center; }
.login-card > p.muted { text-align: center; margin-top: -4px; }
