:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  --bg: #e9e9e6;
  --surface: #f9f9f7;
  --surface-raised: #fff;
  --stage: #d9d9d5;
  --text: #191a18;
  --muted: #62645f;
  --line: #d1d2cd;
  --accent: #3659e3;
  --accent-soft: #e6eafd;
  --focus: #174bd1;
  --shadow: 0 12px 36px rgb(24 26 22 / 12%);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171816;
  --surface: #20221f;
  --surface-raised: #292b28;
  --stage: #111210;
  --text: #f1f2ed;
  --muted: #aaada5;
  --line: #3b3e39;
  --accent: #8da2ff;
  --accent-soft: #303957;
  --focus: #a9b8ff;
  --shadow: 0 14px 38px rgb(0 0 0 / 38%);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 280px; min-height: 100%; }
body { min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, output, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
button:disabled { opacity: .46; cursor: not-allowed; }
.visually-hidden { position: absolute!important; width: 1px!important; height: 1px!important; padding: 0!important; margin: -1px!important; overflow: hidden!important; clip: rect(0,0,0,0)!important; white-space: nowrap!important; border: 0!important; }
.skip-link { position: fixed; z-index: 20; top: 8px; left: 8px; padding: 10px 14px; border-radius: 7px; background: var(--text); color: var(--surface); font-weight: 700; transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }
.app-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 100vh; }
.app-header { z-index: 2; display: grid; grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr); align-items: center; min-height: 64px; padding: 9px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.site-place { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; width: max-content; color: inherit; font-size: 18px; font-weight: 800; letter-spacing: -.03em; text-decoration: none; }
.brand-mark { width: 24px; height: 24px; border: 6px solid var(--accent); border-radius: 50% 45% 55% 40%; transform: rotate(-12deg); }
/* Where you are, in the channels the site nav already uses on every other page:
   the neutral ink promoted to full weight, plus a 2px rule inset under the word
   so the state survives greyscale and a reader who cannot separate the two inks.
   Never --accent: the design system flags blue as both the input series and the
   selection colour, so a marker drawn in it reads as a link or a chart key.
   Keyed off the attribute, so the semantic state and the visual state are the
   same fact — the mark cannot be lost or faked by editing a class. */
