/* Warm paper, one amber accent, sage for success, no red anywhere.
   Two typefaces: a generous serif for the passage, a quiet humanist sans for UI. */

:root {
  --panel-h: 40dvh;
  --paper: #faf5ec;
  --ink: #443a30;
  --ink-soft: #7d7061;
  --amber: #c98a2c;
  --amber-soft: #f3e3c6;
  --sage: #8ba888;
  --serif: "Iowan Old Style", "Palatino", "Georgia", serif;
  --sans: "Seravek", "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
}

/* --- Brand: quiet wordmark, present but never busy --- */
#brand {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  pointer-events: none;
  padding: max(0.9rem, env(safe-area-inset-top)) 0 0.6rem;
  background: linear-gradient(to bottom, var(--paper) 75%, transparent);
  z-index: 10;
}
#brand a { pointer-events: auto; display: block; }
#brand img {
  height: 36px;
  display: block;
}

#stage {
  min-height: 100vh;
  min-height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  box-sizing: border-box;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Auto-margin centering: short content sits centered; tall content
     top-aligns and scrolls — nothing ever clips under the fixed header. */
  justify-content: flex-start;
  gap: 1.5rem;
  padding: 1.25rem;
  padding-top: calc(env(safe-area-inset-top, 0px) + 64px);
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  transition: padding-bottom 250ms ease;
}
#stage::before { content: ''; margin-top: auto; }
#stage::after { content: ''; margin-bottom: auto; }
/* Law: stage children never shrink below their content. Without this, a
   tall card gets crushed to zero height and its centered content bleeds
   over everything above and below it. Tall content scrolls instead. */
#stage > * { flex-shrink: 0; }
/* An open panel turns the stage into its own scrollable region above the
   sheet — nothing ever hides underneath. */
body.panel-open #stage {
  min-height: 0;
  height: calc(100dvh - var(--panel-h) - 5.2rem);
  overflow-y: auto;
  justify-content: flex-start;
  padding-top: 0.5rem;
  padding-bottom: 1rem;
}

/* --- Passage: the hero --- */
#passage-area {
  width: 100%;
  max-width: 65ch;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 30dvh;
}

.passage {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.75;
  text-align: left;
  transition: opacity 500ms ease; /* 400-600ms cross-dissolve */
}
@media (min-width: 600px) {
  .passage { font-size: 21px; }
}
.passage.fading { opacity: 0; }
.passage.dimmed { opacity: 0.35; }

.passage .pointer-line {
  display: block;
  margin: 0.4em 0;
  color: var(--ink);
}
/* Live fade: words dissolve as they're spoken well */
.passage .w { transition: opacity 700ms ease; }
.passage .w.spoken { opacity: 0.18; }

.passage .restored {
  color: var(--ink);
  background: var(--amber-soft);
  border-radius: 6px;
  padding: 0.1em 0.3em;
}

/* --- Agent presence --- */
#agent-pulse {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--amber);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.55; }
  50% { transform: scale(1.5); opacity: 1; }
}

#agent-line {
  max-width: 55ch;
  text-align: center;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.6;
}

/* --- Chips: pill-shaped, 2-3 max, 44px touch targets --- */
.chips {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
  max-width: 24rem;
  align-items: stretch;
}
@media (min-width: 600px) {
  .chips { flex-direction: row; flex-wrap: wrap; justify-content: center; max-width: 34rem; }
}

.chip {
  min-height: 44px;
  padding: 0.6rem 1.4rem;
  border-radius: 999px;
  border: 1.5px solid var(--amber);
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  cursor: pointer;
}
.chip:hover { background: var(--amber-soft); }
.chip-primary { background: var(--amber); color: #fff; border-color: var(--amber); }
.chip-primary:hover { background: #b57a24; }
.chip-quiet { border-color: var(--amber-soft); color: var(--ink-soft); }
.chip { white-space: nowrap; }
.chip-lifebuoy { border-color: var(--sage); color: var(--ink); }

/* --- Record button: breathes while listening --- */
#record-zone { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }

#record-hint {
  font-size: 0.9rem;
  color: var(--ink-soft);
  transition: opacity 500ms ease;
}
#record-hint.hidden-soft { opacity: 0; }

#record-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 2px solid var(--amber);
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#record-mic {
  width: 34px;
  height: 34px;
  fill: var(--amber);
}
#record-dot {
  display: none;
  width: 26px;
  height: 26px;
  border-radius: 6px; /* the stop square */
  background: var(--amber);
}
#record-btn.recording #record-mic { display: none; }
#record-btn.recording #record-dot { display: block; }
#record-btn.recording {
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201, 138, 44, 0.25); }
  50% { box-shadow: 0 0 0 16px rgba(201, 138, 44, 0); }
}
#record-btn:disabled { opacity: 0.35; cursor: default; }

