/* СГИБ — оформление.
   Чёрно-белая типографская подача: моноширинный шрифт в интерфейсе, крупные
   кнопки-переключатели, никаких украшений, которые спорили бы с самим зином. */

:root {
  --ink: #111111;
  --ink-soft: #4a4a4a;
  --ink-faint: #8a8a8a;
  --paper: #f4f2ee;
  --paper-raised: #ffffff;
  --line: #d8d4cc;
  --line-strong: #111111;
  --accent: #1f3a93;
  --dark: #141414;
  --dark-soft: #2a2a2a;

  --mono: 'PT Mono', 'SFMono-Regular', Consolas, monospace;
  --display: 'Oswald', 'Arial Narrow', sans-serif;

  --topbar-h: 56px;
  --footer-h: 40px;
  --radius: 3px;
}

* { box-sizing: border-box; }

/* Собственный display у флекс-контейнеров перебивает атрибут hidden, из-за чего
   скрытые блоки настроек оставались на экране. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 400; }
button { font: inherit; color: inherit; }

/* ---------- Шапка ---------- */

.topbar {
  flex: 0 0 auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--dark);
  color: #fff;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand__mark {
  width: 15px;
  height: 19px;
  flex: 0 0 auto;
  align-self: center;
  background: #fff;
  /* Уголок загнут — знак сложенного листа. */
  clip-path: polygon(0 0, 100% 0, 100% 62%, 58% 100%, 0 100%);
}

.brand__name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.16em;
  line-height: 1;
}

.brand__tag {
  color: #9a9a9a;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- Кнопки и переключатели ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, transform 0.06s;
}

