/* Trimwright
   Paper, ink, and one proofing red. No framework, no build step, no external
   requests: every rule here ships as written.

   Radius rule, applied everywhere: panels 10px, controls 6px, nothing pill.
   Accent rule: --accent is the only chromatic colour on the page. */

:root {
  color-scheme: light dark;

  --paper: #faf9f7;
  --paper-sunk: #f2f0ec;
  --paper-raised: #ffffff;
  --ink: #191b1f;
  --ink-soft: #5b6068;
  --ink-faint: #8b9098;
  --rule: #dedbd5;
  --rule-strong: #c7c3bb;
  --accent: #c33c26;
  --accent-soft: #f6e6e2;
  --good: #2f6b4f;

  --r: 10px;
  --r-sm: 6px;

  /* Type scale. Six steps, and every size on the page is one of them. Small UI
     text separates by weight and colour rather than by another half pixel:
     a dozen sizes inside a five pixel band is not a hierarchy. */
  --t-display: clamp(2.1rem, 5vw, 3.15rem);
  --t-h2: clamp(1.5rem, 3.2vw, 2rem);
  --t-lead: 1.125rem;
  --t-body: 1rem;
  --t-small: 0.8125rem;
  --t-micro: 0.6875rem;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;

  --shell: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15171b;
    --paper-sunk: #101216;
    --paper-raised: #1d2025;
    --ink: #e9e7e2;
    --ink-soft: #a2a7af;
    --ink-faint: #757b84;
    --rule: #2b2f36;
    --rule-strong: #3b4048;
    --accent: #f0705a;
    --accent-soft: #33211d;
    --good: #6cc39a;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.12; letter-spacing: -0.02em; font-weight: 640; }
p { margin: 0; }
a { color: inherit; }

.shell {
  width: 100%;
  max-width: var(--shell);
  margin-inline: auto;
  padding-inline: 20px;
}

/* ---------- navigation ---------- */

.nav {
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 20;
}

.nav__inner {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav__mark {
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: var(--t-lead);
  display: flex;
  align-items: center;
  gap: 9px;
  margin-right: auto;
}

/* Registration mark, the printer's alignment target. Decorative only. */
.nav__reg { width: 15px; height: 15px; flex: none; color: var(--accent); }

.nav__links { display: flex; gap: 22px; align-items: center; }

.nav a {
  text-decoration: none;
  color: var(--ink-soft);
  font-size: var(--t-body);
  white-space: nowrap;
}
.nav a:hover { color: var(--ink); }

@media (max-width: 700px) {
  .nav__links a:not(.nav__cta) { display: none; }
}

/* ---------- hero and workbench ---------- */

.hero { padding: 56px 0 8px; }

.hero__grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 56px;
  align-items: center;
}

.hero h1 {
  font-size: var(--t-display);
  max-width: 21ch;
}

.hero h1 em {
  font-style: normal;
  color: var(--accent);
}

.hero__sub {
  margin-top: 18px;
  font-size: var(--t-lead);
  color: var(--ink-soft);
  max-width: 46ch;
}

.hero__cta { margin-top: 28px; display: flex; gap: 12px; flex-wrap: wrap; }

@media (max-width: 900px) {
  .hero { padding-top: 34px; }
  .hero__grid { grid-template-columns: 1fr; gap: 32px; }
  .hero h1 { max-width: none; }
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-weight: 560;
  font-size: var(--t-body);
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  padding: 11px 20px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { filter: brightness(1.07); }

@media (prefers-color-scheme: dark) {
  .btn--primary { color: #1a0f0c; }
}

.btn--ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule-strong);
}
.btn--ghost:hover { background: var(--paper-sunk); }

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Below the narrowest common handset a long label has to be allowed to wrap.
   Overflowing the viewport is worse than a two line button. */
@media (max-width: 380px) {
  .btn { white-space: normal; max-width: 100%; }
}

.btn:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- the preview sheet ---------- */

.sheet {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 22px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 12px 32px -18px rgb(0 0 0 / 0.28);
}

.sheet__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

.sheet__title { font-weight: 640; font-size: var(--t-body); }

.sheet__meta { font-family: var(--mono); font-size: var(--t-micro); color: var(--ink-faint); }

#preview-grid {
  display: grid;
  gap: 0;
  font-family: var(--mono);
  text-align: center;
  user-select: none;
}

