:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #181b22;
  --border: #2a2f3a;
  --text: #e6e6e6;
  --muted: #9097a6;
  --accent: #818cf8;
  --accent-hover: #a5b1ff;
  --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); }

#app { min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, transform 0.05s;
}
button:hover { background: #232734; }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent);
  color: #1a1d2a;
  border-color: var(--accent);
  font-weight: 600;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--danger); border-color: #5a2a2a; }
button.danger:hover { background: #2a1818; }
button.icon { padding: 0.35rem 0.55rem; }

input[type="text"], input[type="url"], textarea {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .title { font-weight: 600; font-size: 1.05rem; }
.topbar .crumbs { color: var(--muted); font-size: 0.95rem; display: flex; gap: 0.4rem; align-items: center; }
.topbar .crumbs .sep { opacity: 0.5; }
.topbar .spacer { flex: 1; }

.page { padding: 1.25rem 1.25rem 3rem; max-width: 980px; width: 100%; margin: 0 auto; }
.page h1 { margin: 0 0 1rem; font-size: 1.4rem; }
.page h2 { margin: 1.5rem 0 0.75rem; font-size: 1.1rem; }

.empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
}

.unit-grid, .section-list { display: grid; gap: 0.6rem; }
.unit-card, .section-row, .part-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.unit-card .meta, .section-row .meta { color: var(--muted); font-size: 0.9rem; }
.unit-card .grow, .section-row .grow { flex: 1; }
.unit-card .unit-title { font-weight: 600; }
.unit-card .expr { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; }
.unit-card.clickable, .section-row.clickable { cursor: pointer; }
.unit-card.clickable:hover, .section-row.clickable:hover { background: #1f232c; }

.part-block { flex-direction: column; align-items: stretch; }
.part-block .part-header { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.part-block .part-label { font-weight: 600; }
.part-block .part-pres { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.part-block .pres-tag {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: #2a2f4a; color: #c7d2fe; padding: 0.25rem 0.55rem; border-radius: 999px; font-size: 0.85rem;
}
.part-block .section-list { margin-top: 0.5rem; }
.part-block .add-section { align-self: flex-start; margin-top: 0.6rem; }

.error { color: var(--danger); font-size: 0.9rem; margin-top: 0.4rem; min-height: 1.1em; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 1.25rem;
  width: min(440px, 92vw); box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 0.85rem; font-size: 1.1rem; }
.modal.export-modal { width: min(720px, 92vw); }
.modal .export-area {
  width: 100%;
  height: 280px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  white-space: pre;
  margin-bottom: 0.85rem;
}
.modal .row { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.85rem; }
.modal label { font-size: 0.9rem; color: var(--muted); }
.modal .actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.modal .help { font-size: 0.82rem; color: var(--muted); }

.editor-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 0;
}
.editor-layout .pane {
  border-right: 1px solid var(--border);
  overflow: auto;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}
.editor-layout .pane:last-child { border-right: none; background: var(--bg); }

.pres-pane { padding: 0.5rem; }
.pres-pane .pres-empty {
  height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--muted); padding: 2rem; text-align: center;
}
.pres-pane canvas { display: block; margin: 0 auto 0.5rem; max-width: 100%; box-shadow: var(--shadow); background: white; }
.pres-pane iframe { width: 100%; height: 100%; min-height: 70vh; border: none; }

.notes-pane { padding: 1.25rem 1.5rem; display: flex; flex-direction: column; }
.notes-pane .section-title-input {
  font-size: 1.4rem; font-weight: 600; border: none; background: transparent;
  padding: 0.25rem 0; margin-bottom: 0.85rem; border-bottom: 1px solid transparent;
}
.notes-pane .section-title-input:focus { outline: none; border-bottom-color: var(--accent); }
.notes-pane .save-status { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.5rem; min-height: 1em; }

.bullet-editor {
  outline: none;
  font-size: 1rem;
  line-height: 1.6;
  flex: 1;
  min-height: 0;
}
.bullet-editor ul {
  list-style: none;
  padding-left: 1.4rem;
  margin: 0;
}
.bullet-editor > ul { padding-left: 0.4rem; }
.bullet-editor li {
  position: relative;
  padding: 0.05rem 0 0.05rem 1.1rem;
  min-height: 1.6em;
}
.bullet-editor li::before {
  content: "\2022";
  position: absolute;
  left: 0;
  top: 0.05em;
  color: var(--muted);
  font-size: 1.05em;
}
.bullet-editor li > ul li::before { content: "\25E6"; }
.bullet-editor li > ul > li > ul li::before { content: "\25AA"; font-size: 0.8em; top: 0.25em; }

.notes-readonly .unit-name { margin: 0.25rem 0 1rem; }
.notes-readonly .section-heading {
  margin: 1.25rem 0 0.4rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}
.notes-readonly ul { margin: 0.25rem 0 0.75rem; padding-left: 1.5rem; }
.notes-readonly ul ul { margin: 0.1rem 0; }
.notes-readonly li { margin: 0.15rem 0; line-height: 1.55; }
.notes-readonly .section-block + .section-block { margin-top: 0.25rem; }
.notes-readonly .subtle { padding: 0.15rem 0 0.5rem; }

.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: #2a2f3a; color: var(--text); border: 1px solid var(--border); padding: 0.6rem 0.95rem; border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 1000; font-size: 0.9rem; max-width: 90vw;
}

.row-actions { display: flex; gap: 0.4rem; }

.flex-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.subtle { color: var(--muted); font-size: 0.9rem; }
