:root {
  --bg-primary: #f3f6fb;
  --bg-secondary: #ffffff;
  --bg-tertiary: #dbe4f2;
  --surface: #ffffff;
  --surface-hover: #f7f9fd;
  --text-primary: #111827;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --accent-primary: #3b82f6;
  --accent-secondary: #8b5cf6;
  --accent-tertiary: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: rgba(100, 116, 139, 0.22);
  --shadow: 0 20px 25px -5px rgba(15, 23, 42, 0.12), 0 10px 10px -5px rgba(15, 23, 42, 0.08);
  --glow: 0 0 18px rgba(59, 130, 246, 0.22);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
}

html {
  scrollbar-gutter: stable;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Noto Sans KR", sans-serif;
  color: var(--text-primary);
  background:
    radial-gradient(ellipse at top, rgba(59, 130, 246, 0.09), transparent 50%),
    radial-gradient(ellipse at bottom, rgba(139, 92, 246, 0.08), transparent 50%),
    linear-gradient(180deg, #eff4fb 0%, #e9eff8 100%);
  line-height: 1.45;
  font-size: 14px;
  overflow: hidden;
}

.container {
  width: 100%;
  height: 100%;
  animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.header-btn {
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}

.header-btn:hover {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

/* Main Card */
.main-card {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  background: var(--surface);
  backdrop-filter: blur(20px);
}

.app-shell {
  display: grid;
  grid-template-columns: 220px 0 minmax(0, 1fr);
  height: 100%;
  position: relative;
  transition: grid-template-columns 0.18s ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 0 minmax(0, 1fr);
}

.sidebar {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-width: 0;
  padding: 12px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden auto;
  transition: padding 0.18s ease, border-color 0.18s ease;
}

.app-shell.sidebar-collapsed .sidebar {
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  pointer-events: none;
}

.sidebar-actions {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-action-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-action-group[hidden] {
  display: none;
}

.sidebar-actions .btn {
  width: 100%;
  justify-content: center;
  padding: 10px 12px;
  font-size: 12px;
}

.sidebar-actions .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.sidebar-gutter {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  width: 0;
  min-width: 0;
  background: transparent;
}

.sidebar-toggle {
  position: absolute;
  left: 0;
  top: 320px;
  z-index: 10;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transform: translateX(-50%);
  transition: background 0.12s, border-color 0.12s, left 0.18s ease;
  font-size: 17px;
  line-height: 1;
}

.sidebar-toggle:hover {
  background: var(--surface-hover);
  border-color: var(--accent-primary);
}

.sidebar-toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  line-height: 1;
  transform: translateY(-1px);
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  left: 8px;
  transform: none;
}

.sidebar-footer {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.sidebar-footer .header-btn {
  flex: 1;
  text-align: center;
}

.workspace {
  grid-column: 3;
  grid-row: 1;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
}

.panel-columns,
.panel-cols-top,
.panel-col-left,
.panel-col-right {
  display: contents;
}

@media (min-width: 769px) {
  .panel-cols-top {
    display: flex;
    flex: 1;
    align-items: stretch;
  }

  .panel-col-left,
  .panel-col-right {
    display: block;
    flex: 1;
    min-width: 0;
  }

  .panel-col-left {
    border-right: 1px solid rgba(100, 116, 139, 0.12);
  }

  .upload-area {
    height: 260px;
    min-height: 0;
  }

  .file-list {
    height: 260px;
    min-height: 0;
  }
}

.tab-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 16px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
  gap: 8px;
}

#mergeTab { border-color: rgba(59, 130, 246, 0.28); background: rgba(59, 130, 246, 0.08); }
#txtTab { border-color: rgba(139, 92, 246, 0.28); background: rgba(139, 92, 246, 0.08); }
#epubTxtTab { border-color: rgba(6, 182, 212, 0.28); background: rgba(6, 182, 212, 0.08); }

.tab-button:hover {
  color: var(--text-primary);
  background: var(--surface-hover);
}

.tab-button.active {
  color: #fff;
  border-color: transparent;
}

#mergeTab.active {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.38);
}

#txtTab.active {
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.38);
}

#epubTxtTab.active {
  background: linear-gradient(135deg, #0891b2, #06b6d4);
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.38);
}

.tab-panel[hidden] {
  display: none;
}

.txt-file-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.txt-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

.txt-file-item span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.txt-file-size {
  flex: none;
  color: var(--text-muted);
  font-size: 12px;
}

.txt-cover-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.txt-cover-preview {
  width: 72px;
  height: 96px;
  flex: none;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
}

