/* Layout: one centred card per step; the call is equal tiles (Alex, the other kids, you) over a question board. */
:root {
  --bg: #f3f1fa;
  --surface: #ffffff;
  --ink: #23213a;
  --muted: #6b6886;
  --accent: #5b4bd6;
  --accent-ink: #ffffff;
  --go: #23a26d;
  --stop: #d64b5b;
  --warn: #e0a423;
  --line: #dcd8ee;
  --tile: #2b2846;
  --alex: #ea580c;
  --alex-dark: #c2410c;
  --alex-face: #fff1e6;
  --alex-eye: #ffffff;
  --alex-pupil: #23213a;
  --alex-cheek: #fdba74;
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17152a; --surface: #221f3a; --ink: #f1effa; --muted: #a6a2c4; --accent: #8b7dff; --accent-ink: #17152a;
    --line: #36325a; --tile: #2e2a4f; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17152a; --surface: #221f3a; --ink: #f1effa; --muted: #a6a2c4; --accent: #8b7dff; --accent-ink: #17152a;
  --line: #36325a; --tile: #2e2a4f; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 17px; line-height: 1.45;
  padding: env(safe-area-inset-top, 0) max(16px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0)
    max(16px, env(safe-area-inset-left, 0px));
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#app { min-height: 100%; display: grid; place-items: center; padding-block: 24px; }

.card {
  width: min(460px, 100%); background: var(--surface); border-radius: var(--radius); padding: 28px;
  display: grid; gap: 16px; box-shadow: 0 8px 30px rgb(35 33 58 / 0.08);
}
h1 { margin: 0; font-size: 1.6rem; text-wrap: balance; }
.lead { margin: 0; color: var(--muted); }
.hint { margin: 0; color: var(--muted); font-size: 0.9rem; }
.error { margin: 0; color: var(--stop); font-weight: 600; }

form { display: grid; gap: 12px; }
input {
  font: inherit; font-size: 1.15rem; padding: 14px 16px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg); color: var(--ink); width: 100%;
}
.primary {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 14px 20px;
  font-weight: 700; font-size: 1.05rem;
}
.primary:disabled { opacity: 0.45; cursor: default; }
.primary.big { font-size: 1.25rem; padding: 18px 24px; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 4px; }

