/* Pratham Mukewar. One column, set like a paper, with notes in the right margin on wide screens. */

@font-face { font-family: "Libertinus Serif"; src: url("../fonts/serif-regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Libertinus Serif"; src: url("../fonts/serif-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Libertinus Serif"; src: url("../fonts/serif-semibold.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Libertinus Sans"; src: url("../fonts/sans-regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }

:root {
  --paper: #faf8f3;
  --ink: #1d1c19;
  --muted: #5d584f;
  --rule: #ddd6c9;
  --accent: #a2271c;
  --tint: rgba(162, 39, 28, 0.07);
  --line: #b5ac9c;
  --text: 35rem;
  --gap: 2.75rem;
  --notes: 13.5rem;
  --serif: "Libertinus Serif", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Libertinus Sans", "Gill Sans", "Seravek", "Segoe UI", system-ui, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15140f;
    --ink: #e9e5da;
    --muted: #a59f92;
    --rule: #38342c;
    --accent: #ee8a6a;
    --tint: rgba(238, 138, 106, 0.09);
    --line: #6a6357;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  font-size: 112.5%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 1.5rem;
}
@media (min-width: 64em) { html { font-size: 125%; } }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.55;
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  font-variant-ligatures: common-ligatures;
  hanging-punctuation: first;
}

.page {
  max-width: var(--text);
  margin: 0 auto;
  padding: 0 1rem;
}

/* Wide screens: the text column plus a margin for notes, centred together. */
@media (min-width: 72em) {
  .page {
    box-sizing: content-box;
    margin-left: max(5rem, calc(50% - (var(--text) + var(--gap) + var(--notes)) / 2));
    padding: 0;
  }
}

p { margin: 0 0 0.9em; }
h1, h2, h3 { font-weight: 400; margin: 0; }
i, cite, em { font-style: italic; }
cite { font-style: italic; }
sub, sup { font-size: 0.72em; line-height: 0; }

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--line);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
a:hover { color: var(--accent); text-decoration-color: var(--accent); }

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

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  padding: 0.4em 0.8em;
  background: var(--paper);
  border: 1px solid var(--accent);
  z-index: 2;
}
.skip:focus { top: 1rem; }

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

/* Opening */

.opening { padding-top: clamp(2.5rem, 9vh, 6rem); }

h1 {
  font-size: clamp(2.3rem, 1.6rem + 3vw, 3.3rem);
  line-height: 1.05;
  letter-spacing: -0.012em;
  margin-bottom: 0.55em;
}

.lede { font-size: 1.14em; line-height: 1.45; }

.honors {
  font-variant-caps: all-small-caps;
  font-variant-numeric: oldstyle-nums;
  letter-spacing: 0.035em;
  color: var(--muted);
}
.honors span { white-space: nowrap; }

.contents {
  list-style: none;
  padding: 0;
  margin: 1.6em 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2em 1.4em;
}
.contents { counter-reset: toc; }
.contents li { counter-increment: toc; }
.contents a { text-decoration: none; padding: 0.3em 0; display: inline-block; }
.contents a:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.contents a::before, h2::before, h3::before {
  color: var(--accent);
  font-variant-numeric: lining-nums tabular-nums;
  font-weight: 400;
  font-style: normal;
}
.contents a::before { content: counter(toc); margin-right: 0.4em; }
main { counter-reset: sec; }
main > section { counter-increment: sec; counter-reset: sub; }
.entry { counter-increment: sub; }
h2::before { content: counter(sec); margin-right: 0.7em; }
.entry h3::before { content: counter(sec) "." counter(sub); margin-right: 0.55em; }

/* Section and entry heads. Numbers hang in the left margin when there is room. */

section { margin-top: 3.2em; }

h2 {
  font-weight: 600;
  font-size: 1.22em;
  margin-bottom: 0.8em;
  position: relative;
}

.entry { margin-top: 1.8em; position: relative; }

h3 {
  font-size: 1em;
  line-height: 1.4;
  margin-bottom: 0.25em;
  font-weight: 600;
}
h3 cite { font-weight: 400; }

@media (min-width: 72em) {
  .opening { position: relative; }
  .opening nav {
    position: absolute;
    top: clamp(2.5rem, 9vh, 6rem);
    left: calc(100% + var(--gap));
    width: var(--notes);
  }
  .contents { flex-direction: column; gap: 0; margin: 0; }
  .contents a { padding: 0.15em 0; }
  .fig { margin-top: 0.6em; }
  .cutter { max-width: 19rem; }
  h2::before, .entry h3::before {
    position: absolute;
    right: 100%;
    margin-right: 1.1rem;
    top: 0;
  }
  .entry h3 { position: relative; }
}

main .meta a { padding-block: 0.3em; }
.meta {
  color: var(--muted);
  font-size: 0.93em;
  margin-bottom: 0.45em;
}

/* Margin notes: in the margin on wide screens, set off inline otherwise. */

.note {
  font-size: 0.84em;
  line-height: 1.45;
  color: var(--muted);
  border-left: 2px solid var(--accent);
  padding-left: 0.8em;
  margin: 0.4em 0 1.2em;
}
.note p { margin: 0 0 0.6em; }
.note p:last-child { margin-bottom: 0; }
.note a { color: var(--ink); }
.note .display { padding-left: 0.6em; color: var(--ink); }

@media (min-width: 72em) {
  .fig, .entry { position: relative; }
  .note {
    position: absolute;
    top: 0;
    left: calc(100% + var(--gap));
    width: var(--notes);
    margin: 0;
    border-left: 0;
    padding-left: 0;
  }
  .note::before {
    content: "";
    display: block;
    width: 1.5rem;
    border-top: 1px solid var(--line);
    margin: 0.75em 0 0.6em;
  }
  .fig .note { top: 2.5rem; }
}

/* Figure 1 */

.fig { margin: 2.6em 0 0; }

.cutter {
  display: block;
  width: 100%;
  max-width: 22rem;
  max-height: 62vh;
  margin: 0 auto;
  overflow: visible;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cutter:focus-visible { outline-offset: 0; border-radius: 4px; }

.rim { fill: none; stroke: var(--ink); stroke-width: 1.4; stroke-linejoin: round; }
.face { fill: transparent; transition: fill 0.4s; }
.face.new { fill: var(--tint); }
.cut { stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.cut.warn { stroke-width: 4; }
.cut-hit { stroke: transparent; stroke-width: 16; cursor: pointer; }
.band { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 4; stroke-linecap: round; pointer-events: none; }
.corner { fill: var(--ink); }
.corner.anchor { fill: var(--accent); }
.corner-ring { fill: none; stroke: var(--accent); stroke-width: 1.5; opacity: 0; }
.cutter:focus-visible .corner-ring.cursor { opacity: 1; }
.corner-hit { fill: transparent; cursor: pointer; }
.sides, .corner-name {
  font-family: var(--sans);
  font-size: 11px;
  fill: var(--muted);
  text-anchor: middle;
  dominant-baseline: central;
  font-variant-numeric: lining-nums;
  pointer-events: none;
}
.corner-name { font-size: 9.5px; opacity: 0; }
.cutter:focus-visible .corner-name { opacity: 1; }

@media (prefers-reduced-motion: no-preference) {
  .cut.new { stroke-dasharray: 260; stroke-dashoffset: 260; animation: draw 0.28s ease-out forwards; }
  .cut.warn { animation: warn 0.7s ease-out; }
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes warn { 0%, 60% { stroke-width: 4.5; } 100% { stroke-width: 2; } }

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem 1.4rem;
  margin: 0.9rem 0 1.1rem;
  font-family: var(--sans);
  font-size: 0.86rem;
}
.controls .group { display: inline-flex; align-items: center; gap: 0.4rem; }
.controls button {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 3px;
  min-height: 2.2rem;
  min-width: 2.2rem;
  padding: 0 0.7em;
  cursor: pointer;
}
.controls button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.controls button:disabled { color: var(--muted); opacity: 0.55; cursor: default; }
.controls output { min-width: 5.6em; text-align: center; font-variant-numeric: lining-nums tabular-nums; }

figcaption { font-size: 0.93em; }
figcaption .label { font-style: italic; }

.readout {
  margin: 0.7em 0 0.5em;
  font-family: var(--sans);
  font-size: 0.92em;
  font-variant-numeric: lining-nums tabular-nums;
}
.readout div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.35em 0;
  border-bottom: 1px solid var(--rule);
}
.readout div:first-child { border-top: 1px solid var(--rule); }
.readout dt { color: var(--muted); }
.readout dd { margin: 0; text-align: right; }
.readout .ways { font-size: 1.35em; line-height: 1; color: var(--accent); }

.formula {
  font-variant-numeric: lining-nums;
  color: var(--muted);
  margin: 0.4em 0 0.5em;
}

/* "Show all": every cut with the same pieces */
.show { margin: 0.6em 0 0.4em; font-family: var(--sans); font-size: 0.92em; color: var(--muted); }
.show button {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 3px;
  min-height: 2.2rem;
  padding: 0 0.8em;
  margin-right: 0.5em;
  cursor: pointer;
}
.show button:hover { border-color: var(--accent); color: var(--accent); }
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.2rem, 1fr));
  gap: 0.5rem;
  margin: 0.5em 0 0.4em;
}
.thumb { width: 100%; height: auto; display: block; overflow: visible; padding: 0.2rem; border-radius: 4px; }
.thumb .rim { stroke-width: 1.1; }
.thumb .cut { stroke-width: 1.6; }
.thumb.mine { background: var(--tint); outline: 1px solid var(--accent); }

