/* Layout: two-panel workbench — stamp "paper" + downloads on the right (top on phones), form on the left. */
@font-face { font-family: "Figtree UI"; src: url("../fonts/Figtree.ttf") format("truetype"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "Kaushan UI"; src: url("../fonts/KaushanScript.ttf") format("truetype"); font-display: swap; }

:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --fg: #19202d;
  --muted: #5b6579;
  --line: #d6dce5;
  --accent: #284b8f;
  --accent-fg: #ffffff;
  --accent-soft: #e3e9f6;
  --warn-fg: #8a4b00;
  --warn-bg: #fff3df;
  --paper: #ffffff;
  --paper-edge: #c9d0db;
  --font-ui: "Figtree UI", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Kaushan UI", "Segoe Script", cursive;
  --radius: 10px;
  --space: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10141b; --surface: #181e27; --fg: #e5e9f0; --muted: #9ba5b6; --line: #2b3441;
    --accent: #93adeb; --accent-fg: #0e1420; --accent-soft: #212b3d;
    --warn-fg: #ffc978; --warn-bg: #33270f; --paper: #fbfbf8; --paper-edge: #3a4452;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #10141b; --surface: #181e27; --fg: #e5e9f0; --muted: #9ba5b6; --line: #2b3441;
  --accent: #93adeb; --accent-fg: #0e1420; --accent-soft: #212b3d;
  --warn-fg: #ffc978; --warn-bg: #33270f; --paper: #fbfbf8; --paper-edge: #3a4452;
  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(--fg);
  font: 15px/1.5 var(--font-ui);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.page { max-width: 1180px; margin: 0 auto; padding-inline: max(16px, 3vw); padding-block: 28px 40px; display: grid; gap: 28px; }

/* Masthead */
.masthead { display: grid; gap: 4px; }
.wordmark { font-family: var(--font-display); font-weight: 400; font-size: clamp(2.4rem, 5vw, 3.4rem); line-height: 1.05; margin: 0; color: var(--accent); }
.wordmark-from { font-size: .62em; color: var(--muted); white-space: nowrap; }
.tagline { margin: 0; color: var(--muted); max-width: 60ch; text-wrap: pretty; }

/* Workspace grid */
.workspace { display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); grid-template-areas: "form preview"; gap: 28px; align-items: start; }
.controls { grid-area: form; display: grid; gap: 14px; min-width: 0; }
.preview-panel { grid-area: preview; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 16px); display: grid; gap: 16px; min-width: 0; }
.preview-sticky { display: grid; gap: 16px; min-width: 0; }
@media (max-width: 820px) {
  /* Phones: the stamp stays pinned on top while the form scrolls; downloads follow the form */
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: none; gap: 20px; }
  .preview-panel { display: contents; }
  .controls { grid-area: auto; order: 2; }
  .preview-sticky {
    order: 1; position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
    gap: 8px; background: var(--bg);
    margin-inline: calc(-1 * max(16px, 3vw)); padding: 8px max(16px, 3vw) 10px;
    box-shadow: 0 10px 14px -14px rgba(20, 30, 60, .45);
  }
  .download { order: 3; }
  .coffee { order: 4; }
}

/* Paper + stamp */
.paper {
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius);
  padding: clamp(16px, 4vw, 40px);
  display: grid; place-items: center;
  min-height: 220px;
  box-shadow: 0 1px 0 rgba(0,0,0,.03), 0 10px 30px -18px rgba(20,30,60,.35);
}
.stamp { width: 100%; display: grid; place-items: center; }
.stamp svg { width: 100%; height: auto; max-height: 52vh; display: block; }
.stamp .empty { color: #6b7385; font-size: 14px; text-align: center; padding: 32px 8px; }
.preview-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.dims { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; letter-spacing: .02em; }
.ink { display: flex; align-items: center; gap: 8px; }
.ink-label { color: var(--muted); font-size: 14px; }
.ink-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--surface); background: var(--dot); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.ink-dot[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.ink-dot:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.warnings { list-style: none; margin: 0; padding: 10px 14px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-fg); font-size: 14px; display: grid; gap: 4px; }

/* Panels */
.download, .block, .coffee { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.download { padding: 16px 18px; display: grid; gap: 12px; }
.panel-title { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.dl-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.png-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 14px; color: var(--muted); }
.png-opts select { width: auto; }
.hint { margin: 0; font-size: 13px; color: var(--muted); text-wrap: pretty; }

.coffee { padding: 14px 18px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; }
.coffee-icon { width: 30px; height: 30px; color: var(--accent); }
.coffee-title { margin: 0; font-weight: 600; }
.coffee-text { margin: 0; font-size: 14px; color: var(--muted); }
@media (max-width: 460px) { .coffee { grid-template-columns: auto minmax(0, 1fr); } .btn-coffee { grid-column: 1 / -1; } }

/* Form blocks */
.block { margin: 0; padding: 14px 16px 16px; display: grid; gap: 8px; min-width: 0; }
.block-title { padding: 0 4px; font-weight: 600; font-size: 15px; }
.block-body { display: grid; gap: 8px; }
.block.is-off .block-body { display: none; }
.block.is-off { background: transparent; }
.field-label { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.field-note { color: var(--muted); opacity: .8; }
output { font-variant-numeric: tabular-nums; color: var(--fg); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.col { display: grid; gap: 6px; align-content: start; min-width: 0; }
.col-end { align-content: end; padding-bottom: 8px; }

input[type="text"], input[type="number"], select, textarea {
  width: 100%; font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
textarea { resize: vertical; min-height: 70px; line-height: 1.4; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* Switch in block legends */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-ui { width: 36px; height: 20px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; flex: none; }
.switch-ui::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Segmented control */
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; text-align: center; padding: 8px 4px; font-size: 13px; cursor: pointer; background: var(--bg); white-space: nowrap; }
.segmented input:checked + span { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Shape picker + per-shape fields */
body[data-shape="round"] [data-mode="rect"],
body:not([data-shape="round"]) [data-mode="round"] { display: none !important; }
.shape-picker { display: grid; gap: 6px; }
.segmented-lg span { padding: 10px 6px; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.segmented-lg svg { height: 14px; width: auto; fill: none; stroke: currentColor; stroke-width: 1.6; }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; letter-spacing: .02em; cursor: pointer;
  border-radius: 8px; padding: 10px 14px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); text-align: center; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-coffee { background: var(--accent-soft); border-color: transparent; color: var(--accent); white-space: nowrap; }
.btn-ghost { background: transparent; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; }

.footer { color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding-top: 16px; display: grid; gap: 4px; }
.footer p { margin: 0; max-width: 75ch; }
.credits { opacity: .8; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Phones: compact pinned preview (kept last so it overrides the base .paper / .stamp rules) */
@media (max-width: 820px) {
  .paper { min-height: 0; padding: 10px 12px; }
  .stamp svg { max-height: 26vh; }
}
