* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--c-bg); color: var(--c-ink);
  font: 500 17px/1.5 var(--font-body);
  min-height: 100vh; overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}
#app { max-width: 560px; margin: 0 auto; padding-block: 12px 96px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.boot { padding: 40px 0; color: var(--c-muted); }
h1, h2, h3 { line-height: 1.1; margin: 0 0 10px; text-wrap: balance; }
h1 { font: 700 44px/1 var(--font-script); }
h2 { font: 700 34px/1.02 var(--font-script); letter-spacing: -.005em; }
h3 { font: 700 18px/1.25 var(--font-display); letter-spacing: -.01em; }
p { margin: 0 0 12px; }
a { color: var(--c-ink); text-underline-offset: 3px; }
small, .muted { color: var(--c-on-bg-muted); }
.muted { font-size: 15px; }
.card small, .card .muted, .sheet small, .sheet .muted { color: var(--c-muted); }
.sheet { color: var(--c-ink); }
.stack > * + * { margin-top: 12px; }
.stack-lg > * + * { margin-top: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* ---------- Шапка и герой ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 14px; min-height: 40px; }
.back { background: none; border: 0; color: var(--c-ink); font: 700 16px var(--font-body); padding: 8px 0; cursor: pointer; }
.hero { position: relative; padding: 6px 0 18px; margin-bottom: 8px; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: start; }
.hero .author { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 12px; font: 600 14px/1.25 var(--font-body); }
.hero .author small { color: var(--c-ink); font-size: 11px; text-align: right; max-width: 15ch; }
.hero h1 { margin: 4px 0 0; color: var(--c-ink); min-width: 0; }
.hero h1 .w1 { display: block; font: 700 64px/.9 var(--font-script); position: relative; width: max-content; }
.hero h1 .w1::after { content: ''; position: absolute; left: 30%; width: 34%; bottom: 2px; height: 8px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 8'%3E%3Cpath d='M2 5c10-3 22-3 34-1s16 1 22-1' fill='none' stroke='%23141414' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E") center/100% 100% no-repeat; }
.hero h1 .star { display: block; font: 700 112px/.82 var(--font-star); letter-spacing: .02em; margin: 2px 0 0 -4px; }
.hero h1 .sub { display: block; font: 700 40px/1 var(--font-script); margin-top: 2px; }
.hero .book { width: 104px; aspect-ratio: 415 / 598; max-width: 100%; border: 2px solid var(--c-ink); border-radius: 4px; background: var(--hero-image) center/cover no-repeat; transform: rotate(4deg); margin-top: 18px; box-shadow: 4px 4px 0 var(--c-ink); }
.hero .lead { grid-column: 1 / -1; font: 500 16px/1.45 var(--font-body); color: var(--c-ink); max-width: 40ch; margin: 6px 0 4px; }
.hero .lead b { font-weight: 800; text-transform: uppercase; }
.hero .sticker { grid-column: 1 / -1; justify-self: start; transform: rotate(-2.5deg); margin-top: 6px; }
.chair { width: 86px; height: auto; color: var(--c-ink); flex: none; }
.screen-title { margin-bottom: 4px; }
.kicker { font: 800 12px var(--font-display); text-transform: uppercase; letter-spacing: .1em; color: var(--c-ink); margin-bottom: 2px; display: inline-block; background: var(--c-surface); border: 1.5px solid var(--c-ink); padding: 4px 8px; transform: rotate(-1.5deg); }
.card .kicker, .sheet .kicker, .ace .kicker { background: none; border: 0; padding: 0; transform: none; color: var(--c-muted); }

/* ---------- Карточки ---------- */
.card { background: var(--c-surface); color: var(--c-ink); border: 2px solid var(--c-line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.card.flat { box-shadow: none; }
.card.tight { padding: 12px 14px; }
.exercise { display: grid; grid-template-columns: 48px 1fr; gap: 12px; align-items: start; text-decoration: none; color: inherit; cursor: pointer; width: 100%; text-align: left; font: inherit; }
.exercise .num { width: 48px; height: 48px; border-radius: 50% 46% 52% 48%; border: 2px solid var(--c-ink); background: var(--c-mark); color: var(--c-ink); display: grid; place-items: center; font: 700 34px/1 var(--font-script); }
.exercise h3 { margin-bottom: 4px; }
.exercise p { margin: 0; color: var(--c-muted); font-size: 15px; }
.status { display: inline-block; margin-top: 8px; font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: var(--c-surface-2); color: var(--c-muted); }
.status.done { background: color-mix(in srgb, var(--c-ok) 15%, transparent); color: var(--c-ok); }
.status.progress { background: var(--c-surface-2); color: var(--c-ink); }

/* ---------- Кнопки ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 12px 20px; border-radius: 14px; border: 2px solid var(--c-ink); background: var(--c-surface); color: var(--c-ink); font: 800 17px var(--font-body); cursor: pointer; text-decoration: none; text-align: center; line-height: 1.2; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--c-accent); border-color: var(--c-accent); color: var(--c-accent-ink); }
.btn-dark { background: var(--c-ink); border-color: var(--c-ink); color: var(--c-bg); }
.btn-gold { background: var(--c-gold); border-color: var(--c-ink); color: var(--c-gold-ink); border-radius: 4px; text-transform: uppercase; letter-spacing: .02em; box-shadow: 3px 3px 0 var(--c-ink); }
.btn-ghost { border-color: var(--c-line); background: transparent; }
.btn-small { min-height: 40px; padding: 8px 14px; font-size: 15px; border-radius: 12px; border-width: 1.5px; }
.btn-link { background: none; border: 0; padding: 6px 0; color: var(--c-ink); font: 700 16px var(--font-body); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.btn-block { width: 100%; }
.btn-ai::before { content: '✦'; font-size: 15px; }
.actions { display: grid; gap: 10px; margin-top: 16px; }
.sticky-actions { position: sticky; bottom: 0; padding: 14px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(color-mix(in srgb, var(--c-bg) 0%, transparent), var(--c-bg) 14px); z-index: 5; margin-top: 16px; }

/* ---------- Формы ---------- */
label.field { display: block; }
.field > span { display: block; font-weight: 800; margin-bottom: 6px; }
.field > small { display: block; margin-top: 4px; }
input[type=text], input[type=url], input[type=search], input[type=tel], textarea, select {
  width: 100%; font: 500 17px/1.45 var(--font-body); color: var(--c-ink); background: var(--c-surface);
  border: 1.5px solid var(--c-line); border-radius: var(--radius-sm); padding: 12px 14px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--c-ink); }
textarea { min-height: 96px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--c-ink) 50%), linear-gradient(135deg, var(--c-ink) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--c-accent); flex: none; margin-top: 2px; }
.file-drop { display: block; border: 2px dashed var(--c-line); border-radius: var(--radius); padding: 18px; text-align: center; cursor: pointer; background: var(--c-surface); }
.file-drop input { display: block; margin: 10px auto 0; max-width: 100%; font-size: 15px; }

