/* ── Zine tool ── */

main.wide .page-layout {
  max-width: 1440px;
}

main.wide .page-layout > .container {
  flex: 1 1 auto;
  max-width: none;
}

.zine-intro { margin-bottom: var(--stack-md); }
.zine-intro .back-link { margin-top: 0; margin-bottom: var(--stack-xs); }

.zine-layout {
  display: grid;
  grid-template-columns: minmax(340px, 2fr) minmax(0, 3fr);
  gap: 48px;
  align-items: start;
}

[hidden] { display: none !important; }

/* ── Controls ── */
.zine-controls {
  position: sticky;
  top: var(--stack-sm);
  /* At least the viewport's height; taller when the window is too short to fit it all. */
  min-height: max(560px, calc(100vh - 2 * var(--stack-sm)));
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: var(--stack-md);
}

.zine-controls fieldset {
  border: none;
  display: flex;
  flex-direction: column;
  gap: var(--stack-sm);
  min-width: 0;
}

.zine-controls legend {
  font-family: 'Libre Caslon Text', Georgia, serif;
  font-size: 24px;
  line-height: 1.4;
  padding: 0 0 var(--stack-xs);
  width: 100%;
  border-bottom: 0.5px solid var(--outline-variant);
  margin-bottom: var(--stack-sm);
}

.zine-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--stack-sm);
}

.zine-checks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--stack-xs) var(--stack-md);
}

.zine-controls select,
.zine-controls input[type="number"] {
  font-family: 'Libre Caslon Text', Georgia, serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--on-surface);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--outline);
  border-radius: 0;
  padding: 0.3rem 0;
  width: 100%;
  outline: none;
  text-transform: none;
  letter-spacing: normal;
}

.zine-controls select:focus,
.zine-controls input[type="number"]:focus {
  border-bottom: 2px solid var(--primary);
  padding-bottom: calc(0.3rem - 1px);
}

.zine-controls select option { background: var(--surface); }

.zine-unit {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  text-transform: none;
}

.zine-unit input[type="number"] { flex: 1; min-width: 0; }

/* The editor takes whatever height the settings leave over. */
.zine-controls fieldset.zine-editor {
  gap: var(--stack-xs);
}

.zine-editor textarea {
  flex: 1 1 auto;
  min-height: 240px;
  resize: none;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
  font-size: 14px;
  line-height: 1.55;
  tab-size: 4;
  border: 1px solid var(--outline-variant);
  padding: 0.75rem 0.9rem;
  background: var(--surface-container-low);
}

.zine-editor textarea:focus {
  border: 1px solid var(--primary);
  outline: 1px solid var(--primary);
}

.zine-warnings {
  list-style: none;
  font-size: 14px;
  line-height: 1.45;
  color: var(--error);
}

.zine-warnings li + li { margin-top: 0.25rem; }

.zine-help {
  font-size: 14px;
  line-height: 1.5;
  color: var(--on-surface-variant);
}

.zine-help summary {
  cursor: pointer;
  font-family: 'Work Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.zine-help p,
.zine-help table { margin-top: 0.5rem; }
.zine-help table { width: auto; }
.zine-help td { padding: 0.1rem 1rem 0.1rem 0; vertical-align: baseline; }

.zine-help code {
  font-size: 13px;
  background: var(--surface-container);
  padding: 0.05em 0.3em;
}

.zine-actions {
  display: flex;
  gap: var(--stack-xs);
  flex-wrap: wrap;
}

/* The library's buttons sit under its picker, so they are kept compact. */
.zine-lib-actions {
  display: flex;
  gap: var(--stack-xs);
  flex-wrap: wrap;
}

.zine-lib-actions button { padding: 0.5rem 0.9rem; }

.zine-hint {
  font-size: 15px;
  line-height: 1.5;
  color: var(--on-surface-variant);
}

/* Segmented radio group */
.zine-seg {
  display: inline-flex;
  border: 1px solid var(--outline);
}

.zine-seg > label {
  position: relative;
  flex-direction: row;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  color: var(--on-surface);
  border-left: 1px solid var(--outline);
  line-height: 1.2;
  user-select: none;
}

.zine-seg > label:first-child { border-left: none; }

.zine-seg input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.zine-seg > label:has(input:checked) {
  background: var(--primary);
  color: var(--on-primary);
}

.zine-seg > label:has(input:focus-visible) {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.zine-seg > label:hover:not(:has(input:checked)) { background: var(--surface-container); }

/* ── Preview ── */
.zine-preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--stack-sm);
  flex-wrap: wrap;
  font-family: 'Work Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
  margin-bottom: var(--stack-sm);
}

#zine-status.over { color: var(--error); }

#zine-sheet-view,
#zine-booklet-view {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Heads each sheet when the text runs to more than one zine. */
.zine-sheet-caption {
  align-self: stretch;
  font-family: 'Work Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
  margin-bottom: var(--stack-xs);
}

.zine-frame + .zine-sheet-caption { margin-top: var(--stack-md); }

.zine-frame {
  overflow: hidden;
  flex: none;
}

#zine-sheet-view .zine-frame {
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 6px 24px rgba(0, 0, 0, 0.08);
}

.zine-sheet,
.zine-booklet {
  transform-origin: 0 0;
}

.zine-sheet {
  position: relative;
  background: #fff;
  overflow: hidden;
}

.zine-slot { position: absolute; }
.zine-slot.flipped > .zine-page { transform: rotate(180deg); }

.zine-slot-label {
  position: absolute;
  top: 1.2mm;
  right: 1.5mm;
  font-family: 'Work Sans', sans-serif;
  font-size: 7pt;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #b3b3ad;
  pointer-events: none;
}

