:root {
  --bg: #14110f;
  --panel: #1d1916;
  --panel-2: #262019;
  --ink: #ece4d6;
  --muted: #9a8f7e;
  --line: #3a3127;
  --gold: #d9a441;
  --accent: #c97b54;
  --eleanor: #b07cc6;
  --marcus: #d65a4f;
  --clara: #d9a441;
  --daniel: #5aa978;
  /* The Last Sitting — cooler, signal-like palette */
  --sol: #e0b15a;
  --mauve: #b08bd6;
  --clove: #4fb8b0;
  --wren: #d97b6c;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  background:
    radial-gradient(1200px 500px at 50% -10%, #221b14 0%, var(--bg) 60%),
    var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* track the mobile address bar so nothing gets clipped */
}

/* ── Header ──────────────────────────────────────────────── */
header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--panel), transparent);
}
header h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.5px;
  color: var(--gold);
  font-weight: 600;
}
.setting {
  margin: 0.25rem 0 0;
  max-width: 70ch;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
  line-height: 1.4;
}
.controls { display: flex; align-items: center; gap: 1rem; flex-shrink: 0; }

button {
  font-family: inherit;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s;
}
button:hover:not(:disabled) { background: #322a20; border-color: var(--gold); }
button:disabled { opacity: 0.45; cursor: default; }

.toggle { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.85rem; cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--gold); }

/* ── Layout ──────────────────────────────────────────────── */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  padding: 1rem 1.5rem;
  min-height: 0;
}
.stage { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* ── Transcript ──────────────────────────────────────────── */
.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  scroll-behavior: smooth;
}
.line { display: flex; flex-direction: column; gap: 0.2rem; max-width: 80ch; animation: rise 0.35s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.line .who { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; }
.line .text {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--who, var(--line));
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 0.7rem 0.9rem;
  line-height: 1.5;
  font-size: 1.02rem;
  overflow-wrap: break-word; /* long names/words can't push the layout sideways */
}
.line.player { align-self: flex-end; align-items: flex-end; }
.line.player .text { border-radius: var(--radius) 0 var(--radius) var(--radius); border-left: none; border-right: 3px solid var(--daniel); }

.line.speaking .text { box-shadow: 0 0 0 1px var(--who, var(--gold)), 0 0 18px -4px var(--who, var(--gold)); }
.narration.speaking { color: var(--gold); }

.line .reveals { font-size: 0.72rem; color: var(--gold); margin-top: 0.15rem; }
.line .thought {
  font-size: 0.8rem; color: var(--muted); font-style: italic;
  border-left: 2px dashed var(--line); padding-left: 0.6rem; margin-top: 0.1rem;
}

.narration {
  align-self: center;
  text-align: center;
  color: var(--accent);
  font-style: italic;
  font-size: 0.92rem;
  max-width: 60ch;
  padding: 0.2rem 0;
}

/* emphasised stage directions the model writes inline, e.g. *like this* */
.text em { color: var(--muted); font-style: italic; }

/* ── Thinking indicator ──────────────────────────────────── */
.thinking { display: flex; align-items: center; gap: 0.6rem; color: var(--muted); font-style: italic; padding: 0.4rem 0.6rem; font-size: 0.9rem; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ── Dock (input area) ───────────────────────────────────── */
.dock { border-top: 1px solid var(--line); padding-top: 0.8rem; }
.status { display: flex; align-items: center; gap: 0.8rem; min-height: 1.6rem; margin-bottom: 0.5rem; }
.status .spacer { flex: 1; }
.await-cue {
  color: var(--gold); font-style: italic; font-size: 0.9rem;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
button.ghost { background: transparent; border-color: var(--line); color: var(--muted); font-size: 0.82rem; padding: 0.3rem 0.7rem; }
button.ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--gold); }
.hint { color: var(--muted); font-size: 0.85rem; font-style: italic; }
/* the input glows while they wait on you */
body:has(#await-cue:not([hidden])) #say-input { border-color: var(--gold); box-shadow: 0 0 14px -4px var(--gold); }

.say-form { display: flex; flex-direction: column; gap: 0.5rem; }
.reveal-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.25rem 0.6rem; font-size: 0.78rem; color: var(--muted); cursor: pointer;
}
.chip input { accent-color: var(--gold); }
.chip.hidden-fact { border-color: var(--gold); color: var(--gold); }

.say-row { display: flex; gap: 0.6rem; }
#say-input {
  flex: 1; font-family: inherit; font-size: 1rem;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 0.7rem 0.9rem;
}
#say-input:focus { outline: none; border-color: var(--gold); }
#say-btn { background: var(--gold); color: #1a1409; border-color: var(--gold); font-weight: 700; }
#say-btn:hover:not(:disabled) { background: #e9b85a; }

