/* Макет нового сайта. Образ — лист комикса: блоки-кадры в чёрной рамке, ярусы, цветные слоги.
   Сторонние шрифты не подгружаются: Georgia Bold — шрифт слогов на листе, PT Sans — для текста. */
:root {
  --desk: #E8ECEF;      /* стол, на котором лежат листы */
  --paper: #FFFFFF;
  --ink: #16181D;
  --muted: #56606B;
  --rule: #C6CED5;
  --red: #C62828;       /* слог: первый цвет, как на листе */
  --violet: #7B2FBE;    /* слог: второй цвет */
  --yellow: #FFCF33;    /* только главная кнопка */
  --tier: 24px;         /* между ярусами вдвое шире, чем между кадрами в ярусе, — как на листе */
  --gutter: 12px;
  --display: Georgia, "PT Serif", "Times New Roman", serif;
  --text: "PT Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* иначе display у ярусов и таблиц перебивает атрибут hidden */
html { background: var(--desk); }
body { margin: 0; color: var(--ink); font: 17px/1.5 var(--text); }
a { color: inherit; }
img { display: block; max-width: 100%; }

.page { max-width: 1080px; margin: 0 auto; padding: 20px 20px 64px; }

.top { display: flex; align-items: baseline; gap: 28px; margin-bottom: 20px; }
.top nav { display: flex; gap: 22px; }
.top nav a { font: 700 1.05rem/1.2 var(--display); text-decoration: none; padding-bottom: 4px; border-bottom: 3px solid transparent; }
.top nav a[aria-current="page"] { border-bottom-color: var(--ink); }
.top nav a:hover { border-bottom-color: var(--rule); }
.top .who { margin-left: auto; color: var(--muted); }
.top .account { margin-left: auto; color: var(--muted); white-space: nowrap; }
.top .who + .account { margin-left: 0; }


/* ярусы и кадры */
.tier { display: grid; gap: var(--gutter); margin-bottom: var(--tier); }
.tier.wide-narrow { grid-template-columns: 1.6fr 1fr; }
.tier.halves { grid-template-columns: 1fr 1fr; }
.panel { background: var(--paper); border: 2px solid var(--ink); padding: 24px 26px; min-width: 0; }
.panel > :first-child { margin-top: 0; }
.panel > :last-child { margin-bottom: 0; }

h1, h2 { font-family: var(--display); font-weight: 700; margin: 0 0 .5em; }
h1 { font-size: 2.3rem; line-height: 1.12; }
h2 { font-size: 1.3rem; line-height: 1.2; }
p { margin: 0 0 .8em; max-width: 62ch; }
.quiet { color: var(--muted); }
.small { font-size: .92rem; }

/* слоги: два цвета по очереди, граница цвета — на границе слога */
.sy { font-family: var(--display); font-weight: 700; }
.sy.a { color: var(--red); }
.sy.b { color: var(--violet); }

.units { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 6px 0 18px; padding: 0; list-style: none; }
.units li { display: flex; flex-direction: column; align-items: flex-start; }
.units .sy { font-size: 2.6rem; line-height: 1.05; }
.units .count { color: var(--muted); font-size: .88rem; }

.cloud { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; padding: 0; list-style: none; }
.cloud .sy { font-size: 1.35rem; line-height: 1.5; }

/* единственная главная кнопка */
.go {
  display: inline-block; font: 700 1.35rem/1.15 var(--display); color: var(--ink);
  background: var(--yellow); border: 3px solid var(--ink); padding: 17px 26px; cursor: pointer;
  box-shadow: 6px 6px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.go:hover { transform: translate(2px, 2px); box-shadow: 4px 4px 0 var(--ink); }
.go:active { transform: translate(6px, 6px); box-shadow: 0 0 0 var(--ink); }
.go:disabled { cursor: progress; opacity: .6; }
.go-note { margin: 16px 0 0; }
.result { margin: 14px 0 0; padding: 10px 14px; border-left: 4px solid var(--ink); background: var(--desk); }
.problem { margin: 0 0 var(--tier); padding: 14px 18px; background: var(--paper); border: 2px solid var(--red); }
.problem.calm { border-color: var(--ink); }   /* пустой кабинет: не ошибка, а состояние (решение 102) */

.btn { font: 700 1rem/1.2 var(--text); color: var(--ink); background: var(--paper); border: 2px solid var(--ink); padding: 9px 16px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { background: var(--desk); }
:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; }

/* что пойдёт в историю */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 16px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; }

/* таблицы: история генераций, чтения */
table { width: 100%; border-collapse: collapse; }
.panel:has(> table) { overflow-x: auto; }   /* широкая таблица прокручивается внутри кадра, а не двигает страницу */
th { text-align: left; font-weight: 400; color: var(--muted); font-size: .92rem; padding: 0 12px 6px 0; }
td { padding: 10px 12px 10px 0; border-top: 1px solid var(--rule); vertical-align: top; }
td.num, th.num { text-align: right; padding-right: 0; white-space: nowrap; }
.costs td.num, .costs th.num { padding-left: 18px; }   /* на странице расходов числа стоят подряд */
td a { font-weight: 700; }
.state { white-space: nowrap; }
.state::before { content: ""; display: inline-block; width: 11px; height: 11px; margin-right: 8px; border: 2px solid var(--ink); vertical-align: -1px; }
.state.queue::before { background: var(--yellow); }
.state.ready::before { background: var(--violet); }
.state.hard::before { background: var(--red); }
.state.read::before { background: var(--ink); }

/* большая история в истории генераций (решение 104): шапка блока и полоса клеток — по клетке на эпизод */
.history tbody + tbody::before { content: ""; display: table-row; height: 26px; }
.story-head td { border-top: 3px solid var(--ink); padding: 14px 0 14px; }
.story-head { cursor: pointer; }
.story-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; width: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.story-line strong { font: 700 1.2rem/1.2 var(--display); }
.story-line strong::before { content: "▾"; display: inline-block; width: 1.1em; }
.folded .story-line strong::before { content: "▸"; }
.story-head:hover .story-line strong { text-decoration: underline; }
.history tbody.folded tr:not(.story-head) { display: none; }
.story-strip { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.story-strip li { width: 30px; height: 30px; border: 2px solid var(--ink); font: 700 .9rem/26px var(--text); text-align: center; }
.story-strip .read { background: var(--ink); color: var(--paper); }
.story-strip .ready { background: var(--violet); color: var(--paper); }
.story-strip .work { background: var(--yellow); }
.story-strip .none { border-style: dashed; border-color: var(--muted); color: var(--muted); }

details { margin-top: 6px; font-size: .92rem; color: var(--muted); }
details summary { cursor: pointer; }
details ul { margin: 6px 0 0; padding-left: 1.2em; }

ol.next { margin: 0; padding: 0 0 0 1.3em; }
ol.next li { padding: 5px 0; }
ol.next .group { margin-right: .5em; }
ol.next .sy { font-size: 1.15rem; }

.notes { margin: 0; padding: 0; list-style: none; }
.notes li { padding: 10px 0; border-top: 1px solid var(--rule); }
.notes li:first-child { border-top: 0; padding-top: 0; }
.notes time { color: var(--muted); font-size: .92rem; display: block; }

/* экран «Прогресс»: слева два кадра друг под другом, справа весь план обучения (решение 106) */
.stack { display: grid; gap: var(--gutter); align-content: start; min-width: 0; }
.plan { margin: 0; padding: 0; list-style: none; counter-reset: plan; }
.plan li { counter-increment: plan; display: grid; grid-template-columns: 1.9em 1fr; align-items: baseline; padding: 6px 0; border-top: 1px solid var(--rule); }
.plan li::before { content: counter(plan) "."; color: var(--muted); }
.plan li > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 10px; }
.plan .group { font: 700 1.15rem/1.3 var(--display); }
.plan .name { color: var(--muted); font-size: .88rem; }
.plan .closed .group .sy { color: var(--muted); }
.plan .closed::before { content: "✓"; color: var(--ink); font-weight: 700; }
.plan li.current { margin: 2px -12px; padding: 8px 12px; border: 2px solid var(--ink); background: var(--desk); }
.plan li:first-child, .plan .current + li { border-top-color: transparent; }
.plan li.current { border-top-color: var(--ink); }
.plan .here { padding: 0 7px; background: var(--ink); color: var(--paper); font: 700 .78rem/1.5 var(--text); }

/* вопрос про группу, дочитанную до нормы (решение 107): окно поверх «Генерации» и ответы на «Прогрессе» */
dialog.ask { width: min(560px, calc(100vw - 32px)); padding: 26px 28px; border: 3px solid var(--ink); background: var(--paper); color: var(--ink); box-shadow: 8px 8px 0 var(--ink); }
dialog.ask::backdrop { background: rgba(22, 24, 29, .55); }
dialog.ask h2 { margin-top: 0; }
.ask-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 14px; margin: 0 0 14px; }
.confirm .ask-buttons { margin-bottom: 0; }
/* слог закрытой группы — кнопка «повторить» */
.plan button.sy { font: inherit; background: none; border: 0; border-bottom: 2px dotted transparent; padding: 0; cursor: pointer; }
.plan button.sy:hover { border-bottom-color: var(--muted); }
.plan .closed .group button.sy.again { color: var(--ink); border-bottom: 2px solid var(--ink); }