.txt-cover-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.txt-setting-stack { display: grid; gap: 8px; margin-top: 16px; }
.cover-setting-label-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; }
.cover-setting-label-row .form-label { margin-bottom: 0; }
.cover-add-toggle { position: relative; display: inline-flex; flex: 0 0 auto; align-items: center; gap: 8px; min-height: 44px; margin-left: auto; color: var(--text-secondary); font-size: 12px; line-height: 1.4; white-space: nowrap; cursor: pointer; -webkit-user-select: none; user-select: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.cover-add-toggle input { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; border: 0; overflow: hidden; clip: rect(0, 0, 0, 0); clip-path: inset(50%); white-space: nowrap; }
.cover-add-toggle-ui { position: relative; display: block; box-sizing: border-box; width: 38px; min-width: 38px; height: 22px; flex: 0 0 38px; overflow: hidden; border-radius: 999px; background: var(--border); transition: background-color .2s ease; }
.cover-add-toggle-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s ease; }
.cover-add-toggle input:checked + .cover-add-toggle-ui { background: var(--accent-primary); }
.cover-add-toggle input:checked + .cover-add-toggle-ui::after { transform: translateX(16px); }
.cover-add-toggle input:focus-visible + .cover-add-toggle-ui { outline: 2px solid var(--accent-primary); outline-offset: 2px; }
.cover-add-toggle.disabled { opacity: .45; cursor: not-allowed; }
.form-field.merge-toc-reset-field { display: flex; flex-direction: row; align-items: center; gap: 10px; }
.merge-toc-reset-field > input[type="text"] { flex: 1 1 auto; min-width: 0; }
.merge-toc-reset-field > input[type="checkbox"] { flex: none; }
.txt-setting-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-secondary); color: var(--text-secondary);
}
.txt-setting-row .option-label { flex: 1; }
.txt-setting-row select { width: auto; min-width: 180px; }
.txt-setting-row > select { flex: 1; width: 100%; }
.txt-detail-toggle { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 16px; }
.txt-setting-detail { padding: 12px; border: 1px solid var(--border); border-radius: 9px; background: rgba(15, 23, 42, 0.2); }
.txt-setting-detail[hidden] { display: none; }
.txt-css-editor { width: 100%; min-height: 340px; padding: 6px; box-sizing: border-box; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; tab-size: 2; resize: vertical; }
.merge-css-template-field { margin-top: 14px; }
.merge-css-template-field[hidden] { display: none; }
.merge-css-diagnostics { max-height: 150px; overflow: auto; padding: 8px 10px; border: 1px solid rgba(245, 158, 11, .35); border-radius: 7px; background: rgba(245, 158, 11, .08); color: var(--text-secondary); font-size: 11px; line-height: 1.5; }
.merge-css-diagnostic + .merge-css-diagnostic { margin-top: 3px; }
.merge-css-diagnostic-location { padding: 0; border: 0; color: #f59e0b; background: transparent; font: inherit; font-variant-numeric: tabular-nums; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.txt-css-layout { display: grid; grid-template-columns: minmax(120px, 170px) minmax(0, 1fr); align-items: stretch; overflow: hidden; border: 1px solid var(--border); border-radius: 9px; background: var(--bg-secondary); }
.txt-css-list { width: 100%; height: 100%; min-height: 340px; padding: 6px; border: 0; border-right: 1px solid var(--border); border-radius: 0; background: transparent; }
.merge-css-file-pane { min-width: 0; padding: 6px; border-right: 1px solid var(--border); }
.merge-css-drag-list { max-height: 340px; min-height: 200px; overflow: auto; }
.merge-css-drag-list button { display: block; width: 100%; padding: 8px 6px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--text-secondary); text-align: left; overflow-wrap: anywhere; font: inherit; font-size: 12px; cursor: grab; }
.merge-css-drag-list button[aria-selected="true"] { background: rgba(99, 102, 241, .18); color: var(--text-primary); }
.merge-css-drag-list button.css-drop-target, .merge-css-drag-list button:focus-visible { border-color: #818cf8; outline: 2px solid #818cf8; outline-offset: -2px; }
.merge-css-drag-list button.css-dragging { opacity: .5; border-color: #818cf8; }
@media (any-pointer: coarse) {
  .merge-css-drag-list button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
@media (max-width: 768px) {
  .merge-css-file-pane { border-right: 0; border-bottom: 1px solid var(--border); }
  .merge-css-drag-list { min-height: 0; max-height: 180px; }
}
.txt-css-editor-pane { min-width: 0; padding: 0; background: transparent; }
.txt-css-editor-pane .txt-css-editor { height: 100%; border: 0; border-radius: 0; background: transparent; }
.css-comment-highlight-wrap { position: relative; width: 100%; height: 100%; min-height: 340px; }
.css-line-numbers { position: absolute; inset: 0 auto 0 0; z-index: 2; width: 36px; height: 100%; margin: 0; padding: 6px 5px 6px 0; overflow: hidden; border: 0; border-right: 1px solid var(--border); color: #fff; background: #818FA0; font: 11px/1.6909 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: right; white-space: pre; pointer-events: none; user-select: none; }
.css-comment-highlight { position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; margin: 0; padding: 6px 6px 6px 42px; overflow: hidden; border: 0; color: var(--text-primary); background: transparent; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; tab-size: 2; pointer-events: none; }
.css-comment-highlight .css-comment { color: var(--text-muted); }
.txt-css-editor-pane .css-comment-highlight-editor { position: relative; z-index: 1; padding-left: 42px; border: 0 !important; outline: 0 !important; box-shadow: none !important; background: transparent !important; color: transparent; caret-color: var(--text-primary); -webkit-text-fill-color: transparent; resize: none; }
.txt-css-editor-pane .css-comment-highlight-editor:focus,
.txt-css-editor-pane .css-comment-highlight-editor:focus-visible { border: 0 !important; outline: 0 !important; box-shadow: none !important; }
.css-comment-highlight-editor::placeholder { color: var(--text-muted); -webkit-text-fill-color: var(--text-muted); }
.css-comment-highlight-editor::selection { background: rgba(59, 130, 246, .28); }
.txt-field-label-row { position: relative; display: flex; align-items: center; min-height: 1em; padding-right: 78px; }
.txt-field-label-row .form-label { margin-bottom: 0; }
.txt-template-actions { position: absolute; right: 0; top: 50%; display: inline-flex; align-items: center; gap: 4px; transform: translateY(-50%); }
.txt-template-action { display: inline-grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 1px solid var(--border); border-radius: 5px; background: var(--bg-secondary); color: var(--text-secondary); cursor: pointer; font-size: 14px; font-weight: 700; line-height: 1; }
.txt-template-action:hover { border-color: var(--accent-primary); color: var(--text-primary); }
.txt-detected-list { display: block; max-height: 240px; overflow: auto; }
.txt-detected-item { min-height: 22px; margin: 0px 4px; padding: 2px 0; border-radius: 6px; background: transparent; color: var(--text-secondary); line-height: 1.3; }
.txt-detected-item { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.txt-detected-item + .txt-detected-item {
  background-image: linear-gradient(rgba(148, 163, 184, 0.14), rgba(148, 163, 184, 0.14));
  background-position: 6px top;
  background-repeat: no-repeat;
  background-size: calc(100% - 12px) 1px;
}
.txt-heading-drag-handle { flex: none; display: inline-grid; place-items: center; width: 22px; height: 26px; padding: 0; border: 0; background: transparent; color: var(--text-muted); cursor: grab; font-size: 16px; line-height: 1; touch-action: none; user-select: none; }
.txt-heading-drag-handle:active { cursor: grabbing; color: var(--accent-primary); }
.txt-detected-item input { flex: none; accent-color: var(--accent-primary); }
.txt-detected-item.excluded { opacity: .55; text-decoration: line-through; }
.txt-detected-item[data-heading-level="2"] { padding-left: 20px; }
.txt-detected-item[data-heading-level="3"] { padding-left: 40px; }
.txt-detected-item[data-heading-level="4"] { padding-left: 60px; }
.txt-detected-item[data-heading-level="5"] { padding-left: 80px; }
.txt-detected-item[data-heading-level="6"] { padding-left: 100px; }
.txt-detected-item.dragging { opacity: .35; }
.txt-detected-item.heading-drop-target { outline: 2px solid var(--accent-primary); }
.txt-detected-item.heading-drop-before,
.txt-detected-item.heading-drop-after { position: relative; }
.txt-detected-item.heading-drop-before::before,
.txt-detected-item.heading-drop-after::after { content: ""; position: absolute; z-index: 2; left: 0; right: 0; height: 3px; border-radius: 2px; background: var(--accent-primary); pointer-events: none; }
.txt-detected-item.heading-drop-before::before { top: -5px; }
.txt-detected-item.heading-drop-after::after { bottom: -5px; }
.txt-pattern-box { display: grid; gap: 9px; margin: 8px 0 12px; padding: 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg-secondary); }
.txt-pattern-checks { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.txt-pattern-checks label { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); cursor: pointer; }
.txt-pattern-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.txt-unlisted-pattern-heading { color: var(--text-secondary); font-size: 11px; white-space: nowrap; }
.txt-custom-pattern-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 9px; }
.txt-custom-pattern-row input[type="text"] { min-width: 0; }
.txt-custom-pattern-row label { display: inline-flex; align-items: center; gap: 6px; }
.txt-chapter-layout { --chapter-panel-content-height: 351px; display: grid; grid-template-columns: minmax(300px, .9fr) minmax(0, 1.1fr); overflow: hidden; border: 1px solid var(--border); border-radius: 9px; background: var(--bg-secondary); }
.txt-chapter-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px; }
.txt-chapter-pane + .txt-chapter-pane { border-left: 1px solid var(--border); }
.txt-chapter-pane > .form-label { display: block; margin-bottom: 10px; }
#txtChapterLayout .txt-pattern-box { height: var(--chapter-panel-content-height); margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; }
#txtChapterLayout .txt-setting-detail { flex: none; height: var(--chapter-panel-content-height); min-height: 0; max-height: none; overflow: auto; padding: 0; border: 0; border-radius: 0; background: transparent; }
#txtChapterLayout .txt-detected-list { height: auto; max-height: none; overflow: visible; }
#txtChapterLayout .merge-toc-unlisted-list { max-height: 160px; overflow: auto; }
#mergeTocLayout #mergeTocBookList { height: var(--chapter-panel-content-height); max-height: none; }
#mergeTocLayout .txt-setting-detail { flex: none; height: var(--chapter-panel-content-height); min-height: 0; max-height: none; overflow: auto; padding: 0; border: 0; border-radius: 0; background: transparent; }
#mergeTocLayout .txt-setting-detail .txt-detected-list { height: auto; max-height: none; }
.txt-chapter-preview-btn { flex: 0 0 30px; width: 30px; margin-left: auto; border: 1px solid var(--border); border-radius: 5px; padding: 2px; background: var(--surface); color: var(--text-secondary); cursor: pointer; font-size: 11px; line-height: 1.2; text-align: center; text-decoration: none; white-space: nowrap; }
.txt-modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 18px; background: rgba(2, 6, 23, .72); }
.txt-modal[hidden] { display: none; }
.txt-modal-card { width: min(900px, 100%); max-height: 92vh; overflow: auto; padding: 20px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.txt-modal-title-options { display: flex; align-items: center; gap: 10px; min-width: 0; }
.txt-modal-title-options h2 { white-space: nowrap; }
#txtChapterSourceMode { width: auto; min-width: 110px; padding: 6px 28px 6px 9px; font-size: 12px; }
.txt-modal-close { border: 0; background: transparent; color: var(--text-secondary); cursor: pointer; font-size: 24px; }

#logModal { inset: auto 20px 20px auto; display: block; padding: 0; background: transparent; width: auto; }
#logModal[hidden] { display: none; }
.log-modal-card { width: min(760px, 100%); display: flex; flex-direction: column; max-height: 82vh; box-shadow: var(--shadow); }
#logModal .log-modal-card { width: 420px; height: 520px; max-width: calc(100vw - 24px); max-height: calc(100vh - 24px); min-width: 280px; min-height: 200px; overflow: auto; position: relative; }
#logModal .modal-header { cursor: move; touch-action: none; }
.log-resize-handle { position: absolute; right: 2px; bottom: 2px; width: 20px; height: 20px; display: flex; align-items: flex-end; justify-content: flex-end; padding: 2px; line-height: 1; font-size: 14px; color: var(--text-muted); cursor: nwse-resize; touch-action: none; user-select: none; opacity: .6; }
.log-resize-handle:hover { opacity: 1; }
.log-modal-body { overflow-y: auto; padding-right: 4px; flex: 1; min-height: 0; }
.log-modal-head-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.merge-chapter-modal-title-file { font-size: 0.65em; font-weight: 400; color: var(--text-muted); }
.log-entry { padding: 10px 0; border-bottom: 1px solid var(--border); font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; font-size: 12px; }
.log-entry:last-child { border-bottom: none; }
.log-entry-head { margin-bottom: 6px; font-weight: 700; color: var(--text-secondary); }
.log-entry-line { white-space: pre-wrap; word-break: break-word; line-height: 1.6; color: var(--text-muted); }
.log-entry-line--after { color: var(--text-primary); }
.log-diff { color: #e11d48; font-weight: 700; }
.log-entry--success { color: var(--success); }
.log-entry--error { color: var(--danger); }
.log-entry--busy { color: var(--warning); }
.log-entry--action { cursor: pointer; border-radius: 8px; padding-inline: 8px; }
.log-entry--action:hover, .log-entry--action:focus-visible { background: rgba(59, 130, 246, 0.1); outline: none; }
.log-entry-empty { padding: 24px 0; text-align: center; color: var(--text-muted); font-size: 13px; }
.txt-chapter-editor { width: 100%; height: 420px; min-height: 420px; max-height: 420px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; outline: none; resize: none; background: var(--bg-secondary); color: var(--text-primary); font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.txt-chapter-editor:focus { border-color: var(--accent-primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16); }
.txt-chapter-body-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; margin-top: 12px; overflow: hidden; border: 1px solid var(--border); border-radius: 9px; background: var(--bg-secondary); }
.txt-chapter-body-pane { min-width: 0; }
.txt-chapter-body-pane + .txt-chapter-body-pane { border-left: 1px solid var(--border); }
.txt-chapter-body-pane > .form-label { display: block; margin: 0; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.txt-chapter-body-pane > .txt-chapter-editor { display: block; border: 0; border-radius: 0; }
.txt-chapter-body-pane > .txt-chapter-editor:focus { box-shadow: inset 0 0 0 1px rgba(59, 130, 246, .35); }
.txt-chapter-html-scroll { position: relative; width: 100%; height: 420px; overflow-x: hidden; overflow-y: auto; background: #fff; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain; }
.txt-chapter-html-preview { display: block; width: 100%; height: 420px; min-height: 100%; overflow: hidden; border: 0; border-radius: 0; background: #fff; pointer-events: auto; }
.txt-chapter-html-preview { -webkit-transform: translateZ(0); transform: translateZ(0); }
#mergeChapterModal .txt-chapter-html-scroll { overflow: hidden; }
#mergeChapterModal .txt-chapter-html-preview { height: 100%; min-height: 0; overflow: auto; }
#mergeChapterHtmlPreview { overflow: hidden; pointer-events: auto; }
.merge-chapter-use-selection-btn { position: absolute; z-index: 5; padding: 6px 12px; border: 0; border-radius: 999px; background: var(--accent-primary); color: #fff; font-size: 12px; font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,.25); cursor: pointer; }
.merge-chapter-use-selection-btn[hidden] { display: none; }
.actions.txt-chapter-modal-actions { margin-top: 16px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.txt-chapter-modal-actions .btn { width: 100%; min-height: 44px; justify-content: center; }
.txt-chapter-modal-actions .btn span:last-child { white-space: nowrap; }
#txtChapterAddImage { border-color: rgba(6, 182, 212, .55); color: var(--accent-tertiary); }
#txtChapterAddImage:hover { background: rgba(6, 182, 212, .1); border-color: var(--accent-tertiary); }
.actions.chapter-editor-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  flex: none;
}
.chapter-editor-quote-actions,
.chapter-editor-preview-actions { display: grid; min-width: 0; gap: 6px; }
.chapter-editor-quote-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); padding-right: 3px; }
.chapter-editor-preview-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); padding-left: 3px; }
.actions.chapter-editor-actions .btn { min-width: 0; }
.chapter-editor-actions .btn { padding: 10px 6px; gap: 5px; font-size: 12px; }
.chapter-editor-actions .btn.chapter-quote-button { padding: 0; font-size: 24px; line-height: 1; }
@media (max-width: 768px) {
  .actions.chapter-editor-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr)) repeat(2, minmax(0, 2fr));
    gap: 4px;
  }
  .chapter-editor-quote-actions,
  .chapter-editor-preview-actions { display: contents; }
  #mergeChapterModalTitle { font-size: 16px; line-height: 1.35; }
  .txt-css-layout, .txt-chapter-layout, .txt-chapter-body-grid { grid-template-columns: 1fr; }
  .txt-chapter-pane + .txt-chapter-pane, .txt-chapter-body-pane + .txt-chapter-body-pane { border-left: 0; border-top: 1px solid var(--border); }
  #txtChapterLayout .txt-setting-detail, #mergeTocLayout .txt-setting-detail { flex: none; height: auto; max-height: 430px; overflow: auto; }
  #txtChapterLayout .txt-detected-list, #mergeTocLayout .txt-detected-list { height: auto; max-height: 430px; }
  #txtChapterLayout .txt-pattern-box, #mergeTocLayout #mergeTocBookList { height: auto; max-height: 430px; }
  #txtChapterModal, #mergeChapterModal { padding: 8px; }
  #txtChapterModal .txt-modal-card,
  #mergeChapterModal .txt-modal-card { display: flex; flex-direction: column; height: calc(100vh - 16px); height: calc(100svh - 16px); max-height: calc(100vh - 16px); max-height: calc(100svh - 16px); overflow: hidden; }
  #txtChapterEditTitle, #mergeChapterTitle, #txtChapterSelect, #mergeChapterSelect, .txt-chapter-editor, #txtChapterSourceMode { font-size: 16px; }
  #txtChapterModal .txt-chapter-body-grid,
  #mergeChapterModal .txt-chapter-body-grid { flex: 1; min-height: 0; grid-template-rows: repeat(2, minmax(0, 1fr)); }
  #txtChapterModal .txt-chapter-body-pane,
  #mergeChapterModal .txt-chapter-body-pane { display: flex; flex-direction: column; min-height: 0; }
  .txt-chapter-body-pane > .txt-chapter-editor, .txt-chapter-html-scroll { flex: 1; width: 100%; height: auto; min-height: 0; max-height: none; }
  .txt-chapter-html-preview { border-left: 0; }
  .txt-chapter-modal-actions .btn { padding: 10px 6px; gap: 5px; font-size: 12px; }
  .txt-css-list {
    height: auto;
    min-height: 0;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  #txtCssEditor, #txtCssHighlight, #txtCssLineNumbers,
  #mergeCssEditor, #mergeCssHighlight, #mergeCssLineNumbers { font-size: 16px; line-height: 1.55; }
  .txt-css-editor-pane .txt-css-editor {
    height: 400px;
    min-height: 400px;
    max-height: 400px;
  }
  .txt-setting-row select { min-width: 0; max-width: 45%; }
}

.main-card > .section:first-child {
  border-radius: 18px 18px 0 0;
}

.main-card > .section:last-child {
  border-radius: 0 0 18px 18px;
}

/* Section Headers */
.section {
  padding: 16px 22px;
  background: var(--surface);
  border-bottom: 1px solid rgba(100, 116, 139, 0.12);
}

.section:first-child {
  padding-top: 18px;
}

.section:last-child {
  border-bottom: none;
  padding-bottom: 34px;
}

.panel-col-left > .section:last-child,
.panel-col-right > .section:last-child {
  padding-bottom: 16px;
}

.section-header {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  grid-template-areas:
    "icon title tip";
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

summary.section-header {
  cursor: pointer;
  list-style: none;
}

summary.section-header::-webkit-details-marker {
  display: none;
}

.section-toggle-icon {
  grid-area: tip;
  color: var(--text-muted);
  font-size: 14px;
  transition: transform 0.2s ease;
}

.section-collapsible:not([open]) .section-toggle-icon {
  transform: rotate(-90deg);
}

.section-collapsible:not([open]) .section-header {
  margin-bottom: 0;
}


.section-icon {
  grid-area: icon;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: var(--glow);
}

.section-title {
  grid-area: title;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.section-tip {
  grid-area: tip;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  position: relative;
  user-select: none;
}

.section-tip::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  max-width: 300px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 30;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
}

.section-tip:hover::after {
  opacity: 1;
  transform: translateY(0);
}

/* File Upload Area */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 170px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 22px;
  text-align: center;
  background: rgba(59, 130, 246, 0.05);
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.upload-area::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.1) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.upload-area:hover::before {
  opacity: 1;
}

.upload-area:hover {
  border-color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.08);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.2);
}

