:root {
  --bg-dark: #0f1117;
  --bg-panel: #171b24;
  --bg-card: #1e2430;
  --bg-hover: #262e3d;
  --border-color: #2b3446;
  --text-main: #f0f4f8;
  --text-muted: #9aa5b5;
  --accent-gold: #d4a853;
  --accent-gold-hover: #e3ba68;
  --accent-blue: #4f8cff;
  --accent-emerald: #2ec4b6;
  --danger: #ff6b6b;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: "Pretendard", "Noto Sans KR", -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.5;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 18px 24px;
  background: linear-gradient(135deg, #191e29 0%, #131720 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 22px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  font-size: 32px;
  background: rgba(212, 168, 83, 0.14);
  border: 1px solid rgba(212, 168, 83, 0.35);
  width: 54px;
  height: 54px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

.header-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  font-weight: 600;
}

.badge-gold {
  background: rgba(212, 168, 83, 0.15);
  color: #f3c978;
  border: 1px solid rgba(212, 168, 83, 0.35);
}

.badge-emerald {
  background: rgba(46, 196, 182, 0.15);
  color: #64dfdf;
  border: 1px solid rgba(46, 196, 182, 0.35);
}

.badge-indigo {
  background: rgba(79, 140, 255, 0.15);
  color: #8ab4ff;
  border: 1px solid rgba(79, 140, 255, 0.35);
}

.main-grid {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 22px;
  align-items: start;
}

@media (max-width: 1080px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 22px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
}

.mode-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-dark);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--accent-gold);
}

.dropzone {
  border: 2px dashed #3a465e;
  border-radius: 10px;
  padding: 24px 18px;
  text-align: center;
  background: rgba(30, 36, 48, 0.55);
  cursor: pointer;
  transition: all 0.2s;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent-gold);
  background: rgba(212, 168, 83, 0.07);
}

.dropzone-icon {
  font-size: 32px;
  margin-bottom: 6px;
}

.dropzone-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.dropzone-desc {
  font-size: 12.5px;
  color: var(--text-muted);
}

.server-picker-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

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

.selected-books-wrap {
  margin-top: 16px;
}

.section-subhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.subhead-actions {
  display: flex;
  gap: 12px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent-blue);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.btn-link:hover {
  text-decoration: underline;
}

.text-danger {
  color: var(--danger);
}

.book-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 210px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-dark);
}

.book-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-color);
  font-size: 13.5px;
  cursor: pointer;
}

.book-item:last-child {
  border-bottom: none;
}

.book-item:hover {
  background: var(--bg-hover);
}

.book-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.book-item-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-item-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(79, 140, 255, 0.16);
  color: #9bc0ff;
}

.empty-item {
  padding: 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 20px 0;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #d6deeb;
}

.input-with-btn {
  display: flex;
  gap: 8px;
}

input[type="text"] {
  width: 100%;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13.5px;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-gold);
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  font-size: 12px;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 4px 9px;
  cursor: pointer;
}

.chip:hover {
  color: #fff;
  border-color: var(--accent-gold);
}

.local-dir-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  padding: 9px 12px;
  border-radius: 8px;
}

.local-dir-status {
  font-size: 12.5px;
  color: var(--text-muted);
}

.checkbox-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.check-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
}

.meta-details {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.meta-details summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}

@media (max-width: 640px) {
  .meta-grid {
    grid-template-columns: 1fr;
  }
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 15px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
}

.btn-lg {
  width: 100%;
  padding: 13px 20px;
  font-size: 15.5px;
}

.btn-primary {
  background: linear-gradient(135deg, #d4a853 0%, #b8862d 100%);
  color: #111;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #e2b866 0%, #ca963b 100%);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-outline {
  background: transparent;
  color: var(--accent-gold);
  border: 1px solid rgba(212, 168, 83, 0.5);
}

.btn-outline:hover {
  background: rgba(212, 168, 83, 0.1);
}

.progress-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(212, 168, 83, 0.1);
  color: #f3c978;
  font-size: 13.5px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(243, 201, 120, 0.3);
  border-top-color: #f3c978;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

.preview-container {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px;
  max-height: 360px;
  overflow-y: auto;
}

.preview-empty {
  text-align: center;
  padding: 28px 14px;
  color: var(--text-muted);
  font-size: 13.5px;
}

.toc-preview-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toc-part-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
}

.toc-part-head {
  font-weight: 700;
  color: var(--accent-gold);
  font-size: 13.5px;
  margin-bottom: 6px;
}

.toc-chap-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.toc-chap-chip {
  font-size: 12px;
  background: var(--bg-dark);
  padding: 3px 8px;
  border-radius: 5px;
  color: #cfd8e3;
}

.sample-prose-box {
  margin-top: 12px;
  background: #f7f4ed;
  color: #1a1a1a;
  padding: 14px 16px;
  border-radius: 8px;
  font-family: "Noto Serif KR", "NanumMyeongjo", serif;
  font-size: 13.5px;
  line-height: 1.85;
}

.sample-prose-box p {
  margin: 0;
  text-indent: 1em;
}

.results-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 430px;
  overflow-y: auto;
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.result-title {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}

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

.result-path {
  font-size: 12px;
  color: #9bc0ff;
  background: rgba(15, 17, 23, 0.65);
  padding: 5px 8px;
  border-radius: 6px;
  font-family: monospace;
  word-break: break-all;
}

.result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.dl-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--bg-dark);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.dl-btn:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

.modal-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-color);
}

.path-input {
  flex: 1;
  font-family: monospace;
}

.modal-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 18px;
  border-bottom: 1px solid var(--border-color);
}

.modal-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  min-height: 260px;
}

.fs-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
}

.fs-row:hover {
  background: var(--bg-hover);
}

.fs-row.selected {
  background: rgba(212, 168, 83, 0.16);
  border: 1px solid rgba(212, 168, 83, 0.45);
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
}

.modal-info {
  font-size: 12.5px;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  gap: 8px;
}
