:root {
  --ink: #171512;
  --ink-soft: #4a453d;
  --paper: #f4eee4;
  --paper-2: #ebe3d4;
  --cream: #fbf7f0;
  --line: rgba(23, 21, 18, 0.12);
  --brick: #b8431f;
  --brick-deep: #8f3014;
  --moss: #2f4a3d;
  --shadow: 0 24px 60px rgba(23, 21, 18, 0.12);
  --ui: "Manrope", system-ui, sans-serif;
  --display: "Fraunces", "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--ui);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(184, 67, 31, 0.08), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(47, 74, 61, 0.08), transparent 45%),
    var(--paper);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brick); }

/* CSS display на .busy/.modal/.editor перебивает нативный [hidden] { display:none } */
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 247, 240, 0.72);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  padding: 0;
}
.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--display);
  font-style: italic;
  border-radius: 8px;
}
.brand-name {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: 0.12em;
  font-size: 14px;
}
.topbar-note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
  flex: 1;
}
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.ghost, .solid, .icon-btn {
  border-radius: 999px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: var(--cream);
}
.ghost.light {
  background: transparent;
  color: #f4eee4;
  border-color: rgba(255,255,255,0.2);
}
.solid {
  background: var(--brick);
  color: #fffaf4;
  border-color: transparent;
}
.solid:hover { background: var(--brick-deep); }
.solid.wide { padding: 12px 22px; }
.icon-btn { width: 40px; height: 40px; padding: 0; }

.home {
  width: min(920px, calc(100% - 40px));
  margin: 0 auto;
  padding: 56px 0 80px;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--moss);
  margin: 0 0 16px;
}
.hero h1 {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(40px, 6vw, 68px);
  line-height: 1.05;
  margin: 0 0 16px;
  letter-spacing: -0.03em;
}
.hero h1 em {
  font-style: italic;
  color: var(--brick);
}
.lede {
  font-size: 18px;
  line-height: 1.5;
  color: var(--ink-soft);
  max-width: 640px;
  margin: 0 0 36px;
}

.composer {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.mode-switch {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--paper-2);
  border-radius: 999px;
  width: fit-content;
  margin-bottom: 12px;
}
.mode {
  border: 0;
  background: transparent;
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--ink-soft);
}
.mode.is-on {
  background: var(--ink);
  color: var(--cream);
}
#source {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: #fff;
  resize: vertical;
  min-height: 180px;
  line-height: 1.5;
}
.composer-row {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr 0.9fr auto;
  gap: 10px;
  margin-top: 12px;
  align-items: end;
}
.field { display: grid; gap: 6px; font-size: 12px; color: var(--ink-soft); }
.field input, .field select {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
}
.hint { font-size: 13px; color: var(--ink-soft); margin: 12px 4px 4px; }
code { font-size: 0.92em; background: var(--paper-2); padding: 1px 5px; border-radius: 4px; }

.editor {
  display: grid;
  grid-template-columns: 196px 1fr 280px;
  gap: 16px;
  padding: 16px 20px 32px;
  flex: 1;
}
.thumbs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  max-height: calc(100vh - 110px);
  padding-right: 4px;
}
.thumb {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 0;
  text-align: left;
  overflow: hidden;
}
.thumb.is-on { outline: 2px solid var(--brick); }
.thumb-num {
  display: block;
  font-size: 11px;
  padding: 6px 8px 0;
  color: var(--ink-soft);
}
.thumb .slide {
  pointer-events: none;
  border-radius: 0 0 11px 11px;
  border: 0;
  width: 100%;
}

.stage-wrap { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.stage {
  background: #d8d0c3;
  border-radius: 20px;
  padding: 18px;
  display: grid;
  place-items: center;
  min-height: 0;
}
.stage .slide {
  width: min(100%, calc((100vh - 180px) * 16 / 9));
  box-shadow: 0 18px 50px rgba(0,0,0,0.18);
}
.stage-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  color: var(--ink-soft);
}

.inspector {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 110px);
  overflow: auto;
}
.inspector h3 {
  margin: 0 0 4px;
  font-family: var(--display);
  font-size: 22px;
  font-weight: 500;
}
.inspector textarea, .inspector input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}
.inspector textarea { min-height: 90px; resize: vertical; }
.mini-images {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.mini-images button {
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16/10;
}
.mini-images img { width: 100%; height: 100%; object-fit: cover; display: block; }

.slide {
  container-type: inline-size;
  aspect-ratio: 16 / 9;
  position: relative;
  overflow: hidden;
  background: var(--bg, #f4efe6);
  color: var(--text, #1c1915);
  font-family: var(--font-body, Manrope, sans-serif);
  border-radius: 4px;
}
.slide * { position: relative; z-index: 1; }
.slide-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
}
.slide-shade {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--bg) 92%, transparent), color-mix(in srgb, var(--bg) 35%, transparent));
}
.slide.layout-cover .slide-shade,
.slide.layout-closing .slide-shade {
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--bg) 88%, black 12%) 80%);
}
.slide-pattern {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.35;
}
.slide-pattern.grain {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");
}
.slide-pattern.dots {
  background-image: radial-gradient(currentColor 0.8px, transparent 0.9px);
  background-size: 18px 18px;
  opacity: 0.08;
}
.slide-pattern.grid {
  background-image:
    linear-gradient(color-mix(in srgb, var(--text) 10%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--text) 10%, transparent) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.5;
}

