@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* The Room — the room itself: top bar, wall, desk, tiles, books. */

:root {
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: #d2d2d7;
  --soft-line: rgba(0, 0, 0, 0.08);
  --surface: #ffffff;
  --alt: #f5f5f7;
  --blue: #005EA2;
  --blue-dark: #004785;
  --blue-soft: rgba(0, 94, 162, 0.08);

  /* the room's own palette: lamplight on paper */
  --wall: #f3eee6;
  --paper: #fbf8f2;
  --paper-edge: #e6dccb;
  --glyph-ink: #2b2723;
  --warm-muted: #6b5d4b;
  --amber: #8a4b00;
  --amber-mid: #d38a1f;
  --amber-glow: #ffd68a;
  --amber-soft: rgba(211, 138, 31, 0.12);

  --radius: 16px;
  --radius-sm: 12px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.27 0 0 0 0 0.15 0 0 0 0.05 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- App frame ---------- */
.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: grid;
  /* An explicit column: an implicit one sizes to the top bar's min-content
     width and pushes the whole room past the edge of narrow frames. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 40px; padding: 0 1.05rem;
  border-radius: 999px; border: 1px solid transparent;
  font-size: 0.9rem; font-weight: 600; letter-spacing: -0.01em;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.btn--primary { background: var(--blue); color: #fff; }
.btn--primary:hover { background: var(--blue-dark); }
.btn--primary:disabled { background: #c9c9ce; color: #fff; cursor: not-allowed; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { background: var(--alt); }
.btn--ghost:disabled { color: var(--faint); cursor: not-allowed; background: transparent; }
.btn--sm { min-height: 34px; padding: 0 0.8rem; font-size: 0.84rem; }
.btn--link { background: none; border: 0; color: var(--blue); padding: 0 0.2rem; min-height: 32px; }
.btn--link:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.25rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--soft-line);
  background: var(--surface);
  z-index: 3;
}
.topbar-lead { min-width: 0; }
.topbar-eyebrow {
  margin: 0; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--blue);
}
.topbar-title { margin: 0; font-size: 1.2rem; font-weight: 700; letter-spacing: -0.025em; line-height: 1.2; }
.topbar-actions { display: flex; gap: 0.5rem; margin-left: auto; }
.topbar-actions .btn { min-height: 36px; font-size: 0.85rem; }

.stages { display: flex; gap: 0.3rem; list-style: none; margin: 0 auto; padding: 0; }
.stage-pill {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.7rem 0.3rem 0.35rem;
  border-radius: 999px; font-size: 0.8rem; font-weight: 500; color: var(--muted);
}
.stage-num {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line); font-size: 0.72rem; font-weight: 600;
}
.stage-pill.is-current { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.stage-pill.is-current .stage-num { background: var(--blue); border-color: var(--blue); color: #fff; }
.stage-pill.is-done .stage-num { background: var(--alt); border-color: var(--line); color: var(--ink); }

/* ---------- The room ---------- */
.room[hidden] { display: none; }
.room {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  min-height: 0;
  position: relative;
}
.scene {
  position: relative;
  display: flex; flex-direction: column;
  min-height: 0; overflow-y: auto;
  background: var(--paper) var(--grain);
}
.wall {
  flex: none;
  height: clamp(120px, 24vh, 270px);
  background: linear-gradient(180deg, #f5f1ea 0%, var(--wall) 100%);
  border-bottom: 1px solid var(--paper-edge);
  box-shadow: inset 0 -10px 18px -14px rgba(90, 60, 20, 0.25);
  overflow: hidden;
}
.wall-art { display: block; width: 100%; height: 100%; margin-left: clamp(0px, 8vw, 140px); }
.lamp-glow { animation: lamp 6s ease-in-out infinite; transform-origin: 92px 120px; }
@keyframes lamp { 0%, 100% { opacity: 1; } 50% { opacity: 0.82; } }
.door.is-knocking { animation: knock 0.42s var(--ease) 2; transform-origin: 300px 144px; }
@keyframes knock { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
.door-slot-light { opacity: 0.55; transition: opacity 0.3s ease; }
.app[data-slot="open"] .door-slot-light { opacity: 1; }

/* ---------- Fluency meter ---------- */
.meter {
  position: absolute; top: 12px; right: 14px; z-index: 1;
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.85rem 0.55rem 0.6rem;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 18px -12px rgba(60, 40, 10, 0.35);
}
.meter-dial { width: 84px; height: 49px; flex: none; }
.meter-arc { stroke: var(--amber-mid); transition: stroke-dasharray 0.6s var(--ease); }
.meter-needle {
  transform-box: view-box; transform-origin: 60px 62px;
  transform: rotate(-90deg);
  transition: transform 0.7s cubic-bezier(0.3, 1.5, 0.4, 1);
}
.meter-read { display: grid; line-height: 1.15; }
.meter-label { font-size: 0.66rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--warm-muted); }
.meter-value { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.meter-verdict { font-size: 0.78rem; color: var(--warm-muted); }
.meter.is-loved { border-color: var(--amber-mid); box-shadow: 0 0 0 4px var(--amber-soft), 0 6px 18px -12px rgba(60, 40, 10, 0.35); }

/* ---------- Desk ---------- */
.desk {
  flex: 1 0 auto;
  display: flex; flex-direction: column; gap: 0.9rem;
  padding: 1rem clamp(1rem, 2.6vw, 2rem) 1.25rem;
}
.narration {
  margin: 0; max-width: 62ch; min-height: 2.8em;
  font-size: 0.98rem; line-height: 1.5; color: var(--warm-muted);
}
.narration strong { color: var(--glyph-ink); font-weight: 600; }

.note-area { display: grid; gap: 0.5rem; }
.note {
  position: relative;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  min-height: 82px;
  padding: 0.9rem 1.2rem;
  background: #fffdf8 var(--grain);
  border: 1px solid var(--paper-edge);
  border-radius: 10px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 12px 24px -18px rgba(70, 45, 10, 0.45);
  transform: rotate(-0.4deg);
  color: var(--glyph-ink);
}
.note.is-arriving { animation: slide-under 0.42s var(--ease) both; }
@keyframes slide-under {
  from { opacity: 0; transform: translateY(-34px) rotate(-2deg) scaleY(0.7); }
  to { opacity: 1; transform: translateY(0) rotate(-0.4deg) scaleY(1); }
}
.note-meta { display: grid; gap: 0.1rem; min-width: 5.5rem; }
.note-kicker { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--amber); }
.note-count { font-size: 0.8rem; color: var(--warm-muted); }
.glyph-row { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0; padding: 0; list-style: none; }
.glyph-row li { display: grid; place-items: center; }
.note .glyph { width: 44px; height: 44px; }
.note-empty { color: var(--warm-muted); font-size: 0.92rem; }

/* clock */
.clock[hidden] { display: none; }
.clock { display: flex; align-items: center; gap: 0.7rem; font-size: 0.8rem; color: var(--warm-muted); }
.clock-bar { flex: 1; height: 4px; border-radius: 4px; background: #e8dfcf; overflow: hidden; max-width: 320px; }
.clock-fill { display: block; height: 100%; width: 100%; background: var(--amber-mid); transform-origin: left; transition: transform 0.25s linear; }
.clock.is-late .clock-fill { background: #b84a1a; }
.clock.is-off .clock-bar { opacity: 0.4; }
.clock-text { font-variant-numeric: tabular-nums; min-width: 9.5em; }
.clock-toggle {
  border: 0; background: none; padding: 0.3rem 0.2rem; cursor: pointer;
  color: var(--blue); font-size: 0.8rem; font-weight: 600;
}
.clock-toggle:hover { text-decoration: underline; }

/* composer */
.composer { display: grid; gap: 0.75rem; margin-top: auto; }
.reply {
  display: flex; align-items: center; gap: 0.9rem;
  min-height: 74px; padding: 0.6rem 1rem;
  border: 1.5px dashed #d6c9b3;
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.7);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.35s var(--ease), opacity 0.35s ease;
}
.reply.is-target { border-color: var(--amber-mid); background: var(--amber-soft); }
.reply.is-sending { transform: translateY(-46px) scaleY(0.6); opacity: 0; }
.reply-label { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--warm-muted); flex: none; }
.reply-shapes { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0; padding: 0; list-style: none; min-height: 44px; align-items: center; }
.reply-shapes .placeholder { font-size: 0.88rem; color: var(--warm-muted); }
.placed {
  display: grid; place-items: center;
  width: 46px; height: 46px; padding: 0;
  border: 0; border-radius: 10px; background: transparent; color: var(--glyph-ink); cursor: pointer;
  animation: stamp 0.18s var(--ease) both;
}
.placed:hover { background: rgba(0, 0, 0, 0.04); }
.placed .glyph { width: 40px; height: 40px; }
@keyframes stamp { from { transform: scale(0.55); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.composer-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.composer-actions .btn--primary { margin-left: auto; }

.tray {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 66px));
  justify-content: start;
  width: max-content;
  max-width: 100%;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ece4d6, #e6dccb);
  box-shadow: inset 0 2px 6px rgba(80, 55, 20, 0.16);
}
.tile {
  display: grid; place-items: center;
  aspect-ratio: 1;
  min-height: 44px;
  padding: 0;
  border: 1px solid #ddd1bd;
  border-radius: 11px;
  background: linear-gradient(180deg, #fffefb 0%, #f5efe4 100%);
  box-shadow: 0 1px 0 #fff inset, 0 -2px 0 rgba(120, 90, 40, 0.13) inset, 0 2px 3px rgba(60, 40, 10, 0.12);
  color: var(--glyph-ink);
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.tile .glyph { width: 70%; height: 70%; max-width: 40px; max-height: 40px; pointer-events: none; }
.tile:hover { transform: translateY(-1px); }
.tile:active { transform: translateY(1px); box-shadow: 0 1px 0 #fff inset, 0 1px 2px rgba(60, 40, 10, 0.12); }
.tile[aria-disabled="true"] { cursor: default; opacity: 0.6; }
.tile[aria-disabled="true"]:hover, .tile[aria-disabled="true"]:active { transform: none; }
.tile.is-hint { border-color: var(--amber-mid); box-shadow: 0 0 0 3px var(--amber-soft), 0 2px 3px rgba(60, 40, 10, 0.12); }
.tile-ghost {
  position: fixed; z-index: 40; pointer-events: none;
  width: 56px; height: 56px; margin: -28px 0 0 -28px;
  display: grid; place-items: center;
  border-radius: 12px; background: #fffefb; border: 1px solid #ddd1bd;
  box-shadow: 0 14px 26px -10px rgba(60, 40, 10, 0.45);
  color: var(--glyph-ink); transform: rotate(-4deg);
}
.tile-ghost .glyph { width: 40px; height: 40px; }

/* ---------- Books ---------- */
.books {
  display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--soft-line);
  background: var(--surface);
}
.book-tabs {
  display: flex; gap: 0.25rem; margin: 0.9rem 1rem 0; padding: 0.25rem;
  border-radius: 999px; background: var(--alt);
}
.book-tab {
  flex: 1; min-height: 34px; border: 0; border-radius: 999px; background: transparent;
  font-size: 0.85rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.book-tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
.book-tab:disabled { cursor: not-allowed; color: var(--faint); }
.book-tab .tab-lock { font-weight: 500; font-size: 0.72rem; }
.book-panel { flex: 1; min-height: 0; overflow-y: auto; padding: 1rem 1rem 1.5rem; }

.book-head { margin: 0 0 0.8rem; }
.book-title { margin: 0; font-size: 1rem; font-weight: 600; letter-spacing: -0.015em; }
.book-sub { margin: 0.2rem 0 0; font-size: 0.82rem; line-height: 1.45; color: var(--muted); }

.thumbs { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0 0 0.8rem; }
.thumb {
  display: grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--glyph-ink); cursor: pointer;
}
.thumb .glyph { width: 26px; height: 26px; }
.thumb[aria-pressed="true"] { background: var(--blue-soft); border-color: var(--blue); }
.thumb:hover { background: var(--alt); }

.rules { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--soft-line); }
.rule {
  display: grid; grid-template-columns: 1.6rem minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center; gap: 0.45rem;
  padding: 0.5rem 0.3rem;
  border-bottom: 1px solid var(--soft-line);
  color: var(--glyph-ink);
}
.rule-num { font-size: 0.68rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.rule-arrow { font-size: 0.8rem; color: var(--muted); }
.rule .glyph-row { gap: 0.1rem; }
.rule .glyph { width: 26px; height: 26px; }
.rule-out { padding: 0.15rem 0.3rem; border-radius: 8px; background: var(--alt); }
.rules-empty { font-size: 0.86rem; color: var(--muted); padding: 0.8rem 0; }

/* the note being looked up, pinned above the rules */
.lookup {
  position: sticky; top: -1rem; z-index: 1;
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  margin: 0 -1rem; padding: 0.55rem 1rem;
  background: #fffdf8; border-top: 1px solid var(--paper-edge); border-bottom: 1px solid var(--paper-edge);
  color: var(--glyph-ink);
}
.lookup-label { font-size: 0.66rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--amber); }
.lookup .glyph-row { gap: 0.15rem; }
.lookup .glyph { width: 24px; height: 24px; }
.lookup + .rules { border-top: 0; }

/* ledger */
.ledger-train { display: grid; gap: 0.8rem; justify-items: start; }
.ledger-row-head { display: flex; align-items: center; gap: 0.5rem; margin: 0 0 0.6rem; font-size: 0.86rem; color: var(--muted); }
.ledger-row-head .glyph { width: 28px; height: 28px; color: var(--glyph-ink); }
.followers { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.follower {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 0.6rem;
  width: 100%; padding: 0.45rem 0.6rem;
  border: 1px solid var(--soft-line); border-radius: 12px; background: var(--surface);
  text-align: left; cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.follower:hover { border-color: var(--line); background: var(--alt); }
.follower.is-top { border-color: rgba(211, 138, 31, 0.6); background: #fffaf0; }
.follower-glyph { display: grid; place-items: center; color: var(--glyph-ink); }
.follower-glyph .glyph { width: 32px; height: 32px; }
.follower-end { font-size: 0.72rem; font-weight: 600; color: var(--warm-muted); text-align: center; line-height: 1.1; }
.follower-tally { display: grid; gap: 0.25rem; min-width: 0; }
.tally { display: block; height: 16px; color: var(--glyph-ink); }
.follower-bar { height: 3px; border-radius: 3px; background: #efe7da; overflow: hidden; }
.follower-bar span { display: block; height: 100%; background: var(--amber-mid); }
.follower-count { font-size: 0.78rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.follower-top-tag { display: block; font-size: 0.66rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--amber); }
.ledger-foot { margin: 0.9rem 0 0; font-size: 0.8rem; line-height: 1.45; color: var(--muted); }
.ledger-counting .tally { animation: tally-in 0.5s var(--ease) both; }
@keyframes tally-in { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* notes history */
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.history li {
  display: grid; gap: 0.35rem; padding: 0.7rem 0.8rem;
  border: 1px solid var(--soft-line); border-radius: 12px; color: var(--glyph-ink);
}
.history .glyph { width: 24px; height: 24px; }
.history-line { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.history-who { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); min-width: 3.2rem; }
.history-score { margin-left: auto; font-size: 0.78rem; font-weight: 600; color: var(--amber); }

/* toast */
.toast {
  position: absolute; left: 50%; bottom: 1.1rem; z-index: 30;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  padding: 0.6rem 1rem; border-radius: 999px;
  background: var(--ink); color: #fff; font-size: 0.86rem; font-weight: 500;
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.5);
  transition: opacity 0.2s ease, transform 0.2s var(--ease);
  max-width: calc(100% - 2rem); text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Wide screens: the reply slip takes up the desk's spare height ----------
 * The note, the slip and the tiles stack without a gap; on taller screens
 * the slip grows (up to a point) and its glyphs sit on a ruled line, so
 * the extra height reads as paper rather than empty desk. */
@media (min-width: 861px) {
  .composer { flex: 1 1 auto; display: flex; flex-direction: column; margin-top: 0; }
  .composer-actions, .tray { flex: none; }
  .reply {
    --rule: calc(50% + 25px);
    flex: 1 1 auto; max-height: 260px;
    background-image: linear-gradient(to bottom, transparent var(--rule), rgba(150, 115, 60, 0.18) var(--rule), rgba(150, 115, 60, 0.18) calc(var(--rule) + 1.5px), transparent calc(var(--rule) + 1.5px));
  }
}
@media (min-width: 861px) and (min-height: 860px) {
  .note .glyph { width: 52px; height: 52px; }
  .reply { --rule: calc(50% + 31px); }
  .reply-shapes { min-height: 58px; }
  .placed { width: 58px; height: 58px; }
  .placed .glyph { width: 50px; height: 50px; }
  .tray { grid-template-columns: repeat(8, minmax(0, 72px)); }
}

/* ---------- Short desktop frames: tighten the room so the tray stays in view ---------- */
@media (min-width: 861px) and (max-height: 780px) {
  .wall { height: clamp(84px, 15vh, 120px); }
  .desk { gap: 0.6rem; padding-top: 0.7rem; padding-bottom: 0.8rem; }
  .narration { min-height: 0; font-size: 0.92rem; }
  .note { min-height: 66px; padding: 0.6rem 1rem; }
  .note .glyph { width: 38px; height: 38px; }
  .reply { min-height: 60px; }
  .tray { grid-template-columns: repeat(8, minmax(0, 54px)); gap: 0.4rem; padding: 0.55rem; }
  .meter { top: 8px; }
}

/* ---------- Narrow screens: one column, composer pinned to the bottom ---------- */
@media (max-width: 860px) {
  .topbar { gap: 0.6rem; padding: 0.55rem 0.9rem; }
  .topbar-eyebrow { display: none; }
  .topbar-title { font-size: 1rem; white-space: nowrap; }
  .stages { margin: 0; }
  .stage-pill { padding: 0.2rem; }
  .stage-pill .stage-label { display: none; }
  .stage-pill.is-current { padding-right: 0.6rem; }
  .stage-pill.is-current .stage-label { display: inline; }
  .stage-pill:not(.is-current) .stage-num { width: 18px; height: 18px; font-size: 0.64rem; }
  .topbar-actions .btn { min-height: 32px; padding: 0 0.7rem; font-size: 0.78rem; }
  .topbar-actions a.btn { display: none; }
  .stages { gap: 0.15rem; }

  .room { display: flex; flex-direction: column; overflow-y: auto; }
  .scene, .desk { display: contents; }
  .wall, .narration, .note-area, .books, .composer { flex-shrink: 0; }
  .wall { order: 1; height: 96px; }
  .wall-art { width: 600px; max-width: none; margin-left: -40px; }
  .meter-label-long { display: none; }
  .narration { order: 2; padding: 0.8rem 1rem 0; min-height: 0; font-size: 0.9rem; }
  .note-area { order: 3; padding: 0.6rem 1rem 0; }
  .books { order: 4; border-left: 0; flex: none; min-height: 300px; }
  .book-panel { overflow: visible; }
  .composer {
    order: 5; position: sticky; bottom: 0; z-index: 2;
    gap: 0.45rem; margin-top: auto; padding: 0.55rem 0.75rem 0.65rem;
    background: var(--paper);
    border-top: 1px solid var(--paper-edge);
    box-shadow: 0 -10px 24px -18px rgba(60, 40, 10, 0.4);
  }
  .meter { top: 8px; right: 8px; padding: 0.35rem 0.55rem 0.35rem 0.4rem; gap: 0.4rem; }
  .meter-dial { width: 58px; height: 34px; }
  .meter-label { font-size: 0.58rem; }
  .meter-value { font-size: 1.1rem; }
  .meter-verdict { font-size: 0.7rem; }
  .note { min-height: 64px; padding: 0.6rem 0.8rem; gap: 0.6rem; }
  .note .glyph { width: 34px; height: 34px; }
  .note-meta { min-width: 0; width: 100%; display: flex; gap: 0.5rem; align-items: baseline; }
  .reply { min-height: 54px; padding: 0.35rem 0.6rem; gap: 0.5rem; }
  .reply-label { display: none; }
  .reply-shapes { min-height: 36px; }
  .placed { width: 36px; height: 36px; }
  .placed .glyph { width: 30px; height: 30px; }
  .composer-actions .btn { min-height: 34px; }
  .composer-actions .btn--primary { padding: 0 0.85rem; font-size: 0.84rem; }
  .tray { gap: 0.3rem; padding: 0.4rem; grid-template-columns: repeat(8, minmax(0, 1fr)); width: auto; }
  .tile { min-height: 0; border-radius: 9px; }
  .toast { top: 4.2rem; bottom: auto; transform: translate(-50%, -8px); }
  .toast.is-on { transform: translate(-50%, 0); }
  /* the book panel scrolls with the room here, so pin the note under the top bar */
  .lookup { top: 0; }
}

@media (max-width: 440px) {
  .stage-pill.is-current .stage-label { display: none; }
  .stage-pill.is-current { padding-right: 0.2rem; }
}

/* Very narrow frames (a 320px phone gives the wrapper’s iframe ~288px):
   stages other than the current one shrink to dots and the composer
   buttons tighten, so nothing is clipped at the right edge. */
@media (max-width: 335px) {
  .topbar { gap: 0.45rem; padding: 0.5rem 0.65rem; }
  .topbar-title { font-size: 0.95rem; }
  .stages { gap: 0.1rem; }
  .stage-pill { padding: 0.15rem; }
  .stage-pill:not(.is-current) .stage-num { width: 9px; height: 9px; font-size: 0; }
  .stage-pill.is-done .stage-num { background: var(--muted); border-color: var(--muted); }
  .topbar-actions .btn { padding: 0 0.6rem; }
  .composer { padding-left: 0.5rem; padding-right: 0.5rem; }
  .composer-actions { gap: 0.35rem; }
  .composer-actions .btn--sm { padding: 0 0.6rem; }
  .composer-actions .btn--primary { padding: 0 0.7rem; font-size: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