/* --- Corner glyphs --- */
#glyphs {
  position: fixed;
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  right: 0.75rem;
  display: flex;
  gap: 0.4rem;
  z-index: 30; /* stays tappable above open drawers */
}
.glyph {
  position: relative;
  min-width: 48px;
  min-height: 48px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: #6d6154;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
}
.glyph:hover { color: var(--ink); background: var(--amber-soft); }
.glyph svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#icon-play { fill: currentColor; stroke: none; }

/* Labels appear on hover/focus as a small tooltip above the icon */
.glyph-label {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--amber-soft);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}
.glyph:hover .glyph-label,
.glyph:focus-visible .glyph-label { opacity: 1; }

/* --- Drawers (text fallback + settings) --- */
.drawer {
  position: fixed;
  /* The sheet ends above the button strip — panels and buttons never overlap */
  bottom: calc(4.2rem + env(safe-area-inset-bottom));
  left: 0.6rem;
  right: 0.6rem;
  background: #fffdf8;
  border: 1px solid var(--amber-soft);
  border-radius: 16px;
  padding: 0.6rem 1.25rem 1.1rem;
  height: var(--panel-h); /* consistent panel size for settings, type, and drawer */
  overflow-y: auto;
  box-shadow: 0 6px 28px rgba(68, 58, 48, 0.1);
  z-index: 20;
}

.panel-minimize {
  display: block;
  margin: -0.5rem auto 0.4rem;
  min-width: 64px;
  min-height: 30px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 999px;
}
.panel-minimize:hover { color: var(--ink); background: var(--amber-soft); }

#text-log { font-size: 0.95rem; color: var(--ink-soft); line-height: 1.6; margin-bottom: 0.75rem; }
#text-log .said { color: var(--ink); }

#text-input, #name-input {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  border-radius: 12px;
  border: 1.5px solid var(--amber-soft);
  background: #fff;
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink);
}
#text-input:focus, #name-input:focus { outline: 2px solid var(--amber); border-color: var(--amber); }

#name-correct { display: flex; gap: 0.5rem; width: 100%; max-width: 24rem; }
#name-correct.hidden { display: none; }

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 44px;
  font-size: 1rem;
}

#recordings-list { margin-top: 0.75rem; font-size: 0.9rem; }
#recordings-list .rec-item {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 44px; border-top: 1px solid var(--amber-soft);
}
#recordings-list button { background: none; border: none; color: var(--amber); cursor: pointer; font-size: 0.9rem; min-height: 44px; }
.rec-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.rec-actions button:last-child { color: var(--ink-soft); }
#rec-delete-all {
  display: block;
  margin-top: 0.5rem;
  color: var(--ink-soft) !important;
  border: 1px solid var(--amber-soft) !important;
  border-radius: 999px;
  padding: 0 1rem;
}

.hidden { display: none !important; }

/* Short viewports: smaller panels so passage + mic still fit above */
@media (max-height: 780px) {
  :root { --panel-h: 34dvh; }
}

/* Small screens: controls compress, tooltips stay off the edges */
@media (max-width: 600px) {
  #brand img { height: 30px; }
  .glyph { min-width: 44px; min-height: 44px; padding: 3px 4px; }
  .glyph svg { width: 21px; height: 21px; }
  #glyphs { right: 0.4rem; gap: 0.1rem; }
  #glyph-settings .glyph-label { left: auto; right: 0; transform: none; }
  #record-btn { width: 68px; height: 68px; }
  :root { --panel-h: 46dvh; }
  .drawer { left: 0.4rem; right: 0.4rem; }
}

/* Now-playing pill: sits right below the mic, exists only when sound does */
#now-playing {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  margin-top: 0.35rem;
  background: #fffdf8;
  border: 1px solid var(--amber-soft);
  border-radius: 999px;
  padding: 0.15rem 0.9rem 0.15rem 0.3rem;
  box-shadow: 0 3px 14px rgba(68, 58, 48, 0.08);
  transition: opacity 300ms ease;
}
#now-playing button {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#now-playing button:hover { background: var(--amber-soft); }
#now-playing svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#np-icon-play { fill: currentColor; stroke: none; }
#np-label {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
#now-playing.np-idle { opacity: 0.65; }
#now-playing.np-idle #np-toggle,
#now-playing.np-idle #np-stop { display: none; }

