@font-face {
  font-family: "Instrument Serif";
  src: url("./assets/InstrumentSerif-Regular.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: Barlow;
  src: url("./assets/Barlow-Regular.ttf") format("truetype");
  font-display: swap;
}
:root {
  --paper: #f8f6f0;
  --ink: #182d35;
  --muted: #56686a;
  --rust: #963c24;
  --rule: #c7ccc5;
  --wash: #e9ebe5;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font:
    16px/1.45 Barlow,
    Arial,
    sans-serif;
}
header,
main {
  max-width: 1320px;
  margin: auto;
  padding: 0 clamp(18px, 4vw, 62px);
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 72px;
}
header:after {
  content: "";
  position: absolute;
  top: 71px;
  left: 0;
  right: 0;
  border-bottom: 1px solid var(--rule);
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-weight: 600;
  letter-spacing: 0.025em;
}
.brand img {
  border-radius: 50%;
}
a,
.link {
  color: var(--rust);
  text-underline-offset: 3px;
}
header a {
  text-decoration: none;
}
h1,
h2,
p {
  margin: 0;
}
.intro {
  padding: clamp(22px, 4vh, 48px) 0 25px;
}
h1 {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  letter-spacing: -0.025em;
  font-size: clamp(42px, 5.7vw, 78px);
  line-height: 1.06;
}
.intro p {
  margin-top: 10px;
  color: var(--muted);
  font-size: clamp(16px, 1.5vw, 20px);
}
.bench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 300px);
  gap: clamp(20px, 3vw, 45px);
  padding-bottom: 36px;
}
.preview {
  min-width: 0;
  align-self: start;
  border: 1px solid var(--rule);
  border-radius: 5px;
  overflow: hidden;
}
.previewbar,
.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
}
.previewbar {
  min-height: 54px;
  border-bottom: 1px solid var(--rule);
}
#filename {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.switch {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 4px;
  background: var(--wash);
}
button,
.choose {
  font: inherit;
  cursor: pointer;
}
button:focus-visible,
.choose:focus-within,
a:focus-visible,
input:focus-visible {
  outline: 3px solid #287580;
  outline-offset: 3px;
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
.switch button {
  border: 0;
  color: var(--muted);
  background: transparent;
  padding: 4px 10px;
  border-radius: 3px;
}
.switch button[aria-pressed="true"] {
  background: var(--ink);
  color: white;
}
.stage {
  height: clamp(340px, 51vh, 640px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background-color: #e2e5df;
  background-image: radial-gradient(#bfc6bf 0.8px, transparent 0.8px);
  background-size: 10px 10px;
}
.stage.drag {
  outline: 3px dashed var(--rust);
  outline-offset: -6px;
}
canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: 0 4px 13px #17282226;
}
.foot {
  font-size: 13px;
  color: var(--muted);
  min-height: 36px;
}
.controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 3px 0;
}
h2,
legend {
  font-family: "Instrument Serif", Georgia, serif;
  letter-spacing: -0.025em;
  font-weight: normal;
  font-size: 23px;
  margin-bottom: 9px;
}
.choose,
.save {
  border-radius: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  min-height: 44px;
}
.choose {
  border: 1px solid var(--ink);
  background: var(--paper);
}
.choose:hover,
.turns button:hover {
  background: var(--wash);
}
.controls:has(#file:focus-visible) .choose {
  outline: 3px solid #287580;
  outline-offset: 2px;
}
#file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.file-note,
#status {
  font-size: 14px;
  color: var(--muted);
}
.file-note {
  margin: 5px 0;
}
.link {
  border: 0;
  background: transparent;
  text-decoration: underline;
  padding: 0;
  font-size: 14px;
}
.line {
  border-top: 1px solid var(--rule);
  padding-top: 13px;
}
#status {
  min-height: 20px;
}
.readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 8px;
}
.readout div {
  display: grid;
  gap: 1px;
}
.readout span,
.slider-label {
  color: var(--muted);
  font-size: 14px;
}
.readout strong {
  font-size: 21px;
  font-weight: normal;
  font-variant-numeric: tabular-nums;
}
fieldset {
  padding: 0;
  border: 0;
  margin: 0;
}
legend {
  font: inherit;
  font-weight: 600;
  margin-bottom: 6px;
}
.turns {
  display: flex;
  gap: 8px;
}
.turns button {
  flex: 1;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: transparent;
  padding: 5px 0;
}
.slider-label {
  display: flex;
  justify-content: space-between;
  margin: 8px 0 0;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--rust);
  margin: 5px 0;
}
.save {
  border: 1px solid var(--ink);
  color: var(--paper);
  background: var(--ink);
}
.save:hover:enabled {
  background: #28434c;
}
@media (max-width: 790px) {
  .bench {
    grid-template-columns: minmax(0, 1fr);
  }
  .stage {
    height: 46vh;
    min-height: 260px;
  }
  .controls {
    gap: 15px;
  }
  .intro {
    padding-top: 21px;
  }
  header {
    height: 55px;
  }
  header:after {
    top: 54px;
  }
}
@media (max-width: 420px) {
  .foot,
  .previewbar {
    padding: 8px;
  }
  .foot {
    flex-wrap: wrap;
  }
  .stage {
    padding: 12px;
  }
  .switch button {
    padding: 4px 7px;
  }
}
.modes { display: flex; gap: 4px; margin: -7px 0 18px; }
.modes a { padding: 4px 16px; text-decoration: none; border-radius: 3px; color: var(--muted); }
.modes a[aria-current] { background: var(--ink); color: var(--paper); }
.modes a:hover { text-decoration: underline; }
.pager { justify-content: center; font-size: 15px; }
.pager select, .pager button { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--rule); border-radius: 3px; padding: 4px 9px; }
#direction { font-size: 19px; margin: 8px 0 13px; }
#keep, .choose + input + .link { margin-top: 8px; }
[hidden] { display: none !important; }