.upload-area.dragover {
  border-color: var(--accent-tertiary);
  background: rgba(6, 182, 212, 0.12);
  box-shadow: 0 8px 24px rgba(6, 182, 212, 0.28);
  transform: translateY(-2px);
}

.file-list.dragover {
  border-color: var(--accent-tertiary);
  background: rgba(6, 182, 212, 0.12);
  box-shadow: 0 8px 24px rgba(6, 182, 212, 0.28);
}

.upload-area.has-files {
  display: none;
}

.upload-icon {
  font-size: 34px;
  margin-bottom: 10px;
  opacity: 0.8;
}

.upload-text {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 600;
}

.upload-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.upload-count {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 12px;
  background: var(--success);
  color: white;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}

#files,
#txtFiles,
#epubTxtFiles {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

#coverImg,
#txtCover {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* File List */
.file-list {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-secondary);
  width: 100%;
  min-height: 170px;
  text-align: left;
  display: flex;
  flex-direction: column;
}

.file-list.empty {
  display: none;
}

.file-list-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  max-height: 260px;
  padding: 6px;
}

.file-list-scroll::-webkit-scrollbar {
  width: 5px;
}

.file-list-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.file-list-scroll::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.file-list-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.file-item {
  display: grid;
  grid-template-columns: 16px 20px 1fr auto 24px;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  margin-bottom: 3px;
  background: transparent;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.file-item:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.file-item:last-child {
  margin-bottom: 0;
}

.file-item.txt-convert-file { grid-template-columns: 16px 20px 1fr auto 24px; }
.file-item.txt-convert-file.active { background: rgba(59, 130, 246, 0.1); border-color: var(--accent-primary); }
.file-item.txt-convert-file .file-name { cursor: pointer; }

.file-drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  opacity: 0;
  touch-action: none;
  transition: opacity 0.15s ease;
}

