/* 레이아웃: 상단 고정 탭 + 카드형 작업 영역. 섹션 색은 찬양팀이 악보에 칠하는 구분색을 따른다. */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #1b2130;
  --muted: #5c6577;
  --line: #dde2ea;
  --accent: #2e4bd1;
  --accent-ink: #ffffff;
  --danger: #c2362b;
  --ok: #1f8a5b;

  --s-intro: #6b7588;
  --s-verse: #2f68d8;
  --s-prechorus: #0e8c80;
  --s-chorus: #d4520f;
  --s-bridge: #7b3fe0;
  --s-interlude: #56627a;
  --s-tag: #a8751a;
  --s-outro: #3f4a5e;
  --s-other: #8a8f99;

  --font-body: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c; --surface: #1a1f29; --ink: #e7eaf0; --muted: #9aa3b5; --line: #2c3342;
    --accent: #7d95ff; --accent-ink: #0e1220; --danger: #ff7b6e; --ok: #4fd39a;
    --s-intro: #9aa4b8; --s-verse: #6d9cff; --s-prechorus: #3fc9b8; --s-chorus: #ff8a4c;
    --s-bridge: #ae86ff; --s-interlude: #8e9ab3; --s-tag: #e0b04f; --s-outro: #a5b0c4; --s-other: #a0a5ae;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151c; --surface: #1a1f29; --ink: #e7eaf0; --muted: #9aa3b5; --line: #2c3342;
  --accent: #7d95ff; --accent-ink: #0e1220; --danger: #ff7b6e; --ok: #4fd39a;
  --s-intro: #9aa4b8; --s-verse: #6d9cff; --s-prechorus: #3fc9b8; --s-chorus: #ff8a4c;
  --s-bridge: #ae86ff; --s-interlude: #8e9ab3; --s-tag: #e0b04f; --s-outro: #a5b0c4; --s-other: #a0a5ae;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 var(--font-body);
}
[hidden] { display: none !important; }
h2, h3 { text-wrap: balance; margin: 0; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: .8rem; font-weight: 700; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; margin-top: 8px; }
.hint { color: var(--muted); margin: 0; font-size: .9rem; }
.mono { font-family: var(--font-mono); }

/* 상단 */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.top-inner {
  max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; display: flex; align-items: baseline; gap: 8px; }
.brand-sub { font-family: var(--font-mono); font-size: .7rem; color: var(--muted); font-weight: 500; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  white-space: nowrap; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 500;
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--ink); color: var(--surface); }
.sync { font-size: .75rem; color: var(--muted); font-family: var(--font-mono); }
@media (max-width: 560px) {
  .brand-sub, .sync { display: none; }
  .top-inner { gap: 10px; }
  .tabs { justify-content: flex-end; }
  .tab { padding: 6px 10px; }
}