#preview-grid span {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: clamp(0.5rem, 1.35vw, 0.82rem);
  color: var(--ink);
  line-height: 1;
}

.preview__words {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-family: var(--mono);
  font-size: var(--t-micro);
  color: var(--ink-soft);
  text-transform: uppercase;
}

/* ---------- controls ---------- */

.workbench { padding: 44px 0 64px; }

/* min() in the track floor so a viewport narrower than the floor collapses the
   grid instead of overflowing it. Applies to every auto-fit grid below. */
.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(215px, 100%), 1fr));
  gap: 18px 22px;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 24px;
}

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }

.field > label {
  font-size: var(--t-small);
  font-weight: 560;
  color: var(--ink);
}

.field__help { font-size: var(--t-micro); color: var(--ink-faint); font-family: var(--mono); }

select, input[type="text"] {
  font: inherit;
  font-size: var(--t-body);
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
}

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0; }

.field--inline { flex-direction: row; align-items: center; gap: 10px; }
.field--inline input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.field--inline label { font-size: var(--t-small); }

.field :disabled { opacity: 0.45; cursor: not-allowed; }

/* Compact variant, for buttons that sit inside a control group or a line of
   prose rather than standing on their own. */
.btn--compact { padding: 7px 13px; font-size: var(--t-small); }

.locked {
  font-size: var(--t-micro);
  font-family: var(--mono);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---------- generate bar and results ---------- */

.generate {
  margin-top: 22px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.readout {
  font-family: var(--mono);
  font-size: var(--t-small);
  color: var(--ink-soft);
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.readout b { color: var(--ink); font-weight: 600; }

/* A full hairline and a tint, not a coloured tab down one edge. The page is
   built out of rules and paper; a side tab belongs to neither. */
.notice {
  margin-top: 18px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  padding: 13px 16px;
  border-radius: var(--r-sm);
  font-size: var(--t-body);
}

.notice--ok {
  border-color: var(--rule-strong);
  background: transparent;
  color: var(--ink-soft);
}

.notice[hidden] { display: none; }

/* ---------- generic sections ---------- */

.section { padding: 64px 0; border-top: 1px solid var(--rule); }

.section h2 { font-size: var(--t-h2); max-width: 20ch; }

.section__lede {
  margin-top: 14px;
  font-size: var(--t-lead);
  color: var(--ink-soft);
  max-width: 58ch;
}

/* Spec checks: two columns of paired rows, grouped rather than hairlined. */
.checks {
  margin-top: 34px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: 26px 40px;
}

.check__term {
  font-weight: 620;
  font-size: var(--t-body);
  display: flex;
  align-items: center;
  gap: 9px;
}

.check__term svg { width: 15px; height: 15px; flex: none; color: var(--good); }

.check__body { margin-top: 5px; color: var(--ink-soft); font-size: var(--t-body); }

/* Theme cards carry a real mini grid, so the section has visual variation
   rather than being six boxes of text. */
.themes {
  margin-top: 34px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(168px, 100%), 1fr));
  gap: 16px;
}

.theme-card {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--paper-raised);
  padding: 13px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 120ms ease, transform 120ms ease;
}

.theme-card:hover { border-color: var(--accent); }
.theme-card:active { transform: translateY(1px); }

/* Outside the type scale on purpose: this is a texture swatch of a real grid,
   not text anyone reads. Same for the puzzle cells, which scale to their box. */
.theme-card__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-family: var(--mono);
  font-size: 0.5rem;
  line-height: 1.35;
  color: var(--ink-faint);
  text-align: center;
  letter-spacing: 0.04em;
}