/* ---------- Сегменты, чипы, бейджи ---------- */
.q { margin-top: 14px; }
.q > .q-label { font-weight: 800; margin-bottom: 8px; display: block; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button { flex: 1 1 auto; min-height: 48px; min-width: 88px; padding: 8px 12px; border-radius: 12px; border: 1.5px solid var(--c-line); background: var(--c-surface); color: var(--c-ink); font: 700 16px var(--font-body); cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--c-ink); border-color: var(--c-ink); color: var(--c-bg); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 99px; border: 1.5px solid var(--c-line); background: var(--c-surface); font: 700 15px var(--font-body); color: var(--c-ink); cursor: pointer; }
.chip[aria-pressed=true] { background: var(--c-ink); color: var(--c-bg); border-color: var(--c-ink); }
.chip.static { cursor: default; }
.badge { display: inline-block; font: 800 12px/1.2 var(--font-body); text-transform: uppercase; letter-spacing: .04em; padding: 5px 8px; border-radius: 8px; background: var(--c-surface-2); color: var(--c-ink); white-space: nowrap; }
.badge.freq { background: var(--c-ink); color: var(--c-bg); font-size: 13px; }
.badge.explicit { background: color-mix(in srgb, var(--c-ok) 16%, transparent); color: var(--c-ok); }
.badge.inferred { background: var(--c-warn-bg); color: var(--c-warn); }
.badge.demo { background: var(--c-surface); color: var(--c-ink); border: 1.5px solid var(--c-ink); }
.badge.ai { background: var(--c-ink); color: var(--c-surface); }
.badge.call { background: color-mix(in srgb, var(--c-ok) 16%, transparent); color: var(--c-ok); }
.badge.write { background: var(--c-surface-2); color: var(--c-ink); border: 1.5px solid var(--c-ink); }
.badge.later { background: var(--c-surface-2); color: var(--c-muted); }

