/* THE SHELL STYLESHEET (web/index.html).
 *
 * The look comes from the approved design: warm sand, navy ink,
 * hand-drawn outlines, and a solid color that spills a few pixels
 * behind a filled shape. The ink outline always stands in front of
 * the color.
 *
 * Every side and every offset is logical, so `dir="rtl"` mirrors the
 * whole screen. A source pin refuses a physical side property.
 */
@layer reset, tokens, base, components, screens, utilities;

/* ---------- fonts ----------
 * Self-hosted, with no third-party origin (GENERATION.md). Latin text
 * takes Kalam and Nunito Sans. Hebrew text takes Rubik in both
 * families, because the two Latin faces hold no Hebrew letters. Each
 * license is in fonts/ next to its file.
 * The two faces of one family must declare the same weight. Chrome
 * picks one face by weight first, and only its unicode-range counts:
 * two different weights left the Latin text in the system font. */
@font-face {
  font-family: 'Sandcastle Hand';
  src: url(fonts/kalam-latin-700.woff2) format('woff2');
  font-weight: 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Sandcastle Hand';
  src: url(fonts/rubik-hebrew-wght.woff2) format('woff2');
  font-weight: 700;
  font-display: swap;
  unicode-range: U+0307-0308, U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F;
}
@font-face {
  font-family: 'Sandcastle Body';
  src: url(fonts/nunito-sans-latin-wght.woff2) format('woff2');
  font-weight: 200 1000;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Sandcastle Body';
  src: url(fonts/rubik-hebrew-wght.woff2) format('woff2');
  font-weight: 200 1000;
  font-display: swap;
  unicode-range: U+0307-0308, U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F;
}

/* ---------- reset ---------- */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body, h1, h2, h3, p, ol, ul, fieldset, legend { margin: 0; padding: 0; }
  ol, ul { list-style: none; }
  fieldset { border: 0; min-inline-size: 0; }
  svg { display: block; max-inline-size: 100%; }
  button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
  button { cursor: pointer; background: none; border: 0; padding: 0; }
  /* A display rule in a later layer never beats the hidden attribute. */
  [hidden] { display: none !important; }
}

/* ---------- tokens ---------- */
@layer tokens {
  :root {
    color-scheme: light;

    /* Color. Each text pair holds 4.5:1 or more on the sand and on white. */
    --sand: #FFF4E0;
    --sand-deep: #FFE7BF;
    --paper: #FFFFFF;
    --ink: #1F2A44;
    --ink-soft: #46536F;
    --link: #0B5F67;
    --link-hover: #08464C;
    --sun: #FFC968;
    /* The sun at 55 percent over the paper: a picked plan card. */
    --sun-soft: #FFE1AC;
    --sea: #8ED6CE;
    --sea-deep: #0E7C86;
    --coral: #F4A08F;
    --violet: #C3B8EE;
    --green: #A9DCA2;
    --green-dot: #9BD49D;
    --mint: #DFF3F1;
    --dash: #E7C990;
    --handle: #D9CBB0;
    --error: #B03A27;
    --text-built: #2F6B33;
    --text-building: #8A5A00;
    --text-waiting: #5A6478;
    --focus: #0B5F67;

    /* Space. */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-7: 32px;
    --space-8: 48px;
    --space-9: 64px;
    --gutter: clamp(16px, 4vw, 24px);

    /* The two hand-drawn radii and the round one. */
    --wobble-a: 18px 22px 16px 24px / 22px 16px 24px 18px;
    --wobble-b: 22px 16px 24px 18px / 16px 24px 18px 22px;
    --wobble-round: 48% 52% 47% 53% / 52% 48% 53% 47%;

    /* The outline, and the color spill: its offset and its small turn. */
    --stroke: 2.5px;
    --stroke-thin: 2px;
    --spill: 3px;
    --spill-turn: 0.4deg;

    /* Type. */
    --font-hand: 'Sandcastle Hand', 'Comic Sans MS', 'Chalkboard SE', 'Segoe Print', cursive;
    --font-body: 'Sandcastle Body', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    --step--1: clamp(0.8125rem, 0.78rem + 0.15vw, 0.875rem);
    --step-0: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
    --step-1: clamp(1.125rem, 1.05rem + 0.35vw, 1.375rem);
    --step-2: clamp(1.375rem, 1.2rem + 0.8vw, 1.875rem);
    --step-3: clamp(1.625rem, 1.3rem + 1.5vw, 2.25rem);
    --step-4: clamp(2.25rem, 1.6rem + 3vw, 3.75rem);
    --step-5: clamp(2.375rem, 1.5rem + 4.2vw, 4rem);

    --tap: 44px;
    --field-h: 54px;
  }
}

/* ---------- base ---------- */
@layer base {
  html { accent-color: var(--sea-deep); }
  body {
    min-block-size: 100dvh;
    background: var(--sand);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: var(--step-0);
    line-height: 1.45;
    overflow-x: clip;
  }
  h1, h2, h3 {
    font-family: var(--font-hand);
    font-weight: 700;
    line-height: 1.08;
    text-wrap: balance;
  }
  h1 { font-size: var(--step-4); }
  h2 { font-size: var(--step-3); }
  h3 { font-size: var(--step-1); }
  p { text-wrap: pretty; }
  a { color: var(--link); }
  a:hover { color: var(--link-hover); }
  :focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
  }
  /* A heading takes the focus when a screen opens (put() in the page),
     so a screen reader starts there. It shows no ring. */
  [tabindex="-1"]:focus { outline: none; }
  input:focus-visible, textarea:focus-visible { outline-offset: 2px; }
  ::selection { background: var(--sun); color: var(--ink); }
}