.theme-card__name { font-weight: 580; font-size: var(--t-small); }

.theme-card__tier {
  font-family: var(--mono);
  font-size: var(--t-micro);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
}

.theme-card__tier[data-tier="paid"] { color: var(--accent); }

/* Pricing: two options, deliberately not three cards. */
.plans {
  margin-top: 34px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 22px;
  align-items: start;
}

.plan {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 26px;
  background: var(--paper-raised);
}

.plan--paid { border-color: var(--accent); }

.plan__price { font-size: var(--t-h2); font-weight: 660; letter-spacing: -0.03em; }
.plan__price span { font-size: var(--t-small); font-weight: 400; color: var(--ink-soft); letter-spacing: 0; }

.plan__list { margin: 18px 0 22px; padding: 0; list-style: none; display: grid; gap: 9px; }
.plan__list li { font-size: var(--t-body); color: var(--ink-soft); display: flex; gap: 9px; }

.plan__aside {
  margin-top: 14px;
  font-size: var(--t-small);
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}
.plan__list svg { width: 14px; height: 14px; flex: none; margin-top: 4px; color: var(--good); }

details {
  border-top: 1px solid var(--rule);
  padding: 16px 0;
}
details:last-of-type { border-bottom: 1px solid var(--rule); }

summary {
  cursor: pointer;
  font-weight: 560;
  font-size: var(--t-body);
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--accent); font-weight: 400; }
details[open] summary::after { content: "\2013"; }

details p { margin-top: 10px; color: var(--ink-soft); font-size: var(--t-body); max-width: 62ch; }

.faq { margin-top: 30px; }

.footer {
  border-top: 1px solid var(--rule);
  padding: 30px 0 44px;
  color: var(--ink-faint);
  font-size: var(--t-small);
}

.footer__inner {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
}
.dialog-backdrop[hidden] { display: none; }

.dialog {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 26px;
  width: min(420px, 100%);
}

.dialog h3 { font-size: var(--t-lead); }
.dialog p { margin-top: 10px; color: var(--ink-soft); font-size: var(--t-body); }
.dialog .row { margin-top: 18px; display: flex; gap: 10px; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}


/* ---------- theme landing pages ---------- */

/* Static puzzle table, so the page reads with JavaScript switched off. */
.static-grid {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--mono);
  table-layout: fixed;
}
.static-grid td {
  text-align: center;
  padding: 0;
  aspect-ratio: 1;
  font-size: clamp(0.6rem, 1.7vw, 0.95rem);
  color: var(--ink);
}

.crumbs { font-size: var(--t-small); color: var(--ink-faint); margin-bottom: 18px; }

.theme-page { padding-block: 44px 64px; }
.theme-page__title { font-size: var(--t-h2); max-width: 20ch; }
.theme-page__actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.theme-page__sheet { margin-top: 34px; max-width: 620px; }
.theme-page__more { margin-top: 56px; }

/* Inline style attributes are blocked by the Content-Security-Policy in
   _headers, so link colour lives here rather than on the element. */
.link-plain { color: inherit; text-decoration: none; }
.link-inherit { color: inherit; }

.key-input { margin-top: 14px; font-family: var(--mono); }
.key-error { color: var(--accent); }

/* ---------- theme index ---------- */

/* A real link to every theme page. Quiet by design: the cards above are the
   way in for someone using the builder, this is the way in for a crawler and
   for someone who arrived looking for one specific puzzle. */
.theme-index {
  margin-top: 44px;
  padding-top: 28px;
  border-top: 1px solid var(--rule);
}
.theme-index__title {
  font-size: var(--t-small);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
  margin-bottom: 16px;
}
.theme-index__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px 24px;
}
.theme-index__list a {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: var(--t-small);
  border-bottom: 1px solid transparent;
  transition: color 120ms ease, border-color 120ms ease;
}
.theme-index__list a:hover,
.theme-index__list a:focus-visible {
  color: var(--ink);
  border-bottom-color: var(--accent);
}