:root {
  --mat: #2c5a4b;   /* self-healing cutting mat: the desk a zine is made on */
  --mat-text: #cfe3da;
  --paper: #fff;
  --ink: #000;
  --muted: #6b6b6b;
  --line: #e2e2e2;
  --riso: #ff48b0;  /* risograph fluorescent pink, always with black text */
  --cm: 37.8px;     /* 1 cm at CSS 96 dpi, for the mat grid */
}
* { box-sizing: border-box; }
body {
  margin: 0; font: 14px/1.45 "Jost", system-ui, sans-serif; color: var(--ink);
  background-color: var(--mat);
  background-image:
    linear-gradient(rgb(255 255 255 / .12) 1px, transparent 1px),
    linear-gradient(90deg, rgb(255 255 255 / .12) 1px, transparent 1px),
    linear-gradient(rgb(255 255 255 / .05) 1px, transparent 1px),
    linear-gradient(90deg, rgb(255 255 255 / .05) 1px, transparent 1px);
  background-size: calc(var(--cm) * 5) calc(var(--cm) * 5), calc(var(--cm) * 5) calc(var(--cm) * 5), var(--cm) var(--cm), var(--cm) var(--cm);
}
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
input[type=checkbox], input[type=range] { accent-color: var(--ink); }

button, .btn {
  font: inherit; font-size: 13px; line-height: 1.2; border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  padding: 6px 11px; border-radius: 4px; cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--ink); }
button:disabled { opacity: .5; cursor: default; }
button.primary, button.danger { background: var(--riso); border-color: var(--riso); color: var(--ink); font-weight: 700; }
button.primary:hover, button.danger:hover { border-color: var(--ink); }
.btn input { display: none; }

textarea, input[type=text], input[type=url], select {
  font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; width: 100%;
  background: var(--paper); color: var(--ink);
}
textarea { resize: vertical; }

