@font-face {
  font-family: "Cormorant Garamond";
  src: url("/fonts/CormorantGaramond-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Manrope";
  src: url("/fonts/Manrope-Medium.ttf") format("truetype");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Manrope";
  src: url("/fonts/Manrope-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}

/* Всегда светлое окно в цветах LaMirAs — тему Telegram не берём. */
:root {
  color-scheme: light;
  --ivory: #F6F1E9;
  --card: #FFFCF7;
  --line: #E7DDD0;
  --ink: #2B2623;
  --muted: #8A7F77;
  --rose: #B76E79;
  --rose-soft: #F3E3E3;
  --rose-ink: #8E4C57;
  --danger: #A2473F;
  --radius: 18px;
  --serif: "Cormorant Garamond", "Times New Roman", serif;
  --sans: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--ivory);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

body {
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* --- шапка --- */
.top { padding: 22px 4px 8px; }
.brand {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--rose);
}
h1, h2 {
  font-family: var(--serif);
  font-weight: 600;
  margin: 0;
  line-height: 1.1;
}
h1 { font-size: 34px; margin-top: 4px; }
.lead { margin: 8px 0 0; color: var(--muted); font-size: 15px; }

/* --- карточки разделов --- */
.section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-top: 16px;
}
.section h2 { font-size: 25px; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.section > .hint + * , .section > h2 + * { margin-top: 12px; }

/* --- выбор заголовка --- */
.options { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: left;
  width: 100%;
}
.option.on { border-color: var(--rose); background: var(--rose-soft); }
.radio {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #CDBFB2;
  position: relative;
}
.option.on .radio { border-color: var(--rose); }
.option.on .radio::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--rose);
}
.option .text { flex: 1; min-width: 0; }
.option .small { display: block; color: var(--muted); font-size: 13px; }
.option input[type="text"] {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  outline: none;
  font-size: 16px;
}
.option input[type="text"]::placeholder { color: var(--muted); }
.thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; padding: 4px 4px; }

/* --- анимация заголовка --- */
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.chip {
  min-height: 48px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: #fff;
  font-weight: 600;
  font-size: 15px;
}
.chip.on { background: var(--rose); border-color: var(--rose); color: #fff; }
.chips.off { opacity: .45; pointer-events: none; }

/* --- вставки --- */
.inserts { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.insert {
  display: flex;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.insert.removed { background: #F4EFE8; }
.insert.removed .thumb, .insert.removed .meta .label { opacity: .4; }
.insert.removed .meta .label { text-decoration: line-through; }
.thumb {
  flex: none;
  width: 72px;
  height: 128px;
  border-radius: 10px;
  background: var(--ivory) center / cover no-repeat;
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.thumb .tag {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  color: #fff;
  background: rgba(43, 38, 35, .72);
  border-radius: 6px;
  padding: 2px 4px;
}
.meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.meta .when { color: var(--muted); font-size: 13px; }
.meta .label { font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.meta .status { color: var(--rose-ink); font-size: 13px; margin-top: 4px; min-height: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 8px; }
.act {
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.act.on { border-color: var(--rose); background: var(--rose-soft); color: var(--rose-ink); }
.act:disabled { opacity: .45; }

/* --- субтитры --- */
.lines { display: flex; flex-direction: column; margin-top: 8px; }
.line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.line:first-child { border-top: 0; }
.line .when { flex: none; width: 38px; color: var(--muted); font-size: 13px; padding-top: 9px; }
.words { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 2px 2px; }
.word {
  border: 0;
  background: transparent;
  padding: 6px 4px;
  min-height: 36px;
  border-radius: 8px;
  font-size: 17px;
}
.word:active { background: var(--rose-soft); }
.word.fixed { color: var(--rose-ink); background: var(--rose-soft); }
.word-input {
  min-width: 3ch;
  padding: 5px 6px;
  border: 1.5px solid var(--rose);
  border-radius: 8px;
  background: #fff;
  font-size: 17px;
  outline: none;
}
.line .pic {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card) center / cover no-repeat;
  font-size: 19px;
}
.line .pic.on { border-color: var(--rose); }
.line-photo { color: var(--rose-ink); font-size: 13px; width: 100%; padding: 2px 4px 0; }

/* --- переключатели --- */
.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  text-align: left;
  border-top: 1px solid var(--line);
}
.toggle:first-of-type { border-top: 0; }
.toggle .text { flex: 1; }
.toggle .small { display: block; color: var(--muted); font-size: 13px; }
.switch {
  flex: none;
  width: 52px;
  height: 32px;
  border-radius: 999px;
  background: #DCD2C6;
  position: relative;
  transition: background .2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(43, 38, 35, .25);
  transition: transform .2s;
}
.toggle.on .switch { background: var(--rose); }
.toggle.on .switch::after { transform: translateX(20px); }

/* --- загрузка, сообщения --- */
.loading { display: flex; align-items: center; gap: 10px; padding: 40px 4px; color: var(--muted); }
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--rose);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .25; transform: scale(.8); } }

.notice {
  margin-top: 24px;
  padding: 22px 18px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
}
.notice h2 { font-size: 26px; }
.notice p { margin: 8px 0 0; color: var(--muted); }
.notice.warn { margin-top: 16px; border-color: var(--rose); background: var(--rose-soft); }
.notice.warn h2 { font-size: 23px; color: var(--rose-ink); }
.notice.warn p { color: var(--ink); }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  max-width: 528px;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  box-shadow: 0 8px 24px rgba(43, 38, 35, .25);
  z-index: 20;
}

.done {
  position: fixed;
  inset: 0;
  background: rgba(246, 241, 233, .96);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 30;
}
.done-card { text-align: center; }
.done-card h2 { font-size: 34px; margin-top: 18px; }
.done-card p { margin: 6px 0 0; color: var(--muted); font-size: 17px; }
.spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid var(--rose-soft);
  border-top-color: var(--rose);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.fallback-go {
  position: sticky;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: block;
  width: 100%;
  min-height: 54px;
  margin-top: 20px;
  border: 0;
  border-radius: 14px;
  background: var(--rose);
  color: #fff;
  font-weight: 600;
  font-size: 17px;
}
.fallback-go:disabled { opacity: .45; }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .dot, .spinner { animation: none; }
  .switch, .switch::after { transition: none; }
}