.slide-inner {
  height: 100%;
  padding: 6.2cqw 6.6cqw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.4cqw;
}
.kicker {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 1.15cqw;
  color: var(--accent);
  font-weight: 600;
  margin: 0;
}
.slide h2, .slide h3 {
  font-family: var(--font-heading, "Playfair Display", serif);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.12;
  margin: 0;
}
.slide h2 { font-size: 3.8cqw; max-width: 22ch; }
.slide .lead {
  font-size: 1.55cqw;
  line-height: 1.45;
  color: var(--muted);
  max-width: 46ch;
  margin: 0;
}
.slide p.body {
  font-size: 1.7cqw;
  line-height: 1.45;
  margin: 0;
  max-width: 52ch;
}
.slide ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 1cqw;
}
.slide li {
  font-size: 1.7cqw;
  line-height: 1.35;
  padding-left: 1.6cqw;
  position: relative;
}
.slide li::before {
  content: "";
  width: 0.7cqw;
  height: 0.7cqw;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  left: 0;
  top: 0.65cqw;
}

.layout-cover .slide-inner,
.layout-closing .slide-inner,
.layout-section .slide-inner {
  justify-content: flex-end;
}
.layout-cover h2 { font-size: 6.1cqw; max-width: 16ch; }
.layout-section h2 { font-size: 5.4cqw; }
.layout-quote .slide-inner { justify-content: center; }
.layout-quote blockquote {
  margin: 0;
  font-family: var(--font-heading, "Playfair Display", serif);
  font-size: 3.3cqw;
  line-height: 1.2;
  font-style: italic;
  max-width: 18ch;
}
.layout-quote cite {
  color: var(--muted);
  font-style: normal;
  font-size: 1.3cqw;
}

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 100%;
}
.split-grid .copy {
  padding: 6cqw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.2cqw;
}
.split-grid .photo {
  background-size: cover;
  background-position: center;
}
.layout-split-left .split-grid { direction: rtl; }
.layout-split-left .split-grid > * { direction: ltr; }

.stats-grid, .cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.4cqw;
  margin-top: 1cqw;
}
.stat, .card {
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
  border-radius: 1.2cqw;
  padding: 1.6cqw 1.8cqw;
}
.stat strong {
  display: block;
  font-family: var(--font-heading, serif);
  font-size: 3.4cqw;
  color: var(--accent);
  line-height: 1;
}
.stat span, .card p { color: var(--muted); font-size: 1.25cqw; }
.card h3 { font-size: 1.7cqw; margin-bottom: 0.4cqw; }

.present {
  position: fixed;
  inset: 0;
  background: #0b0a09;
  z-index: 40;
  display: grid;
  place-items: center;
}
.present-stage { width: min(100vw, calc(100vh * 16 / 9)); }
.present-stage .slide { width: 100%; border-radius: 0; }
.present-ui {
  position: absolute;
  right: 20px;
  bottom: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  color: #ddd;
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(23, 21, 18, 0.45);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}
.modal-card {
  width: min(520px, 100%);
  background: var(--cream);
  border-radius: 24px;
  padding: 24px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0; font-family: var(--display); font-weight: 500; }
.modal-actions { display: flex; justify-content: space-between; gap: 10px; align-items: center; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--cream);
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 60;
  font-size: 14px;
}
.busy {
  position: fixed;
  inset: 0;
  background: rgba(244, 238, 228, 0.78);
  display: grid;
  place-items: center;
  z-index: 55;
}
.busy-card {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px;
  width: min(420px, calc(100% - 32px));
  text-align: center;
  box-shadow: var(--shadow);
}
.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--paper-2);
  border-top-color: var(--brick);
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.busy-steps {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  text-align: left;
  color: var(--ink-soft);
  font-size: 13px;
  display: grid;
  gap: 6px;
}
.busy-steps li.is-on { color: var(--ink); font-weight: 600; }

.print-root { display: none; }

@media print {
  body { background: #fff; }
  .app, .present, .modal, .toast, .busy { display: none !important; }
  .print-root { display: block !important; }
  .print-root .slide {
    break-after: page;
    page-break-after: always;
    width: 100vw !important;
    border-radius: 0;
    box-shadow: none;
  }
  @page { size: landscape; margin: 0; }
}

@media (max-width: 1100px) {
  .editor { grid-template-columns: 160px 1fr; }
  .inspector { display: none; }
  .composer-row { grid-template-columns: 1fr 1fr; }
  .composer-row .solid { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .editor { grid-template-columns: 1fr; }
  .thumbs { flex-direction: row; max-height: none; }
  .thumb { min-width: 140px; }
  .topbar-note { display: none; }
  .hero h1 { font-size: 36px; }
}
