:root {
  --bg: #fbf7f2;
  --surface: #ffffff;
  --surface-2: #f4ede4;
  --text: #2d2522;
  --muted: #8a7d75;
  --border: #e8ddd2;
  --accent: #b76e79;
  --accent-strong: #9c5560;
  --accent-soft: #f6e4e6;
  --gold: #c49a5a;
  --danger: #b3423a;
  --ok: #3d8b5f;
  --shadow: 0 1px 2px rgba(60, 40, 30, .06), 0 4px 16px rgba(60, 40, 30, .06);
  --radius: 14px;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bar-h: 112px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1517;
    --surface: #241d20;
    --surface-2: #2e2629;
    --text: #f3ebe6;
    --muted: #a89a93;
    --border: #3b3134;
    --accent: #d89aa3;
    --accent-strong: #e8b2ba;
    --accent-soft: #3a2a2e;
    --danger: #e0736a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  padding-bottom: calc(var(--bar-h) + 24px);
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1em; margin: 6px 0 0; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.brand h1 { font: 600 30px/1 var(--serif); margin: 0; color: var(--accent-strong); letter-spacing: .3px; }
.subtitle { color: var(--muted); font-family: var(--serif); font-size: 18px; font-style: italic; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.sync { font-size: 13px; color: var(--muted); margin-right: 6px; }
.sync.saved { color: var(--ok); }
.sync.offline, .sync.error { color: var(--danger); font-weight: 500; }
.warn { color: var(--danger); font-weight: 600; }
/* Hidden player used by "Check all clips". */
.check-player { position: fixed; left: -10000px; top: 0; width: 200px; height: 200px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.big { padding: 12px 26px; font-size: 17px; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid transparent;
  background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.danger:hover { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: 300px 1fr; gap: 24px;
  max-width: 1200px; margin: 24px auto; padding: 0 28px;
}
.sections-panel, .clips-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.sections-panel { align-self: start; position: sticky; top: 16px; }
.panel-title { font: 600 13px/1 var(--sans); text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin: 4px 6px 14px; }

.section-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 4px; }
.section-select {
  display: grid; grid-template-columns: 26px 1fr; grid-template-rows: auto auto; column-gap: 8px;
  width: 100%; text-align: left; padding: 10px 10px; border: 0; border-radius: 10px;
  background: transparent; cursor: pointer;
}
.section-select:hover { background: var(--surface-2); }
.section-item.active .section-select { background: var(--accent-soft); }
.section-num {
  grid-row: span 2; align-self: center; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.section-item.active .section-num { background: var(--accent); color: #fff; }
.section-item.live .section-num { background: var(--ok); color: #fff; animation: pulse 1.6s infinite; }
.section-name { font-weight: 500; }
.section-meta { font-size: 12px; color: var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(61, 139, 95, .15); } }

/* ---------- clips ---------- */
.clips-header { display: flex; align-items: center; gap: 12px; }
.section-title-input {
  flex: 1; min-width: 0; font: 600 30px/1.2 var(--serif); border: 1px solid transparent;
  border-radius: 8px; padding: 2px 8px; margin-left: -8px; background: transparent;
}
.section-title-input:hover { border-color: var(--border); }
.section-title-input:focus { border-color: var(--accent); outline: none; background: var(--bg); }
.clips-header-actions { display: flex; gap: 2px; }
.section-controls { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin: 14px 0 18px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.clip-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.clip {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.clip.playing { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, var(--surface)); }
.clip.has-error { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); }
.clip-play {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent-soft); color: var(--accent-strong); font-size: 14px;
}
.clip-play:hover { background: var(--accent); color: #fff; }
.clip.playing .clip-play { background: var(--ok); color: #fff; }
.clip-main { flex: 1; min-width: 0; }
.clip-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip-num { color: var(--muted); }
.clip-sub { font-size: 13px; color: var(--text); display: flex; align-items: center; gap: 8px; margin-top: 2px; flex-wrap: wrap; }
.clip-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.badge { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; letter-spacing: .3px; }
.badge.yt { background: #fde2e1; color: #b3261e; }
.badge.mp3 { background: #e3eefb; color: #2a5d9f; }
@media (prefers-color-scheme: dark) {
  .badge.yt { background: #4a2523; color: #ffb4ab; }
  .badge.mp3 { background: #22344a; color: #a8c8f0; }
}
.empty { color: var(--muted); text-align: center; padding: 28px 12px; border: 1px dashed var(--border); border-radius: 12px; margin: 0; }

.add-clip { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.yt-form { display: flex; gap: 8px; flex: 1; min-width: 260px; }
.yt-form input, .field input {
  flex: 1; min-width: 0; padding: 9px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.yt-form input:focus, .field input:focus { outline: none; border-color: var(--accent); }
.add-clip .error { flex-basis: 100%; margin: 0; }

/* ---------- player bar ---------- */
.player-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; min-height: var(--bar-h);
  display: flex; align-items: center; gap: 20px; padding: 14px 28px;
  background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(60, 40, 30, .08);
}
.player-bar.active { border-top: 3px solid var(--ok); }
/* YouTube requires a visible player of at least 200x200 while playing. */
.player-screen {
  flex: none; width: 0; height: 0; overflow: hidden; border-radius: 10px; background: #000;
}
.player-bar.show-video .player-screen { width: 200px; height: 200px; }
.player-screen iframe { width: 100%; height: 100%; display: block; }
.player-info { flex: 1; min-width: 0; }
.player-section { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--ok); font-weight: 600; min-height: 1em; }
.player-title { font: 600 22px/1.25 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); margin: 10px 0 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--ok); transition: width .25s linear; }
.player-times { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.player-times span:last-child { font-weight: 600; color: var(--text); }
.player-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; max-width: 380px; }
.player-controls .btn { padding: 12px 20px; font-size: 16px; }
.shortcuts { flex-basis: 100%; text-align: right; font-size: 12px; color: var(--muted); }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25); padding: 24px;
}
dialog::backdrop { background: rgba(30, 20, 20, .45); backdrop-filter: blur(2px); }
.editor { width: min(720px, calc(100vw - 32px)); }
.editor h2 { font: 600 26px/1.2 var(--serif); margin: 0 0 16px; }
.preview { display: flex; gap: 16px; padding: 14px; background: var(--surface-2); border-radius: 14px; margin-bottom: 16px; }
.preview-screen { flex: none; width: 200px; height: 200px; border-radius: 10px; overflow: hidden; background: #000; }
.preview-screen iframe { width: 100%; height: 100%; display: block; }
.preview-body { flex: 1; display: grid; gap: 10px; align-content: start; }
.preview-clock { font: 600 34px/1 var(--sans); font-variant-numeric: tabular-nums; }
.preview-clock .muted { font-size: 18px; font-weight: 400; }
.preview-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.fields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
.field input { color: var(--text); font-size: 15px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.confirm { width: min(420px, calc(100vw - 32px)); }
.confirm p { margin: 0 0 4px; font-size: 16px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bar-h) + 20px); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; padding: 0 16px; }
  .sections-panel { position: static; }
  .topbar { padding: 14px 16px; }
  .player-bar { flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
  .player-bar.show-video .player-screen { width: 200px; height: 200px; }
  .player-controls { max-width: none; width: 100%; justify-content: stretch; }
  .player-controls .btn { flex: 1; }
  .shortcuts { display: none; }
  .preview { flex-direction: column; }
  .preview-screen { width: 100%; height: 200px; }
  .fields { grid-template-columns: 1fr 1fr; }
}
