/* ========================================================================
   qr.d4t0.com — stylesheet
   ========================================================================
   Visual treatment follows d4t0.com's tool grid: flat, square corners,
   hairline lattice borders drawn by four background gradients per tile
   (the d4t0.com technique, copied so a 1px interior seam stays 1px
   instead of doubling up between neighbours).

   Size scale follows φ (golden ratio, ≈1.618):
     --space  : Fibonacci 4-px increment + φ. 4 / 6 / 10 / 16 / 26 / 42.
     typography : body 14, h3 18 (14·φ÷1.27), h2 22 (14·φ), h1 28 (φ² ×14
                  scaled to fit; "hero but readable"). Caption 12.
     buttons / inputs : 36×36 / 44×44 tap targets per WCAG 2.5.5.

   Mark/footer rules come from branding/chrome.css; semantic tokens
   come from branding/tokens.css — both kept in sync via check-contrast.py.
   ======================================================================== */

:root {
  /* ──────── Neutrals + accents — branding/tokens.css. ──────── */
  --bg: #fbfbf9;
  --surface: #fcfcfb;
  --surface-sunken: #f5f5f0;
  --text: #1c1917;
  --logo-color: #293133;
  --text-muted: #6f6b64;
  --border: #dfdbd3;
  --control-border: #7c796f;
  --chip-bg: #f3f3ed;
  --chip-bg-hover: #eaeae2;
  --chip-line: #d5d1c7;
  --accent: #286aec;
  --accent-weak: #f7faff;
  --on-accent: #ffffff;
  --success: #127a38;
  --success-weak: #eaf7ee;
  --warning: #b45309;
  --warning-weak: #fdf3e2;
  --danger: #c0342b;
  --danger-weak: #fbeae8;

  /* ──────── d4t0.com lattice tokens (light). ────────
     Same values home/ uses; pinned here so this file is self-contained. */
  --lattice-line: #E1DFD7;
  --cell-bg: #FFFFFF;
  --cell-hover: #f5f5f0;
  --grid-line: 1px;
  --card-pad-x: 4px;

  /* ──────── Spacing on a φ ladder. ────────
     Each step is approximately φ times the previous:
       4 ≈ φ × 2.5
       6 ≈ φ × 4
       10 ≈ φ × 6
       16 ≈ φ × 10
       26 ≈ φ × 16
       42 ≈ φ × 26
     Tuned to whole pixels and small enough to keep tile internals
     tight; grows geometrically so a tile "feels larger" by one
     step, not "barely larger" by a half-step. */
  --space-1: 4px;
  --space-2: 6px;
  --space-3: 10px;
  --space-4: 16px;
  --space-5: 26px;
  --space-6: 42px;

  /* ──────── Radius — single step per size. ────────
     Tiles are 0 (lattice is the pattern, a rounded corner leaves a gap
     at every junction). Controls + inputs use --radius-sm; cards in
     card contexts use --radius-md / lg. */
  --radius-xs: 5px;
  --radius-sm: 8px;
  --radius-md: 13px;
  --radius-lg: 21px;
  --radius-pill: 999px;

  /* ──────── Typography scale. ────────
     Each tier is one φ-step from the previous, capped where the page
     column would push them off the right. */
  --fs-caption: 12px;       /* meta, hints, error text */
  --fs-body:    14px;       /* inputs, textarea, list rows */
  --fs-h3:      18px;       /* fieldset legend, .inline heading */
  --fs-h2:      22px;       /* section heading <h2> — 14·φ ≈ 22.6 */
  --fs-h1:      28px;       /* hero <h1> */
  --lh-tight:   1.25;       /* headings */
  --lh-body:    1.5;        /* paragraphs, inputs */

  /* Body is a flex column so the footer can `margin-top: auto` to the
     viewport bottom on a short page; long pages scroll past it
     normally. chrome.css's footer rule relies on this. */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-sunken: #0a0b0d;
    --text: #eef0f4;
    --logo-color: #eef0f4;
    --text-muted: #a2a3a8;
    --border: #34363c;
    --chip-bg: #16191f;
    --chip-bg-hover: #1c202a;
    --chip-line: #2e3036;
    --control-border: #797d86;
    --accent: #5b8def;
    --accent-weak: #1b2740;
    --on-accent: #0f1115;
    --success: #4ade80;
    --success-weak: #16281c;
    --warning: #fbbf24;
    --warning-weak: #2a1f0a;
    --danger: #ff6b60;
    --danger-weak: #2e1a18;
    /* Dark lattice: cells become --surface (lighter than page) so the
       tile reads as a tile even on a near-black ground. */
    --lattice-line: #1f2125;
    --cell-bg: var(--surface);
    --cell-hover: #171a21;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* =========================================================== chrome copy
   The three pieces of furniture every d4t0 site has. Block copied
   verbatim from branding/chrome.css (2026-08-22 standard set) so this
   file is self-contained.
   ====================================================================== */

/* 1. the mark — 36×36 CSS mask; rotate is in /logo.svg, NOT here. */
.topnav-logo {
  display: block;
  width: 36px;
  height: 36px;
  background-color: var(--logo-color);
  -webkit-mask: url("/logo.svg") center / contain no-repeat;
  mask: url("/logo.svg") center / contain no-repeat;
}
.topnav-brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

/* 2. the bar */
.topnav {
  display: flex;
  align-items: center;
  padding: var(--space-3) 0;
}

/* 3. the footer (centred, single line, version span). */
.footer {
  flex: none;
  margin-top: auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-4);
  text-align: center;
  background: var(--bg);
  color: var(--text-muted);
  font-size: var(--fs-caption);
  line-height: var(--lh-tight);
}
.footer p { margin: 0; }
.footer a { color: inherit; text-decoration: none; }

