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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --accent: #e94560;
  --accent2: #0f3460;
  --text: #eee;
  --text-dim: #999;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

html { font-size: 16px; }
body {
  font-family: "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh;
}

/* Header */
header { text-align: center; padding: 2rem 1rem 1rem; background: var(--surface); border-bottom: 2px solid var(--accent); }
header h1 { font-size: 1.8rem; letter-spacing: 0.05em; }
header .subtitle { color: var(--text-dim); font-size: 0.9rem; margin-top: 0.25rem; }

/* Layout */
main { max-width: 760px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
section { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: var(--shadow); }
h2 { font-size: 1.1rem; margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--accent2); }
.hint { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.25rem; }

/* Form */
.form-row { margin-bottom: 0.75rem; }
.form-row label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.25rem; }
.form-row input {
  width: 100%; padding: 0.5rem 0.75rem; background: var(--bg);
  border: 1px solid var(--accent2); border-radius: var(--radius); color: var(--text); font-size: 1rem;
}
.form-row input:focus, .form-row select:focus { outline: none; border-color: var(--accent); }
.form-row select {
  width: 100%; padding: 0.5rem 0.75rem; background: var(--bg);
  border: 1px solid var(--accent2); border-radius: var(--radius); color: var(--text); font-size: 1rem;
}

/* Drop zone */
#drop-zone {
  border: 2px dashed var(--accent2); border-radius: var(--radius);
  padding: 2.5rem 1rem; text-align: center; cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
#drop-zone:hover, #drop-zone.dragover { border-color: var(--accent); background: rgba(233,69,96,0.05); }
#drop-zone .drop-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }

.import-row { margin-top: 0.75rem; text-align: center; }

/* Chapter list */
#chapter-list { list-style: none; }
.chapter-item {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem;
  background: var(--bg); border-radius: var(--radius); margin-bottom: 0.5rem;
  cursor: grab; border: 1px solid transparent; transition: background 0.15s;
}
.chapter-item:active { cursor: grabbing; }
.chapter-item.dragging { opacity: 0.4; border: 1px dashed var(--accent); }
.chapter-item.drag-over { border: 1px solid var(--accent); background: rgba(233,69,96,0.08); }
.chapter-handle { color: var(--text-dim); font-size: 1.2rem; flex-shrink: 0; user-select: none; }
.chapter-info { flex: 1; min-width: 0; }
.chapter-name { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-name-input {
  width: 100%; background: var(--surface); border: 1px solid var(--accent2);
  border-radius: 4px; color: var(--text); padding: 0.2rem 0.4rem; font-size: 0.95rem;
}
.chapter-meta { font-size: 0.75rem; color: var(--text-dim); }
.chapter-remove {
  background: none; border: none; color: var(--text-dim); font-size: 1.1rem;
  cursor: pointer; padding: 0.25rem; border-radius: 4px; flex-shrink: 0;
}
.chapter-remove:hover { color: var(--accent); background: rgba(233,69,96,0.1); }

/* Progress */
.progress-bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-bottom: 0.5rem; }
.progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.3s; border-radius: 3px; }
#progress-text { font-size: 0.85rem; color: var(--text-dim); text-align: center; white-space: pre-line; }

/* Buttons */
.output-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }
.btn {
  padding: 0.6rem 1.2rem; border: 1px solid var(--accent2); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: 0.9rem; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); font-weight: bold; }
.btn-primary:hover:not(:disabled) { background: #d63851; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }

/* === Inspector === */
.ir-chapter { margin-bottom: 0.5rem; }
.ir-chapter-header {
  padding: 0.6rem 0.75rem; background: var(--bg); border-radius: var(--radius);
  cursor: pointer; font-size: 0.95rem; display: flex; align-items: center; gap: 0.5rem;
  transition: background 0.15s;
}
.ir-chapter-header:hover { background: rgba(233,69,96,0.06); }
.ir-toggle { font-size: 0.75rem; color: var(--text-dim); width: 1em; text-align: center; }
.ir-ch-meta { font-size: 0.8rem; color: var(--text-dim); margin-left: auto; }

.ir-chapter-body { padding: 0.25rem 0 0 0; }

.ir-page {
  background: var(--bg); border-radius: var(--radius); margin-bottom: 0.5rem;
  border: 1px solid rgba(255,255,255,0.05); overflow: hidden;
}
.ir-page-header {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem;
  padding: 0.5rem 0.75rem; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.ir-page-num { font-size: 0.85rem; font-weight: bold; color: var(--accent); }
.ir-page-controls { display: flex; align-items: center; gap: 0.4rem; margin-left: auto; flex-wrap: wrap; }
.ir-tab {
  padding: 0.2rem 0.6rem; border: 1px solid var(--accent2); border-radius: 4px;
  background: transparent; color: var(--text-dim); font-size: 0.75rem; cursor: pointer;
}
.ir-tab.active { background: var(--accent2); color: var(--text); }
.ir-tab:hover { border-color: var(--accent); }
.ir-fallback-label { font-size: 0.75rem; color: var(--text-dim); display: flex; align-items: center; gap: 0.25rem; cursor: pointer; }
.ir-use-fallback { accent-color: var(--accent); }

/* Text view */
.ir-text-view { padding: 0.5rem 0.75rem; }
.ir-element { display: flex; align-items: flex-start; gap: 0.5rem; margin-bottom: 0.35rem; }
.ir-el-badge {
  flex-shrink: 0; font-size: 0.65rem; font-weight: bold; padding: 0.1rem 0.35rem;
  border-radius: 3px; background: var(--accent2); color: var(--text-dim);
  min-width: 2em; text-align: center; margin-top: 0.15rem;
}
.ir-el-text {
  flex: 1; font-size: 0.85rem; line-height: 1.5; padding: 0.15rem 0.3rem;
  border-radius: 3px; border: 1px solid transparent; min-height: 1.4em;
  transition: border-color 0.15s;
}
.ir-el-text:focus { outline: none; border-color: var(--accent); background: rgba(233,69,96,0.05); }
.ir-el-text:hover { border-color: rgba(255,255,255,0.1); }

.ir-thumb { max-width: 120px; max-height: 80px; border-radius: 3px; flex-shrink: 0; }
.ir-caption-input {
  flex: 1; background: transparent; border: 1px solid var(--accent2); border-radius: 3px;
  color: var(--text); padding: 0.15rem 0.4rem; font-size: 0.8rem;
}
.ir-caption-input:focus { outline: none; border-color: var(--accent); }

.ir-empty { font-size: 0.8rem; color: var(--text-dim); padding: 0.5rem; font-style: italic; }

/* Image view */
.ir-image-view { padding: 0.5rem; text-align: center; }
.ir-image-view img { max-width: 100%; height: auto; border-radius: 4px; }

/* Footer */
footer { text-align: center; padding: 1.5rem; color: var(--text-dim); font-size: 0.8rem; }

/* Responsive */
@media (max-width: 480px) {
  header h1 { font-size: 1.4rem; }
  section { padding: 1rem; }
  .output-actions { flex-direction: column; }
  .btn { width: 100%; text-align: center; }
  .ir-page-header { flex-direction: column; align-items: flex-start; }
  .ir-page-controls { margin-left: 0; }
}