.who { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.who button {
  border: 2px solid var(--line); background: var(--bg); color: var(--ink); border-radius: var(--radius);
  padding: 28px 12px; font-size: 1.4rem; font-weight: 700;
}
.who button:hover { border-color: var(--accent); }

.eyebrow { margin: 0 0 4px; color: var(--accent); font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }
.card h2 { margin: 0 0 10px; font-size: 1.1rem; }
.invite-head { display: grid; gap: 4px; }
.prep { background: var(--bg); border-radius: 14px; padding: 16px; display: grid; gap: 10px; }
.prep h2 { margin: 0; }
.prep-text p { margin: 0 0 8px; white-space: pre-line; overflow-wrap: anywhere; }
.prep-text p:last-child { margin-bottom: 0; }
.prep-text a { color: var(--accent); }
.prep-done { display: grid; gap: 6px; }
.ticks { display: flex; flex-wrap: wrap; gap: 8px; }
.ticks button { border: 2px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 6px 16px; font-weight: 700; }
.ticks button[aria-pressed="true"] { border-color: var(--go); background: var(--go); color: #fff; }
.ticks button:disabled { cursor: default; opacity: 0.8; }
.confirm { display: grid; gap: 10px; padding: 16px; border-radius: 14px; border: 2px solid var(--accent); }
.confirm p { margin: 0; }
.preview { position: relative; aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden; background: var(--tile); }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-off { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; }
.meter { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
#meter-fill { height: 100%; width: 0; background: var(--go); transition: width 80ms linear; }

/* Call */
.call { width: min(1200px, 100%); display: grid; gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 14px; position: relative; }
.tile {
  margin: 0; position: relative; background: var(--tile); border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 4 / 3; outline: 4px solid transparent; transition: outline-color 120ms;
}
.tile.speaking { outline-color: var(--go); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.me video { transform: scaleX(-1); }
.tile figcaption {
  position: absolute; left: 10px; bottom: 10px; background: rgb(0 0 0 / 0.55); color: #fff; border-radius: 10px;
  padding: 4px 10px; font-weight: 700; display: flex; gap: 8px; align-items: center;
}
.tag { font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.8; }
.placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #d9d6f0; text-align: center; padding: 16px; }
.tile-status { position: absolute; top: 10px; left: 0; right: 0; text-align: center; margin: 0; color: #d9d6f0; font-size: 0.9rem; }

.tile.alex { display: grid; place-items: center; background: linear-gradient(180deg, #3b3570, var(--tile)); }
.alex-art { width: auto; height: 72%; margin-bottom: 14px; transition: transform 200ms; }
.alex[data-state="joining"] .alex-art { opacity: 0.45; }
.alex-body { fill: var(--alex); }
.alex-face { fill: var(--alex-face); }
.alex-ear { fill: var(--alex-dark); }
.alex-stalk { stroke: var(--alex-dark); stroke-width: 5; stroke-linecap: round; }
.alex-bulb { fill: var(--alex-cheek); }
.alex-eye { fill: var(--alex-eye); stroke: var(--alex-pupil); stroke-width: 2; }
.alex-pupil { fill: var(--alex-pupil); transition: cx 300ms, cy 300ms; }
.alex-cheek { fill: var(--alex-cheek); }
.alex-mouth { fill: var(--alex-pupil); transform-origin: 100px 124px; }
.alex-mark { fill: var(--alex-dark); font: 700 15px var(--font); letter-spacing: 2px; }
/* Alex raises a hand before interrupting (like a raised hand on a video call) */
.alex-arm { fill: var(--alex-dark); transform-origin: 160px 124px; transform: rotate(60deg) scale(0.6); opacity: 0;
  transition: transform 250ms ease-out, opacity 150ms; }
.alex.hand .alex-arm { transform: none; opacity: 1; }

.board {
  background: var(--surface); border-radius: var(--radius); padding: 16px 20px; display: grid;
  grid-template-columns: 1fr auto; align-items: baseline; gap: 4px 16px;
}
.board-label { margin: 0; grid-column: 1 / -1; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }
.board-question { margin: 0; font-size: 1.35rem; font-weight: 700; text-wrap: balance; }
.board-clock { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.board-views { margin: 0; grid-column: 1 / -1; color: var(--ink); display: flex; gap: 6px 18px; flex-wrap: wrap; }
.board-views b { color: var(--accent); }
.asking { grid-column: 1 / -1; margin-top: 8px; padding: 10px 14px; border-left: 5px solid var(--accent);
  background: var(--bg); border-radius: 10px; }
.asking-to { margin: 0; color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.asking-text { margin: 2px 0 0; font-size: 1.15rem; font-weight: 600; text-wrap: pretty; }
.story { grid-column: 1 / -1; margin-top: 6px; }
.story summary { cursor: pointer; font-weight: 700; color: var(--accent); padding: 4px 0; }
.story-text { margin: 4px 0 0; max-width: 70ch; line-height: 1.45; }
.story-label { margin: 10px 0 2px; color: var(--muted); font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.08em; }
.case-list { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; }

.bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hears { margin: 0 auto 0 0; color: var(--muted); }
.hears.ok { color: var(--go); font-weight: 700; }
.pill { border: 2px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 8px 18px; font-weight: 700; }
.pill.on { background: var(--stop); border-color: var(--stop); color: #fff; }
.pill.danger { color: var(--stop); }
.pill.help { border-color: var(--warn); color: var(--ink); }
.notice { margin: 0; padding: 12px 16px; border-radius: 12px; background: var(--surface); border: 2px solid var(--line);
  font-weight: 700; }
.notice[data-level="info"] { border-color: var(--go); }
.notice[data-level="warn"] { border-color: var(--warn); }
.notice[data-level="urgent"] { border-color: var(--stop); background: var(--stop); color: #fff; font-size: 1.2rem; }

.overlay { position: fixed; inset: 0; background: rgb(23 21 42 / 0.6); display: grid; place-items: center; z-index: 20; }
.banner {
  position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 700; z-index: 30;
}

@media (max-width: 760px) {
  /* Phone: Alex and the friend stacked full width; your own picture sits in the friend's corner */
  .tiles { grid-template-columns: 1fr; gap: 10px; }
  .tile { aspect-ratio: 16 / 10; }
  .tile.me { position: absolute; right: 8px; bottom: 8px; width: 32%; aspect-ratio: 4 / 3; z-index: 5;
    box-shadow: 0 6px 20px rgb(0 0 0 / 0.35); border-radius: 12px; }
  .tile.me figcaption { display: none; }
  /* Three or four kids: Alex across the top, the kids (you too) two to a row underneath */
  .tiles.group { grid-template-columns: 1fr 1fr; }
  .tiles.group .tile.alex { grid-column: 1 / -1; }
  .tiles.group .tile.kid { aspect-ratio: 4 / 3; }
  .tiles.group .tile.me { position: relative; right: auto; bottom: auto; width: auto; box-shadow: none;
    border-radius: var(--radius); }
  .tiles.group .tile.me figcaption { display: flex; }
  .alex-art { height: 80%; }
  .board { grid-template-columns: 1fr; }
  .hears { flex-basis: 100%; }
  /* Help, Mute and Leave stay on screen however long the board gets (the story makes it tall) */
  .bar { position: sticky; bottom: 0; z-index: 6; background: var(--bg);
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* The shared whiteboard and the problem card (board.js) */
.work { display: grid; gap: 10px; }
.problem { background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; padding: 12px 16px; }
.problem-label { margin: 0 0 4px; font-size: 0.85rem; color: #92400e; font-weight: 600; }
.problem-text { margin: 0; overflow-x: auto; font-size: 1.15rem; line-height: 1.45; white-space: pre-wrap; }
.problem-text .katex-display { margin: 0.5em 0; }
.asking-text .katex-display { margin: 0.4em 0; }
.problem-fig { display: block; max-width: 100%; max-height: 260px; margin-top: 10px; }
.wb-wrap { position: relative; }
.wb { display: block; width: 100%; aspect-ratio: 16 / 10; background: #fff; border: 1px solid #d1d5db;
      border-radius: 12px; cursor: crosshair; }
.wb[data-tool="text"] { cursor: text; }
.wb[data-tool="erase"] { cursor: cell; }
.wb-tools { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; }
.wb-tools .pill.on { background: #111827; color: #fff; }
.wb-input { position: absolute; transform: translateY(-4px); font: 1rem system-ui, sans-serif; padding: 2px 6px;
            border: 1px solid #9ca3af; border-radius: 6px; min-width: 8em; }

/* Math layout, wider than a phone: the board is the main area; the faces and Alex's notes sit in a column beside it */
@media (min-width: 761px) {
  .call { width: min(1440px, 100%); grid-template-columns: minmax(0, 1fr) 240px; align-items: start;
          grid-template-areas: "work tiles" "work board" "notice notice" "bar bar"; grid-template-rows: auto 1fr; }
  .work { grid-area: work; }
  .tiles { grid-area: tiles; grid-template-columns: 1fr !important; gap: 10px; }
  .tile { aspect-ratio: 16 / 10; }
  .call > .board { grid-area: board; grid-template-columns: 1fr; padding: 12px 14px; }
  .board-question { font-size: 1.05rem; }
  .notice { grid-area: notice; }
  .bar { grid-area: bar; }
  .wb { width: min(100%, calc((100vh - 150px) * 1.6)); }
}
@media (min-width: 761px) {
  /* With a problem card above it, the board shrinks so Help, Mute and Leave stay on screen */
  .work:has(.problem:not([hidden])) .wb { width: min(100%, calc((100vh - 360px) * 1.6)); }
}

/* Board tools: a column beside the board, finger-sized (iPad); colours for the counter tool under it */
.wb-wrap { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 8px; align-items: start;
           -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.wb-wrap .wb { grid-column: 2; }
.wb-tools { position: static; display: flex; flex-direction: column; gap: 4px; }
.tool { display: grid; justify-items: center; gap: 1px; width: 64px; padding: 6px 0 4px; border: 2px solid var(--line);
        border-radius: 12px; background: var(--surface); color: var(--ink); font: 600 0.68rem system-ui, sans-serif;
        touch-action: manipulation; }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
            stroke-linejoin: round; }
.tool svg .solid { fill: currentColor; }
.tool.on { background: #111827; border-color: #111827; color: #fff; }
.wb-fills { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 2px 4px; }
.wb-fills[hidden] { display: none; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #9ca3af; background: var(--swatch);
          touch-action: manipulation; }
.swatch.on { outline: 3px solid #111827; outline-offset: 1px; }
@media (max-width: 760px) {
  .wb-wrap { grid-template-columns: 1fr; }
  .wb-wrap .wb { grid-column: 1; }
  .wb-tools { flex-direction: row; flex-wrap: wrap; }
  .tool { width: 52px; }
}
@media (min-width: 761px) {
  .wb { width: min(100%, calc((100vh - 150px) * 1.6)); }
  .work:has(.problem:not([hidden])) .wb { width: min(100%, calc((100vh - 360px) * 1.6)); }
}
.swatch[data-fill="red"] { background: #dc2626; }
.swatch[data-fill="blue"] { background: #2563eb; }
.swatch[data-fill="green"] { background: #16a34a; }
.swatch[data-fill="yellow"] { background: #facc15; }
.swatch[data-fill="black"] { background: #111827; }
.swatch[data-fill="white"] { background: #ffffff; }
/* iPad in portrait: the faces in a row on top, the board full width under them */
@media (min-width: 761px) and (orientation: portrait) {
  .call { grid-template-columns: minmax(0, 1fr); grid-template-rows: none;
          grid-template-areas: "tiles" "work" "board" "notice" "bar"; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important; }
  .tile { aspect-ratio: 4 / 3; }
  .call > .board { padding: 8px 14px; }
  .wb, .work:has(.problem:not([hidden])) .wb { width: 100%; }
}