/* ---------- components ---------- */
@layer components {
  /* An icon: a hand-drawn stroke drawing at the size of the text. */
  .icon {
    inline-size: 1.15em;
    block-size: 1.15em;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  /* An arrow points along the line of reading, so it mirrors in RTL. */
  [dir="rtl"] .icon.flip { transform: scaleX(-1); }

  /* THE SPILL: the one filled look. A shape with `.fill` gets its
     color from --fill. The color sits a few pixels down and to the
     inline end, turned a little, and the ink outline draws on top.
     --stroke sets the outline width; a dot sets it to zero, because
     its ring is part of its drawing. */
  .fill,
  .seg input:checked + .pill {
    --fill: var(--sea);
    position: relative;
    isolation: isolate;
    border-color: transparent;
    background: transparent;
  }
  .fill::before, .fill::after,
  .seg input:checked + .pill::before, .seg input:checked + .pill::after {
    content: "";
    position: absolute;
    border-radius: inherit;
    pointer-events: none;
  }
  .fill::before,
  .seg input:checked + .pill::before {
    inset-block-start: calc(var(--spill) - var(--stroke));
    inset-inline-start: calc(var(--spill) - var(--stroke));
    inset-block-end: calc(-1 * var(--spill) - var(--stroke));
    inset-inline-end: calc(-1 * var(--spill) - var(--stroke));
    background: var(--fill);
    rotate: var(--spill-turn);
    z-index: -1;
  }
  [dir="rtl"] .fill::before,
  [dir="rtl"] .seg input:checked + .pill::before { rotate: calc(-1 * var(--spill-turn)); }
  .fill::after,
  .seg input:checked + .pill::after {
    inset: calc(-1 * var(--stroke));
    border: var(--stroke) solid var(--ink);
    z-index: 1;
  }
  .fill:nth-child(even) { --spill-turn: -0.45deg; }
  .fill:hover::before { filter: brightness(1.04) saturate(1.08); }
  .sun, .seg input:checked + .pill { --fill: var(--sun); }
  .sea { --fill: var(--sea); }
  .coral { --fill: var(--coral); }
  .violet { --fill: var(--violet); }
  .green { --fill: var(--green); }

  /* The brand: the small castle and the name. */
  .brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-inline-size: 0;
  }
  .brand .logo { inline-size: 40px; block-size: 40px; flex: none; }
  .brandName {
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: var(--step-2);
    line-height: 1;
  }
  .topbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }
  .topbar .brand { flex: 1; }
  .topbar a {
    min-block-size: var(--tap);
    display: inline-flex;
    align-items: center;
    padding-inline: var(--space-2);
    font-weight: 700;
    text-decoration: none;
  }

  /* An outlined box with the first wobble. */
  .sk {
    position: relative;
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-a);
  }

  /* A button. The plain kind is a white box with an ink outline. */
  .btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-block-size: var(--tap);
    min-inline-size: var(--tap);
    padding-inline: var(--space-4);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-b);
    background: var(--paper);
    color: var(--ink);
    font-weight: 700;
    line-height: 1.1;
    text-decoration: none;
    white-space: nowrap;
    transition: transform 0.08s ease-out;
  }
  .btn:active { transform: translateY(1px); }
  .btn.fill { font-weight: 800; }
  .btn.big { min-block-size: var(--field-h); padding-inline: var(--space-5); font-size: var(--step-1); font-weight: 800; }
  .btn.wide { inline-size: 100%; }

  /* A round button: the mic and the send arrow. */
  .round {
    border-radius: var(--wobble-round);
    inline-size: 52px;
    block-size: 52px;
    min-inline-size: 52px;
    padding: 0;
    flex: none;
  }
  .round .icon { inline-size: 24px; block-size: 24px; }
  .mic.rec { --fill: var(--error); color: var(--paper); }
  /* The mic missed the words: the button calms to sand until the next try. */
  .mic.missed { --fill: var(--sand-deep); }
  @media (prefers-reduced-motion: no-preference) {
    .mic.rec::before { animation: rec-pulse 1.2s ease-in-out infinite; }
  }
  @keyframes rec-pulse { 50% { opacity: 0.55; } }

  /* An icon button: a square tap target with no visible words. */
  .iconOnly { padding-inline: 0; inline-size: var(--tap); }

  /* A field. */
  .field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }
  .fieldLabel, legend {
    font-weight: 800;
    font-size: var(--step-0);
  }
  legend { margin-block-end: var(--space-2); }
  .input {
    inline-size: 100%;
    min-inline-size: 0;
    min-block-size: var(--field-h);
    padding-inline: var(--space-4);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-a);
    background: var(--paper);
    color: var(--ink);
    font-size: var(--step-1);
  }
  textarea.input {
    padding-block: var(--space-3);
    min-block-size: 7.5em;
    resize: vertical;
    line-height: 1.4;
  }
  .input::placeholder { color: var(--ink-soft); opacity: 1; }
  .input[aria-invalid="true"] { border-color: var(--error); }
  .hint { color: var(--ink-soft); font-size: var(--step--1); }
  .note { color: var(--ink-soft); }

  /* A segmented control: radios that look like two pills. The radio
     stays in the page for the keyboard, and the pill is its label. The
     checked pill takes the spill. */
  .seg {
    display: flex;
    gap: var(--space-3);
  }
  .seg label { flex: 1; min-inline-size: 0; position: relative; }
  .seg input {
    position: absolute;
    opacity: 0;
    inline-size: 1px;
    block-size: 1px;
  }
  .seg .pill {
    display: grid;
    place-items: center;
    min-block-size: 48px;
    padding-inline: var(--space-3);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-a);
    background: var(--paper);
    font-weight: 700;
    cursor: pointer;
  }
  .seg label:nth-child(even) .pill { border-radius: var(--wobble-b); }
  .seg input:checked + .pill { font-weight: 800; }
  .seg input:focus-visible + .pill {
    outline: 3px solid var(--focus);
    outline-offset: 4px;
  }

  /* Chips: outlined pills for options and ideas. */
  .chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .chips button, #opts button {
    min-block-size: var(--tap);
    padding-inline: var(--space-4);
    padding-block: var(--space-2);
    border: var(--stroke-thin) solid var(--ink);
    border-radius: var(--wobble-b);
    background: var(--paper);
    font-weight: 700;
    text-align: start;
    line-height: 1.2;
    max-inline-size: 100%;
    overflow-wrap: anywhere;
  }
  .chips button:nth-child(even), #opts button:nth-child(even) { border-radius: var(--wobble-a); }
  .chips button:hover, #opts button:hover { background: var(--mint); }
  /* The last chip of a list is the soft way out: "You pick", or
     "Something else". */
  .chips.soft button:last-child, #opts button.soft {
    background: transparent;
    border-style: dashed;
  }
  .linkBtn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-block-size: var(--tap);
    padding-inline: var(--space-3);
    border: var(--stroke-thin) dashed var(--ink-soft);
    border-radius: 999px;
    color: var(--ink-soft);
    font-weight: 700;
    white-space: nowrap;
  }
  .linkBtn:hover { color: var(--ink); border-color: var(--ink); }

  /* Chat bubbles. Sandy talks from the start side, the kid from the
     end side, so RTL mirrors the conversation. Each bubble finds its
     own direction from its first strong letter. */
  #log {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .msg {
    max-inline-size: 85%;
    padding-block: var(--space-2);
    padding-inline: var(--space-3);
    border: var(--stroke-thin) solid var(--ink);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    unicode-bidi: plaintext;
  }
  .msg.guide {
    align-self: flex-start;
    border-radius: var(--wobble-b);
    background: var(--sand);
  }
  /* A build note: status from Sandy while a row builds, lighter than talk. */
  .msg.guide.note {
    background: transparent;
    border-style: dashed;
  }
  .msg.kid {
    align-self: flex-end;
    border-radius: var(--wobble-a);
    background: var(--mint);
    font-weight: 600;
  }
  .typing .dots { display: inline-flex; gap: 4px; padding-block: 6px; }
  .typing .dots span {
    inline-size: 8px;
    block-size: 8px;
    border-radius: 50%;
    background: var(--ink);
    opacity: 0.35;
  }
  @media (prefers-reduced-motion: no-preference) {
    .typing .dots span { animation: blink 1.2s infinite; }
    .typing .dots span:nth-child(2) { animation-delay: 0.2s; }
    .typing .dots span:nth-child(3) { animation-delay: 0.4s; }
  }
  @keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

  /* The build list (<build-list>, web/shell/elements.js). The desktop
     shows the heading and every row. A phone shows the summary line,
     and the rows open under it. */
  build-list { display: block; }
  .bpHead {
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: var(--step-1);
    margin-block-end: var(--space-1);
  }
  .bpBox > summary { display: none; }
  .bpList { display: flex; flex-direction: column; }
  .bprow { display: flex; align-items: center; gap: var(--space-1); }
  .bpMain {
    flex: 1;
    min-inline-size: 0;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-block-size: var(--tap);
    padding-inline: var(--space-1);
    border-radius: 10px;
    text-align: start;
  }
  .bpMain:hover { background: var(--sand); }
  .bpMain[aria-disabled="true"] { cursor: default; }
  .bpMain[aria-disabled="true"]:hover { background: none; }
  .bpMain .words {
    flex: 1;
    min-inline-size: 0;
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
  }
  .bpMain .lbl {
    flex: 1 1 6ch;
    min-inline-size: 6ch;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .bpMain small, .bpNow {
    flex: none;
    font-size: var(--step--1);
    font-weight: 700;
    color: var(--text-waiting);
    text-align: end;
  }
  /* A failed row is the one the kid acts on: the label keeps its whole
     line, and the note wraps under it. */
  .bprow.failed .words { flex-direction: column; align-items: flex-start; gap: 0; }
  .bprow.failed .lbl { flex: none; white-space: normal; overflow-wrap: anywhere; }
  .bprow.failed small { text-align: start; }
  .bprow.done small, .bpNow.done { color: var(--text-built); }
  .bprow.building small, .bpNow.building { color: var(--text-building); }
  .bprow.failed small, .bpNow.failed { color: var(--error); }
  .bprow .del {
    flex: none;
    inline-size: var(--tap);
    block-size: var(--tap);
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: var(--ink-soft);
  }
  .bprow .del:hover { color: var(--ink); background: var(--sand); }
  /* A state dot: a hand-drawn ring over a spill of the state color.
     The ring is part of the drawing, so the spill draws no outline. */
  .dot {
    --stroke: 0px;
    --spill: 2px;
    position: relative;
    flex: none;
    inline-size: 22px;
    block-size: 22px;
    border-radius: var(--wobble-round);
  }
  .dot.fill { --spill-turn: 0deg; }
  .dot svg { inline-size: 100%; block-size: 100%; fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; }
  .dot.done { --fill: var(--green-dot); }
  .dot.building { --fill: var(--sun); }
  .dot.failed { --fill: var(--coral); }
  .dot.small { inline-size: 16px; block-size: 16px; }
  @media (prefers-reduced-motion: no-preference) {
    .dot.building .hand { transform-origin: 12px 12px; animation: turn 2s linear infinite; }
  }
  @keyframes turn { to { rotate: 360deg; } }

  /* The view toggle over the preview: You and Visitor. */
  #viewAs {
    display: flex;
    gap: var(--space-3);
  }
  #viewAs button[aria-pressed="false"] { color: var(--ink-soft); }
}