.file-drag-handle:active {
  cursor: grabbing;
}

.file-item:hover .file-drag-handle {
  opacity: 0.6;
}

@media (hover: none), (any-pointer: coarse) {
  .file-item .file-drag-handle {
    opacity: 0.7;
  }
}

.file-item.dragging {
  opacity: 0.3;
  background: var(--surface-hover);
}

.file-item.drag-over-top {
  box-shadow: inset 0 2px 0 var(--accent-primary);
}

.file-item.drag-over-bottom {
  box-shadow: inset 0 -2px 0 var(--accent-primary);
}

.file-list-head {
  display: grid;
  grid-template-columns: 16px 20px 1fr auto 24px;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  background: linear-gradient(135deg, rgba(59,130,246,0.06), rgba(139,92,246,0.04));
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.file-list-head-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.file-count-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  background: rgba(59,130,246,0.15);
  color: var(--accent-primary);
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
}

.file-icon {
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
}

.file-name {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.15s ease;
}

.file-item:hover .file-name {
  color: var(--text-primary);
}

.file-size {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.file-check {
  width: 15px;
  height: 15px;
  accent-color: var(--accent-primary);
  cursor: pointer;
  justify-self: center;
}

.file-add,
.file-remove {
  width: 22px;
  height: 22px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  opacity: 0;
  transition: opacity 0.15s ease, border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.file-item:hover .file-remove {
  opacity: 1;
}

@media (hover: none), (any-pointer: coarse) {
  .file-item .file-remove {
    opacity: 1;
  }
}

.file-remove:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(239, 68, 68, 0.12);
}

.empty-state {
  text-align: center;
  padding: 22px;
  color: var(--text-muted);
  font-size: 12px;
}

/* Form Grid */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-field-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.form-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

input[type="text"],
input[type="date"],
input[type="datetime-local"],
input[type="number"],
select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: all 0.2s ease;
  font-family: inherit;
}

