:root {
  --paper: #f3ebe2;
  --card: #fbf7f1;
  --ink: #1a1a1a;
  --ink-soft: #3d3d3d;
  --muted: #9a938b;
  --line: #c5beb6;
  --accent: #d4916e;
  --danger: #c0392b;
  --serif-display: "Playfair Display", Georgia, serif;
  --serif-body: "Literata", Georgia, serif;
  --sans: "Inter", -apple-system, sans-serif;
}

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

html { height: 100%; }

body {
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif-body);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 24px calc(32px + env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* --- типографика --- */
.eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--ink-soft);
}

h1 {
  font-family: var(--serif-display);
  font-weight: 400;
  font-size: 34px;
  line-height: 1.15;
}

.rule { border: 0; border-top: 1px solid var(--line); width: 100%; }

/* --- шапка --- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 18px;
}

.back {
  font-family: var(--sans);
  font-size: 22px;
  text-decoration: none;
  color: var(--ink);
  padding: 4px 10px 4px 0;
}

/* --- кнопки --- */
button { font: inherit; cursor: pointer; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  border-radius: 4px;
  padding: 12px 22px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  text-decoration: none;
}

.btn-solid { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-ghost { border-color: transparent; color: var(--muted); letter-spacing: 2px; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* --- главная --- */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 26px 0 30px;
}

.record-btn {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 0 rgba(26, 26, 26, 0.08);
}

.record-btn:active { transform: scale(0.97); }
.record-btn svg { width: 44px; height: 44px; }

.icon-row { display: flex; gap: 20px; padding-top: 4px; }

.icon-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.icon-btn:active { background: var(--card); }

/* --- списки --- */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 10px;
}

.section-head .more {
  font-family: var(--serif-body);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
  text-decoration: none;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
}

.row:last-child { border-bottom: 1px solid var(--line); }

.row-main { display: flex; align-items: baseline; gap: 14px; min-width: 0; }

.row-num {
  font-family: var(--serif-display);
  font-size: 16px;
  color: var(--accent);
  min-width: 20px;
}

.row-title { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-meta { font-family: var(--sans); font-size: 11px; color: var(--muted); }

.row-sub {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--muted);
  padding: 4px 0 0 34px;
}

.chev { color: var(--line); flex: none; }

.list-item { display: block; padding: 16px 0; border-top: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.list-item:last-child { border-bottom: 1px solid var(--line); }

/* --- запись --- */
.rec-screen { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center; }

.rec-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 28px;
}

.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: pulse 1.6s infinite; }

@keyframes pulse { 50% { opacity: 0.25; } }

.rec-timer { font-family: var(--serif-display); font-size: 56px; padding-top: 8px; }

.rec-save { font-family: var(--sans); font-size: 11px; color: var(--muted); min-height: 16px; }

.rec-wave-zone { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 24px; width: 100%; }

canvas.wave { width: 100%; max-width: 320px; height: 72px; }

.rec-hint { font-style: italic; font-size: 15px; color: var(--ink-soft); }

.stop-btn {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stop-btn::after { content: ""; width: 26px; height: 26px; border-radius: 3px; background: #fff; }

.rec-bottom { display: flex; flex-direction: column; align-items: center; gap: 18px; padding-bottom: 16px; }

/* --- статусы обработки --- */
.wait {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 40px 0;
}

.wait .big { font-family: var(--serif-display); font-size: 26px; }
.wait .note { font-style: italic; color: var(--ink-soft); font-size: 15px; max-width: 320px; }

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}

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

/* --- карточки версий --- */
.version-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.version-head { display: flex; justify-content: space-between; align-items: baseline; }

.version-label {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--accent);
  text-transform: uppercase;
}

.version-toggle {
  font-family: var(--serif-body);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-soft);
  background: none;
  border: none;
  padding: 0;
}

.version-excerpt { font-size: 15px; line-height: 1.55; }

.fine-print { font-style: italic; font-size: 13px; color: var(--muted); text-align: center; padding-top: 4px; }

/* --- чтение --- */
.prose { font-size: 17px; line-height: 1.65; }
.prose.with-bar { padding-bottom: 110px; }
.version-card .prose { font-size: 15px; line-height: 1.55; }
.prose h1 { font-size: 30px; padding: 2px 0 6px; }
.prose h2, .prose h3 { font-family: var(--serif-display); font-weight: 400; font-size: 22px; padding-top: 10px; }
.prose p { padding: 9px 0; }
.prose h2 + p, .prose h3 + p { padding-top: 4px; }
.prose blockquote { border-left: 2px solid var(--accent); padding: 4px 0 4px 16px; font-style: italic; color: var(--ink-soft); }
.prose ul, .prose ol { padding: 9px 0 9px 24px; }
.prose .tick { width: 40px; height: 2px; background: var(--accent); margin: 4px 0 10px; }

.action-bar {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 48px), 592px);
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 36px;
}

.action-bar .main-action {
  flex: 1;
  height: 52px;
  border-radius: 26px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.action-bar .side-action {
  width: 52px;
  height: 52px;
  border-radius: 26px;
  border: none;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- формы --- */
textarea {
  width: 100%;
  min-height: 40dvh;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 16px;
  font-family: var(--serif-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  resize: vertical;
}

textarea:focus { outline: none; border-color: var(--ink-soft); }

.form-actions { display: flex; gap: 10px; padding-top: 16px; flex-wrap: wrap; }

/* --- прочее --- */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px 16px;
  margin-bottom: 22px;
  text-decoration: none;
  color: var(--ink);
}

.banner .spinner { width: 18px; height: 18px; flex: none; }
.banner span { font-style: italic; font-size: 15px; }

.error-box {
  background: var(--card);
  border: 1px solid var(--danger);
  border-radius: 4px;
  padding: 16px;
  font-size: 14px;
  color: var(--danger);
  margin: 12px 0;
  overflow-wrap: break-word;
}

.footer-links {
  margin-top: auto;
  padding-top: 36px;
  display: flex;
  justify-content: center;
  gap: 24px;
}

.footer-links a {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
}

.empty { font-style: italic; color: var(--muted); padding: 24px 0; text-align: center; }

/* плашка «комментарий к выделенному» */
.sel-bar {
  position: fixed;
  bottom: calc(84px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 48px), 592px);
  z-index: 10;
}

.sel-bar .main-action {
  width: 100%;
  height: 48px;
  border-radius: 26px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
}

/* --- редактор оглавления --- */
.toc-section {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 0 8px;
}

.toc-section input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--line);
  padding: 4px 0;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.toc-section input:focus { outline: none; border-bottom-color: var(--accent); }

.toc-x {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
}

.toc-row { cursor: default; user-select: none; -webkit-user-select: none; }

.toc-row.dragging { opacity: 0.55; background: var(--card); }

.idea-check { display: flex; align-items: center; padding-right: 4px; }

.idea-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.drag-handle {
  touch-action: none;
  cursor: grab;
  color: var(--muted);
  font-size: 18px;
  padding: 6px 10px 6px 2px;
}
