/* ===== 디자인 토큰 ===== */
:root {
  color-scheme: dark;
  --ink: #080909;
  --ink-soft: #101212;
  --panel: #141616;
  --panel-raised: #1a1c1c;
  --paper: #f2f0e9;
  --paper-muted: #aaa9a3;
  --line: #2b2e2d;
  --line-bright: #414441;
  --signal: #12b8a6;
  --signal-bright: #2fd0be;
  --signal-wash: #12b8a621;
  --safe: #9bdd91;
  --warning: #ffd166;
  --shadow: 0 24px 80px #00000057;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --topbar-height: 62px;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-family: "Pretendard Variable", Pretendard, "SUIT Variable", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}
:root[data-ui-theme="light"] {
  color-scheme: light;
  --ink: #f4f5f1;
  --ink-soft: #eceee8;
  --panel: #fff;
  --panel-raised: #f7f8f4;
  --paper: #1b1e1b;
  --paper-muted: #606760;
  --line: #d6dad2;
  --line-bright: #bcc3b9;
  --signal: #0fa392;
  --signal-bright: #0c8f80;
  --signal-wash: #0fa3921a;
  --safe: #368c50;
  --warning: #8f6410;
  --shadow: 0 20px 60px #252d251f;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--ink);
  color: var(--paper);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--signal-bright); outline-offset: 2px; }
.icon { flex: 0 0 auto; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ===== 공용 컴포넌트 ===== */
.kicker {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--signal-bright);
}
.eyebrow { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--signal-bright); }
.mono { font-family: var(--mono); }

