:root {
  --bg: #0c0c0e;
  --surface: #151518;
  --surface2: #1e1e23;
  --line: #2b2b33;
  --text: #f3f3f5;
  --muted: #8d8d99;
  --accent: #2dd4bf;
  --accent-ink: #04201c;
  --soon: #fbbf24;
  --danger: #f87171;
  --wave: #4a4a56;
  --wave-played: #7c7c8c;
  --marker: #2dd4bf;
  --marker-sel: #fbbf24;
  --playhead: #ffffff;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f4f6;
    --surface: #ffffff;
    --surface2: #ececf0;
    --line: #dcdce2;
    --text: #141417;
    --muted: #6a6a76;
    --accent: #0d9488;
    --accent-ink: #ffffff;
    --soon: #b45309;
    --danger: #dc2626;
    --wave: #c4c4cc;
    --wave-played: #8a8a96;
    --marker: #0d9488;
    --marker-sel: #d97706;
    --playhead: #141417;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
kbd {
  font: 600 11px/1 var(--font);
  padding: 3px 5px; border-radius: 4px;
  border: 1px solid var(--line); background: var(--surface2); color: var(--muted);
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--soon); }
.grow { flex: 1; }
[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface2); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary kbd { background: transparent; border-color: currentColor; color: inherit; opacity: .7; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface2); }
.btn.danger { color: var(--danger); }
.ib {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: transparent; cursor: pointer;
}
.ib:hover { background: var(--surface2); }
.ib.play { width: 52px; height: 52px; background: var(--text); color: var(--bg); }
.ib.play svg { width: 28px; height: 28px; }
.ib.on { color: var(--soon); }

/* ---------- edit ---------- */
.edit {
  display: flex; flex-direction: column; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .01em; }