/* ---------- Заметки ---------- */
.notice { border-radius: var(--radius-sm); padding: 12px 14px; background: var(--c-surface-2); font-size: 15px; }
.notice b { font-weight: 800; }
.notice.warn { background: var(--c-warn-bg); color: var(--c-ink); border-left: 4px solid var(--c-warn); }
.notice.demo { background: var(--c-surface); border: 2px dashed var(--c-ink); }
.notice.ok { background: color-mix(in srgb, var(--c-ok) 12%, transparent); border-left: 4px solid var(--c-ok); }
.notice.privacy::before { content: '🔒 '; }
#banner .demo-bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--c-demo); color: var(--c-demo-bg); font: 800 14px var(--font-body); padding: 8px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#banner .demo-bar button { background: var(--c-demo-bg); color: var(--c-demo); border: 0; border-radius: 10px; padding: 6px 10px; font: 800 14px var(--font-body); cursor: pointer; }

/* ---------- Прогресс и шаги ---------- */
.progress { height: 10px; border: 1.5px solid var(--c-ink); background: var(--c-surface); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--c-ink); border-radius: 99px; transition: width .25s; }
.steps { display: flex; gap: 6px; margin: 4px 0 16px; }
.steps span { flex: 1; height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--c-surface) 55%, transparent); }
.steps span.on { background: var(--c-ink); }
.steps span.cur { background: var(--c-surface); outline: 2px solid var(--c-ink); }
.tabs { display: flex; gap: 6px; background: var(--c-surface-2); padding: 4px; border-radius: 14px; margin-bottom: 14px; }
.tabs button { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent; font: 800 15px var(--font-body); color: var(--c-muted); cursor: pointer; }
.tabs button[aria-selected=true] { background: var(--c-surface); color: var(--c-ink); box-shadow: var(--shadow); }
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.filters .chip { flex: none; }

/* ---------- Списки ---------- */
.list-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--c-line); }
.list-item:last-child { border-bottom: 0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--c-surface-2); display: grid; place-items: center; font: 800 15px var(--font-display); flex: none; }
.rec-reason { font-size: 15px; color: var(--c-muted); margin: 4px 0; }
.rec-occasion { font-size: 15px; margin: 4px 0; }

