:root {
  --linen: #E9DFD0;
  --paper: #F6F1E9;
  --charcoal: #27282D;
  --teal: #183C3B;
  --jade: #559B94;
  --copper: #C58B65;
  --muted: #5E5A55;
  --line: #CFC3B1;
  --focus: var(--teal);
  --bg: var(--linen);
  --surface: var(--paper);
  --text: var(--charcoal);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1E1F23;
    --surface: var(--charcoal);
    --text: var(--linen);
    --muted: #BDB4A6;
    --line: #45464D;
    --focus: var(--jade);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.skip { position: absolute; left: -999px; top: 8px; background: var(--teal); color: #fff; padding: 8px 12px; border-radius: 6px; z-index: 10; }
.skip:focus { left: 8px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.wordmark { display: block; font: 600 22px/1 var(--serif); letter-spacing: 0.04em; }
.brand .mark { display: block; height: 28px; width: auto; }
.tagline { display: block; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.top-actions { display: flex; gap: 8px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  min-height: calc(100vh - 70px);
}

.stage {
  display: flex; flex-direction: column; align-items: center;
  padding: clamp(16px, 3vw, 40px);
  gap: 18px;
}
.canvas {
  margin: 0;
  width: min(100%, calc(100vh - 330px));
  min-width: 260px;
  aspect-ratio: 1;
  display: grid; place-items: center;
}
.canvas svg, .canvas canvas { width: 100%; height: 100%; display: block; border-radius: 4px; box-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 12px 32px rgb(39 40 45 / 0.10); }
.stage-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 6px 24px; margin: 0; width: min(100%, 720px);
}
.stats div { border-top: 1px solid var(--line); padding-top: 8px; }
.stats dt { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.stats dd { margin: 2px 0 0; font: 500 18px/1.3 var(--serif); font-variant-numeric: tabular-nums; }
.stats .ok { color: var(--teal); }
@media (prefers-color-scheme: dark) { .stats .ok { color: var(--jade); } }
.stats .warn { color: #8A3B12; }
@media (prefers-color-scheme: dark) { .stats .warn { color: var(--copper); } }

.note { font-size: 13px; color: var(--muted); max-width: 640px; text-align: center; margin: 0; }
.panel .note { text-align: left; }

.panel {
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 8px 22px 32px;
  overflow-y: auto;
  max-height: calc(100vh - 70px);
  position: sticky; top: 0;
}
fieldset { border: 0; border-bottom: 1px solid var(--line); margin: 0; padding: 18px 0; }
fieldset:last-child { border-bottom: 0; }
legend { font: 600 13px/1 var(--sans); letter-spacing: 0.12em; text-transform: uppercase; padding: 0; margin-bottom: 14px; float: left; width: 100%; }
legend + * { clear: both; }

.field { display: grid; grid-template-columns: 96px 1fr auto; align-items: center; gap: 10px; margin: 10px 0; }
.field label { font-size: 14px; }
.field output { min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }
.field select, .field input[type="text"] { grid-column: 2 / 4; }
.field input[type="color"] { grid-column: 2 / 4; width: 100%; height: 36px; }
.field[hidden] { display: none; }

input[type="range"] { width: 100%; accent-color: var(--teal); min-height: 28px; }
@media (prefers-color-scheme: dark) { input[type="range"] { accent-color: var(--jade); } }
input[type="number"], input[type="text"], select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-height: 36px;
}
.num { width: 84px; }
.num.wide { grid-column: 2 / 4; width: 100%; }

.row { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

.seg { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg span { display: block; text-align: center; padding: 8px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.seg input:checked + span { background: var(--teal); border-color: var(--teal); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.check { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.check input { width: 18px; height: 18px; accent-color: var(--teal); }

.palette { display: flex; gap: 8px; flex-wrap: wrap; }
.palette label { position: relative; }
.palette input[type="color"] { width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 50%; overflow: hidden; cursor: pointer; background: none; }
.palette input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.palette input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 50%; }
.palette input[type="color"]::-moz-color-swatch { border: 0; border-radius: 50%; }
.palette .idx { position: absolute; right: -2px; bottom: -2px; font-size: 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0 5px; line-height: 16px; }

button {
  font: 500 14px/1 var(--sans); border-radius: 999px; padding: 11px 18px; min-height: 40px;
  cursor: pointer; border: 1px solid transparent; color: var(--text); background: transparent;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.primary { background: var(--teal); color: #fff; }
.primary:hover { background: #0F2928; }
.ghost { border-color: var(--line); }
.ghost:hover { border-color: var(--text); }
.spark { background: var(--copper); color: var(--charcoal); font-weight: 600; }
.spark:hover { background: #B67B55; }
.small { padding: 7px 12px; min-height: 34px; font-size: 13px; }
@media (prefers-color-scheme: dark) {
  .primary { background: var(--jade); color: var(--charcoal); }
  .primary:hover { background: #6AAFA8; }
}

.status { min-height: 1.5em; font-size: 14px; margin: 10px 0 4px; }
.status.error { color: #8A3B12; }
@media (prefers-color-scheme: dark) { .status.error { color: var(--copper); } }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .panel { border-left: 0; border-top: 1px solid var(--line); max-height: none; position: static; }
  .canvas { width: 100%; }
  .tagline { display: none; }
}

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

/* Tabs */
.tabs { display: flex; gap: 4px; margin: 14px 0 0; border-bottom: 1px solid var(--line); }
.tabs [role="tab"] {
  border-radius: 8px 8px 0 0; border: 1px solid transparent; border-bottom: 0;
  padding: 10px 18px; margin-bottom: -1px; color: var(--muted); font-weight: 600; letter-spacing: 0.02em;
}
.tabs [role="tab"][aria-selected="true"] { color: var(--text); background: var(--surface); border-color: var(--line); }
[role="tabpanel"][hidden], [data-mode][hidden] { display: none; }

/* Photo */
.drop { display: grid; grid-template-columns: 1fr; gap: 12px; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; text-align: center; }
.drop .note { text-align: center; }
.drop.over { border-color: var(--focus); background: var(--bg); }
.drop canvas { width: 100%; max-width: 280px; height: auto; aspect-ratio: 1; display: block; margin: 0 auto; border-radius: 8px; background: var(--bg);
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.drop canvas.dragging { cursor: grabbing; }
.drop canvas:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.frame-tools { display: flex; justify-content: center; gap: 8px; margin-top: 8px; }
.frame-tools button { min-width: 44px; min-height: 44px; font-size: 18px; }
.frame-tools #frameReset, .frame-tools #clearFocus { font-size: 14px; }
.frame-tools { flex-wrap: wrap; }
.framer .note { text-align: center; margin-top: 6px; }
.drop .note { margin-top: 8px; }
.progress { min-height: 1.4em; margin: 0; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sub { font: 600 13px/1 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; margin: 20px 0 6px; color: var(--muted); }
.block { width: 100%; margin-top: 8px; border-radius: 10px; }
.stats .full { grid-column: 1 / -1; }

/* What was checked (REV-003) */
.checks { border-top: 0 !important; padding-top: 0 !important; }
.checks summary { cursor: pointer; font-size: 14px; color: var(--muted); padding: 4px 0; }
.checks ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.checks li { margin: 4px 0; }
.checks li strong { color: var(--text); font-weight: 600; }

/* Studio (E05) */
.variations { padding: 16px 0 6px; border-bottom: 1px solid var(--line); }
.var-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.var-head .sub { margin: 0; }
.var-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.var-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 34px; font-size: 13px; border: 1px solid var(--line); border-radius: 999px; }
.var-chip[aria-pressed="true"] { background: var(--teal); border-color: var(--teal); color: #fff; }
@media (prefers-color-scheme: dark) { .var-chip[aria-pressed="true"] { background: var(--jade); border-color: var(--jade); color: var(--charcoal); } }
.var-chip .kind { font-size: 11px; opacity: 0.75; text-transform: uppercase; letter-spacing: 0.06em; }
.var-del { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.var-name { margin-top: 8px; }
.locks { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
.locks .check { margin-top: 6px; font-size: 14px; }

.notice { width: min(100%, 720px); display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--copper); border-radius: 10px; padding: 10px 14px; background: var(--surface); }
.notice p { margin: 0; font-size: 14px; }
.notice[hidden] { display: none; }

dialog#projectsDialog { width: min(640px, 94vw); max-height: 86vh; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--text); padding: 18px 20px; }
dialog#projectsDialog::backdrop { background: rgb(39 40 45 / 0.45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head h2 { font: 600 20px/1.2 var(--serif); margin: 0; }
.project-list { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 8px; }
.project-list li { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.project-list li[aria-current="true"] { border-color: var(--focus); }
.project-list .thumb { width: 64px; height: 64px; border-radius: 6px; overflow: hidden; background: var(--bg); }
.project-list .thumb svg { width: 100%; height: 100%; display: block; }
.project-list .meta { font-size: 13px; color: var(--muted); }
.project-list .name { font-weight: 600; }
.project-list .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Design options */
dialog#optionsDialog { width: min(760px, 96vw); max-height: 90vh; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--text); padding: 18px 20px; }
dialog#optionsDialog::backdrop { background: rgb(39 40 45 / 0.45); }
.options-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 12px 0; }
.option { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  font: 500 13px/1.3 var(--sans); color: var(--text); text-align: left; min-height: auto; }
.option:hover, .option:focus-visible { border-color: var(--focus); }
.option svg { width: 100%; height: auto; aspect-ratio: 1; display: block; border-radius: 8px; }
@media (max-width: 560px) { .options-grid { grid-template-columns: repeat(2, 1fr); } }

/* Photo help */
.photo-help { margin-top: 10px; }
.tips { list-style: none; padding: 0; margin: 6px 0 0; font-size: 13px; }
.tips li { padding: 6px 10px; border-radius: 8px; margin-top: 4px; background: var(--bg); }
.tips li.good { border-left: 3px solid var(--teal); }
.tips li.advice { border-left: 3px solid var(--copper); }

/* Phones: keep the artwork in view while adjusting (Review 003, mobile usability) */
@media (max-width: 860px) {
  .stage { display: contents; }
  .layout { display: flex; flex-direction: column; }
  .notice { order: 1; margin: 12px auto 0; }
  /* Full-width sticky band: nothing shows half-hidden beside the artwork (brand guide §7). */
  /* One pinned block (REV-031): artwork, main actions and the result line
     stay together at the top while the controls scroll, and grow with the
     text size instead of relying on fixed heights. */
  .pin { order: 2; position: sticky; top: 0; z-index: 3; background: var(--bg); box-shadow: 0 6px 10px -8px rgb(0 0 0 / 0.35); }
  .canvas { width: 100%; aspect-ratio: auto; margin: 0; padding: 6px 0; display: flex; justify-content: center; }
  .canvas svg, .canvas canvas { width: min(88vw, 34vh); height: min(88vw, 34vh); }
  .stage-actions { padding: 6px 12px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
  .progress { margin: 0; padding: 0 16px 6px; text-align: center; font-size: 14px; }
  .progress:empty { padding: 0; min-height: 0; }
  .panel { order: 5; }
  .stats { order: 6; padding: 16px; width: 100%; }
  .stage > .note { order: 7; padding: 0 16px 24px; }
}
@media (pointer: coarse) {
  button { min-height: 44px; }
  input[type="range"] { min-height: 44px; }
  .seg span { padding: 12px 8px; }
  .var-chip, .var-del { min-height: 44px; }
  .locks .check input, .check input { width: 22px; height: 22px; }
}

/* Autosave state (REV-015) */
.save-state { display: block; min-height: 1.2em; font-size: 0.8rem; color: var(--muted, #6b6b6b); margin-top: 0.2rem; }
.save-state.failed { color: #9b2c2c; font-weight: 600; }

/* Outside phone layout the pinned block is just part of the stage. */
.pin { display: contents; }
@media (max-width: 860px) { .pin { display: block; } }
/* Landscape phones and very short screens: don't pin, so controls stay reachable (REV-031). */
@media (max-width: 860px) and (max-height: 520px) { .pin { position: static; box-shadow: none; } }
/* Printer correction (R2.2) */
.printfix { margin: 10px 0 12px; }
.printfix summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.printfix summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.printfix input[type="number"] { width: 6.5em; font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--muted); background: transparent; color: inherit; }

/* Family projects and Make mode (E06, R2.4) */
dialog#familyDialog, dialog#makeDialog { width: min(760px, 96vw); max-height: 92vh; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--text); padding: 18px 20px; }
dialog#familyDialog::backdrop, dialog#makeDialog::backdrop { background: rgb(39 40 45 / 0.45); }
.option .meta { font-size: 12px; color: var(--muted); }
.option .ages { font-weight: 600; color: var(--teal); }
#makeDialog h4 { margin: 12px 0 4px; font-size: 14px; }
#makeDialog ul { margin: 0; padding-left: 20px; line-height: 1.5; }
.make-progress { display: flex; gap: 12px; align-items: center; font-weight: 600; margin: 8px 0; }
.make-progress progress { flex: 1; height: 10px; accent-color: var(--teal); }
#makeCanvas { width: min(100%, 52vh); aspect-ratio: 1; height: auto; display: block; margin: 0 auto; background: var(--bg); border-radius: 12px; }
.make-headline { font: 700 clamp(34px, 9vw, 56px)/1.1 var(--sans); text-align: center; margin: 12px 0 4px; display: flex; gap: 12px; justify-content: center; align-items: center; }
.make-headline .swatch { width: 0.8em; height: 0.8em; border-radius: 50%; border: 2px solid var(--text); display: inline-block; }
.make-text { text-align: center; font-size: 17px; margin: 0 0 12px; }
.make-buttons { justify-content: center; }
.make-buttons button { min-height: 56px; min-width: 120px; font-size: 18px; }
#makeNext { flex: 1; max-width: 320px; }
.make-headline .swatch[hidden] { display: none; }

/* Where Lines Meet header (R2.1): on narrow screens the symbol stands alone; the name stays available to screen readers. */
@media (max-width: 560px) {
  .wordmark { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
/* Build sessions (REV-045, REV-047) */
.build-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.build-list li { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.build-list li span { flex: 1 1 240px; }
#makeSaveState { text-align: center; }
#makeSaveState.error { color: #8A1C1C; font-weight: 600; }
@media (prefers-color-scheme: dark) { #makeSaveState.error { color: #F2A3A3; } }
#makeMaterials { width: 100%; }

/* Site footer and plain information pages (R2.5 web MVP, ADR 0011) */
.site-footer { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; justify-content: center; padding: 1.5rem 1rem 2.5rem; font-size: 0.95rem; }
.site-footer a, .info-page a { color: inherit; text-underline-offset: 3px; }
.info-page { max-width: 44rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; line-height: 1.6; }
.info-page h1 { font-size: 1.6rem; margin: 1rem 0 0.5rem; }
.info-page h2 { font-size: 1.15rem; margin: 1.75rem 0 0.4rem; }
.info-page .meta { opacity: 0.75; font-size: 0.9rem; }
.info-page .back { display: inline-block; margin-top: 0.5rem; }

/* Feedback form (ADR 0012) */
.fb fieldset { border: 1px solid color-mix(in srgb, currentColor 18%, transparent); border-radius: 12px; padding: 0.75rem 1rem 1rem; margin: 0 0 1rem; }
.fb legend { font-weight: 600; padding: 0 0.35rem; }
.fb label { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0.3rem 1rem 0.3rem 0; }
.fb label.block { display: flex; flex-direction: column; align-items: stretch; margin-top: 0.6rem; }
.fb textarea, .fb input[type="text"], .fb input[type="number"] { font: inherit; padding: 0.5rem; border-radius: 8px; border: 1px solid color-mix(in srgb, currentColor 25%, transparent); background: transparent; color: inherit; }
.fb .hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
