:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e2dfd8;
  --accent: #d7262f;
  --accent-ink: #ffffff;
  --soft: #f7f5f1;
  --used: #e9f6ec;
  --used-line: #3a9a55;
  --missing-bg: #fff1c2;
  --missing-ink: #8a5a00;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --panel: #1e1e22;
    --ink: #f1f1f3;
    --muted: #a0a0a8;
    --line: #34343a;
    --soft: #26262b;
    --used: #1c3324;
    --used-line: #5cc97b;
    --missing-bg: #4a3a10;
    --missing-ink: #ffd772;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.45; }
h1, h2, h3 { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between;
  padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.3rem; }
.onair {
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: .7rem;
  letter-spacing: .12em; padding: 4px 8px; border-radius: 4px;
}
.station { color: var(--muted); font-weight: 600; }
.topcontrols { display: flex; flex-wrap: wrap; gap: 12px; }
.topcontrols label { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }

input, select, textarea {
  background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
.topcontrols input { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Layout */
.layout {
  display: grid; gap: 16px; padding: 16px; max-width: 1500px; margin: 0 auto;
  grid-template-columns: 1fr;
}
@media (min-width: 800px) {
  .layout { grid-template-columns: 1fr 1fr; }
  #scriptPanel { grid-column: 1 / -1; }
}
@media (min-width: 1200px) {
  .layout { grid-template-columns: 1.1fr 1fr 1.1fr; align-items: start; }
  #scriptPanel { grid-column: auto; position: sticky; top: 84px; }
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel h2 { font-size: 1.1rem; margin-bottom: 4px; }
.muted { color: var(--muted); margin: 0 0 12px; font-size: .9rem; }

/* Content lists */
.block { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.blockhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.blockhead h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.items li {
  display: flex; gap: 10px; align-items: flex-start; justify-content: space-between;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft);
}
.items li.used { background: var(--used); border-color: var(--used-line); }
.items li.note { color: var(--muted); font-size: .9rem; border-style: dashed; background: transparent; }
.itext { font-size: .95rem; flex: 1; }
.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.isub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.storylink { display: inline-block; font-size: .8rem; margin-top: 4px; color: var(--accent); }

button {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
  padding: 9px 14px; font-weight: 600; cursor: pointer;
}
button.ghost, button.mini, button.use { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.mini { padding: 3px 10px; font-size: .8rem; }
button.use { padding: 4px 10px; font-size: .8rem; flex-shrink: 0; }
li.used button.use { border-color: var(--used-line); color: var(--used-line); }
button:hover { filter: brightness(1.05); }

.custom { display: flex; gap: 8px; align-items: flex-start; margin-top: 8px; }

/* Builder */
.field { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
.field input { margin-top: 4px; color: var(--ink); }
.pair { display: grid; grid-template-columns: 1.3fr 1fr; gap: 8px; }
.moresongs { margin-bottom: 10px; }
.moresongs summary { cursor: pointer; font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
#sections { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; display: grid; gap: 12px; }
.secrow label { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.secpreview { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* Script */
.script {
  background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
  font-size: 1.15rem; line-height: 1.6; min-height: 140px;
}
.script p { margin: 0 0 .8em; }
.script p:last-child { margin-bottom: 0; }
.script .empty { color: var(--muted); font-size: .95rem; }
.missing { background: var(--missing-bg); color: var(--missing-ink); border-radius: 4px; padding: 0 4px; font-weight: 600; }
.stats { color: var(--muted); font-size: .85rem; margin: 8px 0 0; }

/* Reader */
.reader { position: fixed; inset: 0; background: #000; color: #fff; z-index: 50; display: flex; flex-direction: column; }
.reader[hidden] { display: none; }
.readerbar { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid #333; }
.readerbar button { background: #222; color: #fff; border: 1px solid #444; }
.readerbar #closeReader { margin-left: auto; background: var(--accent); border: 0; }
.readerstats { color: #aaa; font-size: .9rem; margin-left: 8px; }
.readertext { flex: 1; overflow-y: auto; padding: 4vh 6vw 30vh; line-height: 1.5; max-width: 1100px; margin: 0 auto; width: 100%; }
.readertext p { margin: 0 0 1em; }
.readertext .missing { background: #6b4e00; color: #ffd772; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: .9rem; z-index: 60;
}

/* Admin */
.toplink { color: var(--ink); font-size: .9rem; text-decoration: none; align-self: center; }
.toplink:hover { text-decoration: underline; }
.loginbox { max-width: 380px; margin: 48px auto; }
.loginbox h2 { margin-bottom: 14px; }
.errmsg { color: var(--accent); font-size: .9rem; min-height: 1.2em; margin: 10px 0 0; }
.adminmain { max-width: 960px; margin: 0 auto; padding: 16px; }
.banner { background: var(--missing-bg); color: var(--missing-ink); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: .9rem; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.tab { background: transparent; color: var(--muted); border: 1px solid transparent; }
.tab.active { background: var(--panel); color: var(--ink); border-color: var(--line); }
.savebar {
  position: sticky; top: 72px; z-index: 4; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--bg); padding: 10px 0; margin-bottom: 4px;
}
.savebar button:disabled { opacity: .45; cursor: default; filter: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  background: var(--soft); color: var(--ink); border: 1px dashed var(--line); padding: 3px 8px;
  font: 500 .8rem ui-monospace, SFMono-Regular, Menlo, monospace; border-radius: 6px;
}
.grouphead { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 8px; }
.rowcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.rowfields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 10px; }
.rowfields .wide { grid-column: 1 / -1; }
.rowfields .narrow { max-width: 200px; }
.rowfields .field { margin-bottom: 8px; }
.field textarea, .field select { margin-top: 4px; color: var(--ink); }
.field textarea { resize: vertical; font-size: 1rem; line-height: 1.45; }
.rowcontrols { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.rowcontrols button { padding: 4px 10px; font-size: .85rem; }
button.danger { color: var(--accent); }
.addbtn { margin: 2px 0 6px; }
.checkres { font-size: .85rem; margin-top: 8px; color: var(--muted); }
.checkres:empty { display: none; }
.checkres.ok { color: var(--used-line); }
.checkres.bad { color: var(--accent); }

/* Print */
.printsheet { display: none; }
@media print {
  body { background: #fff; color: #000; }
  body > *:not(.printsheet) { display: none !important; }
  .printsheet { display: block; font-family: Georgia, serif; }
  .printsheet h1 { font-size: 16pt; margin-bottom: 4pt; }
  .printsheet .pmeta { font-size: 10pt; color: #444; margin-bottom: 16pt; border-bottom: 1px solid #999; padding-bottom: 8pt; }
  .printsheet p { font-size: 16pt; line-height: 1.6; margin: 0 0 12pt; }
  .printsheet .missing { background: none; color: #000; border-bottom: 2px solid #000; }
}
