/* Editor-only chrome. Never part of the printed page itself (layout.css
   owns the printed sheet). */

:root {
  color-scheme: light;
  --bg: #f4f0e8;
  --surface: #fffdf9;
  --ink: #2b2622;
  --muted: #7a7068;
  --line: #e3dbcf;
  --accent: #d9603a;
  --accent-dark: #b9502c;
  --accent-soft: #fbe7df;
  --radius: 10px;
  --shadow-page: 0 1px 2px rgba(60, 40, 20, 0.08), 0 6px 18px rgba(60, 40, 20, 0.1);
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  font-family: var(--ui-font);
  font-size: 14px;
}

/* --- Top bar --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 24px;
  background: rgba(255, 253, 249, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-logo {
  width: 28px;
  height: 28px;
}

.brand-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 3px;
  border-radius: 999px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.tab:hover {
  color: var(--ink);
}

.tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(60, 40, 20, 0.15);
}

.actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Site language: switches the interface, the help and preset words. */
.lang-select {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}

/* --- Buttons and form controls --- */

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  border-color: #cbbfae;
  background: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: var(--bg);
  border-color: transparent;
  color: var(--ink);
}

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

.btn-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn-block {
  width: 100%;
}

.panel select,
.panel input[type="date"],
.panel input[type="datetime-local"],
.panel input[type="month"],
.panel input[type="number"],
.panel input[type="text"],
.panel input[type="tel"] {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}

.panel select:focus,
.panel input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input {
  accent-color: var(--accent);
}

/* --- Workspace: tools panel + pages --- */

.workspace {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  padding: 24px;
}

.panel {
  position: sticky;
  top: 76px;
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preset-target {
  color: var(--accent-dark);
}

.panel-card h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* A select is as wide as its longest option; min-width 0 lets it shrink
   to the panel instead (long translated entries overflowed it). */
.row select {
  flex: 1 1 auto;
  min-width: 0;
}

.panel select {
  max-width: 100%;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px dashed var(--line);
}

.options[hidden],
.btn[hidden] {
  display: none;
}

/* Bold / italic / color buttons. */
.format-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.fmt {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}

.fmt:hover {
  border-color: #cbbfae;
}

.fmt svg {
  display: block;
  width: 16px;
  height: 16px;
  margin: auto;
  fill: var(--ink);
  stroke: var(--ink);
  stroke-width: 1.4;
  stroke-linecap: round;
}

.fmt svg circle,
.fmt svg text {
  stroke: none;
}

.fmt svg text {
  font: 700 6px var(--ui-font);
}

.fmt svg rect {
  fill: none;
}

.fmt-bold {
  font-weight: 800;
}

.fmt-italic {
  font-style: italic;
  font-family: Georgia, serif;
}

/* Line break: formatting buttons on top, colors below. */
.fmt-sep {
  flex-basis: 100%;
  height: 2px;
}

.swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
  background: currentColor;
  cursor: pointer;
  padding: 0;
}

.swatch:hover {
  transform: scale(1.15);
}

/* --- Pages --- */

.pages {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8mm;
  zoom: var(--zoom, 1.25);
}

.sheet-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3mm;
}

/* "Back side" unchecked: pages 9-16 are neither shown nor printed. */
body.no-back .sheet-group.back {
  display: none;
}

.sheet-label {
  font-size: 3.2mm;
  font-weight: 700;
  color: var(--muted);
}

/* Hiding the label frees its space for .cell-content via flex (see
   layout.css: .cell-label is flex:0 0 auto, .cell-content flex:1 1 auto).
   Applies on screen and at print time alike. */
body.hide-page-numbers .cell-label {
  display: none;
}

.sheet {
  background: #fff;
  box-shadow: var(--shadow-page);
}

/* By default every page shows its rendered view (formatting, presets).
   Clicking a page switches that one page to a plain-text textarea; clicking
   away renders it again. The raw markdown stays the single source of truth
   (what's stored and exported). */
textarea.cell-content {
  display: none;
}

/* A flex column, so a preset block (layout.css: .preset) can take whatever
   height is left below the page's text. */
.cell-print {
  display: flex;
  flex-direction: column;
  cursor: text;
}

.cell-inner.editing textarea.cell-content {
  display: block;
}

.cell-inner.editing .cell-print {
  display: none;
}

/* Page view (the default on screen): each page is a normal upright card,
   in reading order, instead of the rotated cells of the printed sheet.
   Same DOM, same mm sizes; only the arrangement differs. Printing uses
   layout.css's sheet as is. */