/* Things left for the owner to fill in. Hidden on the public page until filled. */
html:not(.draft) #now:has(.todo),
html:not(.draft) body:has(#now .todo) .contents li:has(a[href="#now"]),
html:not(.draft) #contact:has(.email .todo) .if-email,
#contact:not(:has(.email .todo)) .if-no-email,
html.draft #contact .if-no-email { display: none; }
.todo {
  color: var(--accent);
  border-bottom: 1px dashed var(--accent);
  font-style: italic;
}

.print-only { display: none; }

.foot {
  margin-top: 4.5em;
  padding-bottom: 3em;
  color: var(--muted);
  font-size: 0.84em;
}
.foot p { border-top: 1px solid var(--rule); padding-top: 1em; }

@media (max-width: 30em) {
  .readout div { flex-direction: column; gap: 0.1em; }
  .readout dd { text-align: left; }
}

/* Print: one page, no figure, notes inline. */
@media print {
  @page { margin: 13mm 15mm; }
  :root { --paper: #fff; --ink: #000; --muted: #333; --accent: #000; --rule: #999; }
  html { font-size: 9.4pt; }
  body { line-height: 1.32; }
  .page { max-width: none; margin: 0; padding: 0; }
  .skip, .fig, .contents, .foot, #now, .note { display: none !important; }
  .opening { padding-top: 0; }
  h1 { font-size: 2em; margin-bottom: 0.2em; }
  .lede { font-size: 1em; }
  p { margin-bottom: 0.35em; }
  section { margin-top: 0.9em; }
  h2 { margin-bottom: 0.2em; font-size: 1.1em; }
  .entry { margin-top: 0.45em; break-inside: avoid; }
  .meta { margin-bottom: 0.1em; }
  a { text-decoration: none; }
  .print-only { display: block; }
  .todo, .links, .intro { display: none; }
  .entry h3 { display: inline; }
  .entry .meta { display: inline; }
  .entry .meta.links { display: none; }
  .entry .meta::before { content: " \00B7  "; }
  .entry p:not(.meta) { margin-top: 0.1em; }
}