/* ── Guests sidebar ──────────────────────────────────────── */
.guests { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; overflow-y: auto; }
.guests h2 { margin: 0 0 0.6rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
#guest-list { list-style: none; margin: 0 0 1.4rem; padding: 0; display: flex; flex-direction: column; gap: 0.7rem; }
.guest { padding: 0.6rem 0.7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.guest.speaking { border-color: var(--who, var(--gold)); box-shadow: 0 0 0 1px var(--who, var(--gold)) inset; }
.guest .name { font-weight: 700; color: var(--who, var(--ink)); }
.guest .role { font-size: 0.76rem; color: var(--muted); font-style: italic; }
.guest .mood { font-size: 0.78rem; margin-top: 0.3rem; color: var(--accent); }
.guest.player .you { font-size: 0.7rem; color: var(--daniel); font-weight: 700; letter-spacing: 0.5px; }

.bars { margin-top: 0.5rem; display: none; flex-direction: column; gap: 0.25rem; }
.director .bars { display: flex; }
.bar { display: grid; grid-template-columns: 56px 1fr; align-items: center; gap: 0.4rem; font-size: 0.68rem; color: var(--muted); }
.bar .track { height: 5px; background: #000; border-radius: 3px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); }

.revealed h2 { margin-top: 0; }
#revealed-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
#revealed-list li { font-size: 0.83rem; line-height: 1.4; padding-left: 0.8rem; border-left: 2px solid var(--gold); color: var(--ink); }
#revealed-list li.muted { border-color: var(--line); color: var(--muted); font-style: italic; }
#revealed-list li.revealed-truth {
  margin-top: 0.5rem; color: var(--gold); font-weight: 700; letter-spacing: 0.3px;
  border-left-color: var(--marcus); animation: rise 0.4s ease;
}

.muted { color: var(--muted); }

/* ── Start screen ────────────────────────────────────────── */
.start-screen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(900px 500px at 50% 30%, #221b14 0%, var(--bg) 70%), var(--bg);
}
.start-screen.gone { display: none; }
.start-card {
  max-width: 540px; width: calc(100% - 3rem); text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2.2rem 2rem; box-shadow: var(--shadow);
}
.start-card h1 { margin: 0 0 0.8rem; color: var(--gold); font-size: 1.8rem; letter-spacing: 0.5px; }
.start-setting { color: var(--muted); font-style: italic; line-height: 1.5; margin: 0 0 1.6rem; }
#start-form { display: flex; flex-direction: column; gap: 0.8rem; align-items: stretch; }
#start-form label { color: var(--ink); font-size: 0.95rem; }
#start-name {
  font-family: inherit; font-size: 1.05rem; text-align: center;
  background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 0.7rem 0.9rem;
}
#start-name:focus { outline: none; border-color: var(--gold); }
#start-btn {
  background: var(--gold); color: #1a1409; border-color: var(--gold);
  font-weight: 700; font-size: 1rem; padding: 0.7rem 1rem;
}
#start-btn:hover { background: #e9b85a; }
.end-beat { color: var(--muted); font-style: italic; margin: 0 0 0.6rem; }
#end-again-btn { margin-top: 1.2rem; padding: 0.6rem 1.2rem; }

@media (max-width: 820px) {
  /* Header: compact, wrapping, hide the long blurb. */
  header { padding: 0.5rem 0.8rem; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
  header h1 { font-size: 1.1rem; }
  .setting { display: none; }
  .controls { gap: 0.7rem; }
  button { padding: 0.5rem 0.8rem; }

  /* Single column: a compact "table" strip on top, the conversation filling the rest. */
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
  }

  /* Guests collapse to a compact, scrollable strip of NAME-ONLY chips. */
  .guests {
    order: -1;
    padding: 0.35rem 0.45rem;
    max-height: none;
    overflow: visible;
  }
  .guests > h2,
  .revealed { display: none; } /* the dialogue itself carries these on a small screen */
  #guest-list {
    flex-direction: row;
    gap: 0.4rem;
    margin: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.1rem;
  }
  /* Name-only pill: no role, no mood/feelings, no meters. */
  .guest {
    flex: 0 0 auto;
    min-width: 0;
    padding: 0.3rem 0.6rem;
    border-radius: 999px;
    white-space: nowrap;
  }
  .guest .role,
  .guest .mood,
  .guest .bars { display: none; }
  .guest .name { font-size: 0.82rem; }
  .guest.player .you { display: none; }

  /* Conversation + input. */
  .stage { min-height: 0; }
  .line { max-width: 100%; }
  .line .text { font-size: 1rem; }
  .dock { padding-top: 0.5rem; }
  .status { gap: 0.6rem; }
  #say-input { font-size: 16px; padding: 0.8rem 0.9rem; } /* 16px stops iOS zoom-on-focus */
  #say-btn { padding: 0.8rem 1.1rem; }
  .chip { padding: 0.4rem 0.7rem; } /* bigger touch targets */

  /* Start / end cards fit small screens. */
  .start-card { padding: 1.6rem 1.3rem; }
  .start-card h1 { font-size: 1.45rem; }
}

/* ── Phone widths (small iPhone ≈ 320–430px) ─────────────────
   Squeeze the chrome a little further so nothing overflows and
   the conversation keeps as much room as possible. */
@media (max-width: 430px) {
  header { padding: 0.45rem 0.6rem; column-gap: 0.5rem; }
  header h1 { font-size: 1rem; }
  .controls { gap: 0.5rem; }
  .toggle { font-size: 0.8rem; }
  button { padding: 0.45rem 0.65rem; font-size: 0.85rem; }

  main { padding: 0.45rem 0.55rem; }

  .guest { padding: 0.28rem 0.55rem; }
  .guest .name { font-size: 0.78rem; }

  .line .text { font-size: 0.96rem; padding: 0.6rem 0.75rem; }
  .reveal-chips { gap: 0.35rem; }
  .say-row { gap: 0.45rem; }
  #say-btn { padding: 0.8rem 0.9rem; }

  .start-card { padding: 1.3rem 1rem; width: calc(100% - 1.6rem); }
  .start-card h1 { font-size: 1.3rem; }
}