/* ---------- screens ---------- */
@layer screens {
  main { min-block-size: 100dvh; }
  #preview { display: none; }

  /* A page screen: the sign-in, the setup, My stuff, and the new
     project steps. */
  .page {
    max-inline-size: 1120px;
    margin-inline: auto;
    padding-block: var(--space-5) var(--space-9);
    padding-inline: var(--gutter);
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
  }
  .page.narrow { max-inline-size: 640px; }
  .page h1 { margin-block-start: var(--space-4); }
  .stack { display: flex; flex-direction: column; gap: var(--space-4); }

  /* The homepage (Entry-Home). */
  .hero {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    grid-template-areas: "words sandy";
    align-items: center;
    gap: var(--space-8);
    padding-block-start: var(--space-8);
  }
  .heroWords { grid-area: words; display: flex; flex-direction: column; gap: var(--space-7); min-inline-size: 0; }
  .hero h1 { font-size: var(--step-5); line-height: 1.02; margin: 0; }
  .hero h1 span { display: block; }
  .heroSandy { grid-area: sandy; justify-self: center; inline-size: min(270px, 100%); }
  .signin { display: flex; flex-direction: column; gap: var(--space-3); max-inline-size: 460px; }
  .signin form { display: flex; flex-direction: column; gap: var(--space-2); }
  .sendRow { display: flex; flex-wrap: wrap; gap: var(--space-3); }
  .sendRow .input { flex: 1 1 220px; inline-size: auto; }
  .sendRow .btn { flex: 0 0 auto; }
  .stateCard { display: flex; flex-direction: column; gap: var(--space-2); }
  .stateCard:empty { display: none; }
  .stateCard h2 { font-size: var(--step-3); }
  .stateCard p { font-size: var(--step-1); }
  .how { display: flex; flex-direction: column; gap: var(--space-5); padding-block-start: var(--space-8); }
  .steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: var(--space-6);
  }
  .step {
    background: var(--paper);
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }
  .step .num {
    inline-size: var(--tap);
    block-size: var(--tap);
    display: grid;
    place-items: center;
    margin-block-end: var(--space-2);
    border: var(--stroke) solid transparent;
    border-radius: var(--wobble-round);
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: var(--step-1);
  }
  .step .words { display: flex; flex-direction: column; gap: var(--space-1); }
  .step .title { font-family: var(--font-hand); font-weight: 700; font-size: var(--step-2); line-height: 1.1; }
  .step .sub { color: var(--ink-soft); font-size: var(--step-1); }

  /* The plan picker (Funnel-Plans). Each plan is a card with a radio.
     The picked card takes the sun spill and the aqua check. */
  .funnel h1 { font-size: var(--step-5); line-height: 1.05; }
  .emailLine { margin-block-start: calc(-1 * var(--space-4)); color: var(--ink-soft); }
  .emailLine a { font-weight: 700; display: inline-flex; align-items: center; min-block-size: var(--tap); }
  .funnelNote { font-size: var(--step-1); }
  .planPick {
    border: 0;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
    gap: var(--space-6);
  }
  .planOpt {
    position: relative;
    isolation: isolate;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-1) var(--space-2);
    padding: var(--space-6);
    background: var(--paper);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-a);
    cursor: pointer;
  }
  .planOpt:nth-child(odd) { border-radius: var(--wobble-b); }
  .planOpt input {
    position: absolute;
    opacity: 0;
    inline-size: 1px;
    block-size: 1px;
  }
  .planOpt::after {
    content: "";
    grid-row: 1;
    grid-column: 2;
    inline-size: 30px;
    block-size: 30px;
    border: 2px solid var(--ink);
    border-radius: 50%;
  }
  .planOpt:has(input:checked) { background: var(--sun-soft); }
  /* The check is a glyph, so the stylesheet names no URL at all. */
  .planOpt:has(input:checked)::after {
    content: "\2713";
    display: grid;
    place-items: center;
    background: var(--sea);
    color: var(--ink);
    font-weight: 800;
    font-size: 18px;
    line-height: 1;
  }
  .planOpt:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 4px; }
  .optName { font-family: var(--font-hand); font-weight: 700; font-size: var(--step-3); line-height: 1.1; }
  .optPrice { grid-column: 1 / -1; font-weight: 800; font-size: var(--step-2); }
  .timeline {
    list-style: none;
    margin: 0;
    padding: var(--space-6);
    display: flex;
    gap: var(--space-6);
    background: var(--paper);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-b);
  }
  .timeline li { flex: 1 1 0; min-inline-size: 0; display: flex; flex-direction: column; gap: var(--space-1); }
  .timeline li::before {
    content: "";
    inline-size: 34px;
    block-size: 34px;
    margin-block-end: var(--space-1);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-round);
    background: var(--fill);
  }
  .timeline b { font-weight: 800; font-size: var(--step-1); }
  .timeline span { color: var(--ink-soft); }
  .funnelGo { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
  .features { display: flex; flex-direction: column; gap: var(--space-5); }
  .featCols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
    gap: var(--space-7);
  }
  .featCol h3 { font-family: var(--font-body); font-weight: 800; font-size: var(--step-1); margin-block-end: var(--space-3); }
  .featCol ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
  .featCol li { display: flex; gap: var(--space-3); align-items: flex-start; font-size: var(--step-1); }
  .tick {
    flex: none;
    inline-size: 22px;
    block-size: 22px;
    margin-block-start: 1px;
    fill: none;
    stroke: var(--link);
    stroke-width: 2.6;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  /* "Who is building?" (Entry-States, the fourth card). */
  .card {
    background: var(--paper);
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }
  .whoCard { max-inline-size: 440px; inline-size: 100%; margin-inline: auto; }
  .whoCard sandy-face { inline-size: 74px; }
  .whoCard form { display: flex; flex-direction: column; gap: var(--space-4); }
  /* A server page (PLATFORM.md §6½): the same card, a little lower. */
  .serverPage { margin-block-start: var(--space-7); }
  .serverPage p { font-size: var(--step-1); }
  .topbar .homeLink { padding-inline: 0; color: inherit; flex: 1; }

  /* Sandy asks the question: the face stands beside the heading of the
     category screen and the idea screen. */
  .askHead { display: flex; align-items: flex-end; gap: var(--space-3); }
  .askHead sandy-face { inline-size: clamp(52px, 7vw, 80px); flex: none; }
  .askHead h1 { min-inline-size: 0; margin-block-end: var(--space-2); }

  /* My stuff (A2-Home). */
  .projects {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
    gap: var(--space-6);
  }
  .projects > li { display: flex; container-type: inline-size; }
  .projCard {
    inline-size: 100%;
    display: flex;
    flex-direction: column;
    min-block-size: 250px;
    background: var(--paper);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-a);
    text-align: start;
    transition: transform 0.08s ease-out;
  }
  .projCard:hover { transform: translateY(-2px); }
  .projCard:active { transform: translateY(0); }
  .tile {
    --stroke: var(--stroke-thin);
    block-size: 150px;
    margin-block-start: var(--space-3);
    margin-inline: var(--space-3);
    display: grid;
    place-items: center;
    border: var(--stroke) solid transparent;
    border-radius: var(--wobble-b);
  }
  .projects > li:nth-child(odd) .tile { --spill-turn: -0.45deg; }
  .tile .art { inline-size: 64px; block-size: 64px; stroke-width: 1.6; }
  .badge {
    position: absolute;
    inset-block-start: var(--space-2);
    inset-inline-end: var(--space-2);
    z-index: 2;
    padding-block: 2px;
    padding-inline: var(--space-3);
    border: var(--stroke-thin) solid var(--ink);
    border-radius: var(--wobble-b);
    background: var(--paper);
    font-size: var(--step--1);
    font-weight: 800;
  }
  .projCard .t {
    padding-block-start: var(--space-3);
    padding-inline: var(--space-5);
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: var(--step-1);
    line-height: 1.15;
    overflow-wrap: anywhere;
  }
  .projCard .kind {
    padding-block-end: var(--space-4);
    padding-inline: var(--space-5);
    color: var(--ink-soft);
    font-size: var(--step--1);
  }
  .newCard {
    inline-size: 100%;
    min-block-size: 250px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    border: var(--stroke) dashed var(--ink);
    border-radius: var(--wobble-b);
    background: var(--sand-deep);
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: var(--step-1);
  }
  .newCard:hover { background: var(--sun); }
  /* The plus of the design: a 72-pixel ring over a sea spill. */
  .newCard .plusRing {
    inline-size: 72px;
    block-size: 72px;
    display: grid;
    place-items: center;
    border: var(--stroke) solid transparent;
    border-radius: var(--wobble-round);
  }
  .newCard .plusRing .icon { inline-size: 38px; block-size: 38px; stroke-width: 2.4; }
  .newBar { display: none; }
  @container (max-width: 180px) {
    .tile { block-size: 104px; margin-block-start: var(--space-2); margin-inline: var(--space-2); }
    .tile .art { inline-size: 48px; block-size: 48px; }
    .projCard { min-block-size: 0; }
    .projCard .t { padding-inline: var(--space-3); font-size: var(--step-0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .projCard .kind { padding-inline: var(--space-3); padding-block-end: var(--space-3); }
  }

  /* The category picker and the first words. */
  .cats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: var(--space-6);
  }
  .cats button {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
    padding: var(--space-5);
    background: var(--paper);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-a);
    text-align: start;
  }
  .cats button:nth-child(even) { border-radius: var(--wobble-b); }
  .cats button:hover { background: var(--mint); }
  .cats .art { inline-size: 56px; block-size: 56px; stroke-width: 1.6; margin-block-end: var(--space-2); }
  .cats .name { font-family: var(--font-hand); font-weight: 700; font-size: var(--step-2); }
  .cats small { color: var(--ink-soft); font-size: var(--step-0); }
  .actRow { display: flex; align-items: center; gap: var(--space-3); }
  .actRow .btn.big { flex: 1; }
  .askRow { display: flex; align-items: center; gap: var(--space-2); }
  .askRow .input { flex: 1; }

  /* The builder (Main and A2-PhoneBuilder). One DOM: the grid places
     the header, the chat panel, and the preview. */
  body[data-screen="builder"] { block-size: 100dvh; overflow: hidden; }
  body[data-screen="builder"] main {
    block-size: 100dvh;
    display: grid;
    grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "head head" "chat app";
    gap: var(--space-5) var(--space-6);
    padding-block: var(--space-5);
    padding-inline: var(--gutter);
  }
  body[data-screen="builder"] #chat,
  body[data-screen="builder"] #pane { display: contents; }
  body[data-screen="builder"] #preview {
    grid-area: app;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-block-size: 0;
    position: relative;
  }
  .bar {
    grid-area: head;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    min-inline-size: 0;
  }
  #pTitle {
    flex: 1;
    min-inline-size: 4ch;
    font-size: var(--step-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .bar .actions { display: flex; gap: var(--space-3); flex: none; }
  .chatPanel {
    grid-area: chat;
    display: flex;
    flex-direction: column;
    min-block-size: 0;
    min-inline-size: 0;
    background: var(--paper);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-a);
    container-type: inline-size;
  }
  .chatHead {
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding-block: var(--space-4) var(--space-2);
    padding-inline: var(--space-5);
  }
  .chatHead sandy-face { inline-size: 40px; }
  .chatHead h2 { font-size: var(--step-1); }
  .chatHead #soundBtn { margin-inline-start: auto; }
  .chatPanel #log { flex: 1 1 auto; min-block-size: 3lh; padding-block: var(--space-2); padding-inline: var(--space-5); }
  .optsRow {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    padding-block: var(--space-2);
    padding-inline: var(--space-5);
  }
  #opts { display: contents; }
  .chatPanel #bp {
    flex: none;
    margin-block-start: var(--space-2);
    margin-inline: var(--space-4);
    padding-block-start: var(--space-3);
    /* Room for the focus ring of a row inside the scroll box. */
    padding-inline: var(--space-2);
    padding-block-end: var(--space-2);
    border-block-start: var(--stroke-thin) dashed var(--dash);
    max-block-size: 30dvh;
    overflow-y: auto;
  }
  .chatPanel #bp:has(build-list[empty]) { display: none; }
  #say {
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding-block: var(--space-3) var(--space-4);
    padding-inline: var(--space-5);
  }
  #say .input { flex: 1; min-inline-size: 8ch; min-block-size: 52px; border-radius: var(--wobble-a); font-size: var(--step-0); }
  @container (max-width: 360px) {
    #say { gap: var(--space-1); padding-inline: var(--space-3); }
    .chatHead, .chatPanel #log, .optsRow { padding-inline: var(--space-3); }
    .chatPanel #bp { margin-inline: var(--space-2); }
  }
  .sea-frame {
    --frame-pad: 14px;
    position: relative;
    flex: 1;
    min-block-size: 0;
    display: flex;
    padding: var(--frame-pad);
    background: var(--sea-deep);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-a);
  }
  /* The frame stands on the sea, so its ring is sun, not teal. */
  .sea-frame :focus-visible { outline-color: var(--sun); }
  #preview iframe {
    flex: 1;
    inline-size: 100%;
    block-size: 100%;
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-b);
    background: var(--paper);
  }
  /* The making layer covers the empty app while the first version
     builds: a big Sandy builds, with the two lines under it. */
  .making {
    position: absolute;
    inset: var(--frame-pad);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-4);
    text-align: center;
    background: var(--sand);
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-b);
  }
  .making[hidden] { display: none; }
  /* The full drawing, not the crop: the building mood holds its bucket
     beside the tower. */
  .making sandy-face { inline-size: clamp(140px, 22vw, 220px); }
  .makingTitle { margin: var(--space-2) 0 0; font-family: var(--font-hand); font-size: var(--step-3); }
  .makingNote { margin: 0; color: var(--ink-soft); font-size: var(--step-1); }

  /* A narrow desktop: the header gives its room to the title. */
  @media (max-width: 1000px) {
    .bar .brand { display: none; }
  }

  /* The builder on a phone: the app first, Sandy as a sheet below it.
     The DOM keeps the chat before the preview, so the keyboard reaches
     the chat first on a phone too. The chat is where the kid works, and
     a second copy of the markup for the phone order would double every
     id. */
  @media (max-width: 700px) {
    body[data-screen="builder"] main {
      grid-template-columns: minmax(0, 1fr);
      grid-template-rows: auto minmax(0, 1fr) auto;
      grid-template-areas: "head" "app" "chat";
      gap: var(--space-2);
      padding: 0;
    }
    .bar { padding-block: var(--space-3) var(--space-1); padding-inline: var(--space-3); gap: var(--space-2); }
    .bar .brand { display: none; }
    .bar .btn:has(.vh-phone) { padding-inline: 0; inline-size: var(--tap); }
    .bar .actions { gap: var(--space-2); }
    #newBtn { display: none; }
    /* Undo is an outlined icon on a phone; Share keeps the color. */
    #undoBtn { border-color: var(--ink); background: var(--paper); }
    #undoBtn::before, #undoBtn::after { display: none; }
    #pTitle { font-size: var(--step-1); }
    body[data-screen="builder"] #preview { padding-inline: var(--space-3); }
    .sea-frame { --frame-pad: var(--space-2); }
    #viewAs {
      position: absolute;
      inset-block-start: var(--space-4);
      inset-inline-end: calc(var(--space-3) + var(--space-4));
      z-index: 2;
      gap: 0;
      border: var(--stroke-thin) solid var(--ink);
      border-radius: var(--wobble-b);
      background: var(--paper);
      overflow: hidden;
    }
    #viewAs .btn { border: 0; border-radius: 0; min-block-size: 40px; padding-inline: 0; inline-size: var(--tap); }
    #viewAs .btn + .btn { border-inline-start: var(--stroke-thin) solid var(--ink); }
    #viewAs .btn::before { inset: 0; rotate: none; }
    #viewAs .btn::after { display: none; }
    /* The group clips its corners, so the ring draws inside. */
    #viewAs .btn:focus-visible { outline-offset: -5px; }
    .chatPanel {
      border-inline: 0;
      border-block-end: 0;
      border-start-start-radius: 26px 20px;
      border-start-end-radius: 30px 24px;
      border-end-start-radius: 0;
      border-end-end-radius: 0;
      max-block-size: 58dvh;
      padding-block-start: var(--space-2);
    }
    .chatPanel::before {
      content: "";
      flex: none;
      align-self: center;
      inline-size: 44px;
      block-size: 5px;
      border-radius: 3px;
      background: var(--handle);
    }
    /* The sheet has no name row: a small Sandy at the start, and the
       sound toggle at the end. */
    .chatHead { padding-block: var(--space-1) 0; padding-inline: var(--space-4); }
    .chatHead sandy-face { inline-size: 34px; }
    /* Only the log and the open build list give up height, so the talk
       bar always stays whole on the screen. */
    .chatPanel #log { min-block-size: 0; max-block-size: 24dvh; padding-inline: var(--space-4); }
    .optsRow {
      flex-wrap: nowrap;
      overflow-x: auto;
      overscroll-behavior-inline: contain;
      padding-inline: var(--space-4);
      scrollbar-width: none;
    }
    .optsRow button { white-space: nowrap; flex: none; }
    .chatPanel #bp { flex: 0 1 auto; min-block-size: var(--tap); margin-inline: var(--space-3); max-block-size: 34dvh; padding-block-start: 0; }
    .bpBox > summary {
      display: flex;
      align-items: center;
      gap: var(--space-3);
      min-block-size: var(--tap);
      padding-inline: var(--space-1);
      cursor: pointer;
      list-style: none;
    }
    .bpBox > summary::-webkit-details-marker { display: none; }
    .bpBox > summary .bpHead { margin: 0; font-size: var(--step-0); }
    .bpHead.wide { display: none; }
    .bpDots { flex: 1; display: flex; gap: 5px; min-inline-size: 0; overflow: hidden; }
    .bpChevron { inline-size: 16px; block-size: 16px; transition: rotate 0.15s; }
    .bpBox[open] .bpChevron { rotate: 180deg; }
    #say { gap: 6px; padding-inline: var(--space-3); padding-block-end: max(var(--space-4), env(safe-area-inset-bottom)); }
    #say .input { padding-inline: var(--space-3); }

    /* My stuff on a phone: two columns and a pinned "Something new". */
    .projects { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4) var(--space-3); }
    .projects .newItem { display: none; }
    .newBar {
      display: block;
      position: sticky;
      inset-block-end: 0;
      margin-inline: calc(-1 * var(--gutter));
      padding-block: var(--space-4) max(var(--space-5), env(safe-area-inset-bottom));
      padding-inline: var(--gutter);
      background: var(--sand);
      border-block-start: var(--stroke-thin) dashed var(--dash);
    }
    .page:has(.newBar) { padding-block-end: 0; min-block-size: 100dvh; }
    .newBar { margin-block-start: auto; }

    /* The homepage on a phone: the headline beside a small Sandy. */
    .hero {
      grid-template-columns: minmax(0, 1fr) auto;
      grid-template-areas: "title sandy" "form form";
      gap: var(--space-6) var(--space-2);
      padding-block-start: var(--space-4);
      align-items: end;
    }
    .heroWords { display: contents; }
    .hero h1 { grid-area: title; font-size: clamp(2rem, 9vw, 2.5rem); }
    .hero h1 span { display: inline; }
    .heroSandy { inline-size: 92px; }
    .signin { grid-area: form; max-inline-size: none; }
    .sendRow .input, .sendRow .btn { flex: 1 1 100%; }
    .how { padding-block-start: var(--space-4); gap: var(--space-3); }
    .steps { gap: var(--space-3); }
    .step { background: none; border: 0; padding: 0; flex-direction: row; align-items: center; gap: var(--space-3); }
    .step .num { inline-size: 36px; block-size: 36px; margin: 0; font-size: var(--step-0); }
    .step .words { gap: 0; }
    .step .title { font-family: var(--font-body); font-weight: 800; font-size: var(--step-0); }
    .step .sub { font-size: var(--step--1); }

    /* The plan picker on a phone (Funnel-PlansPhone): the timeline
       stacks, with each dot beside its words. */
    .funnel h1 { font-size: clamp(2rem, 9vw, 2.5rem); }
    .planPick { gap: var(--space-3); }
    .planOpt { padding: var(--space-4); }
    .timeline { flex-direction: column; gap: var(--space-3); padding: var(--space-4); }
    .timeline li { display: grid; grid-template-columns: auto 1fr; column-gap: var(--space-3); align-items: center; }
    .timeline li::before { grid-row: 1 / span 2; margin: 0; }
    .funnelGo .btn { inline-size: 100%; }
  }

  /* A short screen: a phone on its side, or a big zoom. The page
     scrolls, the app keeps most of the height, and the chat takes its
     natural height under it. */
  @media (max-height: 500px) {
    body[data-screen="builder"] { block-size: auto; overflow: visible; }
    body[data-screen="builder"] main {
      block-size: auto;
      grid-template-columns: minmax(0, 1fr);
      grid-template-rows: auto auto auto;
      grid-template-areas: "head" "app" "chat";
      gap: var(--space-2);
      padding: 0;
    }
    .bar { padding-block: var(--space-2) 0; padding-inline: var(--space-3); }
    body[data-screen="builder"] #preview { padding-inline: var(--space-3); }
    /* The floor is on the frame, so the view toggle above it takes no
       height from the app. */
    .sea-frame { min-block-size: 70dvh; }
    .chatPanel { max-block-size: none; }
    .chatPanel #log { max-block-size: 60dvh; }
    .chatPanel #bp { max-block-size: none; }
  }

  /* The parent dashboard (PARENT.md). */
  body.parent #preview { display: none; }
  body.parent #chat { display: block; }
  body.parent #pane {
    max-inline-size: 760px;
    margin-inline: auto;
    padding-block: var(--space-6) var(--space-9);
    padding-inline: var(--gutter);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }
  body.parent #pane h2 { font-size: var(--step-4); margin-block-end: var(--space-3); }
  body.parent #pane h3 { font-size: var(--step-2); }
  .flagBanner {
    border: var(--stroke) solid var(--error);
    border-radius: var(--wobble-a);
    background: var(--paper);
    padding-block: var(--space-4);
    padding-inline: var(--space-5);
  }
  .flagBanner b { display: block; margin-block-end: var(--space-1); }
  .flagBanner p { margin-block: var(--space-2); }
  .quotePair {
    background: var(--paper);
    border: var(--stroke-thin) solid var(--ink);
    border-radius: var(--wobble-b);
    padding-block: var(--space-4);
    padding-inline: var(--space-5);
    margin-block: var(--space-3);
  }
  .quotePair .q { font-style: italic; }
  .quotePair .when { color: var(--ink-soft); font-size: var(--step--1); font-style: normal; }
  .quotePair .later { margin-block-start: var(--space-2); }
  .pProj {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-3);
    padding-block: var(--space-3);
    border-block-end: var(--stroke-thin) dashed var(--dash);
  }
  .pProj .t { flex: 1; min-inline-size: 140px; font-weight: 700; overflow-wrap: anywhere; }
  .plink {
    min-block-size: var(--tap);
    display: inline-flex;
    align-items: center;
    color: var(--link);
    text-decoration: underline;
    font-size: var(--step-0);
    font-weight: 600;
  }
  .plink:hover { color: var(--link-hover); }
  .plink.danger { color: var(--error); }
  .psection { margin-block: var(--space-5); }
  .pLang { max-inline-size: 22rem; margin-block: var(--space-3); }
  /* The Plan section (BILLING.md §4). */
  .planBanner {
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-a);
    background: var(--sun);
    padding-block: var(--space-3);
    padding-inline: var(--space-5);
  }
  .planBanner p { margin-block: var(--space-1); }
  .planCards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-4);
    margin-block: var(--space-4);
  }
  .planCard {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    background: var(--paper);
    border: var(--stroke-thin) solid var(--ink);
    border-radius: var(--wobble-b);
    padding: var(--space-4);
  }
  .planCard h4 { font-size: var(--step-1); }
  .planCard .price { font-weight: 800; }
  .planCard .btn { margin-block-start: auto; }
  .parentFrame {
    inline-size: 100%;
    block-size: 70dvh;
    border: var(--stroke) solid var(--ink);
    border-radius: var(--wobble-a);
    background: var(--paper);
  }
  #tLines { display: flex; flex-direction: column; gap: var(--space-2); }
  #tLines .msg { align-self: stretch; max-inline-size: none; }

  /* Forced colors: the spill is a background, and the system paints it
     away. A checked pill and a pressed toggle draw a thick outline
     instead, so the choice still shows. */
  @media (forced-colors: active) {
    .seg input:checked + .pill,
    #viewAs [aria-pressed="true"] {
      outline: 3px solid Highlight;
      outline-offset: 2px;
    }
    .fill::after { border-color: CanvasText; }
  }
}

/* ---------- utilities ---------- */
@layer utilities {
  /* Hidden on the screen, read by a screen reader. */
  .vh {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
  /* The same, on a phone only: the words of an icon button that shows
     its words on a desktop. */
  @media (max-width: 700px) {
    .vh-phone {
      position: absolute;
      inline-size: 1px;
      block-size: 1px;
      margin: -1px;
      padding: 0;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
      border: 0;
    }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}