.btn:hover { background: #eae7e0; }
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn--primary:hover { background: #172d75; }

.btn--ghost {
  border-color: var(--line);
  background: transparent;
  text-transform: none;
  letter-spacing: 0.02em;
}
.btn--ghost:hover { background: rgba(0, 0, 0, 0.05); }

.btn[disabled] { opacity: 0.45; cursor: default; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  overflow: hidden;
}

.topbar .segmented {
  border-color: #444;
  background: transparent;
}

.seg {
  min-height: 30px;
  min-width: 34px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 12px;
  letter-spacing: 0.05em;
  cursor: pointer;
  white-space: nowrap;
}

.seg + .seg { border-left: 1px solid var(--line); }
.topbar .seg + .seg { border-left-color: #444; }
.seg:hover { background: rgba(0, 0, 0, 0.06); }
.topbar .seg:hover { background: rgba(255, 255, 255, 0.1); }

.seg[aria-pressed='true'] {
  background: var(--ink);
  color: #fff;
}
.topbar .seg[aria-pressed='true'] { background: #fff; color: var(--dark); }

.segmented--bw .seg { min-width: 30px; font-size: 11px; }

/* ---------- Раскладка редактора ---------- */

.editor {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 168px 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    'blocks stage'
    'controls controls';
}

/* ---------- Список блоков ---------- */

.blocks {
  grid-area: blocks;
  overflow-y: auto;
  padding: 12px 10px 16px;
  border-right: 1px solid var(--line);
  background: #efece6;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.block {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  text-align: center;
}

.block__frame {
  display: block;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  padding: 4px;
  border-radius: var(--radius);
  transition: border-color 0.12s, box-shadow 0.12s;
}

.block[aria-current='true'] .block__frame {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 2px var(--ink);
}

.block__frame canvas { display: block; margin: 0 auto; }

.block__label {
  display: block;
  margin-top: 5px;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.block--dragging { opacity: 0.4; }
.block--dropbefore .block__frame { box-shadow: 0 -3px 0 0 var(--accent); }
.block--dropafter .block__frame { box-shadow: 0 3px 0 0 var(--accent); }

.block__grip {
  display: inline-block;
  margin-right: 4px;
  color: var(--ink-faint);
  cursor: grab;
}

/* ---------- Сцена ---------- */

.stage {
  grid-area: stage;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #35322d;
}

.stage__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-height: 100%;
  min-height: 0;
}

.stage__label {
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #a8a29a;
}

.stage__canvas-wrap {
  min-height: 0;
  display: flex;
  gap: 0;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  background: #fff;
}

.stage__canvas { display: block; touch-action: none; }
.stage__canvas--grab { cursor: grab; }
.stage__canvas--grabbing { cursor: grabbing; }

.stage__hint {
  margin: 0;
  min-height: 1.2em;
  font-size: 11px;
  color: #a8a29a;
}

/* ---------- Панель настроек ---------- */

.controls {
  grid-area: controls;
  border-top: 1px solid var(--line);
  background: #e9e6df;
  padding: 12px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 46vh;
  overflow-y: auto;
}

.controls__row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 16px;
}

.controls__row--type { gap: 14px 20px; align-items: flex-end; }

.pagetabs { display: flex; flex-direction: column; gap: 4px; }
.pagetabs:empty { display: none; }

.pagetab {
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.pagetab[aria-pressed='true'] { background: var(--ink); color: #fff; border-color: var(--ink); }

.photo { display: flex; flex-direction: column; gap: 7px; }

/* Слоты для фотографий страницы: заполненные миниатюры и один пустой в конце. */

.slots {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  margin: -4px;
  border-radius: var(--radius);
}

.slots--over { background: rgba(31, 58, 147, 0.1); outline: 1.5px dashed var(--accent); }

.slot {
  position: relative;
  width: 88px;
  height: 88px;
  flex: 0 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
}

.slot--filled { border: 1px solid var(--line-strong); background: #ddd; }
.slot--filled img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot--active { box-shadow: 0 0 0 2px var(--accent); }

/* Прозрачная кнопка поверх миниатюры — выбирает снимок для настройки. */
.slot__hit { position: absolute; inset: 0; border: 0; background: none; cursor: pointer; }
.slot__hit:hover { background: rgba(255, 255, 255, 0.22); }

.slot__remove,
.slot__replace {
  position: absolute;
  top: 3px;
  width: 19px;
  height: 19px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.78);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.slot__remove { right: 3px; font-size: 14px; }
.slot__replace { left: 3px; }
.slot__remove:hover { background: #b32020; }
.slot__replace:hover { background: var(--accent); }

.slider { display: flex; flex-direction: column; gap: 2px; }
.slider input[type='range'] { width: 132px; }
.slider input[type='range']:disabled { opacity: 0.4; }

.slot--empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 1.5px dashed var(--ink-faint);
  background: var(--paper-raised);
  color: var(--ink-soft);
  cursor: pointer;
  text-align: center;
  padding: 4px;
}

.slot--empty:hover { border-color: var(--accent); color: var(--accent); background: #fff; }
.slot__plus { font-size: 19px; line-height: 1; }
.slot__text { font-size: 10.5px; }
.slot__hint { font-size: 9px; color: var(--ink-faint); }

.slot__swap {
  flex: 0 0 auto;
  width: 24px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  font-size: 13px;
  cursor: pointer;
}
.slot__swap:hover { border-color: var(--ink); background: #fff; }

/* В один ряд: колонка с фотографиями и без того самая высокая в панели. */
.photo__actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spreadtools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* Цвет страницы: готовые образцы, цвета с фотографии и произвольный цвет. */

.swatches { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-pressed='true'] { box-shadow: 0 0 0 2px var(--accent); }
.swatch--photo { border-radius: 50%; }

.swatches__sep {
  width: 1px;
  height: 20px;
  margin: 0 3px;
  background: var(--line);
}

.colorpick {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px 3px 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  font-size: 10.5px;
  cursor: pointer;
}
.colorpick input {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.fields {
  flex: 1 1 320px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 240px;
}

.field { flex: 1 1 180px; display: flex; flex-direction: column; gap: 3px; }
.field--grow { flex: 1 1 100%; }

.field__label,
.group__label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.field input,
.field textarea {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.seg:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field input::placeholder,
.field textarea::placeholder { color: #b3aea4; }

.group { display: flex; flex-direction: column; gap: 5px; }
.group__inline { display: flex; align-items: center; gap: 8px; }
.group--fonts { flex: 1 1 100%; }

.fontlist { display: flex; flex-wrap: wrap; gap: 5px; }

.fontbtn {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.fontbtn:hover { background: #fff; border-color: var(--ink-faint); }
.fontbtn[aria-pressed='true'] { background: var(--ink); color: #fff; border-color: var(--ink); }
.fontbtn__label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.04em; opacity: 0.7; }

input[type='range'] { width: 116px; accent-color: var(--accent); }

output { font-variant-numeric: tabular-nums; }

.check {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  font-size: 11.5px;
  line-height: 1.4;
  cursor: pointer;
}
.check input { margin: 2px 0 0; accent-color: var(--accent); }
.check em { display: block; font-style: normal; font-size: 10.5px; color: var(--ink-faint); }

/* ---------- Подвал ---------- */

.footer {
  flex: 0 0 auto;
  min-height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 16px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  font-size: 10.5px;
  color: var(--ink-soft);
}

.footer__nav { display: flex; gap: 14px; flex-wrap: wrap; }

.link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.link:hover { color: var(--accent); }

.footer__right { color: var(--ink-faint); text-align: right; }

/* ---------- Модальные окна ---------- */

.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }

.modal__backdrop { position: absolute; inset: 0; background: rgba(10, 10, 10, 0.72); }

.modal__box {
  position: relative;
  width: min(720px, 100%);
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal__box--wide { width: min(1000px, 100%); }

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--dark);
  color: #fff;
}

.modal__head h2 {
  font-family: var(--display);
  font-size: 16px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.modal__close {
  border: 0;
  background: none;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}

.modal__body { padding: 16px; overflow-y: auto; }

/* Печать */

.print { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(260px, 0.85fr); gap: 20px; }
.print__preview { display: flex; flex-direction: column; gap: 8px; }
.print__preview canvas { width: 100%; height: auto; border: 1px solid var(--line); background: #fff; }
.print__caption { margin: 0; font-size: 11px; color: var(--ink-soft); }
.print__side { display: flex; flex-direction: column; gap: 14px; }
.print__buttons { display: flex; flex-direction: column; gap: 7px; }
.print__status { margin: 0; min-height: 1.3em; font-size: 11px; color: var(--accent); }

.tips h3 { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px; }
.tips ol { margin: 0; padding-left: 18px; font-size: 11.5px; line-height: 1.55; }
.tips ol b { background: #e2ded4; padding: 0 3px; }
.tips__extra { font-size: 11px; color: var(--ink-soft); margin: 8px 0 0; }

/* Как сложить */

.fold__lead { margin: 0 0 14px; font-family: var(--display); font-size: 15px; letter-spacing: 0.1em; text-transform: uppercase; }
.fold__diagram svg { width: 100%; height: auto; display: block; margin-bottom: 16px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 9px; font-size: 12.5px; line-height: 1.55; }
.steps b { letter-spacing: 0.02em; }

/* Что это такое */

.about { font-size: 12.5px; line-height: 1.6; }
.about p { margin: 0 0 11px; }
.about h3 { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); margin: 16px 0 6px; }
.about ul { margin: 0 0 11px; padding-left: 20px; }
.about li { margin-bottom: 4px; }
.about a { color: var(--accent); }
.about__credit { color: var(--ink-soft); font-size: 11.5px; border-top: 1px solid var(--line); padding-top: 11px; margin-top: 14px; }

/* ---------- Всплывающее сообщение ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 58px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
  padding: 9px 14px;
  border-radius: var(--radius);
  background: var(--dark);
  color: #fff;
  font-size: 11.5px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.4);
}
.toast[hidden] { display: none; }

/* ---------- Печать ---------- */

#print-sheet { display: none; }

@media print {
  body > *:not(#print-sheet) { display: none !important; }

  #print-sheet {
    display: block;
    margin: 0;
    padding: 0;
  }

  #print-sheet img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  /* Точный размер листа и никаких полей: любое масштабирование сдвигает сгибы.
     Само правило @page подставляется из js/export.js — @page не умеет зависеть
     от класса на body, а формат выбирает читатель. */
  @page { margin: 0; }
}

/* ---------- Узкие экраны ---------- */

@media (max-width: 900px) {
  .print { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  /* На узком экране всё в один экран не помещается: панель настроек съедала
     высоту предпросмотра до нуля. Здесь страница просто прокручивается, а сцене
     отводится фиксированная доля экрана. */
  html, body { height: auto; }
  body { min-height: 100%; }

  .editor { display: block; }

  .stage {
    height: 44vh;
    min-height: 240px;
  }

  .blocks {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 10px;
    gap: 8px;
  }

  .block { flex: 0 0 92px; }

  .stage { padding: 12px 10px; }
  .controls { max-height: none; overflow: visible; }
  .controls__row { gap: 12px; }
  .fields { min-width: 0; flex-basis: 100%; }
  .group--fonts { order: -1; }

  .brand__tag { display: none; }
  .footer { flex-wrap: wrap; justify-content: center; text-align: center; }
  .footer__right { flex-basis: 100%; text-align: center; }
}

@media (max-width: 420px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .btn { padding: 0 10px; font-size: 11px; }
  .dropzone { width: 96px; height: 80px; }
}