/* Drawer screen: plain lists, no counts, no badges, no empty-state guilt */
#drawer-list h3 {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 0.9rem 0 0.3rem;
  letter-spacing: 0.04em;
}
#drawer-list .drawer-item {
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.55;
  padding: 0.35rem 0;
  border-top: 1px solid var(--amber-soft);
}
#drawer-list .occasion {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-left: 0.5rem;
}
#setting-name { max-width: 10rem; }
.setting-field { display: flex; align-items: center; gap: 0.5rem; }
#setting-name-save { min-height: 38px; padding: 0.3rem 1rem; }

#text-row { display: flex; align-items: center; gap: 0.5rem; }
#text-row input { flex: 1; }

/* The typing bar: its own surface, so the keyboard never drags the session
   transcript on screen with it. Sits above the button strip on every width. */
#type-bar {
  position: fixed;
  left: 0.6rem;
  right: 0.6rem;
  bottom: calc(4.2rem + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  background: #fffdf8;
  border: 1px solid var(--amber-soft);
  border-radius: 0.9rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
  z-index: 40;
}
#type-bar.hidden { display: none; }
#type-bar input { flex: 1; }
@media (min-width: 900px) {
  /* Centred and bounded on desktop rather than stretched across the stage. */
  #type-bar { left: 50%; right: auto; transform: translateX(-50%); width: min(34rem, calc(100vw - 2rem)); }
}
#text-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--amber);
  color: #fff;
  font-size: 1.05rem;
  cursor: pointer;
  flex-shrink: 0;
}
#text-send:hover { background: #b57a24; }

/* Success moments use sage, sparingly */
.sage { color: var(--sage); }

/* ---------- Phase 2/3: the quiet clock, the camera room, the account row ---------- */
#countdown {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  right: 18px;
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  color: var(--ink-soft);
  opacity: 0.75;
  z-index: 30;
  pointer-events: none;
}

#camera-wrap { margin: 0.75rem auto 0; max-width: 26rem; }
#camera-view {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 16px;
  background: #1d1a16;
  transform: scaleX(-1); /* mirrored preview feels natural */
}
#camera-wrap.playback #camera-view { transform: none; } /* playback un-mirrored */

.setting-note {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--amber-soft);
  margin-bottom: 0.6rem;
}
.setting-note a { color: var(--amber); }

/* ---------- borrowed passages: attribution + the original ---------- */
#passage-attribution {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-align: right;
  max-width: 34rem;
  margin: 0.4rem auto 0;
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 0.8rem;
}
.attribution-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--amber);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.original-leaf {
  background: #fffdf8;
  border: 1px solid var(--amber-soft);
  border-radius: 16px;
  overflow: hidden;
  text-align: left;
  max-width: 34rem;
  margin: 0 auto;
}
.leaf-well {
  font-family: var(--serif);
  font-style: italic;
  line-height: 1.75;
  max-height: 36vh;
  overflow-y: auto;
  padding: 1.1rem 1.3rem;
}
.leaf-note {
  font-family: var(--sans);
  font-size: 0.88rem;
  color: var(--ink-soft);
  border-top: 1px solid var(--amber-soft);
  padding: 0.8rem 1.3rem 0.2rem;
  line-height: 1.55;
}
.leaf-credit {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-align: right;
  padding: 0.55rem 1.3rem 0.2rem;
}
.leaf-back {
  display: block;
  margin: 0.7rem auto 1rem;
}
#passage-text .chip { margin-top: 0.5rem; }

/* ---------- the phrase shelf: sip cards ---------- */
.sip-phrase {
  font-family: var(--sans);
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0.4rem 0 0.9rem;
}
.sip-scene {
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.75;
  margin-bottom: 1.1rem;
}
.sip-meaning {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink-soft);
  border-top: 1px solid var(--amber-soft);
  padding-top: 0.7rem;
}
.sip-meaning + .sip-meaning { border-top: none; padding-top: 0.15rem; }
.sip-credit {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--amber);
  margin-top: 0.5rem;
}

/* Tap-to-skip affordance: the speaking line is a control, not just text */
#agent-line, #agent-pulse { cursor: pointer; }

/* Passage headings: context before reading, in the quiet register */
.passage-heading {
  display: block;
  font-family: var(--sans);
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  margin-bottom: 0.8rem;
}

/* --- The product entries: names as titles, descriptions on demand --- */
#products {
  width: 100%;
  max-width: 26rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.product {
  background: #fffdf8;
  border: 1px solid var(--amber-soft);
  border-radius: 14px;
  overflow: hidden;
}
.product-name {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  font-family: var(--sans);
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--ink);
  padding: 0.7rem 1.1rem;
  text-align: left;
  cursor: pointer;
}
.product-name:hover { background: var(--amber-soft); }
.product-minor .product-name { font-weight: 400; color: var(--ink-soft); font-size: 0.95rem; }
.product-desc { padding: 0 1.1rem 0.9rem; }
.product-desc p { font-size: 0.92rem; color: var(--ink-soft); line-height: 1.55; margin: 0 0 0.7rem; }
.product-actions { display: flex; gap: 0.5rem; }
.product-actions .chip { min-height: 38px; padding: 0.4rem 1.1rem; }