.primary-button, .secondary-button, .danger-button, .ghost-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 44px; padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 700; font-size: 0.93rem; letter-spacing: -0.01em;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.primary-button { background: var(--signal); color: #fff; box-shadow: 0 10px 30px #12b8a640; }
.primary-button:hover:not(:disabled) { background: var(--signal-bright); }
.secondary-button { background: var(--panel); border-color: var(--line-bright); color: var(--paper); }
.secondary-button:hover:not(:disabled) { border-color: var(--paper-muted); background: var(--panel-raised); }
.danger-button { background: #b8331e; color: #fff; }
.danger-button:hover:not(:disabled) { background: #d33c22; }
.ghost-button { color: var(--paper); padding: 0.5rem 0.75rem; min-height: 40px; }
.ghost-button:hover { background: #ffffff0f; }
.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; color: var(--paper-muted);
  border: 1px solid transparent; transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.icon-button:hover { background: #ffffff10; color: var(--paper); }
.icon-button[aria-pressed="true"] { color: var(--signal-bright); background: var(--signal-wash); border-color: #12b8a655; }

.text-input {
  width: 100%; min-height: 46px; padding: 0.65rem 0.9rem;
  border-radius: 10px; border: 1px solid var(--line-bright);
  background: var(--ink-soft); color: var(--paper);
}
.text-input::placeholder { color: var(--paper-muted); opacity: 0.8; }
.text-input:focus { border-color: var(--signal); outline: none; box-shadow: 0 0 0 3px var(--signal-wash); }
.field-label { display: grid; gap: 0.5rem; font-size: 0.85rem; font-weight: 700; }

.theme-toggle {
  display: inline-flex; align-items: center; gap: 0.5rem;
  height: 44px; padding: 0 1.05rem; border-radius: 999px;
  border: 1px solid var(--line-bright); background: var(--panel);
  color: var(--paper-muted); font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.16em;
}
.theme-toggle:hover { color: var(--paper); border-color: var(--paper-muted); }

.badge-live {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.16em;
  border: 1px solid #12b8a666; color: var(--signal-bright); background: #12b8a612;
  padding: 0.2rem 0.55rem; border-radius: 6px;
}
.badge-live::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 8px var(--signal); }

/* ----- 다이얼로그 ----- */
dialog.dialog {
  width: var(--dialog-width, min(31rem, calc(100% - 2rem)));
  max-height: min(90vh, 45rem);
  border: 1px solid var(--line-bright); border-radius: var(--radius-lg);
  color: var(--paper); background: #151717; padding: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden;
  box-shadow: 0 40px 120px #000000b8;
}
:root[data-ui-theme="light"] dialog.dialog { background: #fff; box-shadow: 0 40px 120px #252d253d; }
dialog.dialog:not([open]) { display: none; }
dialog.dialog::backdrop { backdrop-filter: blur(8px); background: #000000b8; }
:root[data-ui-theme="light"] dialog.dialog::backdrop { background: #262e264d; }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: 1.4rem 1.5rem 1.2rem; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0.45rem 0 0; font-size: 1.35rem; letter-spacing: -0.035em; }
.dialog-header p { margin: 0.45rem 0 0; font-size: 0.87rem; line-height: 1.55; color: var(--paper-muted); }
.dialog-close { flex: 0 0 44px; width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--signal); color: var(--paper); display: inline-flex; align-items: center; justify-content: center; }
.dialog-close:hover { background: var(--signal-wash); }
.dialog-content { display: grid; gap: 1rem; padding: 1.4rem 1.5rem; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.dialog-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.7rem; padding: 1rem 1.5rem; border-top: 1px solid var(--line); background: #00000026; }
:root[data-ui-theme="light"] .dialog-footer { background: #242c2409; }

.info-card { display: flex; gap: 0.9rem; align-items: flex-start; padding: 0.95rem 1rem; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--ink-soft); position: relative; }
.info-card .card-index { position: absolute; left: 1rem; top: 0.55rem; font-family: var(--mono); font-size: 0.55rem; letter-spacing: 0.1em; color: var(--paper-muted); }
.info-card .card-icon { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid #12b8a655; display: inline-flex; align-items: center; justify-content: center; color: var(--signal-bright); background: #12b8a610; }
.info-card h3 { margin: 0 0 0.25rem; font-size: 0.93rem; }
.info-card p { margin: 0; font-size: 0.82rem; line-height: 1.55; color: var(--paper-muted); }
.flow-row { display: flex; align-items: center; justify-content: center; gap: 0.6rem; font-size: 0.8rem; font-weight: 700; color: var(--paper-muted); }
.flow-row .icon { color: var(--signal-bright); }
.privacy-note { text-align: center; font-size: 0.78rem; line-height: 1.6; color: var(--paper-muted); margin: 0; display: grid; gap: 0.1rem; }
.privacy-note strong { color: var(--paper); }

  display: inline-flex; justify-content: center; align-items: center; gap: 0.42rem;
  width: min(25rem, 100%); min-height: 44px; margin: 0 auto; padding: 0.5rem 0.75rem;
  font-family: var(--mono); font-size: 1.41rem; font-weight: 760; letter-spacing: -0.025em;
  color: #d7d8d2; text-decoration: none; border-radius: 6px; white-space: nowrap;
}

/* ----- 토스트 ----- */
#toast-root { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); display: grid; gap: 0.5rem; z-index: 1000; pointer-events: none; width: min(36rem, calc(100% - 2rem)); }
.toast { pointer-events: auto; padding: 0.8rem 1.1rem; border-radius: 12px; border: 1px solid var(--line-bright); background: var(--panel-raised); color: var(--paper); box-shadow: var(--shadow); font-size: 0.86rem; line-height: 1.5; animation: toast-in 0.2s ease-out; }
.toast.error { border-color: #12b8a688; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== 대본함 ===== */
.library-page { min-height: 100vh; }
.topbar {
  height: var(--topbar-height); display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0 clamp(1rem, 4vw, 3.2rem); border-bottom: 1px solid var(--line);
  background: var(--ink); position: sticky; top: 0; z-index: 20;
}
.brand { display: inline-flex; align-items: center; gap: 0.8rem; text-decoration: none; }
.brand-mark { position: relative; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line-bright); display: inline-flex; align-items: center; justify-content: center; color: var(--paper); }
.brand-mark::after { content: ""; position: absolute; right: -1px; bottom: 2px; width: 8px; height: 8px; border-radius: 50%; background: var(--signal); }
.brand-text { display: grid; line-height: 1.1; }
.brand-text strong { font-size: 0.93rem; letter-spacing: -0.02em; }
.brand-text span { font-family: var(--mono); font-size: 0.55rem; letter-spacing: 0.16em; color: var(--paper-muted); }
.topbar-actions { display: flex; align-items: center; gap: 0.9rem; }
.guide-button { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.82rem; font-weight: 700; color: var(--paper-muted); padding: 0.5rem 0.4rem; }
.guide-button:hover { color: var(--paper); }

.library-content { padding: 0 clamp(1rem, 4vw, 3.2rem) 5rem; max-width: 1400px; margin: 0 auto; }
.hero { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr); gap: 3rem; align-items: center; padding: 2.6rem 0 3rem; border-bottom: 1px solid var(--line); }
.hero h1 { margin: 0.9rem 0 0; font-size: clamp(3rem, 7.4vw, 6.4rem); line-height: 0.98; letter-spacing: -0.05em; font-weight: 800; }
.hero h1 em { font-style: normal; color: var(--signal); }
.hero-aside { border-left: 1px solid var(--line-bright); padding-left: 1.6rem; }
.hero-aside p { margin: 0 0 1.3rem; color: var(--paper-muted); font-size: 0.95rem; line-height: 1.7; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; }

.library-head { display: flex; align-items: flex-end; justify-content: space-between; padding-top: 3.2rem; }
.library-head h2 { margin: 0.6rem 0 0; font-size: 2.4rem; letter-spacing: -0.04em; }
.script-count { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.18em; color: var(--paper-muted); padding-bottom: 0.4rem; }
.library-toolbar { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: center; justify-content: space-between; margin-top: 1.4rem; }
.search-box { position: relative; flex: 1 1 320px; max-width: 460px; }
.search-box .icon { position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%); color: var(--paper-muted); }
.search-box input { width: 100%; min-height: 48px; padding: 0.7rem 0.9rem 0.7rem 2.6rem; border-radius: 10px; border: 1px solid var(--line-bright); background: var(--ink-soft); }
.search-box input:focus { border-color: var(--signal); outline: none; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.notice { display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.1rem; margin-top: 1rem; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--ink-soft); text-align: left; width: 100%; color: var(--paper); }
.notice:hover { border-color: var(--line-bright); }
.notice .card-icon { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line-bright); display: inline-flex; align-items: center; justify-content: center; color: var(--paper-muted); }
.notice strong { display: block; font-size: 0.9rem; }
.notice p { margin: 0.2rem 0 0; font-size: 0.82rem; color: var(--paper-muted); }
.notice p b { color: var(--paper); }
.notice > .icon:last-child { margin-left: auto; color: var(--signal-bright); }

.script-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; margin-top: 2rem; }
.script-card { position: relative; display: grid; grid-template-rows: auto 1fr auto; gap: 2.4rem; padding: 1.4rem 1.4rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--ink-soft); transition: border-color 0.15s; }
.script-card:hover { border-color: var(--line-bright); }
.script-card.active { border-left: 3px solid var(--signal); }
.script-card-head { display: flex; gap: 1rem; align-items: flex-start; }
.script-card .file-icon { flex: 0 0 44px; width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line-bright); display: inline-flex; align-items: center; justify-content: center; color: var(--signal-bright); background: var(--panel); }
.script-card h3 { margin: 0.1rem 0 0.35rem; font-size: 1.1rem; letter-spacing: -0.02em; }
.script-card .meta { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.06em; color: var(--paper-muted); }
.script-card .meta span + span::before { content: "·"; margin: 0 0.5rem; }
.script-card-actions { display: flex; align-items: center; gap: 0.2rem; }
.script-card-actions .icon-button { width: 36px; height: 36px; }
.script-card-actions .icon-button.danger:hover { color: var(--signal-bright); }
.open-link { margin-left: auto; display: inline-flex; align-items: center; gap: 0.4rem; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.12em; color: var(--paper); padding: 0.4rem 0.5rem; }
.open-link .icon { color: var(--signal-bright); }
.open-link:hover { text-decoration: underline; }
.empty-state { margin-top: 2rem; padding: 3rem 1.5rem; border: 1px dashed var(--line-bright); border-radius: var(--radius-md); text-align: center; }
.empty-state .empty-index { font-family: var(--mono); color: var(--signal-bright); letter-spacing: 0.2em; font-size: 0.75rem; }
.empty-state p { margin: 0.4rem 0 0; }
.empty-state .empty-title { font-size: 1.25rem; font-weight: 800; }
.empty-state .empty-body { color: var(--paper-muted); font-size: 0.9rem; }

.import-grid { display: grid; gap: 0.7rem; }
.import-note { text-align: center; font-size: 0.78rem; color: var(--paper-muted); margin: 0.3rem 0 0; }
.export-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 250px; padding: 0.4rem; border: 1px solid var(--line-bright); border-radius: 12px; background: var(--panel-raised); box-shadow: var(--shadow); z-index: 30; display: grid; gap: 0.2rem; }
.export-menu .menu-title { font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.16em; color: var(--paper-muted); padding: 0.4rem 0.6rem 0.2rem; }
.export-menu .menu-item { display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 0.7rem; border-radius: 8px; text-align: left; width: 100%; }
.export-menu .menu-item:hover { background: #ffffff10; }
.export-menu .menu-item strong { display: block; font-size: 0.86rem; }
.export-menu .menu-item small { color: var(--paper-muted); font-size: 0.72rem; }

/* ===== 편집실 ===== */
.editor-page { height: 100vh; display: grid; grid-template-rows: var(--topbar-height) minmax(0, 1fr); overflow: hidden; }
.editor-topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 1rem; border-bottom: 1px solid var(--line); background: var(--ink); }
.editor-topbar .topbar-start { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.editor-topbar .topbar-center { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.14em; color: var(--paper-muted); }
.editor-topbar .topbar-end { display: flex; justify-content: flex-end; align-items: center; gap: 0.6rem; position: relative; }
.script-heading { display: grid; min-width: 0; }
.script-heading strong { font-size: 0.95rem; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.script-heading span { font-family: var(--mono); font-size: 0.56rem; letter-spacing: 0.16em; color: var(--paper-muted); }
.editor-body { display: grid; grid-template-columns: 270px minmax(0, 1fr) 430px; min-height: 0; }
.editor-body.sidebar-collapsed { grid-template-columns: 64px minmax(0, 1fr) 430px; }

.sidebar { border-right: 1px solid var(--line); display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; background: var(--ink); min-height: 0; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 0.9rem 0.6rem 1.2rem; }
.sidebar-header h2 { margin: 0.2rem 0 0; font-size: 1.15rem; letter-spacing: -0.03em; }
.sidebar .add-button { margin: 0.4rem 0.8rem 0.8rem; }
.page-list { list-style: none; margin: 0; padding: 0 0.6rem; overflow-y: auto; display: grid; gap: 0.4rem; align-content: start; }
.page-row { position: relative; display: grid; grid-template-columns: 22px 1fr; gap: 0.5rem; align-items: center; padding: 0.9rem 0.6rem 0.9rem 0.4rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--ink-soft); cursor: pointer; transition: border-color 0.15s; }
.page-row:hover { border-color: var(--line-bright); }
.page-row.selected { border-color: var(--signal); background: #12b8a60a; }
.page-row.dragging { opacity: 0.4; }
.page-row.drop-before { box-shadow: 0 -3px 0 0 var(--signal); }
.page-row.drop-after { box-shadow: 0 3px 0 0 var(--signal); }
.drag-handle { color: var(--paper-muted); cursor: grab; display: inline-flex; touch-action: none; }
.page-copy { min-width: 0; display: grid; gap: 0.25rem; }
.page-number { font-family: var(--mono); font-size: 0.55rem; letter-spacing: 0.14em; color: var(--signal-bright); }
.page-title { font-weight: 700; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-stats { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.06em; color: var(--paper-muted); }
.row-actions { position: absolute; right: 0.5rem; top: 0.45rem; display: none; gap: 0.1rem; background: var(--ink-soft); border-radius: 8px; }
.page-row:hover .row-actions, .page-row:focus-within .row-actions { display: inline-flex; }
.row-actions .icon-button { width: 30px; height: 30px; border-radius: 7px; }
.sidebar-foot { padding: 0.9rem 1.2rem; font-size: 0.72rem; color: var(--paper-muted); border-top: 1px solid var(--line); line-height: 1.5; }
.sidebar-collapsed .sidebar-header h2, .sidebar-collapsed .sidebar-header .eyebrow, .sidebar-collapsed .sidebar-foot, .sidebar-collapsed .page-copy, .sidebar-collapsed .row-actions, .sidebar-collapsed .drag-handle, .sidebar-collapsed .add-button span { display: none; }
.sidebar-collapsed .sidebar-header { justify-content: center; padding-left: 0.6rem; }
.sidebar-collapsed .page-row { grid-template-columns: 1fr; justify-items: center; padding: 0.7rem 0.3rem; }
.sidebar-collapsed .add-button { padding: 0.5rem; margin: 0.4rem 0.6rem 0.8rem; }
.collapsed-number { display: none; font-family: var(--mono); font-size: 0.7rem; color: var(--paper); }
.sidebar-collapsed .collapsed-number { display: block; }

.editor-main { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; min-height: 0; background: var(--ink); }
.editor-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; padding: 1rem 1.4rem 0.6rem; }
.editor-head .title-input { width: 100%; border: 0; background: transparent; font-size: 1.25rem; font-weight: 800; letter-spacing: -0.03em; padding: 0.2rem 0; margin-top: 0.2rem; border-bottom: 1px solid transparent; }
.editor-head .title-input:focus { outline: none; border-bottom-color: var(--signal); }
.recovery-banner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0.4rem 1.4rem 0; padding: 0.55rem 0.9rem; border: 1px solid #ffd16644; border-radius: 10px; background: #ffd1660d; font-size: 0.8rem; }
.recovery-banner button { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 700; color: var(--warning); }
.editor-canvas { position: relative; margin: 0.8rem 1.4rem 0; border: 1px solid var(--line-bright); border-radius: var(--radius-sm); background: var(--ink-soft); min-height: 0; display: grid; }
.editor-canvas:focus-within { border-color: var(--signal); }
.editor-canvas textarea { width: 100%; height: 100%; min-height: 200px; resize: none; border: 0; background: transparent; padding: 1.6rem 1.8rem 2.4rem; font-size: 1.05rem; line-height: 1.75; color: var(--paper); }
.editor-canvas textarea:focus { outline: none; }
.editor-canvas textarea::placeholder { color: var(--paper-muted); opacity: 0.75; }
.plain-badge { position: absolute; right: 0.8rem; bottom: 0.7rem; font-family: var(--mono); font-size: 0.55rem; letter-spacing: 0.18em; color: var(--paper-muted); border: 1px solid var(--line-bright); border-radius: 4px; padding: 0.15rem 0.4rem; pointer-events: none; }
.editor-foot { display: flex; align-items: center; gap: 0.8rem; padding: 0.7rem 1.6rem 1rem; font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.06em; color: var(--paper-muted); }
.editor-foot strong { color: var(--paper); }
.editor-foot .divider { width: 1px; height: 12px; background: var(--line-bright); }
.editor-foot em { font-style: normal; color: var(--warning); }

.panel { border-left: 1px solid var(--line); background: var(--ink); overflow-y: auto; min-height: 0; }
.panel-header { position: sticky; top: 0; z-index: 2; padding: 0.9rem 1.1rem; font-size: 0.82rem; font-weight: 800; border-bottom: 1px solid var(--line); background: var(--ink); }
.preview-card { margin: 1rem 1.1rem 0; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--ink-soft); }
.preview-head { display: flex; justify-content: space-between; align-items: center; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--line); }
.preview-head strong { display: block; font-size: 0.92rem; margin-top: 0.15rem; }
.preview-stage { position: relative; height: 300px; overflow: hidden; }
.preview-stage .preview-text { position: absolute; left: 50%; top: 0; transform: translateX(-50%); padding-top: var(--focus, 38%); word-break: keep-all; overflow-wrap: anywhere; }
.preview-stage .preview-text p { margin: 0 0 1em; white-space: pre-wrap; }
.preview-focus { position: absolute; left: 0; right: 0; top: var(--focus, 38%); pointer-events: none; }
.preview-focus::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: var(--thickness, 1px); background: var(--signal); opacity: 0.85; }
.preview-focus .focus-label { position: absolute; right: 0.5rem; top: -0.75rem; font-family: var(--mono); font-size: 0.5rem; letter-spacing: 0.16em; color: var(--signal-bright); }
.preview-meta { display: flex; gap: 0.5rem; padding: 0.5rem 0.9rem; font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.14em; color: var(--paper-muted); border-top: 1px solid var(--line); }
.preview-meta span + span::before { content: "·"; margin-right: 0.5rem; }