input[type="date"],
input[type="datetime-local"] {
  appearance: none;
  -webkit-appearance: none;
}

input[type="text"]:hover,
input[type="date"]:hover,
input[type="datetime-local"]:hover,
input[type="number"]:hover,
select:hover {
  border-color: rgba(148, 163, 184, 0.4);
}

input[type="text"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
  background: var(--surface);
}

input::placeholder {
  color: var(--text-muted);
}

input:disabled,
select:disabled {
  color: var(--text-muted);
  opacity: 0.5;
  cursor: not-allowed;
}

.form-label-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
}

/* Checkbox Options */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-width: 0;
}

.option-card {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary);
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

#imageConfigPanel > .options-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#imageConfigPanel > .options-grid > div,
#imageConfigPanel > .options-grid > label {
  min-width: 0;
}

.option-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.1), transparent);
  transition: left 0.5s ease;
}

.option-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.option-card:hover::before {
  left: 100%;
}

.option-card input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent-primary);
  flex-shrink: 0;
}

.merge-single-book-option {
  align-self: end;
  min-height: 40px;
  padding: 8px 12px;
}

.merge-version-field select {
  height: 40px;
}

.option-label {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  user-select: none;
}

/* Expandable Section */
.expandable {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.05), rgba(139, 92, 246, 0.05));
  display: none;
  animation: slideDown 0.4s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.expandable.active {
  display: block;
}