/* The camera take counter: honest, quiet, only the user sees it */
#camera-wrap { position: relative; }
#camera-take {
  position: absolute;
  top: 10px;
  right: 12px;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  color: #fffdf8;
  background: rgba(68, 58, 48, 0.55);
  border-radius: 999px;
  padding: 2px 10px;
}

.account-actions { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.account-actions .chip { min-height: 36px; padding: 0.3rem 1rem; font-size: 0.9rem; }
#setting-companion, #setting-mix { min-height: 38px; border-radius: 10px; border: 1px solid var(--amber-soft); background: #fffdf8; color: var(--ink); font-family: var(--sans); padding: 0.3rem 0.6rem; }

/* --- The duet: her side quiet, your side the hero --- */
.duet-her {
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink-soft);
  margin: 0.5rem 0 0.9rem;
}
.duet-you {
  font-family: var(--serif);
  font-size: 1.2rem;
  line-height: 1.7;
}
.duet-you-free { color: var(--ink-soft); font-style: italic; }


/* --- The menu: top-left, out of the stage's way --- */
#menu-btn {
  position: fixed;
  top: max(0.7rem, env(safe-area-inset-top));
  left: 0.8rem;
  z-index: 40;
  min-width: 48px;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: #6d6154;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#menu-btn:hover { color: var(--ink); background: var(--amber-soft); }
#menu-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
#menu-panel {
  position: fixed;
  top: calc(max(0.7rem, env(safe-area-inset-top)) + 52px);
  left: 0.8rem;
  z-index: 40;
  width: min(20rem, calc(100vw - 1.6rem));
  max-height: calc(100dvh - 110px);
  overflow-y: auto;
  background: #fffdf8;
  border: 1px solid var(--amber-soft);
  border-radius: 16px;
  padding: 0.6rem;
  box-shadow: 0 8px 30px rgba(68, 58, 48, 0.14);
  /* Slides out of the hamburger; slides back on close. */
  transform-origin: top left;
  transition: transform 240ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 200ms ease, visibility 0s linear 0s;
}
#menu-panel.hidden {
  display: block !important;
  visibility: hidden;
  opacity: 0;
  transform: translateX(-14px) translateY(-8px) scale(0.96);
  pointer-events: none;
  transition: transform 200ms ease-in, opacity 160ms ease-in, visibility 0s linear 210ms;
}
/* The three bars fold into a close mark while the menu is out. */
#menu-btn svg line { transition: transform 220ms ease, opacity 140ms ease; transform-origin: 12px 12px; }
#menu-btn[aria-expanded="true"] svg line:nth-child(1) { transform: translateY(5px) rotate(45deg); }
#menu-btn[aria-expanded="true"] svg line:nth-child(2) { opacity: 0; }
#menu-btn[aria-expanded="true"] svg line:nth-child(3) { transform: translateY(-5px) rotate(-45deg); }
.menu-heading {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0.5rem 0.7rem 0.2rem;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.menu-item:hover { background: var(--amber-soft); }
.menu-item span {
  display: block;
  font-weight: 400;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-top: 1px;
}

/* The drawer glyph, at home under the mic */
#record-zone #glyph-drawer { margin-top: 0.1rem; }

/* --- The exclusive overlay: one thing owns the screen at a time --- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(250, 245, 236, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 64px) 1rem 2rem;
  overflow-y: auto;
}
#overlay .original-leaf { width: min(34rem, 100%); margin: auto; }
body.overlay-open #chips,
body.overlay-open #name-correct,
body.overlay-open #record-zone { visibility: hidden; }

/* --- Panels: side sheet on desktop, bottom sheet on phones --- */
@media (min-width: 900px) {
  .drawer {
    /* Harmony: panels live where the menu lives — a panel within the panel's
       place, top-left, never a stranger on the far side of the screen. */
    top: calc(max(0.7rem, env(safe-area-inset-top)) + 52px);
    bottom: auto;
    left: 0.8rem;
    right: auto;
    width: min(24rem, calc(100vw - 1.6rem));
    height: auto;
    max-height: calc(100vh - 140px);
  }
  body.panel-open #stage {
    /* Desktop keeps the full stage; the side sheet floats beside it */
    min-height: 100vh;
    min-height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    height: auto;
    justify-content: flex-start;
    padding-top: calc(env(safe-area-inset-top, 0px) + 64px);
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }
}

