/* styles.css — Тест Сонди (Метод портретных выборов)
   Спокойная клиническая тема: нейтральный интерфейс, цвет только по смыслу —
   бирюзовый = «приятно», кирпичный = «неприятно». Светлая и тёмная схемы
   переключаются по настройке устройства. */

/* ---------- Шрифты (локально, без обращений к внешним сервисам) ---------- */
@font-face {
  font-family: "IBM Plex Sans";
  src: url("fonts/plex-sans-cyrillic.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("fonts/plex-sans-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Токены ---------- */
:root {
  color-scheme: light dark;

  --page: #ECEEF1;
  --sheet: #FFFFFF;
  --sunken: #E2E5EA;
  --ink: #161B26;
  --on-ink: #F5F7FA;
  --muted: #4B5667;
  --faint: #5A6577;
  --rule: #D2D7DF;
  --rule-strong: #A9B1BE;
  --control: #737D90;

  --pos: #0A7060;
  --pos-soft: #DCF0EB;
  --neg: #A93E24;
  --neg-soft: #F7E2DB;
  --on-color: #FFFFFF;
  --focus: #2A55E5;
  --scrim: rgba(15, 18, 24, 0.5);
  --plate-shadow: 0 1px 2px rgba(22, 27, 38, 0.14), 0 0 0 1px rgba(22, 27, 38, 0.06);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --gutter: 16px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0F1217;
    --sheet: #171B22;
    --sunken: #1F252E;
    --ink: #E9ECF1;
    --on-ink: #0F1217;
    --muted: #A3ACBA;
    --faint: #8E98A9;
    --rule: #2A303B;
    --rule-strong: #475062;
    --control: #6F798C;

    --pos: #4CC9B0;
    --pos-soft: #12302B;
    --neg: #F0906F;
    --neg-soft: #3A2119;
    --on-color: #0F1217;
    --focus: #8FA8FF;
    --scrim: rgba(0, 0, 0, 0.6);
    --plate-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  }
}

@media (min-width: 720px) {
  :root { --gutter: 32px; }
}

/* ---------- Основа ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  background: var(--page);
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

button { font: inherit; color: inherit; -webkit-appearance: none; appearance: none; touch-action: manipulation; cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; }
h1, h2, h3, h4 { text-wrap: balance; }
strong { font-weight: 600; }

.i {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

::selection { background: var(--sunken); }

.skip-link {
  position: absolute;
  left: 12px;
  top: -64px;
  z-index: 10000;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--on-ink);
  font-weight: 600;
  border-radius: var(--r-sm);
  text-decoration: none;
  transition: top 0.15s var(--ease);
}
.skip-link:focus { top: 12px; }

.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px var(--gutter) 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ---------- Шапка и подвал ---------- */
.app-header { padding: 4px 0 20px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.app-title { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }

.app-footer {
  margin-top: auto;
  padding-top: 40px;
  display: flex;
  flex-wrap: wrap;
  gap: 0 20px;
}
.app-footer a {
  font-size: 13px;
  color: var(--muted);
  text-underline-offset: 3px;
  padding: 8px 0;
}
.app-footer a:hover { color: var(--ink); }

/* ---------- Экраны ---------- */
main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen { display: none; }
.screen.active { display: block; animation: screenIn 0.18s var(--ease); }
@keyframes screenIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Кнопки ---------- */
.btn-primary,
.btn-secondary,
.btn-danger-confirm,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 20px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), opacity 0.15s var(--ease);
}

.btn-primary { background: var(--ink); color: var(--on-ink); min-height: 52px; font-size: 16px; font-weight: 600; }
.btn-primary:hover { background: color-mix(in srgb, var(--ink) 88%, var(--page)); }
.btn-primary:active { background: color-mix(in srgb, var(--ink) 76%, var(--page)); }

.btn-secondary { background: transparent; border-color: var(--control); color: var(--ink); }
.btn-secondary:hover { background: var(--sunken); }
.btn-secondary:active { background: color-mix(in srgb, var(--sunken) 80%, var(--ink)); }

.btn-danger-ghost { color: var(--neg); }
.btn-danger-confirm { background: var(--neg); color: var(--on-color); font-weight: 600; }
.btn-danger-confirm:hover { background: color-mix(in srgb, var(--neg) 88%, var(--ink)); }