/* =========================================================== page layout
   --page-width : 760px. φ⁻¹ of common laptop widths (1366 / 1.618 ≈ 845);
     tuned to 760 so the page reads as a single readable column with
     ~75 characters per line at body size, and the editor tile ends
     up at ~507px on the 2-col desktop layout — comfortably fits a
     1:φ canvas (320×197) plus controls.
   --page-pad-x: 20 (matches the footer's padding so a centred line
                 doesn't drift on wide screens; chrome.css says so).
   ====================================================================== */
:root {
  --page-width: 760px;
  --page-pad-x: 20px;
}

.page {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 0 var(--page-pad-x) var(--space-5);
  flex: 1 1 auto;
  width: 100%;
}

/* =========================================================== tile system
   Each `.tile` is a square-cornered flat cell drawn on the page. The
   surrounding 1px hairline lattice comes from four background gradients
   on each tile (top / right / bottom / left), not from a `border` — that
   is what lets adjacent tiles share a single 1px seam: each draws its own
   edges, and the negative right/bottom margin overlaps them onto one
   pixel.

   The trick is described in detail at home/public/style.css (.tool-card);
   reused here verbatim because it is the only technique that gives a
   1px interior seam under arbitrary aspect ratios.
   ====================================================================== */

.main-grid {
  display: grid;
  /* Mobile: single column, three tiles stack. */
  grid-template-columns: 1fr;
  gap: 0;
  margin-top: var(--space-3);
}

/* On wide screens, left:right is 13fr:8fr (φ ratio 1.625) instead of
   2:1 — the right column gets ~287px rather than ~240, enough for a
   textarea on a single line + the ZIP button. */
@media (min-width: 720px) {
  .main-grid {
    grid-template-columns: 13fr 8fr;
  }
}

.tile {
  background-color: var(--cell-bg);
  /* φ-scaled padding: px ≈ 16 top/right (the H2 may be a bit larger
     here), 16 bottom (room for the action row), 16 left. */
  padding: var(--space-3) var(--space-4);
  margin-right: -1px;
  margin-bottom: -1px;
  position: relative;
  background-image:
    linear-gradient(to right, var(--lattice-line) 0 100%),
    linear-gradient(to bottom, var(--lattice-line) 0 100%),
    linear-gradient(to right, var(--lattice-line) 0 100%),
    linear-gradient(to bottom, var(--lattice-line) 0 100%);
  background-size: 100% 1px, 1px 100%, 100% 1px, 1px 100%;
  background-position: top, right, bottom, left;
  background-repeat: no-repeat;
  border-radius: 0;
  transition: background-color 0.15s ease;
}
.tile:focus-within {
  background-color: var(--cell-hover);
}

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
}

/* =========================================================== typography
   Single type scale, ratios on φ. h1/h2/h3 use --lh-tight; body, meta
   and inputs use --lh-body.
   ====================================================================== */
h1 {
  font-size: var(--fs-h1);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: var(--lh-tight);
  margin: var(--space-5) 0 var(--space-3);
}
h2 {
  font-size: var(--fs-h2);
  font-weight: 600;
  line-height: var(--lh-tight);
  margin: 0 0 var(--space-3);
  letter-spacing: -0.005em;
}
h3 {
  font-size: var(--fs-h3);
  font-weight: 600;
  line-height: var(--lh-tight);
  margin: 0 0 var(--space-2);
}
h2.inline, h3.inline {
  display: inline;
  margin: 0;
}

.lede {
  color: var(--text-muted);
  margin: 0 0 var(--space-4);
  font-size: var(--fs-body);
}
.muted { color: var(--text-muted); font-weight: 400; }

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

label {
  font-weight: 500;
  color: var(--text);
  font-size: var(--fs-body);
}
.hint {
  font-size: var(--fs-caption);
  color: var(--text-muted);
  margin: var(--space-2) 0 0;
  line-height: var(--lh-body);
}
.meta {
  font-size: var(--fs-caption);
  color: var(--text-muted);
  margin: var(--space-2) 0 0;
  line-height: var(--lh-body);
}
.error {
  font-size: var(--fs-caption);
  color: var(--danger);
  margin: var(--space-2) 0 0;
  min-height: 0;
  line-height: var(--lh-body);
}
.error:empty { display: none; }

