/* Maze Generator — stylesheet
   Palette: paper #F5F7F2 · ink #17233B · trail #E4572E · hedge #2C7A4B · line #D8DED2 */
:root {
  --paper: #F5F7F2;
  --white: #FFFFFF;
  --ink: #17233B;
  --ink-2: #3D4A63;
  --muted: #5B6578;
  --line: #D8DED2;
  --line-2: #C3CBBC;
  --trail: #E4572E;
  --trail-dark: #B93E1B;
  --trail-tint: #FCE9E2;
  --hedge: #2C7A4B;
  --hedge-tint: #E3EFE6;
  --grid: rgba(23, 35, 59, 0.07);
  --head: "Trebuchet MS", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --body: Georgia, "Times New Roman", Times, serif;
  --ui: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --r: 6px;
  --r-lg: 14px;
  --shadow: 0 1px 0 rgba(23,35,59,.06), 0 8px 24px -12px rgba(23,35,59,.25);
  --wrap: 1180px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { animation: none !important; transition: none !important; } }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--body); font-size: 17px; line-height: 1.65; }
img, svg { max-width: 100%; height: auto; display: block; }
a { color: var(--hedge); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--trail-dark); }
h1, h2, h3, h4 { font-family: var(--head); line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; color: var(--ink); }
h1 { font-size: clamp(2rem, 4.6vw, 3.4rem); font-weight: 700; }
h2 { font-size: clamp(1.6rem, 3vw, 2.3rem); font-weight: 700; }
h3 { font-size: 1.25rem; font-weight: 700; }
p { margin: 0 0 1em; }
.lede { font-size: 1.15rem; color: var(--ink-2); max-width: 62ch; }
.wrap { width: min(var(--wrap), calc(100% - 2rem)); margin-inline: auto; }
.center { text-align: center; }
.center .lede { margin-inline: auto; }
:focus-visible { outline: 3px solid var(--trail); outline-offset: 2px; border-radius: 3px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: #fff; padding: .5rem .9rem; z-index: 99; }
.skip:focus { left: 8px; }

/* ---------- header ---------- */
.site-header { position: sticky; top: 0; z-index: 50; background: rgba(245,247,242,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.site-header .bar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1rem; height: 66px; }
.brand { display: inline-flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); font-family: var(--head); font-weight: 700; font-size: 1.15rem; }
.brand img { width: 38px; height: 38px; }
.nav { justify-self: center; }
.nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: .25rem; }
.nav a { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .8rem; border-radius: 999px; font-family: var(--ui); font-size: .93rem; color: var(--ink-2); text-decoration: none; }
.nav a svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a:hover, .nav a[aria-current="page"] { background: var(--hedge-tint); color: var(--hedge); }
.nav a.guides { color: var(--trail-dark); }
.nav a.guides:hover { background: var(--trail-tint); }
.nav-toggle { display: none; border: 1px solid var(--line-2); background: var(--white); border-radius: var(--r); padding: .45rem .6rem; cursor: pointer; }
.nav-toggle span { display: block; width: 20px; height: 2px; background: var(--ink); margin: 4px 0; }
.header-cta { font-family: var(--ui); font-size: .9rem; color: var(--muted); }
@media (max-width: 900px) {
  .site-header .bar { grid-template-columns: auto 1fr auto; }
  .header-cta { display: none; }
  .nav-toggle { display: block; justify-self: end; }
  .nav { grid-column: 1 / -1; justify-self: stretch; display: none; padding-bottom: .8rem; }
  .nav.open { display: block; }
  .nav ul { flex-direction: column; }
  .site-header .bar { height: auto; min-height: 66px; padding: .4rem 0; }
}

/* ---------- hero + tool ---------- */
.hero { position: relative; padding: 2.5rem 0 3rem; background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px; background-position: center top; }
.hero::after { content: ""; position: absolute; inset: auto 0 0 0; height: 120px; background: linear-gradient(transparent, var(--paper)); pointer-events: none; }
.hero .intro { text-align: center; max-width: 760px; margin: 0 auto 2rem; position: relative; z-index: 1; }
.hero h1 { margin-bottom: .4em; }