.zine-guides {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.zine-guides line { stroke-width: 0.2; }
.zine-guides .fold { stroke: #c4c4bd; stroke-dasharray: 1 1.5; }
.zine-guides .cut { stroke: #555; stroke-dasharray: 3 2; }
.zine-guides .scissors { font-size: 4px; fill: #555; font-family: sans-serif; }

.zine-booklet {
  display: flex;
  flex-direction: column;
}

.zine-spread { display: flex; }

.zine-spread-page {
  position: relative;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.07);
}

.zine-spread-page + .zine-spread-page { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.07), inset 0.3mm 0 0 #e4e4df; }
.zine-spread-page.empty { background: none; box-shadow: none; }

/* Off-screen, true-size pages used while paginating */
.zine-measure {
  position: absolute;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ── A single zine page (all sizes in physical units or em) ── */
.zine-page {
  position: relative;
  overflow: hidden;
  background: #fff;
  color: #000;
  font-family: var(--zine-font);
  font-size: var(--zine-size);
  line-height: var(--zine-lh);
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  overflow-wrap: break-word;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.zine-content {
  position: absolute;
  inset: 0;
  padding: var(--zine-margin);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.zine-page.has-num .zine-content { padding-bottom: calc(var(--zine-margin) + 1.6em); }

.zine-content.v-middle { justify-content: center; }
.zine-content.v-bottom { justify-content: flex-end; }
.zine-content.clipped { justify-content: flex-start; }

.zine-content.h-center .zine-flow { text-align: center; }
.zine-content.h-right .zine-flow { text-align: right; }

.zine-num {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--zine-margin);
  text-align: center;
  font-size: 0.8em;
  line-height: 1;
}

.zine-flow {
  display: flow-root;
  flex: none;
  min-width: 0;
}

.zine-flow > :first-child { margin-top: 0; }
.zine-flow > :last-child { margin-bottom: 0; }

.zine-flow p,
.zine-flow ul,
.zine-flow ol,
.zine-flow blockquote,
.zine-flow pre,
.zine-flow table { margin: 0 0 0.6em; }

.zine-flow h1,
.zine-flow h2,
.zine-flow h3,
.zine-flow h4,
.zine-flow h5,
.zine-flow h6 {
  font-family: inherit;
  font-weight: 700;
  letter-spacing: normal;
  line-height: 1.2;
  margin: 0.9em 0 0.4em;
}

.zine-flow h1 { font-size: 1.9em; line-height: 1.1; }
.zine-flow h2 { font-size: 1.45em; }
.zine-flow h3 { font-size: 1.2em; }
.zine-flow h4 { font-size: 1.05em; }
.zine-flow h5,
.zine-flow h6 { font-size: 1em; font-style: italic; }

.zine-flow ul,
.zine-flow ol { padding-left: 1.3em; }
.zine-flow li > ul,
.zine-flow li > ol { margin: 0.15em 0 0; }
.zine-flow li + li { margin-top: 0.15em; }
.zine-flow li > p { margin-bottom: 0.3em; }
.zine-flow li[data-cont] { list-style: none; }

.zine-content.h-center .zine-flow :is(ul, ol),
.zine-content.h-right .zine-flow :is(ul, ol) { list-style-position: inside; padding-left: 0; }

.zine-flow blockquote {
  border-left: 0.6mm solid currentColor;
  padding-left: 0.8em;
  font-style: italic;
}

.zine-flow a { color: inherit; }

.zine-flow code {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
  font-size: 0.88em;
}

.zine-flow pre {
  background: #f1f1f1;
  padding: 0.5em 0.6em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: left;
  line-height: 1.3;
}

.zine-flow pre[data-cont] { padding-top: 0; }

.zine-flow hr {
  border: none;
  border-top: 0.3mm solid currentColor;
  margin: 1em 0;
}

.zine-flow img {
  display: block;
  max-width: 100%;
  max-height: var(--zine-avail, 100%);
  width: auto;
  height: auto;
  object-fit: contain;
}

.zine-content.h-center .zine-flow img { margin: 0 auto; }
.zine-content.h-right .zine-flow img { margin-left: auto; }

.zine-flow table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
}

.zine-flow th,
.zine-flow td {
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
  color: inherit;
  border: 0.2mm solid currentColor;
  padding: 0.15em 0.35em;
  text-align: left;
}

.zine-flow th { font-weight: 700; }

@media (max-width: 900px) {
  .zine-layout { grid-template-columns: minmax(0, 1fr); }
  .zine-controls { position: static; height: auto; min-height: 0; }
  .zine-editor textarea { min-height: 50vh; }
  .zine-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .zine-row > label:first-child { grid-column: 1 / -1; }
}

/* ── Print: only the sheet, at true size ── */
@media print {
  html, body { background: #fff !important; }
  body > header,
  body > footer,
  .zine-intro,
  .zine-controls,
  .zine-preview-bar,
  #zine-booklet-view,
  .zine-sheet-caption,
  .zine-slot-label { display: none !important; }

  #zine-sheet-view[hidden] { display: block !important; }

  main,
  main.wide .page-layout,
  main.wide .page-layout > .container,
  .zine-layout,
  .zine-preview,
  #zine-sheet-view {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
    gap: 0 !important;
  }

  .zine-frame {
    width: auto !important;
    height: auto !important;
    box-shadow: none !important;
    overflow: visible;
  }

  .zine-sheet {
    transform: none !important;
    break-inside: avoid;
  }

  /* One sheet per printed page. */
  .zine-frame ~ .zine-frame { break-before: page; }

  .zine-sheet.no-print-guides .zine-guides { display: none; }
}

.zine-flow .zine-img-missing {
  display: block;
  padding: 0.5em;
  border: 1px dashed currentColor;
  font-size: 0.8em;
  text-align: center;
  opacity: 0.6;
}
