@font-face {
  font-family: "EB Garamond";
  src: url(fonts/eb-garamond-latin-400-italic.woff2) format("woff2");
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "EB Garamond";
  src: url(fonts/eb-garamond-latin-ext-400-italic.woff2) format("woff2");
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "EB Garamond";
  src: url(fonts/eb-garamond-latin-400-normal.woff2) format("woff2");
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "EB Garamond";
  src: url(fonts/eb-garamond-latin-ext-400-normal.woff2) format("woff2");
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "EB Garamond";
  src: url(fonts/eb-garamond-latin-500-normal.woff2) format("woff2");
  font-weight: 500;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "EB Garamond";
  src: url(fonts/eb-garamond-latin-600-normal.woff2) format("woff2");
  font-weight: 600;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --paper: #f4f1ea;
  --paper-deep: #ebe5d9;
  --ink: #2b2722;
  --muted: #6d655b;
  --line: #d9d2c4;
  --line-strong: #c4b9a6;
  --accent: #b4532a;
  --accent-pressed: #93421f;
  --accent-wash: #f6e7dc;
  --on-accent: #fff;
  --warn: #8a4b00;
  --radius: 6px;
  --serif: "EB Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
  scrollbar-color: var(--line-strong) transparent;
}

* { box-sizing: border-box; }

::selection { background: var(--accent-wash); color: var(--ink); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.masthead {
  padding: 1.75rem clamp(1rem, 4vw, 3rem) 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 1.5rem;
  row-gap: 0.25rem;
}
.masthead h1 {
  margin: 0;
  font: 600 2rem/1.1 var(--serif);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.mark { width: 1.3em; height: 1.3em; }
.masthead p { margin: 0; color: var(--muted); max-width: 40rem; text-wrap: pretty; }
#restart { margin-left: auto; min-height: 2.5rem; padding: 0.4rem 0.85rem; font-weight: 500; color: var(--muted); background: transparent; box-shadow: none; }
#restart:hover { color: var(--ink); background: #fffdf9; }

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20rem;
  gap: clamp(1.5rem, 4vw, 4rem);
  padding: 1.75rem clamp(1rem, 4vw, 3rem);
  align-items: start;
}

/* The sheet */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 1.5rem;
}

.sheet {
  --ratio: 1.4142;
  position: relative;
  width: min(100%, calc((100svh - 11rem) * var(--ratio)));
  aspect-ratio: var(--ratio);
  background: #fff;
  box-shadow:
    0 1px 1px rgb(43 39 34 / 0.08),
    0 2px 4px rgb(43 39 34 / 0.06),
    0 18px 36px -12px rgb(43 39 34 / 0.28);
}

.sheet > * { position: absolute; }

.fold {
  pointer-events: none;
  border: 0 dashed rgb(43 39 34 / 0.22);
}
.sheet[data-shape="portrait"] .fold { left: 50%; top: 0; bottom: 0; border-left-width: 1px; }
.sheet[data-shape="landscape"] .fold { top: 50%; left: 0; right: 0; border-top-width: 1px; }

.caption { pointer-events: none; }

.frame {
  background: var(--paper-deep);
  touch-action: none;
  cursor: grab;
  overflow: hidden;
  outline-offset: 3px;
}
.frame:active { cursor: grabbing; }
.frame canvas { display: block; width: 100%; height: 100%; }
.frame:not(.has-photo) canvas { display: none; }
.frame.has-photo .empty { display: none; }
.frame:not(.has-photo) { cursor: pointer; }

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  padding: 1rem;
  outline: 1.5px dashed var(--line-strong);
  outline-offset: -10px;
  transition: background-color 0.2s var(--ease-out), outline-color 0.2s var(--ease-out);
}
.empty .icon { width: 2.25rem; height: 2.25rem; stroke-width: 1.25; color: var(--accent); margin-bottom: 0.4rem; }
.empty span { font: 600 1.4rem var(--serif); color: var(--ink); }
.empty small { font-size: 0.875rem; }
.empty:hover, .dropping .empty { background: var(--accent-wash); outline-color: var(--accent); }

.legend {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
  max-width: 34rem;
  text-wrap: balance;
}

/* The controls */