.merge-toc-preview-item {
  color: var(--text-secondary);
  border-radius: 4px;
}
:is(#mergeTocPreviewList, #txtDetectedChapters) .merge-toc-preview-item.is-selected { box-shadow: inset 3px 0 var(--accent-primary); }
:is(#mergeTocPreviewList, #txtDetectedChapters).has-multiple-selection .merge-toc-preview-item.is-selected,
:is(#mergeTocPreviewList, #txtDetectedChapters).is-multi-select .merge-toc-preview-item.is-selected { background: rgba(99, 102, 241, .18); }
:is(#mergeTocPreviewList, #txtDetectedChapters) .merge-toc-preview-item.is-selected .merge-toc-play-order { color: var(--accent-primary); font-weight: 700; }
.merge-toc-play-order { flex: none; min-width: 1.6em; text-align: right; font-size: 11px; font-weight: 400; color: var(--text-muted); font-variant-numeric: tabular-nums; cursor: pointer; touch-action: none; user-select: none; }
.merge-toc-row-indent { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
#mergeTocPreviewList .txt-heading-drag-handle { position: relative; z-index: 2; pointer-events: auto; touch-action: none; }
#mergeTocPreviewList .txt-detected-item.dragging { user-select: none; }
@media (any-pointer: coarse) {
  :is(#mergeTocPreviewList, #txtDetectedChapters) .merge-toc-edit-text:not([contenteditable="true"]) { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: pan-y; }
}
.toc-unlisted-section[hidden], .merge-toc-split-line[hidden] { display: none; }
.merge-toc-unlisted-list { max-height: 160px; }
.toc-unlisted-item { display: flex; align-items: center; gap: 7px; color: var(--text-secondary); }
.toc-unlisted-item .toc-unlisted-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc-unlisted-item.is-added { color: var(--text-muted); }
.toc-unlisted-item.is-excluded .toc-unlisted-name { opacity: .55; text-decoration: line-through; }
.toc-unlisted-include-check { flex: none; }
.merge-toc-unlisted-check { flex: none; margin-left: 2px; }
.merge-toc-split-line { height: 1px; margin: 12px 0; background: var(--border); }

.merge-toc-book-title { display: flex; align-items: center; gap: 6px; margin: 0 4px; padding: 6px 0; font-weight: 700; color: var(--text-primary); }
.merge-toc-book-title .merge-toc-edit-text[contenteditable="true"] { margin-left: 2px; }
.merge-toc-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.merge-toc-label-row .form-label { margin: 0; }
.merge-toc-count { color: var(--text-muted); font-weight: 500; }
#mergeTocLayout[hidden] { display: none !important; }
.merge-toc-label-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.merge-toc-renumber-open { width: 30px; min-width: 30px; height: 30px; padding: 0; font-size: 16px; }
#mergeTocRenumberModal .txt-chapter-modal-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#txtTocRenumberModal .txt-chapter-modal-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 4px; }
.merge-toc-renumber-card { width: min(480px, 100%); padding: 18px; overflow: hidden; }
.merge-toc-renumber-card .modal-header { align-items: flex-start; margin-bottom: 12px; }
.merge-toc-renumber-card .modal-header h2 { margin: 0; }
.merge-toc-renumber-description { margin: 6px 0 0; color: var(--text-muted); font-size: 12px; line-height: 1.5; }
.merge-toc-renumber-field { gap: 7px; }
#mergeTocRenumberPattern { font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.merge-toc-renumber-help { color: var(--text-muted); font-size: 11px; line-height: 1.5; }
.merge-toc-missing-numbers { min-height: 1.5em; margin-top: 9px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg-secondary); color: var(--text-secondary); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.merge-toc-missing-numbers strong { color: var(--text-primary); }
.merge-toc-edit-text del { margin-right: 6px; color: var(--text-muted); opacity: .75; }
.merge-toc-renumber-error { min-height: 1.2em; margin-top: 3px; color: var(--danger); font-size: 12px; }
#mergeTocRenumberModal .txt-chapter-modal-actions { margin-top: 4px; }
@media (max-width: 520px) {
  .merge-toc-renumber-card { padding: 16px; }
  #mergeTocRenumberPattern,
  #txtTocRenumberPattern { font-size: 16px; }
}
.merge-toc-book-item { padding: 5px 8px; border-radius: 6px; }
.merge-toc-book-item.active { background: rgba(59, 130, 246, .14); color: var(--text-primary); }
.merge-toc-edit-text { min-width: 0; cursor: text; }
.merge-toc-edit-text[contenteditable="true"] { flex: 1; padding: 2px 5px; outline: 2px solid var(--accent-primary); border-radius: 4px; background: var(--bg-secondary); color: var(--text-primary); }

.expandable-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.expandable-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

/* File Input Custom */
.file-input-wrapper {
  position: relative;
}

.file-input-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 8px;
  background: var(--accent-primary);
  color: white;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.file-input-button:hover {
  background: #2563eb;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.file-input-name {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

/* Action Buttons */
.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  padding: 12px 22px;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
}

.btn-primary::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.btn-primary:hover::before {
  width: 300px;
  height: 300px;
}

.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(59, 130, 246, 0.5);
}

.btn-primary:active {
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.status-badge {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
  border: 1px solid rgba(59, 130, 246, 0.3);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.status-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-primary);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.btn-format {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.2s, color 0.2s;
  font-family: inherit;
}
.btn-format:hover {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.output-name-label-row { align-items: flex-end; }
.output-name-label-row .cover-add-toggle { min-height: 22px; }

.output-name-combo {
  position: relative;
  display: flex;
  width: 100%;
  min-width: 0;
}

.output-name-combo > input {
  padding-right: 42px;
}

.output-name-toggle {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 38px;
  height: calc(100% - 2px);
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0 9px 9px 0;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.output-name-toggle:hover {
  color: var(--text-primary);
  background: var(--surface-hover);
}

.output-name-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
  display: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.output-name-menu.active {
  display: block;
}

.output-name-option {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 9px 12px;
  background: transparent;
  color: var(--text-secondary);
  text-align: left;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.output-name-option:last-child {
  border-bottom: 0;
}

.output-name-option:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

#coverPreviewArea,
#txtCoverPreviewArea {
  border: 2px dashed transparent;
  border-radius: 10px;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

#coverImgPreviewMeta,
#txtCoverPreview {
  max-height: 200px;
  width: auto;
  max-width: 100%;
  border-radius: 8px;
  object-fit: contain;
}

@media (min-width: 769px) {
  #coverImgPreviewMeta,
  #txtCoverPreview {
    width: 50%;
    max-height: none;
    height: auto;
  }
}

.cover-interactive {
  cursor: pointer;
  border-color: var(--accent-primary) !important;
  background: rgba(59, 130, 246, 0.08);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.2);
}

.merge-image-panel {
  grid-column: 1 / -1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: rgba(15, 23, 42, 0.25);
  display: none;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.merge-image-panel.active {
  display: block;
}

.merge-image-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.merge-image-select-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
}

.merge-image-select-all input {
  accent-color: var(--danger);
}

.merge-image-select-count {
  color: var(--text-muted);
  font-weight: 600;
}

.merge-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  width: 100%;
  padding-right: 4px;
}

.merge-image-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  padding: 8px;
  cursor: pointer;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.merge-image-card input {
  margin-bottom: 6px;
  accent-color: var(--danger);
}

.merge-image-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 6px;
  display: block;
}

.merge-image-name {
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.35;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

/* Responsive */
@media (max-width: 768px) {
  .panel-col-left > .section:last-child {
    border-bottom: 1px solid rgba(100, 116, 139, 0.12);
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 0 minmax(0, 1fr);
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: 0 0 minmax(0, 1fr);
  }

  .sidebar {
    grid-column: 1;
    grid-row: 1;
    flex-direction: row;
    flex-wrap: nowrap;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px;
    gap: 8px;
  }

  .app-shell.sidebar-collapsed .sidebar {
    padding-top: 0;
    padding-bottom: 0;
    border-bottom-color: transparent;
  }

  .app-shell.sidebar-collapsed .sidebar-actions {
    pointer-events: auto;
  }

  .sidebar .tab-button {
    width: auto;
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
    text-align: center;
    white-space: normal;
    padding-left: 6px;
    padding-right: 6px;
  }

  .sidebar-footer {
    flex-direction: column;
    margin: 0;
    padding: 0;
    border-top: none;
    border-left: 1px solid var(--border);
    padding-left: 8px;
  }

  .sidebar-gutter {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    min-height: 0;
    border-right: 0;
    border-bottom: 0;
    justify-self: stretch;
  }

  .workspace {
    grid-column: 1;
    grid-row: 3;
  }

  .main-card {
    padding-bottom: 74px;
  }

  .sidebar-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    margin-top: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface);
  }

  #logModal {
    inset: auto 12px 84px auto;
  }

  #logModal .log-modal-card {
    width: min(360px, calc(100vw - 24px));
  }

  #logModal {
    left: 0 !important;
    right: 0 !important;
    top: 66.666vh !important;
    top: 66.666dvh !important;
    bottom: 0 !important;
    width: 100% !important;
    height: auto !important;
    max-width: none;
    padding: 0;
    background: var(--surface);
  }

  #logModal .log-modal-card {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    min-width: 0;
    min-height: 0;
    max-width: none;
    max-height: none;
    padding: 12px 14px max(12px, env(safe-area-inset-bottom));
    overflow: hidden;
    border-width: 1px 0 0;
    border-radius: 0;
    box-shadow: none;
  }

  #logModal .modal-header {
    margin-bottom: 8px;
    cursor: default;
    touch-action: auto;
  }

  #logModal .log-resize-handle {
    display: none;
  }

  body.log-panel-open .container {
    height: 66.666vh;
    height: 66.666dvh;
  }

  body.log-panel-open .sidebar-actions {
    bottom: 33.334vh;
    bottom: 33.334dvh;
  }

  .sidebar-action-group {
    flex-direction: row;
    gap: 8px;
  }

  .sidebar-action-group .btn {
    flex: 1;
  }

  .sidebar-toggle {
    left: auto;
    right: 9px;
    top: 0;
    width: 30px;
    height: 30px;
    transform: translateY(-50%);
    font-size: 12px;
  }

  .sidebar-toggle-icon {
    transform: none;
  }

  .app-shell.sidebar-collapsed .sidebar-toggle {
    left: auto;
    right: 9px;
    top: 9px;
    transform: none;
  }

  .section {
    padding: 18px;
  }

  .form-grid,
  .options-grid,
  .form-field-row {
    grid-template-columns: 1fr;
  }

  .form-grid > .form-field {
    grid-column: 1 / -1 !important;
  }

  .form-field-row > .form-field {
    grid-column: 1 / -1 !important;
  }

  #imageConfigPanel > .options-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  #imageConfigPanel > .options-grid > div > .option-card {
    padding: 10px 8px;
    gap: 6px;
  }

  .actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .actions .btn {
    flex: 1 1 calc(50% - 6px);
    min-width: 120px;
    justify-content: center;
  }

  .actions .status-badge {
    flex-basis: 100%;
    justify-content: center;
  }
}