.site-place-current { padding: 6px 1px; color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.site-place a[aria-current="page"] { color: var(--text); font-weight: 750; box-shadow: inset 0 -2px 0 currentColor; }
.document-title { display: grid; justify-items: center; line-height: 1.25; }
.document-title strong { font-size: 14px; }
.document-title span { color: var(--muted); font-size: 11px; }
.header-actions { display: flex; justify-content: flex-end; gap: 9px; }
.icon-button, .primary-action, .secondary-action, .return-action, .canvas-toolbar button, .section-title button { display: inline-grid; place-items: center; min-width: 40px; min-height: 40px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-raised); cursor: pointer; }
.primary-action { padding-inline: 17px; border-color: var(--accent); background: var(--accent); color: #fff; font-size: 13px; font-weight: 750; }
.secondary-action { padding-inline: 14px; font-size: 12px; font-weight: 700; }
.return-action { padding-inline: 12px; color: var(--text); font-size: 12px; font-weight: 700; text-decoration: none; white-space: nowrap; }
:root[data-theme="dark"] .primary-action { color: #161714; }
.icon-button svg, .tool-button svg { width: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.moon-icon { display: none; }
:root[data-theme="dark"] .sun-icon { display: none; }
:root[data-theme="dark"] .moon-icon { display: block; }
.editor { display: grid; grid-template-columns: 82px minmax(0, 1fr) 260px; min-height: 0; }
.tool-rail, .properties-panel { background: var(--surface); }
.tool-rail { padding: 14px 9px; border-right: 1px solid var(--line); }
.tool-group { display: grid; gap: 7px; }
.tool-button { display: grid; justify-items: center; gap: 4px; min-width: 48px; min-height: 54px; padding: 7px 4px; border: 1px solid transparent; border-radius: 9px; background: transparent; cursor: pointer; }
.tool-button span { font-size: 10px; font-weight: 700; }
.tool-button.is-active { border-color: color-mix(in srgb, var(--accent) 30%, transparent); background: var(--accent-soft); color: var(--accent); }
.canvas-workspace { display: grid; grid-template-rows: auto minmax(280px, 1fr) auto; min-width: 0; min-height: 0; background: var(--stage); }
.canvas-toolbar { display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: 6px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.canvas-toolbar p { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-size: 12px; font-weight: 650; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #2f9c58; }
.zoom-controls { display: flex; align-items: center; gap: 4px; }
.canvas-toolbar button { min-width: 34px; min-height: 34px; padding: 4px; }
.zoom-controls output { min-width: 52px; color: var(--muted); font-size: 12px; font-weight: 700; text-align: center; }
.canvas-viewport { display: grid; place-items: center; min-width: 0; min-height: 0; overflow: auto; padding: clamp(18px, 4vw, 52px); }
.canvas-frame { position: relative; width: min(100%, 900px); aspect-ratio: 3 / 2; flex: none; overflow: hidden; border: 1px solid rgb(0 0 0 / 18%); background-color: var(--surface-raised); background-image: linear-gradient(45deg, var(--line) 25%, transparent 25%), linear-gradient(-45deg, var(--line) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--line) 75%), linear-gradient(-45deg, transparent 75%, var(--line) 75%); background-position: 0 0, 0 8px, 8px -8px, -8px 0; background-size: 16px 16px; box-shadow: var(--shadow); }
.canvas-frame canvas { display: block; width: 100%; height: 100%; background: #fff; touch-action: none; }
.empty-canvas { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 7px; color: #575a54; text-align: center; pointer-events: none; }
.empty-canvas[hidden] { display: none; }
.empty-canvas svg { width: 48px; margin-bottom: 7px; fill: none; stroke: #8a8d86; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.5; }
.empty-canvas strong { color: #30322f; font-size: clamp(15px, 2vw, 18px); }
.empty-canvas span { font-size: 12px; }
.canvas-help { margin: 0; padding: 9px 14px; border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 11px; text-align: center; }
.properties-panel { overflow-y: auto; padding: 20px 17px; border-left: 1px solid var(--line); }
.panel-heading { padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.panel-heading h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.properties-panel section { padding-block: 19px; border-bottom: 1px solid var(--line); }
.properties-panel h3 { margin: 0 0 12px; font-size: 12px; }
.property-list { display: grid; gap: 10px; margin: 0; }
.property-list div { display: flex; justify-content: space-between; gap: 12px; }
.property-list dt, .property-list dd { margin: 0; font-size: 12px; }
.property-list dt { color: var(--muted); }
.property-list dd { font-weight: 650; }
.control-grid { display: grid; gap: 12px; margin-top: 17px; }
.control-grid label { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.control-grid input[type="color"] { width: 38px; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-raised); }
.control-grid output { color: var(--text); font-size: 10px; font-variant-numeric: tabular-nums; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.action-grid button, .import-button { display: grid; place-items: center; min-height: 34px; padding: 7px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-raised); color: var(--text); font: inherit; font-size: 10px; font-weight: 650; cursor: pointer; }
.import-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.canvas-viewport.is-dragging { outline: 4px solid var(--accent); outline-offset: -8px; background: var(--accent-soft); }
.canvas-toolbar p.is-error .status-dot { background: #c43b38; }
.section-title { display: flex; align-items: center; justify-content: space-between; }
.section-title h3 { margin: 0; }
.section-title p { margin: 3px 0 0; color: var(--muted); font-size: 9px; }
.section-title button { min-width: 32px; min-height: 32px; padding: 5px 8px; font-size: 9px; font-weight: 700; }
.layer-controls { display: grid; gap: 12px; margin-top: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-raised); }
.properties-panel .layer-controls h4 { margin: 0; font-size: 10px; }
.select-control, .opacity-control { color: var(--muted); font-size: 10px; font-weight: 650; }
.select-control { display: grid; gap: 6px; }
.select-control select { width: 100%; min-height: 36px; padding: 7px 28px 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 11px; }
.opacity-control { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px 8px; }
.opacity-control output { color: var(--text); font-size: 11px; font-variant-numeric: tabular-nums; }
.opacity-control input { grid-column: 1 / -1; width: 100%; margin: 2px 0; accent-color: var(--accent); }
.opacity-control p { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 9px; font-weight: 400; }
.layer-list { margin: 12px 0 0; padding: 0; list-style: none; }
.layer-list li { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.layer-visibility { display: grid; flex: 0 0 auto; place-items: center; width: 30px; height: 30px; padding: 5px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.layer-visibility:hover { background: var(--surface-raised); color: var(--text); }
.layer-visibility svg { width: 17px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.layer-visibility .hidden-icon, .layer-visibility[aria-pressed="false"] .visible-icon { display: none; }
.layer-visibility[aria-pressed="false"] .hidden-icon { display: block; }
.layer-thumbnail { width: 38px; aspect-ratio: 3 / 2; border: 1px solid var(--line); border-radius: 3px; background: #fff; }
.layer-name { display: grid; min-width: 0; }
.layer-list strong { overflow: hidden; font-size: 11px; text-overflow: ellipsis; }
.layer-list small { color: var(--muted); font-size: 9px; }
.layer-empty, .layer-error { margin: 12px 0 0; padding: 12px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.layer-error { border-style: solid; color: var(--text); }
.canvas-frame.is-layer-hidden canvas { visibility: hidden; }
.publish-status { position: fixed; z-index: 5; right: 16px; bottom: 16px; max-width: min(420px, calc(100% - 32px)); margin: 0; padding: 11px 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-raised); box-shadow: var(--shadow); color: var(--text); font-size: 12px; font-weight: 650; }
.publish-status:empty { display: none; }
/* The handoff card sits above the transient status line, in the same corner the
   editor already uses for post-action feedback. It is a panel, not a toast: it
   stays until it is used or dismissed, and it is the only element on this page
   that offers to leave. */
.paint-handoff { position: fixed; z-index: 6; right: 16px; bottom: 16px; display: grid; gap: 8px; width: min(400px, calc(100% - 32px)); padding: 15px 16px; border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 11px; background: var(--surface-raised); box-shadow: var(--shadow); }
.paint-handoff[hidden] { display: none; }
.paint-handoff-chip { display: inline-flex; align-items: center; gap: 7px; width: max-content; margin: 0; border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px 3px 8px; color: var(--muted); font: 750 10px/1.6 ui-monospace, monospace; letter-spacing: .06em; text-transform: uppercase; }
/* Shape and word together: the chip never asks colour to carry the state. */
.paint-handoff-shape { width: 9px; height: 9px; flex: none; border: 2px solid var(--accent); border-radius: 2px; transform: rotate(45deg); }
.paint-handoff[data-handoff="prepared"] .paint-handoff-shape { border-radius: 50%; transform: none; }
.paint-handoff-title { font-size: 14px; line-height: 1.35; }
.paint-handoff-detail { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.paint-handoff-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 3px; }
.paint-handoff-link { gap: 8px; min-height: 44px; text-decoration: none; }
.paint-handoff-dismiss { min-height: 44px; }
/* The header hides .secondary-action on a narrow screen; inside this card the
   dismiss control is the only way back to the canvas, so it always shows. */
.paint-handoff .paint-handoff-dismiss { display: inline-grid; }

@media (max-width: 820px) {
  .editor { grid-template-columns: 68px minmax(0, 1fr); }
  .properties-panel { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; overflow: visible; padding: 14px 18px; border-top: 1px solid var(--line); border-left: 0; }
  .panel-heading, .properties-panel section { padding: 0; border: 0; }
  .canvas-workspace { min-height: min(68vh, 680px); }
}

@media (max-width: 560px) {
  .app-header { grid-template-columns: auto minmax(0, 1fr); min-height: 58px; padding: 8px 10px; }
  .brand span:last-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .brand { min-width: 40px; min-height: 40px; justify-content: center; }
  .brand-mark { width: 22px; height: 22px; }
  /* The wordmark folds down to its mark here, and the destination name is what
     is left in words — so it stays, one size down. It is the only thing on this
     screen that says which of the eight destinations you are in. */
  .site-place { gap: 8px; }
  .site-place-current { padding: 4px 0; font-size: 12px; }
  .document-title { display: none; }
  .secondary-action { display: none; }
  .header-actions { min-width: 0; gap: 6px; }
  .return-action { min-width: 0; padding-inline: 8px; }
  .primary-action { padding-inline: 11px; }
  .editor { grid-template-columns: 1fr; }
  .tool-rail { padding: 7px 8px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .tool-group { display: flex; width: max-content; }
  .tool-button { min-width: 58px; min-height: 48px; }
  .canvas-workspace { min-height: 58vh; }
  .canvas-toolbar { padding-inline: 10px; }
  .canvas-viewport { padding: 20px 12px; }
  .properties-panel { grid-template-columns: 1fr 1fr; }
  .panel-heading { grid-column: 1 / -1; }
  .layers-section { grid-column: 1 / -1; }
  .canvas-help { text-align: left; }
}

/* Keep the two journey-critical actions visible at the supported 280px floor.
   Theme still follows the system preference when its optional toggle is hidden. */
@media (max-width: 360px) {
  .theme-toggle { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto!important; }
}