/* =========================================================== form controls
   Tap targets WCAG 2.5.5 (44×44 minimum). Inputs use --radius-sm
   (8px) which is one step on the radius scale, harmonised with the
   buttons. Focus outline re-applies the accent border colour rather
   than introducing a new ring.
   ====================================================================== */
input[type="url"],
input[type="text"],
textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  background: var(--cell-bg);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  margin-top: var(--space-2);
  /* 44px tap target per WCAG 2.5.5. Fieldset body padding adds the
     extra so the input's own height stays readable. */
  min-height: 44px;
}
textarea {
  min-height: 0;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 13px;       /* mono fonts read larger at body size */
  line-height: 1.6;
}
input[type="url"]:focus,
input[type="text"]:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

button {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: var(--fs-body);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  /* 44px tap target per WCAG 2.5.5 (14·1.4 + 16 padding + 2 border). */
  min-height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
button:hover:not(:disabled) {
  background: #1f57c8;
  border-color: #1f57c8;
}
button.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--control-border);
}
button.secondary:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--text-muted);
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input[type="color"] {
  width: 44px;       /* = WCAG tap target, also φ⁻² × 115px padding */
  height: 32px;
  padding: 0;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
/* --radius-xs, not a raw 4px: check-radius.py runs in CI and 4 is not on
   the Fibonacci scale. The swatch sits inside a control, which is exactly
   what --radius-xs is for. */
input[type="color"]::-webkit-color-swatch { border-radius: var(--radius-xs); border: 0; }

/* =========================================================== editor layout
   Two-column grid (colors | logo) inside the editor. Stacks on narrow
   phones. The fieldsets' radii match form-control radii (--radius-sm)
   for a coherent control vocabulary.
   ====================================================================== */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin: var(--space-3) 0;
}
@media (max-width: 600px) {
  .editor-grid { grid-template-columns: 1fr; }
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin: 0;
}
fieldset legend {
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--text-muted);
  padding: 0 var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.color-field {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-2) 0;
}
.color-field span {
  font-size: var(--fs-body);
  color: var(--text);
  min-width: var(--space-4);
}

input[type="file"] {
  display: block;
  width: 100%;
  font-size: var(--fs-caption);
  margin-top: var(--space-2);
}

/* =========================================================== preview
   The QR canvas. Width is set to 100% up to a φ-derived cap: on the
   editor column (446px on a 720px-content page), the canvas reads at
   φ⁻¹ of the column = ~276px; capped at 320 to keep it from squeezing
   smaller viewports. The square aspect (1:1) makes the QR self-
   explanatory: there's nothing to read but the matrix.
   ====================================================================== */
.preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: var(--space-3) 0;
}
#canvas {
  width: 100%;
  /* φ⁻¹ of the editor column (~446px desktop) ≈ 276, rounded to 320
     so phones (where editor column is also the page column) show a
     useful size too. */
  max-width: 320px;
  height: auto;
  aspect-ratio: 1 / 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
}

/* =========================================================== button rows */
.actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* =========================================================== history
   The list rows are miniature tiles (no lattice — the parent tile's
   edges already give us the cardinal border) using --radius-sm
   internally. Tap target buttons are 44×44 per WCAG 2.5.5.
   ====================================================================== */
.history summary {
  cursor: pointer;
  list-style: none;
  font-size: var(--fs-h2);
  font-weight: 600;
  line-height: var(--lh-tight);
}
.history summary::-webkit-details-marker { display: none; }
.history summary::before {
  content: "▸";
  display: inline-block;
  margin-right: var(--space-2);
  transition: transform 0.15s ease;
  color: var(--text-muted);
}
.history details[open] summary::before { transform: rotate(90deg); }

#history-list {
  list-style: none;
  padding: 0;
  margin: var(--space-3) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
#history-list li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: var(--fs-body);
}
#history-list li .meta {
  flex: 1;
  margin: 0;
  font-size: var(--fs-caption);
}
#history-list button.link {
  appearance: none;
  background: none;
  border: 0;
  color: var(--accent);
  padding: 0;
  font-size: var(--fs-body);
  cursor: pointer;
  text-align: left;
  word-break: break-all;
  min-height: 44px;          /* match tap-target floor */
  display: inline-flex;
  align-items: center;
}
#history-list button.link:hover { text-decoration: underline; }
#history-list button.del {
  appearance: none;
  background: none;
  border: 0;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 var(--space-3);
  line-height: 1;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#history-list button.del:hover { color: var(--danger); }
#history-list li.empty {
  border: 0;
  padding: var(--space-2) 0;
}