/* экран истории */
ul.plain { margin: 0 0 10px; padding-left: 1.2em; }
.form label { display: block; font-weight: 700; margin: 14px 0 5px; }
.form label:first-child { margin-top: 0; }
.form input, .form textarea { width: 100%; font: inherit; color: inherit; background: var(--paper); border: 2px solid var(--ink); padding: 8px 10px; border-radius: 0; }
.form textarea { min-height: 96px; resize: vertical; }
.choice { display: flex; gap: 8px; flex-wrap: wrap; }
.choice label { margin: 0; font-weight: 400; border: 2px solid var(--ink); padding: 6px 14px; cursor: pointer; }
.choice input { position: absolute; opacity: 0; width: 0; }
.choice input:checked + span { font-weight: 700; }
.choice label:has(input:checked) { background: var(--ink); color: var(--paper); }
.form .btn { margin-top: 16px; }
.load { border-top: 2px solid var(--ink); padding-top: 14px; margin: 0 0 16px; }
.load h3 { margin: 0 0 12px; font: 700 1rem/1.2 var(--text); }
.stepper { display: grid; grid-template-columns: 1fr 40px 3.2rem 40px; align-items: center; gap: 6px; margin-bottom: 8px; }
.stepper-name { color: var(--muted); }
.stepper-value { text-align: center; font: 700 1.5rem/1 var(--display); }
.step { width: 40px; height: 40px; font: 700 1.4rem/1 var(--text); color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: 0; cursor: pointer; padding: 0; }
.step:hover:not(:disabled) { background: var(--desk); }
.step:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.step:disabled { color: var(--rule); border-color: var(--rule); cursor: default; }
.load p { margin: 10px 0 0; }
.load-changes { list-style: none; margin: 6px 0 0; padding: 0; }
/* песочница: один экран без прокрутки — листы во всю высоту окна, управление под ними */
.pgx-body { overflow: hidden; }
.pgx { height: 100vh; display: flex; flex-direction: column; gap: 10px; padding: 10px 16px 12px; }
.pgx-top { display: flex; align-items: center; gap: 18px; flex: none; }
.pgx-name { font: 700 1.25rem/1.2 var(--display); }
.pgx-tabs { display: flex; }
.pgx-tabs [role="tab"] { font: 700 1rem/1.2 var(--text); color: var(--ink); background: var(--paper); border: 2px solid var(--ink); padding: 7px 16px; margin-right: -2px; cursor: pointer; border-radius: 0; }
.pgx-tabs [role="tab"][aria-selected="true"] { background: var(--ink); color: var(--paper); }
.pgx-tabs [role="tab"]:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; position: relative; }
.pgx-back { margin-left: auto; }
.pgx-main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 12px; }
.pgx-stage { min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.pgx-sheets { flex: 1; min-height: 0; display: flex; gap: 12px; justify-content: center; }
.pgx-sheets figure { margin: 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; max-width: calc(50% - 6px); }
.pgx-sheets img { flex: 1; min-height: 0; max-width: 100%; object-fit: contain; object-position: top; }
.pgx-sheets figcaption { flex: none; text-align: center; }
.pgx-strip { flex: none; background: var(--paper); border: 2px solid var(--ink); padding: 10px 14px; }
.pgx-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pgx-row-steps { flex-wrap: nowrap; }
.pgx-row-steps input[type="range"] { flex: 1; min-width: 0; accent-color: var(--ink); }
.pgx-row .stepper-value { min-width: 3rem; }
.pgx-row .btn:disabled { color: var(--rule); border-color: var(--rule); cursor: default; background: var(--paper); }
.pgx-gap { flex: 1; }
.pgx-line { margin: 8px 0 0; max-width: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pgx-line .sy { font-size: 1.2rem; }
.pgx-side { overflow: auto; padding: 16px 18px; }
.pgx-side h2 { font-size: 1.1rem; }
.pgx-sheets.one figure { max-width: 100%; }
.pgx-focus { list-style: none; margin: 0 0 16px; padding: 0; }
.pgx-focus li { padding: 3px 0; }
.pgx-focus .sy { font-size: 1.2rem; margin-right: 6px; }
.pgx-warn { border-left: 4px solid var(--red); padding: 6px 10px; background: var(--desk); }
.pg-fresh { color: var(--red); }
.pg-log { margin: 0 0 14px; padding-left: 1.2em; }
@media (max-width: 1000px), (max-height: 560px) {      /* узкое или низкое окно: обычная страница с прокруткой */
  .pgx-body { overflow: auto; }
  .pgx { height: auto; }
  .pgx-main { grid-template-columns: 1fr; }
  .pgx-sheets { flex-direction: column; align-items: center; }
  .pgx-sheets figure { max-width: 100%; }
  .pgx-line { white-space: normal; }
}
.read-q { margin: 0 0 8px; font-weight: 700; }
.read-box .choice { margin-bottom: 8px; }
.read-box .hint { margin: 0 0 16px; }
@media (prefers-reduced-motion: reduce) { .go { transition: none; } }


.confirm { margin: 0 0 4px; padding: 14px 16px; border: 2px solid var(--ink); background: var(--desk); }
.confirm p { margin-bottom: 12px; }
.confirm .go { margin-right: 10px; }
.link { font: inherit; color: inherit; background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
.plain { margin: 10px 0 0; padding: 0; list-style: none; }
ol.next + p { margin-top: 14px; }
.read-box { margin: 0 0 14px; }
.read-box textarea { width: 100%; min-height: 76px; margin: 8px 0 12px; font: inherit; color: inherit; background: var(--paper); border: 2px solid var(--ink); padding: 8px 10px; resize: vertical; box-sizing: border-box; }
details.note { margin: 0; font-size: inherit; color: inherit; }
details.note summary { cursor: pointer; }
details.note[open] summary { color: var(--muted); }
details.note p { margin: 8px 0 0; }

/* ---------- экран «Вся история» (админский): план арки ---------- */
.arc-facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; margin: 0 0 8px; }
.arc-facts dt { color: var(--muted); }
.arc-facts dd { margin: 0; }
.arc-props { padding-left: 20px; }
.arc-props li { margin-bottom: 8px; }
.arc-props code { display: block; margin-top: 2px; color: var(--muted); font-size: .88rem; }
.arc-episodes { padding-left: 28px; }
.arc-episode { margin-bottom: 16px; padding-left: 6px; }
.arc-episode p { margin: 4px 0 0; }
.arc-episode.done { color: var(--muted); }
.arc-episode.no-sheet > strong { border-bottom: 2px solid var(--red); }
.arc-label { display: block; margin: 12px 0 6px; font-weight: 700; }
.arc-premise { width: 100%; box-sizing: border-box; padding: 10px 12px; font: inherit; border: 2px solid var(--ink); background: var(--paper); }
.arc-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 14px 0 20px; }
.arc-row input { width: 5em; padding: 6px 8px; font: inherit; border: 2px solid var(--ink); background: var(--paper); }

/* ---------- страница входа (решение 101) ---------- */
.login-page { max-width: 460px; padding-top: 12vh; }
.login-page h1 { font-size: 1.9rem; margin-bottom: .7em; }
.login-page .go { margin-top: 22px; }
.login-page .code { font: 700 2rem/1.2 var(--display); letter-spacing: .3em; text-align: center; }
.login-links { margin: 22px 0 8px; }
.link:disabled { color: var(--muted); text-decoration: none; cursor: default; }

/* экран чтения (решение 103): один кадр во весь экран на тёмном столе, остальное не отвлекает */
html:has(body.reader) { background: var(--ink); }
/* touch-action: палец на планшете не увеличивает страницу двойным касанием; листают только кнопки */
/* сцена прибита к краям окна: 100dvh в полном экране после поворота пересчитывался не всегда */
body.reader { position: fixed; inset: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; color: var(--paper); overflow: hidden; touch-action: manipulation; }
.reader-top { display: flex; align-items: center; gap: 18px; padding: 10px calc(18px + env(safe-area-inset-right)) 10px calc(18px + env(safe-area-inset-left)); padding-top: calc(10px + env(safe-area-inset-top)); }
.reader-out { font-size: 1.5rem; line-height: 1; text-decoration: none; padding: 4px 8px; opacity: .7; }
.reader-out:hover { opacity: 1; }
.reader-title { font: 700 1.15rem/1.2 var(--display); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-full { margin-left: auto; font: inherit; font-size: .92rem; color: inherit; background: none; border: 1px solid #56606B; padding: 5px 12px; cursor: pointer; opacity: .8; }
.reader-full:hover { opacity: 1; }
.reader-count { font: 700 1.15rem/1.2 var(--display); white-space: nowrap; min-width: 5.2em; text-align: right; font-variant-numeric: tabular-nums; }
.reader-full[hidden] + .reader-count { margin-left: auto; }
.reader-bar { height: 4px; background: #2B3038; }
.reader-bar i { display: block; height: 100%; width: 0; background: var(--yellow); transition: width .2s; }
.reader-stage { display: flex; align-items: center; justify-content: center; padding: 18px; min-height: 0; min-width: 0; }
.reader-stage .problem { color: var(--ink); margin: 0; }
.reader-wait { color: #AAB3BC; margin: 0; }
.reader-shot { position: relative; overflow: hidden; flex: none; padding: 0; border: 0; background: var(--paper); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.reader-shot img { position: absolute; max-width: none; user-select: none; pointer-events: none; }
.reader-shot.fresh { animation: reader-in .18s ease-out; }
@keyframes reader-in { from { opacity: 0; } to { opacity: 1; } }
.reader-end { color: var(--ink); max-width: 560px; max-height: 100%; overflow-y: auto; }   /* с «Прочитали» экран выше окна планшета */
.reader-ask { border-top: 2px solid var(--ink); margin-top: 18px; padding-top: 16px; }
.reader-ask .ask-buttons { margin-bottom: 10px; }
.reader-ask.read-box { margin-bottom: 0; }
.reader-ask.read-box .hint:last-of-type { margin-bottom: 0; }
.reader-ask .result { margin-top: 12px; }
.reader-end-links { display: flex; flex-wrap: wrap; align-items: center; gap: 22px; margin: 22px 0 6px; }
.reader-end-links .go { text-decoration: none; }
.reader-nav { display: flex; justify-content: space-between; gap: 18px; padding: 10px calc(18px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left)); }
.reader-step { font: 700 1.15rem/1.2 var(--display); color: var(--paper); background: none; border: 2px solid #56606B; padding: 12px 22px; cursor: pointer; }
.reader-step:hover:not(:disabled) { border-color: var(--paper); }
.reader-step:disabled { opacity: .3; cursor: default; }
.reader-step.next { margin-left: auto; color: var(--ink); background: var(--yellow); border-color: var(--yellow); padding: 12px 34px; }
.reader-step.next:hover { filter: brightness(1.08); }
body.reader :focus-visible { outline-color: var(--yellow); }
@media (prefers-reduced-motion: reduce) { .reader-shot.fresh { animation: none; } .reader-bar i { transition: none; } }
.story-links { display: flex; flex-wrap: wrap; gap: 10px; }
/* что дальше на экране прочитанной истории (решение 124) */
.next-box { margin: 22px 0 0; padding-top: 16px; border-top: 2px solid var(--ink); }
.next-box p { margin: 0 0 14px; }
.next-box .go { text-decoration: none; margin-bottom: 8px; }
.read-go { margin-top: 8px; padding: 5px 14px; font-size: .95rem; }

/* пробное чтение нового пользователя (trial.html): анкета, вся история по эпизодам, впечатление, отзыв */
.trial { max-width: 720px; }
.trial .panel { margin-bottom: var(--tier); }
.trial-brand { font: 700 1.05rem/1.2 var(--display); }
.trial .form .go { margin-top: 22px; }
.trial-age { max-width: 7rem; }
.trial-level { flex-direction: column; align-items: stretch; }
.trial-list { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 10px; }
.trial-episode { display: flex; align-items: center; justify-content: space-between; gap: 16px; border: 2px solid var(--ink); padding: 14px 16px; }
.trial-episode.now { box-shadow: 5px 5px 0 var(--ink); }
.trial-episode.shut { border-style: dashed; color: var(--muted); }
.trial-episode .go, .trial-episode .btn { flex: none; text-decoration: none; margin: 0; }
.trial-how { border-top: 2px solid var(--ink); padding-top: 16px; }
.trial-progress { margin: 0 0 18px; }
.trial-progress .story-strip { margin-top: 8px; }
.trial-left { margin: -8px 0 18px; }
.trial-read { margin: 0 0 4px; border-top: 2px solid var(--ink); padding-top: 14px; }
.trial-read summary { cursor: pointer; font-weight: 700; margin-bottom: 12px; }
.trial-read .trial-list { margin-bottom: 0; }
.trial-wait { border: 2px dashed var(--ink); padding: 14px 16px; margin: 0 0 18px; font-weight: 700; }
.trial-hint { border-left: 5px solid var(--ink); padding: 4px 0 4px 12px; margin: 0 0 18px; }
.trial-how .hint { margin: 0; }
