:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --ink: #2b2420;
  --muted: #6b5f57;
  --line: #e6dccf;
  --accent: #a2452e;
  --accent-ink: #ffffff;
  --accent-soft: #f6e4dc;
  --focus: #1f6feb;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1916;
    --surface: #262220;
    --ink: #f1ebe4;
    --muted: #b3a79c;
    --line: #3d3631;
    --accent: #e08a6d;
    --accent-ink: #1c1916;
    --accent-soft: #3a2a24;
    --focus: #79b8ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
header.site { border-bottom: 1px solid var(--line); background: var(--surface); }
header.site .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
.brand { font-weight: 700; text-decoration: none; color: var(--ink); font-size: 1.1rem; }
.brand span { color: var(--accent); }

h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; margin: 28px 0 8px; }
h2 { font-size: 1.3rem; margin: 32px 0 8px; }
.lede { color: var(--muted); margin: 0 0 20px; }

.units { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.units button {
  border: 0; background: transparent; color: var(--ink); padding: 6px 14px;
  font: inherit; font-size: 0.9rem; cursor: pointer; min-height: 36px;
}
.units button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin: 16px 0;
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
label { display: block; font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: 0.85rem; }
input, select {
  width: 100%; font: inherit; padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink);
}
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; min-height: 0; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label { font-weight: 400; display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0; }
.seg input { width: auto; min-height: 0; }

.result { background: var(--accent-soft); border-color: transparent; }
.result .big { font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 750; line-height: 1.1; margin: 4px 0 8px; font-variant-numeric: tabular-nums; }
.result p { margin: 6px 0; }
.result .err { color: var(--accent); font-weight: 600; }
.pattern { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1rem; word-break: break-word; background: var(--surface); border-radius: 8px; padding: 12px; }

.tools { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); padding: 0; list-style: none; }
.tools a { display: block; height: 100%; text-decoration: none; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.tools a:hover { border-color: var(--accent); }
.tools strong { display: block; color: var(--accent); }

details { border-top: 1px solid var(--line); padding: 10px 0; }
summary { cursor: pointer; font-weight: 600; }
footer.site { margin-top: 48px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; }
footer.site .wrap { padding-top: 16px; padding-bottom: 32px; }

.links { list-style: none; padding: 0; display: grid; gap: 6px 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.links a { text-decoration: none; }
.links a:hover { text-decoration: underline; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.result table th, .result table td { border-color: color-mix(in srgb, var(--ink) 15%, transparent); }
.note { color: var(--muted); font-size: 0.9rem; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }

/* Templates: on-screen preview scales to fit; print keeps the SVG's real size. */
.print-area { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px; overflow: hidden; }
.print-area svg.sheet { display: block; width: 100%; height: auto; }
.print-area svg.sheet.native { width: auto; max-width: 100%; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 18px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; cursor: pointer; }
.btn.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
textarea { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); min-height: 120px; }
input[type="color"] { padding: 2px; min-height: 40px; width: 64px; }
.swatch { display: inline-block; width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--line); vertical-align: middle; }
.counter { text-align: center; }
.counter .count { font-size: clamp(4rem, 22vw, 8rem); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; margin: 8px 0; }
.counter .btn { min-width: 96px; min-height: 64px; font-size: 1.5rem; }
.motifs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.motifs button { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px; cursor: pointer; color: var(--ink); font: inherit; font-size: 0.8rem; }
.motifs button[aria-pressed="true"] { border-color: var(--accent); outline: 2px solid var(--accent); }
.motifs svg { width: 100%; height: auto; display: block; }

@page { margin: 0.5in; }
@media print {
  body { background: #fff; }
  header.site, footer.site, main > *:not(.print-area) { display: none !important; }
  main.wrap { padding: 0; max-width: none; }
  .print-area { border: 0; padding: 0; border-radius: 0; }
  .print-area svg.sheet, .print-area svg.sheet.native { width: auto; max-width: none; }
}
[hidden] { display: none !important; }
.counter .actions { justify-content: center; }