.tool { position: relative; z-index: 1; display: grid; grid-template-columns: 330px 1fr; gap: 1.25rem; align-items: start; }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.controls { padding: 1.1rem 1.15rem 1.25rem; font-family: var(--ui); font-size: .92rem; }
.controls fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
.controls legend { font-family: var(--head); font-weight: 700; font-size: .95rem; padding: 0; margin-bottom: .45rem; color: var(--ink); }
.seg { display: grid; gap: 4px; }
.seg.c4 { grid-template-columns: repeat(4, 1fr); }
.seg.c3 { grid-template-columns: repeat(3, 1fr); }
.seg.c2 { grid-template-columns: repeat(2, 1fr); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: .5rem .3rem; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--white); cursor: pointer; font-size: .78rem; color: var(--ink-2); line-height: 1.1; text-align: center; }
.seg span svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linejoin: round; }
.seg input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.seg input:focus-visible + span { outline: 3px solid var(--trail); outline-offset: 1px; }
.seg input:disabled + span { opacity: .4; cursor: not-allowed; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.field label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }
.field input[type="number"], .field input[type="text"], .field select { width: 100%; font: inherit; font-size: .95rem; padding: .5rem .6rem; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--white); color: var(--ink); }
.field input[type="range"] { width: 100%; accent-color: var(--trail); }
.field .hint { font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.check { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: var(--ink-2); margin: .5rem 0; }
.check input { accent-color: var(--hedge); width: 16px; height: 16px; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.colors label { display: flex; flex-direction: column; gap: .25rem; font-size: .75rem; color: var(--muted); }
.colors input[type="color"] { width: 100%; height: 34px; border: 1px solid var(--line-2); border-radius: var(--r); padding: 2px; background: var(--white); cursor: pointer; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; font-family: var(--ui); font-weight: 600; font-size: .95rem; padding: .7rem 1.1rem; border-radius: var(--r); border: 1px solid transparent; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--trail); color: #fff; }
.btn-primary:hover { background: var(--trail-dark); color: #fff; }
.btn-ink { background: var(--ink); color: #fff; }
.btn-ink:hover { background: #0f1729; color: #fff; }
.btn-ghost { background: var(--white); color: var(--ink); border-color: var(--line-2); }
.btn-ghost:hover { border-color: var(--ink); color: var(--ink); }
.btn-block { width: 100%; }
.btn[aria-pressed="true"] { background: var(--hedge); color: #fff; border-color: var(--hedge); }

.stage { display: flex; flex-direction: column; min-height: 560px; overflow: hidden; }
.stage-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; padding: .7rem .9rem; border-bottom: 1px solid var(--line); font-family: var(--ui); font-size: .85rem; color: var(--muted); }
.stage-bar .actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.stage-bar .btn { padding: .45rem .7rem; font-size: .85rem; }
.canvas { flex: 1; display: grid; place-items: center; padding: 1rem; background: var(--white); }
.canvas svg { width: 100%; height: auto; max-height: 72vh; }
.stats { display: flex; flex-wrap: wrap; gap: 1.2rem; padding: .6rem .9rem; border-top: 1px solid var(--line); font-family: var(--ui); font-size: .82rem; color: var(--muted); }
.stats b { color: var(--ink); font-weight: 600; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 999px; font-family: var(--ui); font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; }
.toast.show { opacity: 1; }
@media (max-width: 980px) { .tool { grid-template-columns: 1fr; } .stage { min-height: 420px; } }

/* ---------- sections ---------- */
section.block { padding: 4.5rem 0; }
section.block.tint { background: var(--white); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.section-head { max-width: 700px; margin-bottom: 2.2rem; }
.section-head.center { margin-inline: auto; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; counter-reset: step; }
.step { position: relative; padding: 1.4rem 1.4rem 1.4rem 4.2rem; background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); }
.step::before { counter-increment: step; content: counter(step); position: absolute; left: 1.2rem; top: 1.2rem; width: 2rem; height: 2rem; border-radius: 50%; background: var(--trail); color: #fff; font-family: var(--head); font-weight: 700; display: grid; place-items: center; }
.step p { margin: 0; color: var(--ink-2); font-size: .98rem; }

.gallery { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.2rem; }
.gallery figure { margin: 0; background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1rem; }
.gallery .mini { aspect-ratio: 1; display: grid; place-items: center; }
.gallery .mini svg { max-height: 100%; }
.gallery figcaption { font-family: var(--ui); font-size: .88rem; margin-top: .7rem; color: var(--ink-2); }
.gallery figcaption b { display: block; color: var(--ink); font-family: var(--head); }
.gallery button { margin-top: .6rem; }

.algos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.2rem; }
.algo { display: grid; grid-template-columns: 150px 1fr; gap: 1rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1rem; }
.algo .mini svg { width: 150px; height: 150px; }
.algo h3 { margin-bottom: .3rem; }
.algo p { font-size: .95rem; color: var(--ink-2); margin: 0; }
.algo .tag { display: inline-block; font-family: var(--ui); font-size: .75rem; background: var(--hedge-tint); color: var(--hedge); padding: .15rem .5rem; border-radius: 999px; margin-bottom: .4rem; }

.uses { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.2rem; }
.use { padding: 1.4rem; border-left: 4px solid var(--hedge); background: var(--white); border-radius: 0 var(--r-lg) var(--r-lg) 0; border-top: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.use:nth-child(even) { border-left-color: var(--trail); }
.use p { font-size: .96rem; color: var(--ink-2); margin: 0; }

.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: .9rem 2rem; list-style: none; padding: 0; margin: 0; }
.features li { display: grid; grid-template-columns: 24px 1fr; gap: .7rem; align-items: start; font-size: .98rem; color: var(--ink-2); }
.features li svg { width: 22px; height: 22px; stroke: var(--hedge); fill: none; stroke-width: 2; stroke-linecap: round; }
.features li b { color: var(--ink); font-family: var(--head); display: block; }

.prose { max-width: 72ch; }
.prose h2 { margin-top: 2.2rem; }
.prose h3 { margin-top: 1.6rem; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin-bottom: .35rem; }
.prose table { border-collapse: collapse; width: 100%; font-family: var(--ui); font-size: .92rem; margin: 1rem 0 1.5rem; }
.prose th, .prose td { text-align: left; border-bottom: 1px solid var(--line); padding: .55rem .5rem; vertical-align: top; }
.prose th { font-family: var(--head); }
.prose blockquote { margin: 1.2rem 0; padding: .8rem 1.2rem; border-left: 4px solid var(--trail); background: var(--trail-tint); border-radius: 0 var(--r) var(--r) 0; }
.prose code { font-family: Consolas, "Courier New", monospace; font-size: .9em; background: var(--hedge-tint); padding: .1em .35em; border-radius: 3px; }

.faq { max-width: 820px; margin-inline: auto; }
.faq details { border-bottom: 1px solid var(--line); }
.faq summary { cursor: pointer; padding: 1rem 2.2rem 1rem 0; font-family: var(--head); font-weight: 700; font-size: 1.05rem; list-style: none; position: relative; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; position: absolute; right: .4rem; top: .9rem; font-size: 1.4rem; color: var(--trail); font-weight: 400; }
.faq details[open] summary::after { content: "−"; }
.faq details p { margin: 0 0 1.1rem; color: var(--ink-2); max-width: 70ch; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.4rem; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; display: flex; flex-direction: column; }
.card img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.card .body { padding: 1.1rem 1.2rem 1.3rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.card h3 { font-size: 1.12rem; margin: 0; }
.card h3 a { color: var(--ink); text-decoration: none; }
.card h3 a:hover { color: var(--trail-dark); }
.card p { margin: 0; font-size: .95rem; color: var(--ink-2); flex: 1; }
.card .meta { font-family: var(--ui); font-size: .8rem; color: var(--muted); }

.cta-band { background: var(--ink); color: #fff; padding: 3.5rem 0; text-align: center; }
.cta-band h2 { color: #fff; }
.cta-band p { color: #C9D1E0; max-width: 60ch; margin-inline: auto; }

/* ---------- article ---------- */
.article-head { padding: 3rem 0 1.5rem; }
.article-head .meta { font-family: var(--ui); font-size: .85rem; color: var(--muted); }
.article-hero { border-radius: var(--r-lg); border: 1px solid var(--line); margin: 1rem 0 2rem; }
.article-layout { display: grid; grid-template-columns: 1fr 300px; gap: 3rem; padding-bottom: 4rem; }
.aside { font-family: var(--ui); font-size: .9rem; }
.aside .box { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; }
.aside ul { list-style: none; padding: 0; margin: 0; }
.aside li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
.aside li:last-child { border-bottom: 0; }
.crumbs { font-family: var(--ui); font-size: .85rem; color: var(--muted); margin-bottom: .6rem; }
.crumbs a { color: var(--muted); }
.share { display: flex; gap: .6rem; margin-top: 2rem; flex-wrap: wrap; }

/* ---------- footer ---------- */
.site-footer { background: var(--white); border-top: 1px solid var(--line); padding: 3rem 0 2rem; font-family: var(--ui); font-size: .92rem; color: var(--ink-2); }
.site-footer .cols { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 2rem; }
.site-footer h4 { margin-bottom: .6rem; }
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin: .35rem 0; }
.site-footer a { color: var(--ink-2); text-decoration: none; }
.site-footer a:hover { color: var(--trail-dark); text-decoration: underline; }
.site-footer .legal { border-top: 1px solid var(--line); margin-top: 2rem; padding-top: 1.2rem; display: flex; justify-content: center; align-items: center; text-align: center; flex-wrap: wrap; gap: .5rem; font-size: .82rem; color: var(--muted); }

/* Below-the-fold sections are laid out only as they approach the viewport.
   `auto` keeps the measured size afterwards, so scrolling never jumps. */
#uses, #features, #faq, #guides { content-visibility: auto; contain-intrinsic-size: auto 700px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .steps, .uses, .features, .cards, .gallery { grid-template-columns: repeat(2, 1fr); }
  .algos { grid-template-columns: 1fr; }
  .article-layout { grid-template-columns: 1fr; }
  .site-footer .cols { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
  body { font-size: 16px; }
  .steps, .uses, .features, .cards, .gallery { grid-template-columns: 1fr; }
  .algo { grid-template-columns: 1fr; }
  .site-footer .cols { grid-template-columns: 1fr; }
  section.block { padding: 3rem 0; }
  .seg.c4 { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- print sheet (markup built by app.js at print time) ---------- */
#print-sheet { display: none; }

@media print {
  @page { margin: 12mm; }

  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; height: auto !important; }
  * { content-visibility: visible !important; }

  /* Content pages: drop the chrome, keep the article. */
  .site-header, .site-footer, .nav, .skip, .toast, .share, .cta-band, .aside { display: none !important; }
  a { color: inherit; text-decoration: none; }

  /* Generator page: hide the site outright rather than with visibility, so no
     empty boxes survive to generate blank pages. */
  body.tool-page > * { display: none !important; }

  /* One sheet, exactly one page. 250mm clears US Letter (255mm of usable
     height at 12mm margins) as well as A4, so the maze can never spill over;
     183mm does the same for either of them turned landscape. */
  body.tool-page > #print-sheet {
    display: flex !important;
    flex-direction: column;
    width: 100%;
    height: 250mm;
    overflow: hidden;
    font-family: var(--ui);
    color: var(--ink);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  #print-sheet * { box-sizing: border-box; }

  /* masthead */
  #print-sheet .ps-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10mm; flex: none; }
  #print-sheet .ps-brand { display: flex; align-items: center; gap: 3mm; min-width: 0; }
  #print-sheet .ps-brand img { width: 11mm; height: 11mm; flex: none; }
  #print-sheet .ps-brand b { display: block; font-family: var(--head); font-size: 13pt; font-weight: 700; line-height: 1.1; letter-spacing: -.01em; }
  #print-sheet .ps-brand span { display: block; font-size: 7pt; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-top: .6mm; }
  #print-sheet .ps-meta { text-align: right; min-width: 0; }
  #print-sheet .ps-meta b { display: block; font-family: var(--head); font-size: 11.5pt; font-weight: 700; line-height: 1.1; }
  #print-sheet .ps-meta span { display: block; font-size: 8pt; color: var(--muted); margin-top: .8mm; }

  /* rule with an accent lead-in (borders print without "background graphics") */
  #print-sheet .ps-rule { position: relative; border-top: 1.6pt solid var(--ink); margin-top: 3mm; flex: none; }
  #print-sheet .ps-rule i { position: absolute; left: 0; top: -1.6pt; width: 26mm; border-top: 1.6pt solid var(--trail); }

  /* A maze much wider than it is tall turns the page instead of wasting it. */
  body.tool-page > #print-sheet[data-orientation="landscape"] { height: 183mm; }

  /* The maze takes every millimetre the masthead and footer leave behind. The
     SVG stretches over the whole stage; its viewBox scales the drawing to fit
     and centres it, and the frame drawn inside the SVG hugs it exactly. */
  #print-sheet .ps-stage { flex: 1 1 auto; min-height: 0; display: flex; margin-top: 5mm; }
  #print-sheet .ps-figure { flex: 1 1 auto; display: flex; min-width: 0; min-height: 0; margin: 0; padding: 0; }
  #print-sheet .ps-figure svg { width: 100%; height: auto; max-width: none; max-height: none; display: block; }

  #print-sheet .ps-legend { display: flex; justify-content: center; gap: 7mm; flex: none; margin-top: 3mm; font-size: 7.5pt; color: var(--muted); }
  #print-sheet .ps-legend span { display: inline-flex; align-items: center; gap: 1.6mm; }
  #print-sheet .ps-legend svg { height: 3mm; width: auto; display: block; }

  /* footer: the generator's own readout */
  #print-sheet .ps-foot { flex: none; margin-top: 4mm; border-top: .8pt solid var(--line-2); padding-top: 3mm; }
  #print-sheet .ps-stats { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2mm 6mm; list-style: none; margin: 0; padding: 0; }
  #print-sheet .ps-stats li { min-width: 0; max-width: 48mm; }
  #print-sheet .ps-stats span { display: block; font-size: 6.5pt; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
  #print-sheet .ps-stats b { display: block; font-family: var(--head); font-size: 9.5pt; font-weight: 700; color: var(--ink); line-height: 1.3; overflow-wrap: anywhere; }
  #print-sheet .ps-note { display: flex; justify-content: space-between; align-items: baseline; gap: 6mm; margin-top: 3mm; font-size: 7pt; color: var(--muted); }
  #print-sheet .ps-note em { font-style: normal; white-space: nowrap; }
}
