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

:root {
  --bg: #0d1117;
  --bg-surface: #161b22;
  --bg-elevated: #1c2129;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --danger: #f85149;
  --success: #3fb950;
  --radius: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* Controls Panel */
.controls {
  width: 390px;
  min-width: 390px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 24px;
  overflow-y: auto;
  max-height: 100vh;
  position: sticky;
  top: 0;
}

.controls h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.controls .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.controls .subtitle a {
  color: var(--accent);
  text-decoration: none;
}

.controls .subtitle a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Sections */
.options-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.options-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.options-section h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-header h2 {
  margin-bottom: 0;
}

/* Form Controls */
.option-row {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.option-row > label:first-child {
  font-size: 13px;
  min-width: 110px;
  color: var(--text-muted);
}

.option-row input[type="number"],
.option-row input[type="text"],
.option-row select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}

.option-row input:focus,
.option-row select:focus {
  border-color: var(--accent);
}

.option-row input[type="number"] {
  width: 70px;
  flex: none;
}

.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  accent-color: var(--accent);
}

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  transition: background 0.15s;
}

.btn-add {
  background: var(--accent);
  color: #fff;
}

.btn-add:hover {
  background: var(--accent-hover);
}

.btn-copy {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-copy:hover {
  background: var(--border);
}

.btn-copy.copied {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

/* Book List */
#bookList {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.book-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  cursor: grab;
  transition: border-color 0.15s, opacity 0.15s;
}

.book-item:active {
  cursor: grabbing;
}

.book-item.dragging {
  opacity: 0.4;
}

.book-item.drag-over {
  border-color: var(--accent);
}

.book-item-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.book-item-header .drag-handle {
  color: var(--text-muted);
  font-size: 12px;
  cursor: grab;
  user-select: none;
  opacity: 0.5;
}

.book-item-header .book-title-display {
  font-size: 12px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'SFMono-Regular', Consolas, monospace;
}

.book-item-header .btn-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 2px;
  line-height: 1;
}

.book-item-header .btn-delete:hover {
  color: var(--danger);
}

.book-fields {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.book-field-row {
  display: flex;
  gap: 4px;
  align-items: center;
  width: 100%;
}

.book-field {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.book-field label {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.book-field input,
.book-field select {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 3px 6px;
  font-size: 12px;
  outline: none;
}

.book-field input:focus,
.book-field select:focus {
  border-color: var(--accent);
}

.book-field input,
.book-field select {
  flex: 1;
  min-width: 0;
}

/* Preview Panel */
.preview {
  flex: 1;
  padding: 24px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.preview-header h2 {
  font-size: 16px;
  font-weight: 600;
}

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

.preview-container {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  padding: 32px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

#output {
  font-family: 'SFMono-Regular', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 13px;
  line-height: 1.3;
  color: var(--text);
  white-space: pre;
  margin: 0;
}

#output a {
  color: var(--text);
  text-decoration: none;
}

#output a:hover {
  color: var(--accent);
}

/* Raw Output */
.raw-output {
  margin-top: 16px;
}

.raw-output summary {
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 8px;
}

.raw-output textarea {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  padding: 12px;
  resize: vertical;
  outline: none;
}

/* Responsive */
@media (max-width: 960px) {
  .app {
    flex-direction: column;
  }

  .controls {
    width: 100%;
    min-width: 0;
    max-height: none;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .preview {
    min-height: 50vh;
  }
}