/* Decorative Elements */
/* 로그는 모든 화면에서 본문 아래쪽 1/3을 사용하는 고정 패널로 표시한다. */
#logModal {
  left: 0 !important;
  right: 0 !important;
  top: 66.666vh !important;
  top: 66.666dvh !important;
  bottom: 0 !important;
  width: 100% !important;
  height: auto !important;
  max-width: none;
  padding: 0;
  background: var(--surface);
}

#logModal .log-modal-card {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  min-width: 0;
  min-height: 0;
  max-width: none;
  max-height: none;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom));
  overflow: hidden;
  border-width: 1px 0 0;
  border-radius: 0;
  box-shadow: none;
}

#logModal .modal-header {
  margin-bottom: 8px;
  cursor: default;
  touch-action: auto;
}

#logModal .log-resize-handle {
  display: none;
}

body.log-panel-open .container {
  height: 66.666vh;
  height: 66.666dvh;
}

body.log-panel-open .sidebar-actions {
  bottom: 33.334vh;
  bottom: 33.334dvh;
}

body.log-panel-open #txtChapterModal,
body.log-panel-open #mergeChapterModal {
  inset: 0 0 33.334vh;
  inset: 0 0 33.334dvh;
  height: auto;
  padding: 8px;
}

body.log-panel-open #txtChapterModal .txt-modal-card,
body.log-panel-open #mergeChapterModal .txt-modal-card {
  display: flex;
  flex-direction: column;
  height: calc(66.666vh - 16px);
  height: calc(66.666dvh - 16px);
  max-height: calc(66.666vh - 16px);
  max-height: calc(66.666dvh - 16px);
  overflow: hidden;
}

body.log-panel-open #txtChapterModal .txt-chapter-body-grid,
body.log-panel-open #mergeChapterModal .txt-chapter-body-grid {
  flex: 1;
  min-height: 0;
}