.wrap {
  max-width: 1100px; margin: 0 auto; padding-block: 20px 60px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.view { display: flex; flex-direction: column; gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }

/* 입력 요소 */
.input {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
.input:focus-visible, .btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
textarea.input { resize: vertical; font-size: .9rem; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: .78rem; color: var(--muted); }
.row { display: flex; gap: 8px; }
.btn {
  font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: none; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* 소스 카드 */
.sources { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.source { display: flex; flex-direction: column; gap: 12px; }
.drop {
  border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 22px 12px; text-align: center;
  display: flex; flex-direction: column; gap: 4px; cursor: pointer; color: var(--muted);
}
.drop strong { color: var(--accent); }
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs:empty { display: none; }
.thumb { position: relative; width: 72px; height: 96px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.thumb button {
  position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; cursor: pointer; line-height: 1;
}
.thumb .n { position: absolute; left: 4px; bottom: 2px; font: 700 .7rem var(--font-mono); color: #333; background: rgba(255,255,255,.85); padding: 0 4px; border-radius: 3px; }
.yt-meta { font-size: .9rem; color: var(--muted); }
.yt-meta b { color: var(--ink); }
.player { aspect-ratio: 16 / 9; max-width: 100%; border-radius: 8px; overflow: hidden; background: #000; }
.player iframe, .player > div { width: 100%; height: 100%; }
.how { font-size: .88rem; color: var(--muted); }
.how summary { cursor: pointer; color: var(--accent); }
.how ol { margin: 8px 0 0; padding-left: 20px; }

.ai-off { margin: 0; font-size: .88rem; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 8px 12px; }
.status { padding: 12px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.status.err { border-color: var(--danger); color: var(--danger); }
.status.ok { border-color: var(--ok); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* 편집기 */
.editor { display: flex; flex-direction: column; gap: 12px; }
.editor-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.meta { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.meta .wide { grid-column: span 3; }
.meta .field:not(.wide):not(.narrow) { grid-column: span 3; }
.meta .narrow { grid-column: span 2; }
@media (max-width: 640px) {
  .meta { grid-template-columns: repeat(3, 1fr); }
  .meta .wide, .meta .field:not(.wide):not(.narrow) { grid-column: span 3; }
  .meta .narrow { grid-column: span 1; }
}
.sections-scroll { overflow-x: auto; }
.sections { width: 100%; border-collapse: collapse; min-width: 560px; }
.sections th { text-align: left; font-size: .75rem; color: var(--muted); font-weight: 500; padding: 4px 6px; }
.sections td { padding: 4px 6px; border-top: 1px solid var(--line); vertical-align: middle; }
.sections td:nth-child(1) { width: 84px; }
.sections td:nth-child(2) { width: 130px; }
.sections td:nth-child(4) { width: 30%; }
.sections td:last-child { width: 36px; }
.sections .input { padding: 6px 8px; }
.sec-id { font-family: var(--font-mono); font-weight: 700; }

.tagc { --c: var(--s-other); }
.t-intro { --c: var(--s-intro); } .t-verse { --c: var(--s-verse); } .t-prechorus { --c: var(--s-prechorus); }
.t-chorus { --c: var(--s-chorus); } .t-bridge { --c: var(--s-bridge); } .t-interlude { --c: var(--s-interlude); }
.t-tag { --c: var(--s-tag); } .t-outro { --c: var(--s-outro); } .t-other { --c: var(--s-other); }
.sec-id.tagc { color: var(--c); border-left: 3px solid var(--c); }

.palette-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.palette { display: flex; gap: 6px; flex-wrap: wrap; }
.pal {
  font: 700 .85rem var(--font-mono); padding: 6px 12px; border-radius: 6px; cursor: pointer;
  border: 1.5px solid var(--c); color: var(--c); background: var(--surface);
}
.pal:hover { background: color-mix(in srgb, var(--c) 12%, var(--surface)); }
.tap { font-size: .88rem; display: flex; gap: 6px; align-items: center; }

.flow { list-style: none; margin: 0; padding: 12px; display: flex; flex-wrap: wrap; gap: 6px; min-height: 56px; background: var(--bg); border-radius: 8px; counter-reset: f; }
.flow:empty::before { content: "위 버튼을 눌러 순서를 쌓거나, 아래에 직접 입력하세요."; color: var(--muted); font-size: .9rem; align-self: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border-radius: 6px;
  background: var(--c); color: #fff; font: 700 .85rem var(--font-mono); cursor: grab; user-select: none;
}
:root[data-theme="dark"] .chip { color: #10131a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip { color: #10131a; } }
.chip time { font-weight: 500; font-size: .72rem; opacity: .85; }
.chip .x { border: 0; background: rgba(0,0,0,.18); color: inherit; width: 20px; height: 20px; border-radius: 4px; cursor: pointer; font: inherit; line-height: 1; }
.chip.dragging { opacity: .4; }
.chip.drop-before { box-shadow: -3px 0 0 var(--ink); }
.notes { font-size: .9rem; color: var(--muted); border-left: 3px solid var(--line); padding: 4px 12px; }

/* 곡 목록 */
.list-head { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.list-head .input { flex: 1; min-width: 200px; }
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.song { display: flex; flex-direction: column; gap: 8px; }
.song-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.song-title { font-weight: 700; }
.song-artist { color: var(--muted); font-size: .85rem; }
.key { font: 700 .8rem var(--font-mono); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; white-space: nowrap; }
.flowline { font: 500 .85rem var(--font-mono); word-break: break-word; }
.flowline .tagc { color: var(--c); font-weight: 700; }
.empty { color: var(--muted); padding: 32px 16px; text-align: center; border: 1.5px dashed var(--line); border-radius: var(--radius); }

/* 콘티 */
.setlist-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
@media (max-width: 760px) { .setlist-layout { grid-template-columns: 1fr; } }
.setlists { display: flex; flex-direction: column; gap: 10px; }
.setlists ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.setlists li button {
  width: 100%; text-align: left; border: 0; background: none; font: inherit; color: var(--ink);
  padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column;
}
.setlists li button small { color: var(--muted); font-family: var(--font-mono); font-size: .75rem; }
.setlists li button[aria-current="true"] { background: var(--bg); box-shadow: inset 3px 0 0 var(--accent); }
.setlist-editor { display: flex; flex-direction: column; gap: 14px; }
.sl-meta { display: grid; grid-template-columns: 170px 1fr; gap: 10px; }
@media (max-width: 480px) { .sl-meta { grid-template-columns: 1fr; } }
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; counter-reset: it; }
.item { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; grid-template-columns: 28px 1fr auto; gap: 8px 10px; align-items: start; }
.item::before { counter-increment: it; content: counter(it); font: 700 1.1rem var(--font-mono); color: var(--accent); grid-row: span 3; }
.item-title { font-weight: 700; }
.item-fields { grid-column: 2 / 4; display: grid; grid-template-columns: 70px 1fr; gap: 8px; }
.item-memo { grid-column: 2 / 4; }
.item-tools { display: flex; gap: 2px; }
.icon { border: 1px solid var(--line); background: var(--surface); color: var(--ink); width: 30px; height: 30px; border-radius: 6px; cursor: pointer; font: inherit; }
.add-song { display: flex; gap: 8px; }
.preview { white-space: pre-wrap; font: 500 .88rem/1.6 var(--font-mono); background: var(--bg); border-radius: 8px; padding: 14px; overflow-x: auto; margin: 0; }
.inline-confirm { display: inline-flex; gap: 6px; align-items: center; font-size: .85rem; color: var(--danger); }

.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 20px; width: min(360px, calc(100vw - 32px)); }
.dialog form { display: flex; flex-direction: column; gap: 12px; }
.dialog::backdrop { background: rgba(10, 14, 22, .5); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; z-index: 50; font-size: .9rem;
}

/* 인쇄: 콘티만 A4로 */
.print-area { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; color: #000; }
  .top, .wrap, .toast, dialog { display: none !important; }
  .print-area { display: block; font-family: var(--font-body); }
  .print-area h1 { font-size: 18pt; margin: 0 0 2mm; }
  .print-area .sub { color: #555; margin-bottom: 6mm; }
  .print-area table { width: 100%; border-collapse: collapse; }
  .print-area td { border-bottom: 1px solid #bbb; padding: 3mm 2mm; vertical-align: top; }
  .print-area .no { font: 700 14pt var(--font-mono); width: 10mm; }
  .print-area .t { font-weight: 700; font-size: 12pt; }
  .print-area .k { font: 700 12pt var(--font-mono); width: 16mm; text-align: center; }
  .print-area .f { font: 500 11pt var(--font-mono); margin-top: 1mm; }
  .print-area .m { color: #444; font-size: 9.5pt; margin-top: 1mm; }
}