.flip-option { display: flex; align-items: center; gap: 7px; margin-top: 10px; color: var(--ink); font-size: 15px; }
.flip-option input { accent-color: var(--ink); margin: 0; }
#detect-mirror { margin-bottom: 7px; }

#spread-view { touch-action: none; cursor: crosshair; }
.secondary-save { margin-top: 8px; color: var(--ink); background: var(--paper); }
.secondary-save:hover:enabled { background: var(--wash); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.spread-samples { margin-top: 5px; font-size: 14px; color: var(--muted); }
.mark-fold { margin: 8px 0; }
.mark-fold[aria-pressed="true"] { background: var(--wash); }

.modes { flex-wrap: wrap; }
.book-options { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 10px 0 14px; }
.book-options select { font: inherit; }
.book-decisions { display: flex; gap: 16px; margin-top: 10px; align-items: baseline; }
.book-decisions label { cursor: pointer; text-decoration: underline; }
#book-view { touch-action: none; cursor: crosshair; }
#progress { white-space: nowrap; }

#writing-mode {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 4px 8px;
  margin: 0 0 12px 4px;
}
#writing-mode + label.choose { display: block; width: fit-content; }

#cut-detail { border-bottom: 1px solid var(--rule); border-top: 1px solid var(--rule); }
#cut-detail summary { padding: 10px 16px; cursor: pointer; font-weight: 600; }
#cut-detail summary:focus-visible { outline: 3px solid #287580; outline-offset: -3px; }
.detail-body { padding: 0 16px 12px; }
.detail-body input { width: 100%; }
.detail-frame { position: relative; margin: 3px 0 6px; padding: 7px; background: linear-gradient(#ffe192, #ffe192) left center / 7px 2px no-repeat, linear-gradient(#ffe192, #ffe192) right center / 7px 2px no-repeat, var(--ink); }
.detail-frame canvas { display: block; margin: 0 auto; }
.detail-frame::before, .detail-frame::after { content: ""; position: absolute; left: 50%; height: 7px; width: 2px; background: #ffe192; transform: translateX(-50%); }
.detail-frame::before { top: 0; }
.detail-frame::after { bottom: 0; }
