:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1d2433;
  --ink-2: #4a5468;
  --ink-3: #8a91a0;
  --line: #e4dfd3;
  --accent: #b7791f;
  --accent-ink: #ffffff;
  --accent-soft: #f7ead2;
  --brand: #1d2433;
  --danger: #b4372f;
  --ok: #2f7d4f;
  --chord: #b7791f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(29, 36, 51, .06), 0 4px 16px rgba(29, 36, 51, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", "Roboto Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161f; --surface: #1a202c; --surface-2: #202737; --ink: #ecebe6; --ink-2: #b6bccb; --ink-3: #7c8496;
    --line: #2c3446; --accent: #e8b45a; --accent-ink: #1d2433; --accent-soft: #3a3222; --brand: #0d1017;
    --danger: #e0685e; --ok: #63b98a; --chord: #e8b45a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

/* ---- layout */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--brand); color: #f6f1e7; display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
.topbar .logo { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .2px; cursor: pointer; }
.topbar .logo img { width: 26px; height: 26px; }
.topbar .room { color: #e8b45a; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar button { background: transparent; color: #f6f1e7; border: 1px solid rgba(246,241,231,.25); border-radius: 8px; padding: 5px 10px; cursor: pointer; }
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; background: var(--brand); overflow-x: auto; scrollbar-width: none; }
.tabs button { background: transparent; border: 0; color: #c9cbd2; padding: 8px 12px 10px; border-radius: 8px 8px 0 0; cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--bg); color: var(--ink); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.grid2 { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 820px) { .grid2 { grid-template-columns: minmax(0, 1fr); } .grid2.detail-open > :first-child { display: none; } .grid2:not(.detail-open) > :nth-child(2) { display: none; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ---- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 9px; cursor: pointer; min-height: 38px; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
label.f { display: block; }
label.f > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
label.f > span b { color: var(--danger); font-weight: 600; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 9px; padding: 8px 10px; min-height: 38px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 120px; }
textarea.code { font-family: var(--mono); font-size: 14px; line-height: 1.55; min-height: 320px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; }
legend { padding: 0 6px; font-weight: 600; font-size: 14px; }

/* ---- lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 10px; align-items: center; }
.list li:last-child { border-bottom: 0; }
.list li:hover { background: var(--surface-2); }
.list li.on { background: var(--accent-soft); }
.list .num { color: var(--ink-3); font-variant-numeric: tabular-nums; min-width: 28px; text-align: right; }
.list .grow { flex: 1; min-width: 0; }
.list .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: currentColor; background: transparent; }
.badge.warn { color: var(--accent); border-color: currentColor; background: transparent; }
.search { padding: 10px; border-bottom: 1px solid var(--line); }
.scroll { max-height: calc(100vh - 230px); overflow: auto; }
@media (max-width: 820px) { .scroll { max-height: none; } }

/* ---- song view */
.song { font-size: 17px; }
.song .sec { margin: 0 0 18px; }
.song .sec-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin-bottom: 4px; }
.song .sec.chorus { padding-left: 14px; border-left: 3px solid var(--accent); }
.song .ln { white-space: pre-wrap; }
.song.chords .ln { font-family: var(--mono); font-size: 15px; white-space: pre; overflow-x: auto; }
.song .ch { color: var(--chord); font-weight: 700; }
.song .cm { color: var(--ink-3); font-style: italic; }
.transpose { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.transpose button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; }
.transpose span { padding: 0 10px; min-width: 64px; text-align: center; font-weight: 600; }
.copyright { font-size: 13px; color: var(--ink-2); border-top: 1px dashed var(--line); padding-top: 10px; }

/* ---- editor toolbar */
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.toolbar button { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 4px 10px; font-size: 13px; cursor: pointer; }
.editor-split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .editor-split { grid-template-columns: 1fr; } }
.preview { background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 12px; max-height: 520px; overflow: auto; }

