:root {
  --paper: #f3ead8;
  --paper-deep: #e7d9bf;
  --ink: #2a2118;
  --ink-soft: #5a4c3d;
  --muted: #7a6d5c;
  --rule: #cbbba0;
  --wash: #c9d7c4;
  --wash-blue: #c5d4de;
  --moss: #4d6244;
  --moss-deep: #3a4a33;
  --danger: #7a3b2e;
  --shadow: rgba(42, 33, 24, 0.12);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
}
body {
  min-height: 100dvh;
  font-family: "Source Serif 4", Palatino, "Palatino Linotype", "Times New Roman", serif;
  background-image:
    radial-gradient(ellipse at 12% -10%, rgba(201, 215, 196, 0.55), transparent 50%),
    radial-gradient(ellipse at 110% 0%, rgba(197, 212, 222, 0.4), transparent 46%),
    radial-gradient(ellipse at 80% 110%, rgba(214, 196, 168, 0.45), transparent 50%);
  background-attachment: fixed;
}

img, svg, video, canvas { max-width: 100%; height: auto; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.page {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 20px 16px 40px;
  overflow-x: hidden;
}

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}
.masthead h1 {
  font-family: Fraunces, "Source Serif 4", serif;
  font-weight: 500;
  font-size: clamp(1.6rem, 4vw, 2.15rem);
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}
.lede, .quiet { color: var(--ink-soft); margin: 0; }
.lede { font-size: 1.02rem; max-width: 40rem; }
.quiet { font-size: 0.88rem; }

.gear {
  width: 40px;
  height: 40px;
  border: 1px solid var(--rule);
  background: rgba(255, 252, 245, 0.7);
  border-radius: 999px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.gear svg { width: 18px; height: 18px; }

.panel {
  margin-top: 22px;
}
label.field {
  display: block;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.dropdown {
  position: relative;
  width: 100%;
}
.dropdown-btn {
  width: 100%;
  text-align: left;
  background: rgba(255, 252, 245, 0.85);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 1px 0 var(--shadow);
}
.dropdown-btn .chevron { color: var(--muted); }
.menu {
  margin-top: 8px;
  background: #fffaf1;
  border: 1px solid var(--rule);
  border-radius: 12px;
  max-height: min(60vh, 420px);
  overflow: auto;
  overflow-x: hidden;
  box-shadow: 0 12px 32px var(--shadow);
}
.group-label {
  padding: 10px 12px 4px;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
}
.option:hover, .option:focus { background: rgba(201, 215, 196, 0.35); }
.option.below { opacity: 0.72; }
.option img, .option .ph {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--paper-deep);
  flex: 0 0 36px;
  border: 1px solid var(--rule);
}
.option .ph { display: grid; place-items: center; color: var(--muted); font-size: 0.7rem; }
.option .title { flex: 1; min-width: 0; }
.option input { width: 18px; height: 18px; accent-color: var(--moss); flex: 0 0 auto; }

.picks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 18px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(255, 252, 245, 0.8);
  font-size: 0.88rem;
}
.chip img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
.primary, .secondary, .ghost {
  border-radius: 999px;
  padding: 10px 18px;
  border: 1px solid var(--moss-deep);
}
.primary {
  background: var(--moss);
  color: #f7f3ea;
  border-color: var(--moss-deep);
}
.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule);
}
.ghost { background: transparent; border-color: transparent; padding: 8px 10px; }

.session-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.card {
  background: rgba(255, 252, 245, 0.72);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 10px 0;
  overflow-x: hidden;
}
.card h2, .card summary {
  font-family: Fraunces, serif;
  font-weight: 500;
  font-size: 1rem;
  margin: 0;
  cursor: pointer;
}
.style-card pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Source Serif 4", serif;
  font-size: 0.95rem;
  margin: 10px 0 0;
}
.banner {
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
  background: rgba(197, 212, 222, 0.45);
  border: 1px solid var(--rule);
  font-size: 0.92rem;
}
.banner.warn { background: rgba(214, 196, 168, 0.55); }
.banner.err { background: rgba(180, 90, 70, 0.15); color: var(--danger); }

.answer {
  font-size: 1.12rem;
  line-height: 1.55;
  min-height: 3em;
  white-space: pre-wrap;
  word-break: break-word;
}
.storyboard {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 16px 0;
}
@media (min-width: 640px) {
  .storyboard { grid-template-columns: 1fr 1fr; }
}
.frame {
  background: #fffaf1;
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  min-width: 0;
}
.frame .art {
  aspect-ratio: 1;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 14px, rgba(203, 187, 160, 0.25) 15px),
    #f6efdf;
  display: grid;
  place-items: center;
  position: relative;
}
.frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame figcaption {
  padding: 8px 10px 10px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}
.frame .stage {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(243, 234, 216, 0.88);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 2px 7px;
}
.pending { color: var(--muted); font-style: italic; padding: 12px; text-align: center; }

.composer {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--paper) 70%, transparent);
  padding: 12px 0 8px;
}
.row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  min-height: 48px;
  max-height: 160px;
  border-radius: 12px;
  border: 1px solid var(--rule);
  background: #fffaf1;
  padding: 10px 12px;
}
.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--moss-deep);
  background: var(--moss);
  color: #f7f3ea;
  display: grid;
  place-items: center;
  flex: 0 0 48px;
}
.icon-btn.idle {
  background: #fffaf1;
  color: var(--ink);
  border-color: var(--rule);
}
.icon-btn.listening { background: var(--danger); border-color: var(--danger); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(42, 33, 24, 0.35);
  display: none;
  z-index: 20;
  padding: 16px;
  overflow-x: hidden;
}
.modal.open { display: flex; }
.modal-panel {
  background: #fffaf1;
  border: 1px solid var(--rule);
  width: min(420px, 100%);
  max-width: 100%;
  padding: 18px 16px 16px;
  box-shadow: 0 16px 40px var(--shadow);
}
.modal-panel h2 { font-family: Fraunces, serif; font-weight: 500; margin: 0 0 8px; font-size: 1.2rem; }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--rule);
  margin-top: 8px;
}
.switch {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--moss-deep);
  background: var(--paper-deep);
  position: relative;
  flex: 0 0 44px;
}
.switch.on { background: var(--moss); }
.switch i {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: left 0.15s ease;
}
.switch.on i { left: 20px; }

@media (min-width: 641px) {
  .modal { align-items: center; justify-content: center; }
  .modal-panel { border-radius: 14px; }
}
@media (max-width: 640px) {
  .modal { align-items: flex-end; justify-content: stretch; padding: 0; }
  .modal-panel {
    width: 100%;
    border-radius: 16px 16px 0 0;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

.status-line { font-size: 0.82rem; color: var(--muted); margin-top: 8px; }
.hidden { display: none !important; }