/* Toolbar */
.bar {
  position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 8px 16px; background: var(--ink); color: var(--paper);
}
.bar h1 { font: 400 22px/1 "Archivo Black", sans-serif; margin: 0 16px 0 0; display: flex; align-items: center; gap: 8px; }
.bar h1 img { width: 28px; height: 28px; }
.bar .spacer { flex: 1; }
.bar .field { display: flex; align-items: center; gap: 6px; color: #bbb; font-size: 13px; }
.bar select { width: auto; }
.bar button:not(.primary) { background: transparent; color: var(--paper); border-color: #444; }
.bar button:not(.primary):hover { border-color: var(--paper); }
.bar .seg { border-color: #444; background: transparent; }
.bar .seg button + button { border-left-color: #444; }
.bar .seg button.on { background: var(--paper); color: var(--ink); }
.bar :focus-visible { outline-color: var(--riso); }
.bar input[type=checkbox] { accent-color: var(--riso); }
#btn-reset { border-color: transparent; color: #999; }
#btn-reset:hover { color: var(--paper); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: var(--paper); }
.seg button { border: 0; border-radius: 0; padding: 6px 9px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--ink); color: var(--paper); }

/* Section tabs sit on the mat */
.tabs { margin: 12px 16px 0; max-width: calc(100% - 32px); overflow-x: auto; gap: 2px; border: 0; background: none; }
.tabs button { background: transparent; color: var(--mat-text); border-radius: 4px; padding: 7px 12px; font-size: 14px; }
.tabs button + button { border-left: 0; }
.tabs button:hover { color: var(--paper); background: rgb(255 255 255 / .1); }
.tabs button.on { background: var(--paper); color: var(--ink); }
.tabs :focus-visible { outline-color: var(--riso); }
.col.drop, .tabs .drop { outline: 2px dashed var(--riso); outline-offset: 2px; }

/* Editor: stacked by default, side by side on wide screens (see media query) */
.stage { padding: 16px; }
/* --ar (page aspect ratio) is set by renderEditor; the height cap keeps the whole page in view. */
canvas.page {
  display: block; width: min(100%, calc((100vh - 190px) * var(--ar, 1))); margin: 0 auto;
  background: #fff; touch-action: none;
  box-shadow: 0 1px 2px rgb(0 0 0 / .35), 0 10px 30px rgb(0 0 0 / .3);
}
.hint { color: var(--mat-text); font-size: 12px; text-align: center; margin: 12px 0 0; }

.panel { background: var(--paper); padding: 16px 20px 24px; }
.slide-head { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.slide-head h2 { font-size: 18px; font-weight: 700; margin: 0; white-space: nowrap; }
.slide-head .spacer { flex: 1; }

.controls { display: grid; }
.col { display: flex; flex-direction: column; gap: 8px; padding: 14px 0; }
.col + .col { border-top: 1px solid var(--line); }
.col-head { font-weight: 700; font-size: 15px; cursor: grab; user-select: none; }
select.move { width: auto; margin-left: auto; padding: 3px 6px; font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row > span:first-child { width: 84px; color: var(--muted); font-size: 13px; }
.row input[type=range] { flex: 1; min-width: 60px; }
.note { color: var(--muted); font-size: 12px; }
.note:empty { display: none; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.thumb { position: relative; }
.thumb canvas { display: block; border-radius: 3px; background: #eee; }
.thumb button { position: absolute; top: -6px; right: -6px; padding: 0 6px; border-radius: 50%; font-size: 11px; }

.foot { color: var(--mat-text); font-size: 12px; text-align: center; margin: 0; padding: 16px; }

/* Dialogs */
dialog { border: 0; border-radius: 6px; padding: 20px 24px; max-width: min(1100px, 94vw); }
dialog::backdrop { background: rgb(0 0 0 / .7); }
.dlg-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.dlg-head form { margin-left: auto; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dlg-nav { display: flex; justify-content: center; gap: 12px; margin-top: 16px; }
#confirm h2 { margin-top: 0; }

.book { display: grid; grid-template-columns: 1fr 1fr; width: min(86vw, 900px); margin: 0 auto; }
.book canvas { width: 100%; display: block; box-shadow: 0 4px 20px rgb(0 0 0 / .25); }
.book .empty { visibility: hidden; }
#preview-body > canvas { display: block; width: min(86vw, 1000px); box-shadow: 0 4px 20px rgb(0 0 0 / .25); }

.fold { display: grid; grid-template-columns: 260px 1fr; gap: 24px; align-items: start; }
.fold ol { margin: 0; padding-left: 20px; line-height: 1.6; }
.mini-sheet { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--ink); aspect-ratio: 297 / 210; }
/* The single cut: centre line across the two middle panels */
.mini-sheet .cut {
  position: absolute; left: 25%; right: 25%; top: 50%; border-top: 2px dashed var(--ink);
  font-style: normal; font-size: 20px; line-height: 0; text-indent: -10px;
}
.fold-video { margin: 12px 0 0; }
.fold-video a { color: var(--ink); font-weight: 700; }
.mini-sheet span { display: grid; place-items: center; border: 1px dashed var(--line); font: 700 22px "Jost", sans-serif; }
.mini-sheet .flip { transform: rotate(180deg); background: rgb(255 72 176 / .2); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 4px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}

/* Wide screens: an app layout, the mat fills the window and the panel scrolls on its own */
@media (min-width: 961px) {
  body { height: 100vh; display: flex; flex-direction: column; }
  main {
    flex: 1; min-height: 0; display: grid;
    grid-template-columns: minmax(0, 1fr) 360px; grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "tabs panel" "stage panel";
  }
  .slide { display: contents; }
  .tabs { grid-area: tabs; justify-self: start; margin: 14px 32px 0; }
  .stage { grid-area: stage; min-height: 0; display: flex; flex-direction: column; justify-content: center; padding: 16px 32px 44px; }
  .panel { grid-area: panel; overflow-y: auto; border-left: 1px solid var(--line); }
  .foot { position: fixed; left: 32px; bottom: 0; padding: 0 0 14px; text-align: left; }
}

@media (max-width: 720px) {
  /* Sticky would keep a multi-row bar over a quarter of a phone screen. */
  .bar { position: static; padding: 8px 12px; gap: 6px; }
  .bar h1 { font-size: 20px; margin-right: 4px; }
  .bar h1 img { width: 24px; height: 24px; }
  .bar .spacer { display: none; }
  .bar button { padding: 5px 8px; }
  .fold { grid-template-columns: 1fr; }
}