body.log-panel-open #txtChapterModal .txt-chapter-body-pane,
body.log-panel-open #mergeChapterModal .txt-chapter-body-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.log-panel-open #txtChapterModal .txt-chapter-editor,
body.log-panel-open #mergeChapterModal .txt-chapter-editor,
body.log-panel-open #txtChapterModal .txt-chapter-html-scroll,
body.log-panel-open #mergeChapterModal .txt-chapter-html-scroll {
  flex: 1;
  height: auto;
  min-height: 0;
  max-height: none;
}

body.log-panel-open #txtChapterModal .txt-chapter-html-preview,
body.log-panel-open #mergeChapterModal .txt-chapter-html-preview {
  height: 100%;
}

.decoration {
  position: fixed;
  pointer-events: none;
  opacity: 0.4;
  z-index: -1;
}

.decoration-1 {
  top: 10%;
  right: 10%;
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.3), transparent);
  filter: blur(60px);
  animation: float 8s ease-in-out infinite;
}

.decoration-2 {
  bottom: 10%;
  left: 10%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.3), transparent);
  filter: blur(80px);
  animation: float 10s ease-in-out infinite reverse;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-30px) scale(1.1);
  }
}

.merge-image-controls { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.merge-image-controls input { margin: 0; }
.merge-image-panel .merge-image-remove { flex: 0 0 18px; width: 18px; min-width: 18px; max-width: 18px; height: 18px; min-height: 18px; max-height: 18px; padding: 0; font-size: 12px; line-height: 1; }
.merge-image-head > .merge-image-remove,
.merge-image-controls > .merge-image-remove { margin-left: auto; }

.merge-image-card .image-output-path { display: block; width: 100%; min-width: 0; margin-top: 4px; padding: 0; border: 0; background: transparent; font: inherit; font-size: 11px; line-height: 1.4; color: var(--text-muted); text-align: left; white-space: normal; overflow-wrap: anywhere; cursor: pointer; }
.merge-image-card .image-output-path:not(:disabled):hover { color: var(--accent-primary); text-decoration: underline; }
.merge-image-card .image-output-path:disabled { cursor: default; }

.image-preview-frame { position: relative; }
.merge-image-card .image-resolution { width: auto; min-width: 0; border: 0; position: absolute; left: 4px; top: 4px; padding: 2px 5px; border-radius: 4px; background: rgba(0, 0, 0, .7); color: #fff; font-size: 11px; line-height: 1.4; font-variant-numeric: tabular-nums; cursor: pointer; }


.merge-image-cover-label { position: absolute; right: 4px; bottom: 4px; padding: 2px 5px; border-radius: 4px; background: rgba(0, 0, 0, .7); color: #fff; font-size: 11px; line-height: 1.4; font-weight: 600; pointer-events: none; }
.merge-image-card .image-preview-frame img { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.merge-image-cover-menu { position: fixed; z-index: 10000; padding: 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-secondary); box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.merge-image-cover-menu button { padding: 10px 14px; border: 0; border-radius: 5px; background: transparent; color: var(--text-primary); font: inherit; cursor: pointer; }
.merge-image-cover-menu button:hover, .merge-image-cover-menu button:focus-visible { background: var(--surface); }

/* 모든 파일 목록은 파일이 없어도 같은 드롭 영역을 유지합니다. */
.upload-file-list .file-list-scroll {
  min-height: 126px;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.upload-file-list .file-list-scroll:has(> .empty-state) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-file-list .file-list-scroll.dragover {
  background: rgba(6, 182, 212, 0.12);
  outline: 2px dashed var(--accent-tertiary);
  outline-offset: -2px;
  border-radius: 0 0 12px 12px;
  box-shadow: 0 8px 24px rgba(6, 182, 212, 0.28);
}

.file-add {
  opacity: 1;
}

.file-add:hover,
.file-add:focus-visible {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.08);
}

.upload-file-list .file-list-head {
  grid-template-columns: 16px 20px minmax(0, 1fr) 22px 22px 24px;
}

.file-clear {
  opacity: 1;
}

.file-clear:disabled {
  cursor: default;
  color: var(--text-muted);
  border-color: transparent;
  background: transparent;
}

#txtDetectedChapters .merge-toc-edit-text,
#txtUnlistedList [data-txt-unlisted-line] .toc-unlisted-name {
  touch-action: manipulation;
}

@media (hover: none), (any-pointer: coarse) {
  #txtUnlistedList [data-txt-unlisted-line] .toc-unlisted-name {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}

:is(#mergeTocPreviewList, #txtDetectedChapters).is-multi-select .merge-toc-edit-text:not([contenteditable="true"]) {
  -webkit-user-select: none;
  user-select: none;
}

.section-title-with-help { display: flex; align-items: center; gap: 2px; }
.toc-help-button { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 24px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--text-secondary); font-size: 22px; line-height: 1; cursor: pointer; }
.toc-help-button .bi { display: flex; align-items: center; }
.toc-help-button .bi::before { display: block; vertical-align: 0; }
.toc-help-button:hover, .toc-help-button:focus-visible { color: var(--accent-primary); background: var(--surface-hover); }
.toc-help-dialog { width: min(560px, calc(100% - 32px)); max-height: calc(100dvh - 32px); margin: auto; padding: 22px; overflow-y: auto; border: 1px solid var(--border); border-radius: 16px; background: var(--bg-secondary); color: var(--text-primary); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.toc-help-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.toc-help-dialog .modal-header h2 { margin: 0; font-size: 19px; }
.toc-help-dialog p, .toc-help-steps dd { color: var(--text-secondary); font-size: 13px; line-height: 1.75; }
.toc-help-steps { margin: 16px 0 0; }
.toc-help-steps dt { margin-top: 16px; font-size: 14px; font-weight: 700; }
.toc-help-steps dd { margin: 4px 0 0; }
html.toc-help-open { overflow: hidden; }

@media (max-width: 768px) {
  .form-grid.txt-version-font-grid,
  .options-grid.merge-main-options,
  .options-grid.merge-style-options,
  .options-grid.txt-convert-options,
  .options-grid.epub-txt-convert-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .form-grid.txt-version-font-grid > .form-field {
    grid-column: auto !important;
    min-width: 0;
  }

  :is(.merge-main-options, .merge-style-options, .txt-convert-options, .epub-txt-convert-options) > .option-card {
    padding: 10px 8px;
    gap: 6px;
  }
}