.btn-ghost { background: transparent; color: var(--muted); min-height: 44px; padding: 8px 12px; }
.btn-ghost:hover:not(:disabled) { background: var(--sunken); color: var(--ink); }
.btn-ghost:disabled { opacity: 0.4; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-btn.bordered { border-color: var(--control); color: var(--ink); }
.icon-btn.danger { color: var(--neg); }

.count-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  display: inline-grid;
  place-items: center;
  border-radius: 11px;
  background: var(--sunken);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.count-badge[hidden] { display: none; }

/* ---------- Старт ---------- */
.welcome-grid {
  display: grid;
  gap: 32px;
  grid-template-areas: "head" "panel" "steps";
}
.welcome-head { grid-area: head; }
.welcome-steps { grid-area: steps; }
.welcome-panel { grid-area: panel; }

.welcome-title {
  font-size: clamp(30px, 7vw, 46px);
  line-height: 1.08;
  font-weight: 600;
  letter-spacing: -0.025em;
  max-width: 17ch;
}
.welcome-text {
  margin-top: 16px;
  font-size: 18px;
  line-height: 1.55;
  color: var(--muted);
  max-width: 50ch;
}

.steps { list-style: none; max-width: 58ch; }
.step {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 16px;
  padding: 20px 0;
  border-top: 1px solid var(--rule);
}
.step:last-child { border-bottom: 1px solid var(--rule); }
.step-num {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.step-body h2 { font-size: 17px; font-weight: 600; line-height: 1.3; }
.step-term { font-size: 14px; font-weight: 400; color: var(--faint); margin-left: 6px; }
.step-body p { margin-top: 4px; font-size: 15px; line-height: 1.55; color: var(--muted); }
.step-body strong { color: var(--ink); }

.welcome-panel {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 20px;
}
.panel-title { font-size: 17px; font-weight: 600; margin-bottom: 4px; }

.options { display: grid; }
.option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
}
.option-button {
  width: 100%;
  background: none;
  border: none;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  color: inherit;
}
.option-text { display: grid; gap: 2px; min-width: 0; }
.option-title { font-size: 16px; font-weight: 500; }
.option-desc {
  font-size: 14px;
  line-height: 1.4;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.option-chevron { color: var(--faint); margin-left: auto; }
.option-badge {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--pos);
  color: var(--on-color);
  margin-left: auto;
}
.option-badge .i { width: 14px; height: 14px; stroke-width: 2.5; }
.option-badge + .option-chevron { margin-left: 0; }

.switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: var(--control);
  cursor: pointer;
  transition: background-color 0.18s var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--sheet);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.18s var(--ease);
}
.switch:checked { background: var(--ink); }
.switch:checked::after { transform: translateX(20px); }

.welcome-actions { display: grid; gap: 10px; margin-top: 20px; }

.privacy-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 20px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
}
.privacy-line .i { width: 16px; height: 16px; margin-top: 2px; }
.consent-text { margin-top: 12px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.consent-text a, .legal-link { text-underline-offset: 3px; }

@media (min-width: 900px) {
  .welcome-grid {
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-areas: "head panel" "steps panel";
    grid-template-rows: auto 1fr;
    column-gap: 80px;
    row-gap: 32px;
    align-items: start;
    padding-top: 16px;
  }
  .welcome-panel { position: sticky; top: 24px; padding: 28px; }
}

/* ---------- Тест ---------- */
body.in-test-mode .app-header,
body.in-test-mode .app-footer { display: none; }
body.in-test-mode { overflow: hidden; padding-bottom: 0; }
body.in-test-mode .container {
  height: 100vh;
  height: 100dvh;
  padding-top: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

#screen-test.active {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.test-bar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}
.test-progress { min-width: 0; }
.test-where { font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0 8px; }
#series-label { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.seg-bar { display: flex; gap: 4px; margin-top: 6px; }
.seg { flex: 1; height: 4px; border-radius: 2px; background: var(--rule-strong); transition: background-color 0.2s var(--ease); }
.seg.done { background: color-mix(in srgb, var(--ink) 45%, transparent); }
.seg.current { background: var(--ink); }

.test-task {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 10px;
  border-radius: var(--r-md);
  background: var(--pos-soft);
  transition: background-color 0.2s var(--ease);
}
.test-task[data-phase="unpleasant"] { background: var(--neg-soft); }
.task-mark {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--pos);
  color: var(--on-color);
  transition: background-color 0.2s var(--ease);
}
.task-mark .i { width: 20px; height: 20px; stroke-width: 2.25; }
.test-task[data-phase="unpleasant"] .task-mark { background: var(--neg); }
.task-title { font-size: 17px; font-weight: 600; line-height: 1.25; letter-spacing: -0.005em; }
.task-hint { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

.board {
  flex: 1;
  min-height: 0;
  contain: size;
  display: grid;
  place-items: center;
}

.portraits-container {
  --gap: 10px;
  --cols: 2;
  --rows: 4;
  /* --bw / --bh: размер планшета в px, их задаёт app.js (ResizeObserver) */
  --card-w: min(
    calc((var(--bw, 320px) - (var(--cols) - 1) * var(--gap)) / var(--cols)),
    calc((var(--bh, 480px) - (var(--rows) - 1) * var(--gap)) / var(--rows) * 0.784)
  );
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--card-w));
  gap: var(--gap);
  justify-content: center;
}
.portraits-container[data-count="4"] { --rows: 2; }