/* Drawer item removal: quiet, always available */
.drawer-item { display: flex; align-items: baseline; gap: 0.5rem; }
.drawer-item > span:first-child { flex: 1; }
.drawer-del {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.3rem;
}
.drawer-del:hover { color: var(--ink); }


/* The panel's way back to the menu (desktop only; phones keep the chevron) */
.panel-back {
  display: none;
  border: none;
  background: transparent;
  color: var(--amber);
  font-family: var(--sans);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.5rem 0 0.2rem;
}
@media (min-width: 900px) {
  .panel-back { display: block; }
  .panel-minimize { display: none; }
}

/* The idiom's origin, unfolding on the card */
.sip-story-toggle {
  border: none;
  background: none;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--amber);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  margin-left: 0.6rem;
  padding: 0;
}
.sip-story {
  font-family: var(--serif);
  font-size: 0.98rem;
  line-height: 1.7;
  color: var(--ink-soft);
  border-left: 3px solid var(--amber-soft);
  padding-left: 0.9rem;
  margin-top: 0.6rem;
}

/* --- The Rehearsal Room v3: the script document, chains, the vault --- */
.reh-kicker {
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.reh-title {
  font-family: var(--serif);
  font-size: 1.45rem;
  color: var(--ink);
  margin: 0.2em 0 0.5em;
}
.reh-doc { display: flex; flex-direction: column; gap: 0.7rem; width: 100%; margin-top: 0.6rem; }
.reh-block {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  background: #fffdf8;
  border: 1px solid #eee3d0;
  border-radius: 13px;
  padding: 0.85rem 1.1rem;
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink);
  cursor: pointer;
}
.reh-block:hover { border-color: var(--amber); }
.reh-block-name { font-weight: 600; }
.reh-block-state { font-size: 0.8rem; color: var(--ink-soft); white-space: nowrap; }
.reh-block-state.owned { color: var(--sage); }
.reh-block-text {
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--ink);
  margin-top: 0.5em;
}
.reh-struck {
  text-decoration: line-through;
  text-decoration-color: var(--amber);
  text-decoration-thickness: 1.5px;
  color: var(--ink-soft);
}
.reh-chain { font-size: 1.25em; }
.reh-chain-name {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-top: 0.6em;
}
.reh-read { color: var(--ink-soft); font-size: 0.95em; }
.reh-erase { display: flex; flex-direction: column; align-items: center; gap: 0.9rem; text-align: center; }
.reh-hold {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid var(--amber-soft);
  background: var(--amber-soft);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 3s linear;
}
.reh-hold.holding { border-color: var(--amber); animation: reh-hold-pulse 1s ease infinite; }
@keyframes reh-hold-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.96); }
}

/* --- Rehearsal Room: slideshow practice --- */
.reh-slide {
  display: block;
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid #e8dcc6;
  background: #fff;
  box-shadow: 0 12px 40px rgba(68, 58, 48, 0.12);
  margin: 0.4rem auto;
}
.reh-slide-card {
  width: 100%;
  max-width: 620px;
  aspect-ratio: 16 / 9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 1.5rem;
  text-align: center;
}
.reh-slide-title {
  font-family: var(--sans);
  font-weight: 650;
  font-size: 1.4rem;
  color: #2f3a33;
}
.reh-slide-chain {
  font-family: var(--serif);
  font-size: 1.1rem;
  color: var(--ink-soft);
}


/* The stage steps aside for the menu on wide screens — content slides
   right instead of being covered; narrow screens keep the overlay. */
@media (min-width: 900px) {
  #stage { transition: margin-left 240ms cubic-bezier(0.2, 0.8, 0.2, 1); }
  body.menu-open #stage { margin-left: min(21.5rem, 42vw); }
}


/* --- Keeping a line: tappable words, item 12 --- */
/* Tap the first word, tap the last. The span between them is what you keep,
   so a word, a phrase and a whole line are one interaction. */
.keep-pick { display: block; line-height: 2.1; }
.keep-word {
  display: inline;
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  border-radius: 0.3rem;
  padding: 0.1rem 0.15rem;
  cursor: pointer;
}
.keep-word:hover { background: var(--amber-soft); }
.keep-word.picked { background: var(--amber-soft); outline: 2px solid var(--amber); }
.drawer-empty { color: var(--ink-soft); font-size: 0.95rem; line-height: 1.6; }
.drawer-say {
  flex: 1;
  text-align: left;
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}
.drawer-say:hover { text-decoration: underline; }