.brand img { border-radius: 6px; }
.file { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.drop {
  margin: 16px; padding: 28px 16px; text-align: center;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
}
.drop svg { width: 36px; height: 36px; color: var(--muted); }
.drop p { margin: 6px 0; }
.dropTitle { font-weight: 600; font-size: 17px; }
body.dragging .drop, body.dragging .waves { outline: 2px solid var(--accent); outline-offset: -2px; }

.waves { display: flex; flex-direction: column; gap: 6px; padding: 12px 16px 0; }
.waves canvas { display: block; width: 100%; border-radius: 8px; background: var(--surface); touch-action: none; cursor: pointer; }
.cvOverview { height: 64px; }
.cvDetail { height: 110px; }

.transport {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.clock { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 600; }
.clock .muted { font-size: 15px; font-weight: 400; }
.ctrls { display: flex; align-items: center; gap: 4px; }
.tright { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.btn.add { height: 44px; padding: 0 16px; }

.body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(240px, 32%) 1fr; }
.now { padding: 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.lbl { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.nowNo { font-size: 64px; line-height: 1.05; font-weight: 800; font-variant-numeric: tabular-nums; word-break: break-all; }
.nowMemo { font-size: 20px; font-weight: 500; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; min-height: 1.4em; }
.nowNext { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }
.nextLine { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.nextNo { font-weight: 700; font-size: 20px; }
.nextMemo { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nextIn { font-variant-numeric: tabular-nums; font-size: 28px; font-weight: 700; }
.nextIn.soon { color: var(--soon); }

.list { display: flex; flex-direction: column; min-height: 0; }
.listHead { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.cues { list-style: none; margin: 0; padding: 4px 0 40px; overflow-y: auto; flex: 1; }
.empty { padding: 24px 16px; margin: 0; }
.cue {
  display: grid; grid-template-columns: 36px 92px 72px 1fr 36px 36px; align-items: center; gap: 6px;
  padding: 4px 12px 4px 10px; border-left: 3px solid transparent;
}
.cue.cur { background: color-mix(in srgb, var(--accent) 10%, transparent); border-left-color: var(--accent); }
.cue.sel { box-shadow: inset 0 0 0 1px var(--marker-sel); }
.cue .ib { width: 36px; height: 36px; color: var(--muted); }
.cue .ib:hover { color: var(--text); }
.cue .ib.del:hover { color: var(--danger); }
.cue input {
  width: 100%; min-width: 0; height: 36px; padding: 0 8px;
  border: 1px solid transparent; border-radius: 6px; background: transparent;
}
.cue input:hover { border-color: var(--line); }
.cue input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.cue input.tm { font-variant-numeric: tabular-nums; color: var(--muted); }
.cue input.no { font-weight: 700; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
.dlg { padding: 8px 20px 20px; }
.dlgHead { display: flex; align-items: center; justify-content: space-between; }
.dlg h2 { font-size: 18px; margin: 8px 0; }
.dlg h3 { font-size: 13px; color: var(--muted); margin: 20px 0 8px; }
.dlg p { margin: 4px 0 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.field select { height: 34px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface2); }
.keys { border-collapse: collapse; width: 100%; font-size: 14px; }
.keys td { padding: 5px 0; }
.keys td:first-child { width: 42%; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  padding: 10px 10px 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 50;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast .btn { color: var(--bg); height: 30px; font-weight: 600; }
.toast .btn:hover { background: rgb(128 128 128 / .2); }

/* ---------- show ---------- */
.show {
  position: fixed; inset: 0; z-index: 20;
  display: grid; grid-template-rows: auto 1fr auto;
  background: #000; color: #f5f5f5;
  padding: max(16px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  user-select: none; -webkit-user-select: none; touch-action: none;
  --soon: #fbbf24; --accent: #2dd4bf; --muted: #8d8d99;
}
.sTop { display: flex; align-items: center; gap: 16px; }
.sClock { font-variant-numeric: tabular-nums; font-size: clamp(16px, 2.6vw, 28px); font-weight: 600; color: #bdbdc6; min-width: 4.2em; }
.sClock:last-child { text-align: right; }
.sTrack { position: relative; flex: 1; height: 10px; border-radius: 5px; background: #222; overflow: hidden; }
.sTrackFill { position: absolute; inset: 0 auto 0 0; width: 0; background: #555; }
.sTick { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--accent); }
.sPaused {
  position: absolute; top: max(52px, calc(env(safe-area-inset-top) + 40px)); left: 50%; transform: translateX(-50%);
  padding: 4px 14px; border-radius: 99px; background: #3a2a00; color: var(--soon); font-weight: 700; display: none;
}
.show.paused .sPaused { display: block; }
.sMain { display: flex; flex-direction: column; justify-content: center; min-height: 0; gap: 1vh; }
.sNo {
  font-weight: 800; line-height: .95; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
  font-size: clamp(72px, min(30vh, 36vw), 340px); word-break: break-all;
}
.sNo.blank { display: none; }
.sNo.blank + .sMemo { font-size: clamp(40px, min(14vh, 11vw), 170px); -webkit-line-clamp: 4; }
.sNo.idle { font-size: clamp(40px, min(12vh, 10vw), 140px); color: #8d8d99; }
.sMemo {
  font-weight: 600; line-height: 1.2; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere;
  font-size: clamp(24px, min(7vh, 8vw), 84px);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.sCueBar { height: 6px; border-radius: 3px; background: #1d1d1d; overflow: hidden; margin-top: 2vh; }
.sCueBar div { height: 100%; width: 0; background: #f5f5f5; }
.sNext {
  display: flex; align-items: center; gap: 24px;
  padding: 2vh 2.4vw; border-radius: 16px; background: #121214; border: 2px solid transparent;
}
.sNext.soon { border-color: var(--soon); background: #1d1606; }
.sNextText { flex: 1; min-width: 0; }
.show .lbl { font-size: clamp(12px, 1.6vw, 18px); }
.sNextLine { display: flex; align-items: baseline; gap: .6em; font-size: clamp(20px, min(5vh, 6vw), 54px); min-width: 0; }
.sNextNo { font-weight: 800; }
.sNextMemo { color: #bdbdc6; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sNextIn { font-variant-numeric: tabular-nums; font-weight: 800; font-size: clamp(36px, min(9vh, 12vw), 110px); color: #bdbdc6; }
.sNext.soon .sNextIn { color: var(--soon); }
.sNext.soon .lbl { color: var(--soon); }
.sCtrls {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 18vh); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 99px;
  background: rgb(30 30 34 / .92); border: 1px solid #333;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.sCtrls .ib { color: #f5f5f5; }
.sCtrls .ib:hover { background: #2a2a30; }
.sCtrls .ib.play { background: #f5f5f5; color: #000; }
.sCtrls .btn { background: #1e1e23; border-color: #333; color: #f5f5f5; }
.show.ctrls .sCtrls { opacity: 1; pointer-events: auto; }
.sHint {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24vh); transform: translateX(-50%);
  padding: 8px 16px; border-radius: 99px; background: #1e1e23; color: #bdbdc6; font-size: 14px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .3s;
}
.show.hint .sHint { opacity: 1; }
.sWake {
  position: absolute; left: max(24px, env(safe-area-inset-left)); top: max(46px, calc(env(safe-area-inset-top) + 34px));
  font-size: 13px; color: var(--soon); display: none;
}
.show.nowake .sWake { display: block; }
.show.ctrls .sHint { opacity: 0; }
body.showing .toast { top: calc(56px + env(safe-area-inset-top)); bottom: auto; }
@media (max-aspect-ratio: 1/1) {
  .sNext { flex-direction: column; align-items: stretch; gap: 4px; }
  .sNextIn { text-align: right; }
}

/* ---------- narrow ---------- */
@media (max-width: 760px) {
  .bar { flex-wrap: wrap; padding: 8px 12px; }
  .bar .btn span { display: none; }
  .bar .btn.primary span { display: inline; }
  .file { order: 5; flex-basis: 100%; }
  .waves { padding: 8px 12px 0; }
  .cvDetail { height: 90px; }
  .transport { grid-template-columns: 1fr auto; padding: 8px 12px; }
  .ctrls { grid-column: 1 / -1; grid-row: 2; justify-content: center; }
  .clock { font-size: 18px; }
  .btn.add kbd { display: none; }
  .body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .now { border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; display: grid; grid-template-columns: auto 1fr; column-gap: 12px; }
  .now > .lbl { display: none; }
  .nowNo { font-size: 36px; grid-row: span 2; }
  .nowNext { grid-column: 1 / -1; margin-top: 6px; padding-top: 6px; display: flex; align-items: center; gap: 8px; }
  .nextLine { flex: 1; }
  .nextIn { font-size: 18px; }
  .cue { grid-template-columns: 32px 76px 1fr 32px 32px; grid-template-areas: "go tm no here del" ". memo memo memo memo"; row-gap: 0; padding: 4px 8px; }
  .cue .go { grid-area: go; } .cue .tm { grid-area: tm; } .cue .no { grid-area: no; }
  .cue .memo { grid-area: memo; } .cue .here { grid-area: here; } .cue .del { grid-area: del; }
  .cue .ib { width: 32px; height: 32px; }
  .sNext { gap: 12px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .cvDetail { height: 70px; }
  .cvOverview { height: 44px; }
}