.portrait-slot { width: var(--card-w); aspect-ratio: 247 / 315; position: relative; }

.portrait-card {
  position: absolute;
  inset: 0;
  padding: 0;
  display: block;
  background: #FFFFFF;
  border: none;
  border-radius: var(--r-sm);
  overflow: hidden;
  box-shadow: var(--plate-shadow);
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.portrait-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}
@media (hover: hover) and (pointer: fine) {
  .portrait-card:hover:not(:disabled) { box-shadow: 0 0 0 3px var(--ink); }
}
.portrait-card:active:not(:disabled) { transform: scale(0.97); }
.portrait-card:focus-visible { outline-offset: 3px; border-radius: var(--r-sm); }

/* Выбранный портрет уходит с планшета; на его месте остаётся пустая ячейка с отметкой */
.portrait-card.picked,
.portrait-card.picked:hover {
  background: transparent;
  box-shadow: none;
  border: 2px dashed var(--rule-strong);
  cursor: default;
}
.portrait-card.picked img { opacity: 0; }
.portrait-card.picked::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(44px, 40%);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background-color: var(--pos);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 52%;
}
.portrait-card.picked-pleasant::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M5 12h14M12 5v14'/%3E%3C/svg%3E");
}
.portrait-card.picked-unpleasant::after {
  background-color: var(--neg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  .portrait-card.picked-pleasant::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230F1217' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M5 12h14M12 5v14'/%3E%3C/svg%3E"); }
  .portrait-card.picked-unpleasant::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230F1217' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E"); }
}

/* Низкие портретные экраны: компактнее подсказка, больше места портретам */
@media (max-aspect-ratio: 1/1) and (max-height: 720px) {
  .test-task { padding: 8px 12px 8px 8px; gap: 10px; }
  .task-mark { width: 30px; height: 30px; }
  .task-title { font-size: 15px; }
  .task-hint { font-size: 13px; }
}

/* Широкий экран и ландшафт: панель управления слева, планшет справа */
@media (min-aspect-ratio: 1/1) {
  #screen-test.active {
    display: grid;
    grid-template-columns: clamp(200px, 26vw, 300px) minmax(0, 1fr);
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas: "exit board" "prog board" "task board" "undo board";
    column-gap: 24px;
    row-gap: 12px;
  }
  .test-bar { display: contents; }
  #btn-exit-test { grid-area: exit; justify-self: start; margin-left: -8px; }
  .test-progress { grid-area: prog; }
  #btn-undo { grid-area: undo; justify-self: start; align-self: start; margin-left: -12px; }
  .test-task { grid-area: task; align-items: flex-start; flex-direction: column; gap: 10px; padding: 14px; }
  .board { grid-area: board; }
  .portraits-container { --cols: 4; --rows: 2; }
  .portraits-container[data-count="4"] { --rows: 1; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 520px) {
  body.in-test-mode .container { padding-top: 4px; padding-bottom: calc(4px + env(safe-area-inset-bottom)); }
  .test-task { padding: 10px; gap: 6px; }
  .task-mark { width: 30px; height: 30px; }
  .task-title { font-size: 15px; }
  #screen-test.active { row-gap: 8px; }
}

/* Подсказка на втором плане */
.series-toast {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 9500;
  width: min(420px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--ink);
  color: var(--on-ink);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.series-toast.active { opacity: 1; transform: translate(-50%, 0); }
.series-toast h3 { font-size: 15px; font-weight: 600; }
.series-toast p { margin-top: 2px; font-size: 14px; line-height: 1.45; opacity: 0.88; }

/* ---------- Результаты и история: шапка ---------- */
.results-head { display: grid; gap: 20px; padding: 4px 0 24px; }
.results-meta h1 {
  font-size: clamp(26px, 5.5vw, 36px);
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.results-meta > p { margin-top: 6px; font-size: 15px; color: var(--muted); }
.results-meta #results-date > div + div { margin-top: 8px; }
.test-run-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--sunken);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}
.test-run-tag .i { width: 14px; height: 14px; }

.results-note {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 14px;
  max-width: 62ch;
  border-left: 2px solid var(--rule-strong);
  background: var(--sunken);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.results-note-tag { font-size: 13px; color: var(--muted); flex: none; }
.results-note-text { font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }

.results-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.results-actions .btn-primary,
.results-actions .btn-secondary { min-height: 48px; padding: 10px 12px; font-size: 15px; font-weight: 500; }
.results-actions .btn-primary { font-weight: 600; }

@media (min-width: 720px) {
  .results-head { grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 32px; padding-bottom: 28px; }
  .results-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; }
  .results-actions .btn-primary,
  .results-actions .btn-secondary { padding: 10px 18px; }
}

/* ---------- Результаты: схемы ---------- */
.plans { display: grid; gap: 16px; }
.plan-sheet {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 20px 16px 12px;
  min-width: 0;
}
.plan-head { padding: 0 4px 12px; display: grid; gap: 10px; }
.plan-head h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.plan-term { font-size: 14px; font-weight: 400; color: var(--faint); margin-left: 6px; }
.plan-formula { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 15px; font-variant-numeric: tabular-nums; }
.f-group { display: inline-flex; align-items: baseline; gap: 6px; }
.f-code { font-weight: 600; }
.f-sym { display: inline-block; min-width: 1.1em; text-align: center; font-weight: 600; }
.f-sym.rx-pos { color: var(--pos); }
.f-sym.rx-neg { color: var(--neg); }
.f-sym.rx-amb { color: var(--ink); }
.f-sym.rx-zero { color: var(--faint); }

.szondi-chart-container { width: 100%; }
.szondi-svg-wrapper { width: 100%; }
.szondi-svg { display: block; width: 100%; height: auto; font-family: var(--font); overflow: visible; }
.szondi-svg text { font-family: var(--font); font-variant-numeric: tabular-nums; }
.szondi-svg .bar { transform-box: fill-box; }
.szondi-svg.animate .bar { animation: barGrow 0.5s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms); }
.szondi-svg.animate .bar-pos { transform-origin: 50% 100%; }
.szondi-svg.animate .bar-neg { transform-origin: 50% 0%; }
.szondi-svg.animate .bar-label { animation: fadeIn 0.3s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms + 300ms); }
@keyframes barGrow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 8px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch-pos { background: var(--pos); }
.swatch-neg { background: var(--neg); }
.legend-note { flex-basis: 100%; max-width: 70ch; }