.controls {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

fieldset {
  margin: 0;
  padding: 0 0 1.5rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}
legend {
  padding: 0;
  margin-bottom: 0.75rem;
  font: 600 1.35rem/1.2 var(--serif);
}
legend small { font: 400 0.8125rem var(--sans); color: var(--muted); margin-left: 0.35rem; }

.button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  font: 600 0.9375rem var(--sans);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
  box-shadow: 0 1px 2px rgb(43 39 34 / 0.06);
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s var(--ease-out);
}
.button:hover { border-color: var(--line-strong); background: #fffdf9; }
.button:active { transform: translateY(1px); }
.button.primary {
  min-height: 3.25rem;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-size: 1rem;
  box-shadow: 0 1px 2px rgb(147 66 31 / 0.3), 0 6px 14px -6px rgb(147 66 31 / 0.5);
}
.button.primary:hover { background: var(--accent-pressed); border-color: var(--accent-pressed); }
.button:disabled { opacity: 0.45; cursor: default; box-shadow: none; transform: none; }
.button.primary:disabled:hover { background: var(--accent); border-color: var(--accent); }
#file:focus-visible + .button { outline: 2px solid var(--accent); outline-offset: 2px; }

.zoom { display: flex; align-items: center; gap: 0.25rem; }
.zoom input { flex: 1; min-width: 0; margin: 0 0.35rem; accent-color: var(--accent); }
.zoom input:disabled { opacity: 0.45; }

.icon-button {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  flex: none;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.icon-button:hover { background: var(--paper-deep); }
.icon-button:disabled { opacity: 0.35; cursor: default; background: transparent; }
#rotate { margin-left: 0.5rem; border: 1px solid var(--line); background: #fff; }
#rotate:hover { border-color: var(--line-strong); background: #fffdf9; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.6rem 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  text-align: center;
  font-size: 0.875rem;
  line-height: 1.25;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.tile:hover { border-color: var(--line-strong); }
.tile input { position: absolute; opacity: 0; pointer-events: none; }
.tile svg {
  width: 2.5rem;
  height: 2rem;
  margin-bottom: 0.25rem;
  fill: #fff;
  stroke: var(--muted);
  stroke-width: 1.25;
  stroke-linejoin: round;
}
.tile svg .fill { fill: #e3d6c6; stroke: none; }
.tile span { font-weight: 550; text-wrap: balance; }
.tile small { color: var(--muted); font-size: 0.75rem; }
.tile:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-wash);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.tile:has(input:checked) svg { stroke: var(--accent); }
.tile:has(input:checked) svg .fill { fill: #dc9a78; }
.tile:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

textarea {
  font: italic 1.125rem/1.4 var(--serif);
  color: var(--ink);
  caret-color: var(--accent);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.8rem;
  resize: vertical;
  width: 100%;
  min-height: 5.5rem;
  transition: border-color 0.15s;
}
textarea:hover { border-color: var(--line-strong); }
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

textarea.upright { font-style: normal; }

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 3px;
  gap: 3px;
  border-radius: calc(var(--radius) + 2px);
  background: var(--paper-deep);
}
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.segmented label {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 2.5rem;
  border-radius: var(--radius);
  font-family: var(--serif);
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:hover { color: var(--ink); }
.segmented label:has(input:checked) {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgb(43 39 34 / 0.12), 0 0 0 1px var(--line);
}
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.segmented .italic { font-style: italic; }
.size-small { font-size: 0.9375rem; }
.size-medium { font-size: 1.0625rem; }
.size-large { font-size: 1.25rem; }

.hint { margin: 0; color: var(--muted); font-size: 0.8125rem; text-wrap: pretty; }
.hint.warning { color: var(--warn); }

.finish { display: flex; flex-direction: column; gap: 0.75rem; }

.colophon {
  padding: 1rem clamp(1rem, 4vw, 3rem) 1.75rem;
  color: var(--muted);
  font-size: 0.8125rem;
}
.colophon p { margin: 0; }

@media (max-width: 52rem) {
  .workspace { grid-template-columns: 1fr; padding-top: 1.25rem; }
  .stage { position: static; }
  .sheet { width: min(100%, calc(70svh * var(--ratio))); }
  .masthead { padding-top: 1.25rem; }
  .masthead h1 { font-size: 1.75rem; }
  .masthead p { order: 2; flex-basis: 100%; }
  .masthead p { font-size: 0.9375rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