/* ---- meetings */
.item { display: grid; grid-template-columns: 32px 1fr auto; gap: 10px; align-items: start; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .idx { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.item .kind { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 2px 10px; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---- auth */
.auth { max-width: 420px; margin: 8vh auto 0; }
.auth .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth .brand img { width: 44px; height: 44px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--surface); padding: 8px; cursor: pointer; }
.seg button.on { background: var(--accent-soft); font-weight: 600; }
.empty { padding: 32px 16px; text-align: center; color: var(--ink-3); }

/* ---- modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(13, 16, 23, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: min(640px, 100%); max-height: 90vh; overflow: auto; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 100; max-width: calc(100% - 32px); }
.toast.err { background: var(--danger); color: #fff; }
.back { display: none; }
@media (max-width: 820px) { .back { display: inline-flex; } }

@media (max-width: 560px) {
  .topbar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .topbar .room, .topbar .who { display: none; }
  .song.chords .ln { font-size: 13px; }
  main { padding: 12px; }
}

/* ---- редактор гимна: подсветка поверх textarea */
.code-wrap { position: relative; }
.code-wrap .code-hl, .code-wrap textarea.code {
  font-family: var(--mono); font-size: 14px; line-height: 1.55; padding: 10px 12px; margin: 0;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; tab-size: 4; letter-spacing: 0;
  border: 1px solid var(--line); border-radius: 9px; box-sizing: border-box; width: 100%; min-height: 360px;
}
.code-wrap .code-hl { position: absolute; inset: 0; overflow: hidden; color: var(--ink); background: var(--surface); pointer-events: none; }
.code-wrap textarea.code { position: relative; background: transparent; color: transparent; caret-color: var(--ink); resize: vertical; display: block; }
.code-wrap textarea.code::selection { background: rgba(90, 160, 232, .35); color: transparent; }
.hl-ch { color: #d08a12; font-weight: 700; }
.hl-bad { color: #d23c3c; text-decoration: underline wavy; }
.hl-dir { color: #3b82c4; }
.hl-br { color: #2f9e57; font-weight: 700; }
.hl-cm { color: var(--ink-3); font-style: italic; }
.hl-line.err { background: rgba(220, 60, 60, .16); }
.hl-line.warn { background: rgba(230, 170, 40, .16); }
.problems .prob { font-size: 13px; cursor: pointer; padding: 1px 0; }
.problems .prob.err { color: #d23c3c; }
.problems .prob.warn { color: #b7791f; }
.ok-text { color: #2f9e57; }
.palette { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin: 0 0 6px; }
.palette .pc { border: 1px solid var(--line); background: var(--surface-2); border-radius: 6px; padding: 2px 9px; font-weight: 700; font-family: var(--mono); cursor: pointer; }
.palette .pc.main { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.palette .pc-own { width: 70px; padding: 2px 6px; font-family: var(--mono); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 4px 10px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.slide { container-type: inline-size; aspect-ratio: 16 / 9; background: #10131a; color: #fff; border-radius: 6px; display: flex;
  align-items: center; justify-content: center; text-align: center; overflow: hidden; margin-bottom: 8px; }
.slide .sl-text { line-height: 1.25; padding: 4%; text-shadow: 0 1px 2px #000; }
.slide .stage { align-self: stretch; width: 100%; text-align: left; font-family: var(--mono); font-size: 2.6cqw; padding: 3%; box-sizing: border-box; line-height: 1.2; }
.slide .stage .st-head { color: #9aa3b5; font-family: var(--font); font-size: 2.2cqw; margin-bottom: 3%; }
.slide .stage .st-head span { color: #e8b45a; }
.slide .stage .st-ch { color: #e8b45a; font-weight: 700; white-space: pre; }
.slide .stage .st-body div { white-space: pre; }
.chip.danger { color: #d23c3c; }
.chip.ghost { opacity: .65; cursor: default; }
.chip b { cursor: pointer; margin-left: 4px; }
.chips.order .chip.on { cursor: grab; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { width: 150px; display: flex; flex-direction: column; gap: 2px; }
.thumb img { width: 150px; height: 84px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #000; }
.thumb.add { height: 84px; align-items: center; justify-content: center; border: 1px dashed var(--line); border-radius: 6px; cursor: pointer; }

/* ---- руководство и «о программе» */
.topbar .narrow { display: none; }
@media (max-width: 640px) { .topbar .wide { display: none; } .topbar .narrow { display: inline; font-weight: 700; } .topbar button { padding: 5px 9px; } }
.modal.wide { width: min(880px, 100%); }
.guide { display: flex; flex-direction: column; gap: 12px; }
.guide h2, .guide h3 { margin: 0; }
.guide input[type=search] { width: 100%; }
.guide-cols { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 16px; min-height: 380px; }
.guide-topics { display: flex; flex-direction: column; gap: 2px; }
.guide-topics button { text-align: left; background: transparent; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--ink-2); }
.guide-topics button:hover { background: var(--surface-2); }
.guide-topics button.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.guide-body { display: flex; flex-direction: column; gap: 12px; }
.guide-body .tip b { display: block; }
@media (max-width: 640px) {
  .guide-cols { grid-template-columns: 1fr; min-height: 0; }
  .guide-topics { flex-direction: row; flex-wrap: wrap; }
  .guide-topics button { padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; }
}
.about { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 8px 4px 0; }
.about-logo { width: 64px; height: 64px; }
.about h1 { margin: 4px 0 0; font-size: 34px; letter-spacing: .3px; color: var(--accent); }
.about p { margin: 8px 0; max-width: 46ch; }
.about hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 12px 0 4px; }
.about .row { width: 100%; }

/* загрузка вкладки (#9): полоска сверху и «Загрузка…» вместо пустого списка */
.loadbar { position: sticky; top: 0; height: 3px; z-index: 20; overflow: hidden; background: transparent; }
.loadbar::before { content: ""; position: absolute; inset: 0 auto 0 -40%; width: 40%; background: var(--accent, #c8892b); animation: loadbar 1s ease-in-out infinite; }
@keyframes loadbar { to { left: 100%; } }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 48px 16px; color: var(--muted, #888); }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loadbar::before, .spinner { animation-duration: 3s; } }