@media (min-width: 720px) {
  .plan-sheet { padding: 24px 24px 16px; }
}
@media (min-width: 1000px) {
  .plans:not(.single) { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}

/* ---------- История ---------- */
.history-list { display: grid; gap: 12px; }
@media (min-width: 900px) {
  .history-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.history-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  align-content: start;
}
.history-card-date { font-size: 17px; font-weight: 600; letter-spacing: -0.005em; }
.history-note {
  padding-left: 12px;
  border-left: 2px solid var(--rule-strong);
  font-size: 15px;
  line-height: 1.45;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.history-plans { display: grid; gap: 8px; }
.history-plan { display: grid; gap: 2px; font-size: 15px; }
.history-plan-label { font-size: 13px; color: var(--muted); }
.history-plan .plan-formula { gap: 4px 18px; font-size: 16px; }
.history-actions { display: flex; gap: 8px; }
.history-actions .btn-primary { flex: 1; min-height: 44px; font-size: 15px; font-weight: 600; }
.history-actions .icon-btn { border: 1px solid var(--control); border-radius: var(--r-md); }

.history-empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 56px 16px;
  text-align: center;
  color: var(--muted);
}
.history-empty-state .i { width: 36px; height: 36px; stroke-width: 1.5; color: var(--faint); }
.history-empty-state h2 { font-size: 18px; font-weight: 600; color: var(--ink); margin-top: 4px; }
.history-empty-state p { max-width: 38ch; font-size: 15px; line-height: 1.5; }
.history-empty-state .btn-primary { margin-top: 12px; padding-left: 28px; padding-right: 28px; }

/* ---------- Диалоги ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9800;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.modal-overlay.active { display: flex; animation: screenIn 0.15s var(--ease); }

.modal-card {
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom));
  background: var(--sheet);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.modal-card-legal { max-width: 640px; }
.modal-title { font-size: 20px; font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
.modal-subtitle { margin-top: 4px; font-size: 14px; line-height: 1.45; color: var(--muted); }
.modal-message { font-size: 16px; line-height: 1.5; color: var(--muted); }
.modal-message strong { color: var(--ink); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.modal-btn { flex: 1 1 140px; min-height: 48px; }

.modal-note-body { display: grid; gap: 8px; }
.modal-note-textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px 14px;
  resize: vertical;
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--control);
  border-radius: var(--r-md);
}
.modal-note-textarea::placeholder { color: var(--faint); }
.modal-note-textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.modal-note-footer-meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.note-char-count { font-variant-numeric: tabular-nums; }
.note-char-count.warning { color: var(--ink); font-weight: 600; }
.note-char-count.danger { color: var(--neg); font-weight: 600; }

.legal-body { overflow-y: auto; overscroll-behavior: contain; padding-right: 4px; font-size: 15px; line-height: 1.6; color: var(--muted); }
.legal-body h4 { margin: 20px 0 6px; font-size: 16px; font-weight: 600; color: var(--ink); }
.legal-body p + p { margin-top: 8px; }
.legal-body strong { color: var(--ink); }
.legal-updated { font-size: 13px; color: var(--faint); }

@media (min-width: 560px) {
  .modal-overlay { align-items: center; padding: 24px; }
  .modal-card { border-radius: var(--r-lg); padding: 28px; }
  .modal-btn { flex: 0 1 auto; min-width: 120px; }
}

/* ---------- Баннер обновления ---------- */
.update-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 520px;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px 16px;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-lg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}
.update-banner[hidden] { display: none; }
.update-banner-text { flex: 1 1 220px; min-width: 0; display: grid; gap: 2px; }
.update-banner-text strong { font-size: 15px; font-weight: 600; }
.update-banner-text span { font-size: 14px; color: var(--muted); line-height: 1.45; }
.update-banner-actions { display: flex; gap: 8px; margin-left: auto; }
.update-banner-actions .btn-primary,
.update-banner-actions .btn-secondary { min-height: 44px; padding: 8px 16px; font-size: 15px; }
body.in-test-mode .update-banner { display: none; }

/* ---------- Движение ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Печать / PDF с компьютера ---------- */
@media print {
  :root {
    --page: #FFFFFF; --sheet: #FFFFFF; --sunken: #F1F3F6; --ink: #161B26; --muted: #4B5667; --faint: #5A6577;
    --rule: #D2D7DF; --rule-strong: #A9B1BE; --pos: #0A7060; --neg: #A93E24;
  }
  body { background: #FFFFFF; color: var(--ink); display: block; padding: 0; }
  .app-header, .app-footer, .results-actions, .skip-link, .modal-overlay, .update-banner, .series-toast,
  #screen-welcome, #screen-test, #screen-history { display: none !important; }
  .container { max-width: 100%; padding: 0; }
  .plan-sheet { break-inside: avoid; box-shadow: none; }
  .plans { display: block; }
  .plan-sheet + .plan-sheet { margin-top: 16px; }
  .szondi-svg.animate .bar, .szondi-svg.animate .bar-label { animation: none; }
}

[hidden] { display: none !important; }