/* ---------- Таблицы аудита ---------- */
.audit-row { padding: 14px 0; border-bottom: 1px solid var(--c-line); }
.audit-row:last-child { border-bottom: 0; }
.audit-row .name { font-weight: 800; font-size: 17px; }
.audit-row .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.quote { border-left: 3px solid var(--c-mark); padding: 4px 0 4px 10px; margin: 8px 0; font-size: 15px; }
.quote small { display: block; }
details > summary { cursor: pointer; font-weight: 700; color: var(--c-ink); text-decoration: underline; text-underline-offset: 3px; list-style: none; padding: 6px 0; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: '▸ '; }
details[open] > summary::before { content: '▾ '; }
.preview-table { overflow-x: auto; border: 1px solid var(--c-line); border-radius: var(--radius-sm); }
.preview-table table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.preview-table td, .preview-table th { border-bottom: 1px solid var(--c-line); padding: 6px 8px; white-space: nowrap; text-align: left; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.preview-table th { background: var(--c-surface-2); }

/* ---------- Козырной туз ---------- */
.ace { position: relative; background: var(--c-surface); color: var(--c-ink); border: 2.5px solid var(--c-ink); border-radius: 18px; padding: 22px 18px 18px; box-shadow: 7px 7px 0 var(--c-ink); }
.ace .suit { position: absolute; top: 8px; right: 16px; font: 700 52px var(--font-star); color: var(--c-ink); line-height: .9; }
.ace .suit small { display: block; font-size: 20px; text-align: center; }
.ace h2 { padding-right: 46px; }
.case dt { font: 800 13px var(--font-display); text-transform: uppercase; letter-spacing: .06em; color: var(--c-muted); margin-top: 10px; }
.case dd { margin: 2px 0 0; }
.letter-part { border-left: 3px solid var(--c-line); padding-left: 10px; }
.letter-part > span { font-size: 13px; font-weight: 800; color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; }
.letter-part textarea { min-height: 60px; margin-top: 4px; }
.letter-part.req > span::after { content: ' · обязательная'; font-weight: 600; text-transform: none; letter-spacing: 0; }

/* ---------- Модалка и тост ---------- */
#overlay:empty { display: none; }
#overlay { position: fixed; inset: 0; background: rgba(10, 8, 6, .55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--c-bg); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet pre { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--radius-sm); padding: 12px; white-space: pre-wrap; word-break: break-word; font-size: 13px; max-height: 40vh; overflow: auto; }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--c-ink); color: var(--c-bg); padding: 12px 18px; border-radius: 14px; font-weight: 700; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }

.hr { height: 1px; background: var(--c-line); margin: 18px 0; }
.big-num { font: 900 40px/1 var(--font-display); }
.footer-links { text-align: center; margin-top: 24px; }
.tour-step { min-height: 60vh; }

/* Рукописные мелочи в духе обложки */
.btn-primary, .btn-dark { box-shadow: 3px 3px 0 color-mix(in srgb, var(--c-ink) 35%, transparent); }
.btn-ghost { border-color: var(--c-ink); background: transparent; }
.card .btn-ghost, .sheet .btn-ghost { border-color: var(--c-line-soft); }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--c-ink); outline-offset: 2px; }
.screen-title, h2 { color: var(--c-ink); }
.card h2, .ace h2 { font-size: 32px; }
.tabs { background: color-mix(in srgb, var(--c-surface) 45%, transparent); border: 2px solid var(--c-ink); }
.tabs button { color: var(--c-ink); }
.tabs button[aria-selected=true] { background: var(--c-ink); color: var(--c-surface); box-shadow: none; }
.filters .chip, .chips > .chip { border-color: var(--c-ink); }
.notice { color: var(--c-ink); }
.notice:not(.warn):not(.demo):not(.ok) { background: color-mix(in srgb, var(--c-surface) 70%, transparent); border: 1.5px solid var(--c-ink); }
.card .notice:not(.warn):not(.demo):not(.ok) { background: var(--c-surface-2); border: 0; }
.footer-links .btn-link { font-weight: 800; }
.sticky-actions { background: linear-gradient(color-mix(in srgb, var(--c-bg) 0%, transparent), var(--c-bg) 14px); }
@media (max-width: 360px) { .hero h1 .w1 { font-size: 54px; } .hero h1 .star { font-size: 92px; } .hero .book { width: 84px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
