:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #17202a;
  --muted: #5b6673;
  --border: #dde2e8;
  --accent: #1f5fd1;
  --accent-text: #ffffff;
  --accent-soft: #e8effc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b;
    --surface: #1b2128;
    --text: #e7ebef;
    --muted: #9aa5b1;
    --border: #2d3640;
    --accent: #6c9cf0;
    --accent-text: #0d1420;
    --accent-soft: #1f2b3d;
    --danger: #f27a6e;
    --danger-soft: #3a1f1d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; margin: 28px 0 8px; }
h2 { font-size: 1.15rem; margin: 0 0 14px; }
h3 { font-size: .95rem; margin: 22px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.lead { color: var(--muted); margin: 0 0 22px; max-width: 70ch; }
.muted { color: var(--muted); font-size: .92rem; margin-top: 0; }
small { color: var(--muted); font-weight: 400; }

.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .wrap { height: 56px; display: flex; align-items: center; }
.brand { flex: none; }
.brand { display: flex; gap: 10px; align-items: center; color: var(--text); text-decoration: none; font-weight: 700; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }

/* Page: main column + sticky sidebar ad on wide screens (only when a sidebar ad exists) */
.page { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
.sidebar { display: none; }
@media (min-width: 1180px) {
  .page--ads { max-width: 1460px; grid-template-columns: minmax(0, 1fr) 300px; }
  .page--ads .sidebar { display: block; padding-top: 28px; }
  .page--ads .sidebar .ad { position: sticky; top: 16px; }
}

/* Ad slots: fixed reserved heights so filling them causes no layout shift. Not rendered at all until AdSense is set up. */
.ad { position: relative; display: flex; align-items: center; justify-content: center; width: 100%; margin: 24px auto; overflow: hidden;
  border: 1px dashed var(--border); border-radius: 8px; }
.ad::before { content: attr(data-label); position: absolute; top: 2px; left: 8px; font-size: .68rem; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.ad--banner { min-height: 100px; max-width: 728px; }
.ad--rect { min-height: 280px; max-width: 336px; }
.ad--sky { min-height: 600px; max-width: 300px; margin-top: 0; }
@media (min-width: 768px) { .ad--banner { min-height: 90px; } }
.ad-placeholder { color: var(--muted); font-size: .85rem; }
.ad ins { width: 100%; }

.faq { margin-top: 24px; }
.faq details { border-bottom: 1px solid var(--border); }
.faq details:last-child { border-bottom: 0; }
.faq summary { cursor: pointer; font-weight: 600; padding: 12px 0; min-height: 44px; }
.faq details p { margin: 0 0 14px; color: var(--muted); }

.site-footer { color: var(--muted); font-size: .88rem; padding: 28px 0 36px; text-align: center; }
.site-footer a { color: var(--muted); }
.site-footer p { margin: 8px 0 0; }
.footer-links, .lang-switch ul { list-style: none; padding: 0; margin: 0; display: flex; gap: 6px 18px; flex-wrap: wrap; justify-content: center; }
.lang-switch { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.lang-switch a[aria-current] { color: var(--text); font-weight: 700; text-decoration: none; }
.linklike { font: inherit; color: var(--muted); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tabs button {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 9px 18px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.options { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
.options h3:first-of-type { margin-top: 18px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .9rem; font-weight: 600; margin-bottom: 5px; }
.field.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.field.inline > span { margin: 0; font-weight: 500; }
input[type="text"], input[type="number"], textarea, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.field.inline select { width: auto; }
textarea { resize: vertical; }
#csv-text { font-family: ui-monospace, Consolas, monospace; font-size: .88rem; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, .drop:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="color"] { width: 100%; height: 38px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 3px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .92rem; margin-bottom: 12px; cursor: pointer; }
.check input { margin-top: 4px; accent-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.opt-group { border-top: 1px solid var(--border); padding-top: 4px; margin-top: 14px; }
.opt-group summary { cursor: pointer; font-weight: 600; padding: 8px 0; color: var(--text); }
.opt-group[open] summary { margin-bottom: 6px; }
.hint { font-size: .82rem; color: var(--muted); margin: 0 0 12px; }
.actions.tight { margin: 0 0 8px; }
.actions.tight label.btn { display: inline-block; }
.encoded { font: .82rem/1.4 ui-monospace, Consolas, monospace; color: var(--muted); overflow-wrap: anywhere; margin: 10px 0 0; }
.item .enc { font-family: ui-monospace, Consolas, monospace; font-size: .72rem; }

body:not(.mode-batch) .batch-only { display: none; }
.is-qr .bar-only, .is-bar .qr-only { display: none; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 9px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }

.preview {
  display: flex; align-items: center; justify-content: center;
  min-height: 260px; padding: 20px; margin-top: 4px;
  border-radius: 10px; border: 1px dashed var(--border);
  background: repeating-conic-gradient(var(--bg) 0 25%, var(--surface) 0 50%) 0 0 / 20px 20px;
  overflow: auto;
}
.preview img { max-width: 100%; height: auto; display: block; }
.error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; margin: 12px 0 0; font-size: .92rem; }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  padding: 28px 16px; border: 2px dashed var(--border); border-radius: 10px; cursor: pointer;
  background: var(--bg);
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .link { color: var(--accent); text-decoration: underline; }
.paste { margin: 14px 0; }
.paste summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-bottom: 8px; }

.summary { font-size: .95rem; margin-top: 4px; }
.summary .bad { color: var(--danger); font-weight: 600; }
progress { width: 100%; margin-top: 12px; accent-color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-top: 16px; }
.item { border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: var(--bg); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.item .img { background: #fff; border-radius: 6px; display: flex; align-items: center; justify-content: center; padding: 6px; min-height: 110px; }
.item img { max-width: 100%; max-height: 180px; height: auto; display: block; }
.item .meta { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.item .meta b { color: var(--text); font-weight: 600; }
.item.bad { border-color: var(--danger); background: var(--danger-soft); }
.item.bad .img { display: none; }
.item .why { color: var(--danger); font-size: .82rem; font-weight: 600; }

.article { margin-top: 24px; }
.article p, .article li { max-width: 75ch; }
.article h2 { margin-top: 18px; }
.article h2:first-child { margin-top: 0; }
.article dt { font-weight: 700; margin-top: 10px; }
.article dd { margin: 2px 0 0; color: var(--muted); }
.article li { margin-bottom: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .92rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 10;
}

#print-area { display: none; }

/* Top navigation (scrolls sideways on narrow screens) */
.site-header .wrap { gap: 20px; }
.top-nav { overflow-x: auto; scrollbar-width: none; }
.top-nav ul { list-style: none; display: flex; gap: 4px; margin: 0; padding: 0; white-space: nowrap; }
.top-nav a { display: block; padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: .92rem; }
.top-nav a:hover { color: var(--text); background: var(--bg); }
.top-nav a[aria-current] { color: var(--text); font-weight: 600; background: var(--accent-soft); }

/* Form pages: the type is always QR, content comes from the form */
.has-form #type-field { display: none; }
.form-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-fields .check, .form-fields label:has(textarea) { grid-column: 1 / -1; }
.form-fields input[type="email"], .form-fields input[type="tel"], .form-fields input[type="url"], .form-fields input[type="datetime-local"] {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.series { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 10px; }
.series label:last-child { grid-column: span 2; }
@media (max-width: 520px) { .form-fields, .series { grid-template-columns: 1fr; } .series label:last-child { grid-column: auto; } }

/* Related tools */
.related { margin-top: 24px; }
.cards { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.cards a { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; font-weight: 600; font-size: .92rem; }
.cards a:hover { border-color: var(--accent); }
.card-emoji { font-size: 1.25rem; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .options { position: static; order: 2; }
}

@media print {
  @page { margin: 10mm; }
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area.grid { display: grid; gap: 6mm; grid-template-columns: repeat(var(--cols, 3), 1fr); }
  #print-area .label { break-inside: avoid; display: flex; align-items: center; justify-content: center; padding: 2mm; }
  #print-area .label img { max-width: 100%; height: auto; }
  #print-area.single { display: flex; justify-content: center; }
  #print-area.sheets { display: block; }
  #print-area .sheet { position: relative; overflow: hidden; break-after: page; }
  #print-area .sheet:last-child { break-after: auto; }
  #print-area .cell { position: absolute; display: flex; align-items: center; justify-content: center; padding: 1.5mm; }
  #print-area .cell img { width: 100%; height: 100%; object-fit: contain; }
  #print-area .cell .side { display: flex; align-items: center; gap: 2mm; width: 100%; height: 100%; }
  #print-area .cell .side img { width: auto; height: 100%; aspect-ratio: 1; flex: none; }
  #print-area .cell .side span { flex: 1; min-width: 0; font-family: Arial, Helvetica, sans-serif; line-height: 1.2;
    overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; }
}

/* Tables in guides */
.article table { border-collapse: collapse; width: 100%; max-width: 640px; margin: 8px 0 16px; font-size: .92rem; }
.article th, .article td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.article th { color: var(--muted); font-weight: 600; }

/* Extra tools: QR reader results and check digit table */
.tool-card { margin-bottom: 8px; }
.reader-results { display: grid; gap: 12px; margin-top: 16px; }
.read-item { display: flex; gap: 14px; align-items: flex-start; border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--bg); }
.read-item.bad { border-color: var(--danger); background: var(--danger-soft); }
.read-item .thumb { width: 96px; height: 96px; object-fit: contain; background: #fff; border-radius: 6px; flex: none; }
.read-body { min-width: 0; flex: 1; }
.read-name { font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.read-type { font-weight: 700; margin: 2px 0 6px; }
.read-fields { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 0 0 8px; font-size: .92rem; }
.read-fields dt { color: var(--muted); }
.read-fields dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.read-text { white-space: pre-wrap; overflow-wrap: anywhere; font: .85rem/1.45 ui-monospace, Consolas, monospace; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin: 0; max-height: 220px; overflow: auto; }
.read-warn { font-size: .85rem; color: var(--muted); margin: 8px 0 0; }
.read-item .actions { margin-top: 10px; }
a.btn { display: inline-block; text-decoration: none; }
@media (max-width: 520px) { .read-item { flex-direction: column; } .read-item .thumb { width: 100%; height: 140px; } }
.cd-top { grid-template-columns: minmax(0, 420px); }
.table-wrap { overflow-x: auto; }
.cd-table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.cd-table th, .cd-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.cd-table th { color: var(--muted); font-weight: 600; }
.cd-table tr.bad td { background: var(--danger-soft); }
.cd-table .ok { color: #1a7f37; font-weight: 600; }
.cd-table .no { color: var(--danger); font-weight: 600; }

/* Guide diagrams (tools/figures.py): colours follow the theme, "paper" parts stay black on white */
.fig { margin: 18px 0 22px; }
.fig svg { display: block; width: 100%; max-width: 680px; height: auto; }
.fig text { font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
.fig .f-mono { font-family: ui-monospace, Consolas, monospace; }
.fig figcaption { font-size: .88rem; color: var(--muted); max-width: 640px; margin-top: 6px; }
.f-ink { fill: var(--text); }
.f-muted { fill: var(--muted); }
.f-accent { fill: var(--accent); }
.f-on-accent { fill: var(--accent-text); }
.f-danger { fill: var(--danger); }
.f-soft { fill: var(--accent-soft); }
.f-ok-soft { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.f-danger-soft { fill: var(--danger-soft); stroke: var(--danger); stroke-width: 2; }
.f-ink-stroke { stroke: var(--text); }
.f-muted-stroke { stroke: var(--muted); }
.f-accent-stroke { stroke: var(--accent); }
.f-danger-stroke { stroke: var(--danger); }
.f-banner { fill: #111; }
.f-banner-muted { fill: #666; }
