/* ── tokens ─────────────────────────────────────────────── */
:root {
  color-scheme: light dark;
  --paper: oklch(97% 0.005 95);
  --paper-raised: oklch(99.5% 0.002 95);
  --ink: oklch(20% 0.01 270);
  --ink-soft: oklch(45% 0.015 270);
  --line: oklch(85% 0.01 95);
  --accent: oklch(72% 0.19 155);
  --accent-ink: oklch(35% 0.12 155);
  --danger: oklch(58% 0.2 25);
  --qr-dark: #111318;
  --qr-light: #ffffff;

  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --text-base: clamp(0.95rem, 0.9rem + 0.25vw, 1.05rem);
  --text-hero: clamp(2.4rem, 1.2rem + 4.5vw, 4.5rem);

  --space-gutter: clamp(1.25rem, 4vw, 3.5rem);
  --duration-fast: 160ms;
  --duration-normal: 360ms;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: oklch(18% 0.012 270);
    --paper-raised: oklch(23% 0.014 270);
    --ink: oklch(93% 0.005 95);
    --ink-soft: oklch(65% 0.01 270);
    --line: oklch(32% 0.012 270);
    --accent: oklch(78% 0.19 155);
    --accent-ink: oklch(78% 0.19 155);
  }
}

/* ── base ───────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; }

body {
  font-family: var(--font-display);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px;
  min-height: 100dvh;
}

button, input, select, .seg label {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

.frame {
  max-width: 72rem;
  margin-inline: auto;
  padding: var(--space-gutter);
  padding-inline: max(var(--space-gutter), env(safe-area-inset-left))
                  max(var(--space-gutter), env(safe-area-inset-right));
  padding-bottom: max(var(--space-gutter), env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: clamp(1.5rem, 3vw, 3rem);
}

/* ── masthead ───────────────────────────────────────────── */
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.9rem;
  border-bottom: 2px solid var(--ink);
}

.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-mark { display: grid; place-items: center; }
.brand-name {
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 1.05rem;
}

.masthead-note {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

/* ── stage layout ───────────────────────────────────────── */
.stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  align-items: start;
}

@media (max-width: 820px) {
  .stage { grid-template-columns: 1fr; }
}

/* ── input panel ────────────────────────────────────────── */
.headline {
  font-size: var(--text-hero);
  line-height: 1.02;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.headline em {
  font-style: normal;
  color: var(--accent-ink);
  position: relative;
}

.lede {
  margin-top: 1rem;
  max-width: 34ch;
  color: var(--ink-soft);
}

#qr-form { margin-top: 2.2rem; }

.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.5rem;
}

.url-field {
  display: flex;
  align-items: center;
  background: var(--paper-raised);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  transition: box-shadow var(--duration-fast) var(--ease-out-expo),
              translate var(--duration-fast) var(--ease-out-expo);
}

.url-field:focus-within {
  translate: -2px -2px;
  box-shadow: 6px 6px 0 var(--accent);
}

.url-prefix {
  padding-inline: 0.85rem 0;
  font-family: var(--font-mono);
  color: var(--accent-ink);
  font-weight: 500;
  user-select: none;
}

#url-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 1rem;
  padding: 0.9rem 0.75rem;
  outline: none;
}

#url-input::placeholder { color: var(--ink-soft); opacity: 0.55; }

.clear-btn {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.3rem;
  line-height: 1;
  padding: 0 0.8rem;
  cursor: pointer;
}
.clear-btn:hover { color: var(--danger); }

.hint {
  margin-top: 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  min-height: 1.2em;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}
.hint.is-error { color: var(--danger); }
.hint.is-ok { color: var(--accent-ink); }

/* ── ECC segmented control ──────────────────────────────── */
.options { border: 0; padding: 0; margin-top: 1.8rem; }

.seg { display: inline-flex; border: 2px solid var(--ink); background: var(--paper-raised); }

.seg label { position: relative; display: block; cursor: pointer; }

.seg input {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer;
}

.seg span {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  padding: 0.45rem 0.9rem;
  font-weight: 700;
  font-size: 0.9rem;
  border-right: 2px solid var(--ink);
  transition: background var(--duration-fast), color var(--duration-fast);
}
.seg label:last-child span { border-right: 0; }

.seg small {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 0.62rem;
  color: var(--ink-soft);
}

.seg input:checked + span { background: var(--ink); color: var(--paper); }
.seg input:checked + span small { color: var(--accent); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ── output panel ───────────────────────────────────────── */
.panel-output {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  align-items: stretch;
}

.plate {
  position: relative;
  background: var(--paper-raised);
  border: 2px solid var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
  padding: clamp(1.2rem, 3vw, 2rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.plate-corner {
  position: absolute;
  width: 14px; height: 14px;
  border: 3px solid var(--accent);
}
.plate-corner.tl { top: 6px; left: 6px; border-right: 0; border-bottom: 0; }
.plate-corner.tr { top: 6px; right: 6px; border-left: 0; border-bottom: 0; }
.plate-corner.bl { bottom: 6px; left: 6px; border-right: 0; border-top: 0; }
.plate-corner.br { bottom: 6px; right: 6px; border-left: 0; border-top: 0; }

.qr-holder {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: var(--qr-light);
  border: 1px solid var(--line);
}

.qr-empty {
  display: grid;
  place-items: center;
  gap: 0.9rem;
  color: var(--ink-soft);
  text-align: center;
}

.ghost-qr {
  width: clamp(96px, 40%, 160px);
  opacity: 0.14;
  color: #111;
}

.qr-empty p {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: #888;
}

.qr-svg-wrap { width: 100%; height: 100%; }
.qr-svg-wrap svg { display: block; width: 100%; height: 100%; }

@media (prefers-reduced-motion: reduce) {
  .qr-svg-wrap.reveal svg { animation: qr-fade 200ms ease; }
  @keyframes qr-fade { from { opacity: 0; } to { opacity: 1; } }
}

@media (prefers-reduced-motion: no-preference) {
  .qr-svg-wrap.reveal svg {
    animation: qr-in var(--duration-normal) var(--ease-out-expo);
  }
  @keyframes qr-in {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
  }
}

.plate-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

/* ── actions ────────────────────────────────────────────── */
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.size-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

#png-size {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: var(--paper-raised);
  color: var(--ink);
  border: 2px solid var(--ink);
  padding: 0.35rem 0.4rem;
}

.btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  padding: 0.55rem 1rem;
  background: var(--paper-raised);
  color: var(--ink);
  border: 2px solid var(--ink);
  cursor: pointer;
  transition: translate var(--duration-fast) var(--ease-out-expo),
              box-shadow var(--duration-fast) var(--ease-out-expo);
}

.btn:hover, .btn:focus-visible {
  translate: -2px -2px;
  box-shadow: 3px 3px 0 var(--ink);
}
.btn:active { translate: 0 0; box-shadow: none; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); color: #0b2416; border-color: var(--ink); }

.btn.flash { background: var(--accent); color: #0b2416; }

/* ── footer ─────────────────────────────────────────────── */
.baseline {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  border-top: 1px solid var(--line);
  padding-top: 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-soft);
}
