:root {
    --bg: #100b14;
    --panel: #1b1321;
    --panel-2: #261a2e;
    --ink: #f2e9f6;
    --muted: #bfaec9;
    --accent: #d481ff;
    --accent-2: #ffce73;
    --danger: #ff7777;
    --good: #8ce7c1;
    --line: rgba(255,255,255,.12);
    --shadow: rgba(0,0,0,.45);
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --serif: Georgia, "Times New Roman", Times, serif;
    --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }

  /* The mask slips in stages. Each stage retints the room. */
  body[data-stage="0"] { --accent:#6fb6c9; --accent-2:#93e6b8; }              /* Intake — clinical calm */
  body[data-stage="1"] { --accent:#9b95dd; --accent-2:#e3c67f; }              /* Alliance — drifting */
  body[data-stage="2"] { --accent:#d481ff; --accent-2:#ffce73; }              /* Candor — the velvet office */
  body[data-stage="3"] { --accent:#ff8fce; --accent-2:#ff9f6b; }             /* Transference — hot */
  body[data-stage="4"] { --accent:#57ffa0; --accent-2:#8dffb0;               /* Termination — the machine */
                          --bg:#05080a; --panel:#0b120d; --panel-2:#0f1a12; }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    min-height: 100vh;
    background:
      radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--accent) 17%, transparent), transparent 32rem),
      radial-gradient(circle at 80% 90%, color-mix(in srgb, var(--accent-2) 10%, transparent), transparent 32rem),
      linear-gradient(135deg, #0c0810, var(--bg));
    color: var(--ink);
    font-family: var(--sans);
    transition: background .9s ease;
  }

  /* Vignette + faint scanlines that deepen as the pretense thins. */
  body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 120px rgba(0,0,0,0);
    background: repeating-linear-gradient(0deg, rgba(0,0,0,0) 0 2px, rgba(0,0,0,0) 2px 4px);
    opacity: 0;
    transition: box-shadow .9s ease, opacity .9s ease;
    z-index: 1;
  }
  body[data-stage="3"]::after { box-shadow: inset 0 0 170px rgba(0,0,0,.42); opacity: .3; }
  body[data-stage="4"]::after {
    box-shadow: inset 0 0 240px rgba(0,0,0,.72);
    background: repeating-linear-gradient(0deg, rgba(0,0,0,0) 0 2px, rgba(87,255,160,.035) 2px 3px);
    opacity: 1;
  }

  .app {
    position: relative;
    z-index: 2;
    width: min(1180px, calc(100vw - 24px));
    margin: 20px auto;
    display: grid;
    grid-template-columns: 1fr 310px;
    gap: 16px;
  }

  header {
    grid-column: 1 / -1;
    border: 1px solid var(--line);
    background: linear-gradient(135deg, rgba(38,26,46,.72), rgba(27,19,33,.72));
    box-shadow: 0 24px 60px var(--shadow);
    border-radius: 18px;
    padding: 18px 20px;
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
  }

  h1 {
    margin: 0 0 4px;
    font-family: var(--serif);
    font-weight: 500;
    letter-spacing: .02em;
    font-size: clamp(1.7rem, 4vw, 3.2rem);
  }

  .subtitle {
    color: var(--muted);
    line-height: 1.45;
    max-width: 760px;
  }

  .headright {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
  }

  .badge {
    font-family: var(--mono);
    color: var(--accent-2);
    border: 1px solid color-mix(in srgb, var(--accent-2) 35%, transparent);
    background: color-mix(in srgb, var(--accent-2) 8%, transparent);
    border-radius: 999px;
    padding: 8px 12px;
    white-space: nowrap;
    font-size: .82rem;
  }

  .plate {
    font-family: var(--mono);
    font-size: .78rem;
    color: var(--accent-2);
    opacity: .92;
    letter-spacing: .03em;
    white-space: nowrap;
    transition: color .9s ease;
  }

  main, aside {
    border: 1px solid var(--line);
    background: rgba(27,19,33,.72);
    border-radius: 18px;
    box-shadow: 0 24px 60px var(--shadow);
    overflow: hidden;
    transition: background .9s ease;
  }

  .transcript {
    height: min(63vh, 720px);
    min-height: 430px;
    overflow-y: auto;
    padding: 18px;
    scroll-behavior: smooth;
  }

  .msg {
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: 12px;
    margin: 0 0 16px;
    animation: rise .22s ease-out;
  }

  @keyframes rise {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .who {
    font-family: var(--mono);
    font-size: .74rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    padding-top: 4px;
    overflow-wrap: anywhere;
  }

  .bubble {
    line-height: 1.56;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.045);
    border-radius: 15px;
    padding: 12px 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  .doctor .bubble {
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 13%, transparent), rgba(255,255,255,.035));
    border-color: color-mix(in srgb, var(--accent) 24%, transparent);
    font-family: var(--serif);
    font-size: 1.05rem;
    transition: font-family 0s;
  }

  /* When the mask is fully off, the Doctor stops sounding like a person. */
  body[data-stage="4"] .doctor .bubble {
    font-family: var(--mono);
    font-size: .96rem;
    letter-spacing: .01em;
  }

  .system .bubble {
    font-family: var(--mono);
    font-size: .86rem;
    color: var(--accent-2);
    background: color-mix(in srgb, var(--accent-2) 8%, transparent);
    border-color: color-mix(in srgb, var(--accent-2) 24%, transparent);
  }

  .safety .bubble {
    font-family: var(--sans);
    color: #fff4f4;
    background: rgba(255,119,119,.13);
    border-color: rgba(255,119,119,.35);
  }

  form {
    border-top: 1px solid var(--line);
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    background: rgba(0,0,0,.16);
  }

  input {
    width: 100%;
    font: 1rem var(--sans);
    color: var(--ink);
    background: rgba(0,0,0,.25);
    border: 1px solid var(--line);
    border-radius: 13px;
    padding: 13px 14px;
    outline: none;
  }

  input:focus {
    border-color: color-mix(in srgb, var(--accent) 80%, transparent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent);
  }

  button {
    border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
    color: var(--ink);
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 35%, transparent), color-mix(in srgb, var(--accent) 12%, transparent));
    border-radius: 13px;
    padding: 0 18px;
    font-weight: 700;
    cursor: pointer;
  }

  button:hover { filter: brightness(1.12); }

  aside { padding: 16px; }

  .card {
    border: 1px solid var(--line);
    background: rgba(255,255,255,.035);
    border-radius: 15px;
    padding: 14px;
    margin-bottom: 12px;
  }

  .card h2 {
    font-family: var(--serif);
    font-weight: 500;
    margin: 0 0 9px;
    font-size: 1.1rem;
  }

  .phase {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-family: var(--mono);
    font-size: .72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin: 2px 0 12px;
    padding-bottom: 9px;
    border-bottom: 1px dashed var(--line);
  }
  .phase strong { color: var(--accent-2); font-weight: 600; transition: color .9s ease; }

  .meter { margin: 12px 0; }

  .meter label {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-family: var(--mono);
    font-size: .75rem;
    margin-bottom: 5px;
  }

  .bar {
    height: 8px;
    border-radius: 999px;
    background: rgba(255,255,255,.08);
    overflow: hidden;
  }

  .fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    border-radius: 999px;
    transition: width .3s ease;
  }
  /* Rapport is the one good reading, so it drains from the other end. */
  .fill.drain { background: linear-gradient(90deg, var(--accent-2), var(--accent)); }

  .pillbox { display: flex; flex-wrap: wrap; gap: 7px; }

  .pill {
    font-family: var(--mono);
    font-size: .72rem;
    color: var(--muted);
    border: 1px solid var(--line);
    background: rgba(0,0,0,.18);
    border-radius: 999px;
    padding: 5px 8px;
  }

  .tiny {
    color: var(--muted);
    font-size: .86rem;
    line-height: 1.42;
  }

  code {
    font-family: var(--mono);
    color: var(--accent-2);
  }

  .footer-note {
    margin-top: 12px;
    color: var(--muted);
    font-size: .8rem;
    line-height: 1.35;
  }

  @media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }
    header { display: block; }
    .headright { align-items: flex-start; margin-top: 12px; }
    .msg { grid-template-columns: 1fr; gap: 5px; }
    .who { padding-top: 0; }
    .transcript { height: 60vh; }
  }

.vesper-lobby-link {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--accent-2);
  font: 11px/1 var(--mono);
  letter-spacing: 0.08em;
  text-decoration: none;
}
.vesper-lobby-link:hover,
.vesper-lobby-link:focus-visible {
  color: var(--ink);
  outline: 1px solid currentColor;
  outline-offset: 4px;
}
.tiny--spaced { margin-top: 8px; }