@media screen {
  .sheet {
    width: 100%;
    height: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, 74.25mm);
    grid-template-rows: none;
    justify-content: center;
    gap: 6mm;
    overflow: visible;
    background: transparent;
    box-shadow: none;
  }

  .sheet .cell {
    width: 74.25mm;
    height: 105mm;
    border: 0;
    border-radius: 1.2mm;
    background: #fff;
    box-shadow: var(--shadow-page);
    transition: box-shadow 0.15s;
  }

  .sheet .cell:hover {
    box-shadow: 0 0 0 0.4mm #e9d9c9, var(--shadow-page);
  }

  /* The page presets and formatting buttons will act on. */
  .sheet .cell.selected {
    box-shadow: 0 0 0 0.4mm var(--accent-soft), 0 0 0 0.7mm #f0b9a4, var(--shadow-page);
  }

  .sheet .cell:has(.editing) {
    box-shadow: 0 0 0 0.5mm var(--accent), var(--shadow-page);
  }

  .sheet .cell.drop-target {
    box-shadow: 0 0 0 0.6mm var(--accent), var(--shadow-page);
    background: var(--accent-soft);
  }

  .sheet .cell-inner {
    transform: translate(-50%, -50%);
  }

  /* DOM order is A1,A2,B1,B2,C1,C2,D1,D2 = pages 8,7,1,6,2,5,3,4 (9..16 on
     the back); show them 1..8. */
  .sheet .cell:nth-child(1) { order: 8; }
  .sheet .cell:nth-child(2) { order: 7; }
  .sheet .cell:nth-child(3) { order: 1; }
  .sheet .cell:nth-child(4) { order: 6; }
  .sheet .cell:nth-child(5) { order: 2; }
  .sheet .cell:nth-child(6) { order: 5; }
  .sheet .cell:nth-child(7) { order: 3; }
  .sheet .cell:nth-child(8) { order: 4; }

  .cell-label {
    color: #b3a899;
    font-weight: 600;
  }
}

/* --- Help --- */

.help {
  max-width: 820px;
  margin: 0 auto;
  padding: 24px;
}

/* "How to fold": the picture steps under the list. */
/* Flex, not grid: a short last row stays centred. */
.fold-steps {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin: 16px 0 8px;
}

.fold-steps figure {
  flex: 0 1 110px;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.fold-steps img {
  width: 100%;
  height: 150px;
  object-fit: contain;
}

/* The same pictures, small, in the editor's side panel. */
.fold-steps-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 8px;
  margin: 0;
}

.fold-steps-panel img {
  height: 78px;
}

.fold-steps-panel figcaption {
  font-size: 11px;
}

.fold-steps figcaption {
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted);
  text-align: center;
}

.help-body {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 32px 24px;
  line-height: 1.6;
  font-size: 15px;
}

.help-body[hidden] {
  display: none;
}

.help-body h1 {
  font-size: 26px;
  letter-spacing: -0.02em;
  margin: 20px 0 4px;
}

.help-body .lead {
  color: var(--muted);
  font-size: 16px;
}

.help-body h2 {
  font-size: 18px;
  margin: 28px 0 6px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.help-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
}

.help-body th,
.help-body td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.help-body th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.help-body pre {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 14px;
  overflow-x: auto;
}

.help-body pre code {
  padding: 0;
  background: none;
}

.help-body code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  background: var(--bg);
  border-radius: 4px;
  padding: 1px 5px;
}

.tab-panel[hidden] {
  display: none;
}

/* --- Narrow screens: panel above the pages --- */

@media screen and (max-width: 900px) {
  .workspace {
    flex-direction: column;
    padding: 16px;
  }

  .panel {
    position: static;
    flex: none;
    width: 100%;
    max-height: none;
  }

  .pages {
    width: 100%;
  }
}

@media print {
  body {
    background: #fff;
    margin: 0;
    padding: 0;
    display: block;
  }

  .no-print {
    display: none !important;
  }

  /* Print the booklet even if the Help tab is open. */
  #tab-editor {
    display: block !important;
    padding: 0;
  }

  .pages {
    zoom: 1;
    display: block;
  }

  .sheet {
    box-shadow: none;
  }

  /* Printing always shows the rendered view, even for a page mid-edit. */
  textarea.cell-content {
    display: none !important;
  }

  .cell-print {
    display: flex !important;
  }
}

/* Paper step: a small number field with "mm" after it. */
.step-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
}

.step-label input {
  width: 64px;
}

/* Footer: the site version and a link to the list of changes. */
.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 16px 16px 24px;
}

.site-footer a {
  color: inherit;
}

.changelog h2 {
  font-variant-numeric: tabular-nums;
}

#paper-options .row {
  flex-wrap: nowrap;
}

/* A small caption in front of a field, like "Date". */
.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.field-label input {
  flex: 1 1 auto;
  min-width: 0;
}