/* ----- 표시 설정 ----- */
.settings { padding: 1.1rem 1.1rem 2rem; display: grid; gap: 1.4rem; }
.settings-head { display: flex; justify-content: space-between; align-items: center; }
.settings-head h2 { margin: 0.25rem 0 0; font-size: 1.15rem; letter-spacing: -0.03em; }
.settings-section { display: grid; gap: 0.7rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.settings-section h3 { margin: 0; font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--paper-muted); }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.preset-card { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--ink-soft); text-align: left; }
.preset-card:hover { border-color: var(--line-bright); }
.preset-card.active { border-color: var(--signal); background: #12b8a60d; }
.preset-card .glyph { flex: 0 0 32px; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line-bright); border-radius: 4px; background: var(--ink); font-weight: 800; font-size: 0.9rem; }
.preset-card strong { display: block; font-size: 0.8rem; }
.preset-card small { font-size: 0.62rem; color: var(--paper-muted); }
.color-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.color-field { display: grid; gap: 0.35rem; font-size: 0.68rem; color: var(--paper-muted); }
.color-field .color-box { position: relative; display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.6rem; border: 1px solid var(--line-bright); border-radius: 6px; background: var(--ink-soft); cursor: pointer; }
.color-field .swatch { width: 24px; height: 24px; border-radius: 4px; border: 1px solid var(--line-bright); }
.color-field .hex { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.06em; color: var(--paper); text-transform: uppercase; }
.color-field input[type="color"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.range-control { display: grid; gap: 0.35rem; }
.range-header { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.72rem; color: var(--paper-muted); }
.range-header output { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.06em; color: var(--paper); }
.range-control input[type="range"] { width: 100%; height: 24px; margin: 0; -webkit-appearance: none; appearance: none; background: transparent; }
.range-control input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: linear-gradient(90deg, var(--signal) var(--fill, 0%), var(--line-bright) var(--fill, 0%)); }
.range-control input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6.5px; border-radius: 50%; background: var(--signal); border: 2px solid var(--ink); box-shadow: 0 0 0 1px var(--signal); }
.range-control input[type="range"]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--line-bright); }
.range-control input[type="range"]::-moz-range-progress { height: 3px; background: var(--signal); }
.range-control input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--signal); border: 2px solid var(--ink); }
.range-control input:disabled { opacity: 0.4; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.segmented button { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-height: 42px; padding: 0.4rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--ink-soft); font-size: 0.78rem; font-weight: 700; color: var(--paper-muted); }
.segmented button:hover { border-color: var(--line-bright); color: var(--paper); }
.segmented button.active { border-color: var(--signal); color: var(--paper); background: #12b8a612; }
.select-control { display: flex; align-items: center; justify-content: space-between; gap: 1rem; font-size: 0.78rem; color: var(--paper-muted); }
.select-control > span { display: inline-flex; align-items: center; gap: 0.4rem; }
.select-control select { min-height: 40px; padding: 0.3rem 0.7rem; border-radius: 6px; border: 1px solid var(--line-bright); background: var(--ink-soft); color: var(--paper); }
.icon-label { display: grid; grid-template-columns: 18px 1fr; gap: 0.5rem; align-items: start; color: var(--paper-muted); }
.icon-label > .icon { margin-top: 0.15rem; }
.settings-hint { font-size: 0.7rem; color: var(--paper-muted); margin: 0; }

/* ===== 프롬프터 스테이지 ===== */
.stage { position: fixed; inset: 0; background: var(--stage-bg, #080909); color: var(--stage-text, #f2f0e9); overflow: hidden; user-select: none; }
.stage-top { position: absolute; top: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0.9rem; transition: opacity 0.3s; }
.stage-top .stage-title-block { display: flex; align-items: center; gap: 0.7rem; }
.stage-title-button { display: grid; text-align: left; gap: 0.1rem; color: var(--stage-text); padding: 0.3rem 0.4rem; border-radius: 8px; }
.stage-title-button:hover { background: #ffffff12; }
.stage-title-button .stage-index { font-family: var(--mono); font-size: 0.55rem; letter-spacing: 0.16em; opacity: 0.6; }
.stage-title-button strong { font-size: 0.85rem; }
.stage-tools { display: flex; align-items: center; gap: 0.15rem; }
.stage .icon-button { color: var(--stage-text); opacity: 0.85; width: 38px; height: 38px; border-radius: 8px; border: 1px solid #ffffff1c; background: #00000040; }
.stage .icon-button:hover { opacity: 1; background: #ffffff18; }
.stage .icon-button[aria-pressed="true"] { color: #2fd0be; border-color: #12b8a666; background: #12b8a622; }
.stage-edit-chip { position: absolute; top: 3.6rem; left: 50%; transform: translateX(-50%); z-index: 5; display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.35rem 0.8rem; border-radius: 999px; border: 1px solid #ffffff22; background: #00000060; color: var(--stage-text); font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.1em; opacity: 0.8; transition: opacity 0.3s; }
.stage-edit-chip:hover { opacity: 1; border-color: #12b8a688; }
.stage-edit-chip .icon { color: #2fd0be; }

.stage-viewport { position: absolute; inset: 0; overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none; }
.stage-viewport::-webkit-scrollbar { display: none; }
.stage-viewport.mirror-x { transform: scaleX(-1); }
.stage-viewport.mirror-y { transform: scaleY(-1); }
.stage-viewport.mirror-x.mirror-y { transform: scale(-1, -1); }
.stage-article { margin: 0 auto; width: var(--reading-width, 72%); padding-top: var(--pad-top, 38vh); padding-bottom: var(--pad-bottom, 62vh); font-size: var(--font-size, 64px); line-height: var(--line-height, 1.62); font-weight: var(--font-weight, 700); letter-spacing: var(--letter-spacing, -0.03em); text-align: var(--align, left); word-break: keep-all; overflow-wrap: anywhere; }
.stage-article p { margin: 0 0 1em; white-space: pre-wrap; }
.stage-article p:last-child { margin-bottom: 0; }
.stage-article .empty { opacity: 0.4; }

.focus-line { position: absolute; left: 0; right: 0; top: var(--focus, 38%); z-index: 4; height: 0; pointer-events: none; }
.focus-line .line { position: absolute; left: 0; right: 0; top: 0; height: var(--thickness, 1px); background: #12b8a6; opacity: 0.75; transform: translateY(-50%); }
.focus-line .knob { position: absolute; left: 0.65rem; top: 0; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #12b8a6; background: var(--stage-bg, #080909); transform: translate(0, -50%); pointer-events: auto; cursor: ns-resize; touch-action: none; }
.focus-line.dragging .line { opacity: 1; }
.focus-line .knob:hover { box-shadow: 0 0 0 4px #12b8a633; }

.stage-bottom { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; padding: 0.8rem 1rem 0.9rem; transition: opacity 0.3s; }
.stage-stat { display: grid; gap: 0.05rem; }
.stage-stat .label { font-family: var(--mono); font-size: 0.5rem; letter-spacing: 0.18em; opacity: 0.55; }
.stage-stat .value { font-family: var(--mono); font-size: 1.05rem; font-weight: 700; }
.stage-stat .value small { font-size: 0.55rem; letter-spacing: 0.1em; opacity: 0.6; margin-left: 0.3rem; }
.stage-stat.right { text-align: right; }
.transport { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.4rem 0.6rem; border-radius: 999px; border: 1px solid #ffffff1f; background: #0d0e0ecc; backdrop-filter: blur(10px); box-shadow: 0 20px 60px #00000080; }
.transport button { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; color: var(--stage-text); }
.transport button:hover { background: #ffffff18; }
.transport .speed-btn { font-family: var(--mono); font-size: 0.6rem; width: 46px; gap: 0.05rem; }
.transport .play { width: 48px; height: 48px; background: #12b8a6; color: #fff; margin: 0 0.3rem; }
.transport .play:hover { background: #2fd0be; }

.stage.controls-hidden .stage-top, .stage.controls-hidden .stage-bottom, .stage.controls-hidden .stage-edit-chip { opacity: 0; pointer-events: none; }
.stage.controls-hidden { cursor: none; }

.stage-overlay { position: absolute; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center; background: #000000b0; backdrop-filter: blur(4px); }
.stage-overlay.cover { background: #000; backdrop-filter: none; cursor: pointer; }
.stage-overlay .cover-hint { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.2em; color: #666; text-align: center; line-height: 2; }
.countdown { font-family: var(--mono); font-size: clamp(6rem, 20vw, 14rem); font-weight: 800; color: #12b8a6; line-height: 1; }
.countdown small { display: block; text-align: center; font-size: 0.75rem; letter-spacing: 0.3em; color: #aaa; margin-top: 1rem; }

.shortcut-dialog { position: absolute; top: 3.6rem; right: 0.9rem; z-index: 9; width: min(22rem, calc(100% - 2rem)); padding: 1rem 1.1rem 1.2rem; border-radius: 14px; border: 1px solid #ffffff22; background: #0f1010f2; color: #f2f0e9; box-shadow: 0 30px 80px #000000aa; }
.shortcut-dialog header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.8rem; }
.shortcut-dialog h2 { margin: 0; display: inline-flex; align-items: center; gap: 0.45rem; font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.16em; }
.shortcut-dialog dl { display: grid; grid-template-columns: auto 1fr; gap: 0.55rem 0.9rem; margin: 0; align-items: center; }
.shortcut-dialog dt { display: flex; gap: 0.25rem; }
.shortcut-dialog dd { margin: 0; font-size: 0.8rem; color: #cfcfc8; }
.shortcut-dialog kbd { font-family: var(--mono); font-size: 0.66rem; padding: 0.15rem 0.45rem; border-radius: 5px; border: 1px solid #ffffff33; background: #ffffff10; }

.drawer { position: absolute; top: 0; right: 0; bottom: 0; z-index: 9; width: min(420px, 100%); background: #141616; color: #f2f0e9; border-left: 1px solid #2b2e2d; box-shadow: -30px 0 80px #00000080; display: grid; grid-template-rows: auto auto minmax(0, 1fr); animation: drawer-in 0.2s ease-out; }
:root[data-ui-theme="light"] .drawer { background: #fff; color: #1b1e1b; border-color: #d6dad2; }
@keyframes drawer-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-header { display: flex; justify-content: space-between; align-items: center; padding: 0.9rem 1rem; border-bottom: 1px solid var(--line); }
.drawer-header h2 { margin: 0.2rem 0 0; font-size: 1rem; }
.drawer-header .drawer-actions { display: flex; align-items: center; gap: 0.4rem; }
.drawer-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
.drawer-tabs button { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: 46px; font-size: 0.8rem; font-weight: 700; color: var(--paper-muted); border-bottom: 2px solid transparent; }
.drawer-tabs button.active { color: var(--paper); border-bottom-color: var(--signal); }
.drawer-body { overflow-y: auto; min-height: 0; }
.drawer-body .settings { padding-top: 0.8rem; }
.drawer-note { padding: 0.8rem 1.1rem 0; font-size: 0.72rem; color: var(--paper-muted); }
.live-edit { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; padding: 0.9rem 1.1rem; gap: 0.6rem; }
.live-edit textarea { width: 100%; height: 100%; min-height: 240px; resize: none; padding: 1rem; border-radius: 10px; border: 1px solid var(--line-bright); background: var(--ink-soft); color: var(--paper); line-height: 1.7; }
.live-edit textarea:focus { outline: none; border-color: var(--signal); }
.scene-list { list-style: none; margin: 0; padding: 0.7rem; display: grid; gap: 0.4rem; }
.scene-list button { display: grid; grid-template-columns: 34px 1fr; gap: 0.6rem; align-items: center; width: 100%; padding: 0.8rem 0.7rem; text-align: left; border: 1px solid var(--line); border-radius: 8px; background: var(--ink-soft); color: var(--paper); }
.scene-list button:hover { border-color: var(--line-bright); }
.scene-list button.active { border-color: var(--signal); }
.scene-list .num { font-family: var(--mono); font-size: 0.7rem; color: var(--signal-bright); }
.scene-list strong { display: block; font-size: 0.86rem; }
.scene-list small { color: var(--paper-muted); font-family: var(--mono); font-size: 0.6rem; }
.drawer-summary { padding: 0.9rem 1.1rem 0; font-size: 0.75rem; color: var(--paper-muted); }

.loading { min-height: 100vh; display: grid; place-items: center; color: var(--paper-muted); font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.16em; }

/* ===== 반응형 ===== */
@media (max-width: 1180px) {
  .editor-body { grid-template-columns: 240px minmax(0, 1fr) 360px; }
  .editor-body.sidebar-collapsed { grid-template-columns: 64px minmax(0, 1fr) 360px; }
}
@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; gap: 1.6rem; }
  .hero-aside { border-left: 0; padding-left: 0; }
  .editor-page { height: auto; min-height: 100vh; overflow: visible; }
  .editor-body, .editor-body.sidebar-collapsed { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .page-list { max-height: 260px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .editor-canvas textarea { min-height: 320px; }
  .editor-topbar { grid-template-columns: 1fr auto; }
  .editor-topbar .topbar-center { display: none; }
}
@media (max-width: 640px) {
  .library-head { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions > * { flex: 1 1 auto; }
  .brand-text span { display: none; }
  .guide-button span { display: none; }
  .stage-bottom { grid-template-columns: 1fr; justify-items: center; gap: 0.5rem; }
  .stage-stat, .stage-stat.right { text-align: center; }
  .drawer { width: 100%; }
  dialog.dialog { border-radius: 18px; width: calc(100% - 1rem); }
}

/* ===== AI 음성 읽기 ===== */
.tts-fields { display: grid; gap: 0.6rem; }
.tts-field { display: grid; gap: 0.35rem; font-size: 0.72rem; color: var(--paper-muted); }
.tts-field .text-input, .tts-field select { min-height: 40px; padding: 0.4rem 0.7rem; border-radius: 6px; border: 1px solid var(--line-bright); background: var(--ink-soft); color: var(--paper); font-size: 0.82rem; width: 100%; }
.tts-field .text-input:focus, .tts-field select:focus { border-color: var(--signal); outline: none; box-shadow: none; }
.tts-row { display: flex; gap: 0.5rem; align-items: center; }
.tts-row .text-input, .tts-row select { flex: 1 1 auto; min-width: 0; }
.tts-row .secondary-button { min-height: 40px; padding: 0.4rem 0.7rem; font-size: 0.75rem; }
.tts-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.tts-actions .secondary-button { min-height: 38px; font-size: 0.78rem; }
.tts-note { margin: 0; font-size: 0.68rem; line-height: 1.55; color: var(--paper-muted); }
.tts-note a { color: var(--signal-bright); }
.tts-status { display: inline-flex; align-items: center; gap: 0.35rem; font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.12em; color: var(--paper-muted); }
.tts-status.ready { color: var(--safe); }
.stage-voice { position: absolute; top: 5.4rem; left: 50%; transform: translateX(-50%); z-index: 5; display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0.7rem; border-radius: 999px; border: 1px solid #ffffff1c; background: #00000060; color: var(--stage-text); font-family: var(--mono); font-size: 0.56rem; letter-spacing: 0.12em; opacity: 0.75; transition: opacity 0.3s; pointer-events: none; }
.stage-voice[hidden] { display: none; }
.stage-voice .icon { color: #2fd0be; }
.stage-voice.loading .icon { animation: spin 1s linear infinite; }
.stage-voice.error { border-color: #ff5d5d66; }
.stage-voice.error .icon { color: #ff7b7b; }
.stage.controls-hidden .stage-voice { opacity: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.stage-article .seg.spoken { opacity: 0.55; }
.stage-article .seg.speaking { text-decoration: underline; text-decoration-color: #2fd0be; text-decoration-thickness: 3px; text-underline-offset: 0.18em; }

.preparing { display: grid; justify-items: center; gap: 0.7rem; text-align: center; color: #f2f0e9; }
.preparing .icon { color: #2fd0be; animation: spin 1s linear infinite; }
.preparing strong { font-size: 1.15rem; letter-spacing: -0.02em; }
.preparing small { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.14em; color: #aaa; }
