:root {
  --bg: #120d18;
  --panel: #1c1524;
  --panel-2: #261b31;
  --line: #36294a;
  --text: #f4edf8;
  --muted: #a797b8;
  --accent: #ff4d8d;
  --amber: #ffb347;
  --good: #5fe3a1;
  --bad: #ff6b6b;
  --npc: var(--accent);
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(255, 77, 141, 0.16), transparent 60%),
    radial-gradient(700px 500px at 100% 110%, rgba(255, 179, 71, 0.1), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, select { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 20px 18px;
  gap: 14px;
}

.topbar { display: flex; align-items: center; gap: 12px; }

.topbar h1 {
  margin: 0 auto 0 0;
  font: 700 26px/1 Georgia, "Times New Roman", serif;
  letter-spacing: 0.01em;
}
.topbar h1 em { color: var(--accent); }

.brain {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.brain.ai { color: var(--good); border-color: rgba(95, 227, 161, 0.4); }

.lang select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
}

/* ---------- status ---------- */

.status {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.avatar {
  position: relative;
  flex: none;
  width: 76px; height: 76px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--panel-2);
  border: 3px solid var(--npc);
  box-shadow: 0 0 24px color-mix(in srgb, var(--npc) 35%, transparent);
  transition: border-color 0.3s, box-shadow 0.3s;
}
.avatar .face { font-size: 40px; line-height: 1; }
.avatar .face.pop { animation: pop 0.35s ease-out; }
.avatar .badge {
  position: absolute; right: -6px; bottom: -6px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  font-size: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 50%;
}

.status-main { flex: 1; min-width: 0; }

.who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.who strong { font-size: 19px; }
.who .role { color: var(--muted); font-size: 14px; }

.mood-pill {
  margin-left: auto;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.meter { display: flex; align-items: center; gap: 10px; margin: 9px 0 8px; }
.meter-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.meter-track {
  position: relative;
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff5a5a 0%, #ffb347 45%, #ffe27a 60%, #5fe3a1 100%);
  overflow: hidden;
}
.meter-cover {
  position: absolute; inset: 0 0 0 50%;
  background: rgba(18, 13, 24, 0.82);
  transition: left 0.6s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.meter-needle {
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 3px; margin-left: -1.5px;
  background: #fff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.9);
  transition: left 0.6s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.meter-value { font: 700 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace; min-width: 44px; text-align: right; }

.delta-flash {
  min-width: 46px;
  font: 700 14px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  opacity: 0;
}
.delta-flash.show { animation: flash 2.2s ease-out; }
.up { color: var(--good); }
.down { color: var(--bad); }
.flat { color: var(--muted); }

.thought {
  margin: 0;
  font-style: italic;
  color: #e6d9ee;
  min-height: 1.45em;
}
.thought-tag {
  font-style: normal;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-right: 6px;
}

.pips-wrap { flex: none; text-align: center; }
.pips { display: grid; grid-template-columns: repeat(5, 8px); gap: 5px; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.pips i.spent { background: var(--line); }
.pips-label { display: block; margin-top: 6px; font-size: 11px; color: var(--muted); }

/* ---------- conversation ---------- */

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 4px 4px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.msg { max-width: 78%; padding: 10px 14px; border-radius: 16px; animation: rise 0.25s ease-out; }
.msg.npc {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--npc);
  border-bottom-left-radius: 4px;
}
.msg.you {
  align-self: flex-end;
  background: linear-gradient(135deg, #ff4d8d, #c2367a);
  border-bottom-right-radius: 4px;
}
.msg.you.silent {
  background: var(--panel-2);
  border: 1px dashed var(--line);
  color: var(--muted);
  font-style: italic;
}
.msg .chip {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  font: 700 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  vertical-align: 1px;
}
.msg .chip.up { color: #b8ffd9; }
.msg .chip.down { color: #ffd0d0; }
.msg .chip.flat { color: #f3d9e6; }

.msg.scene, .msg.note {
  align-self: center;
  max-width: 90%;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  padding: 4px 10px;
}
.msg.scene { font-style: italic; }
.msg.note { color: var(--amber); font-size: 13px; }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i, .mic-dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; opacity: 0.4;
  animation: blink 1s infinite;
}
.typing i:nth-child(2), .mic-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3), .mic-dots i:nth-child(3) { animation-delay: 0.3s; }

/* ---------- dock ---------- */

.dock { display: flex; flex-direction: column; align-items: center; gap: 8px; }

.live {
  margin: 0;
  min-height: 1.45em;
  max-width: 640px;
  text-align: center;
  font-size: 17px;
  color: #fff;
}
.live .interim { color: var(--muted); }

.mic {
  position: relative;
  margin: 10px 0 8px; /* room for the countdown ring */
  width: 124px; height: 124px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  background: radial-gradient(circle at 30% 25%, #ff86b1, #ff4d8d 55%, #c22f6f);
  box-shadow: 0 10px 34px rgba(255, 77, 141, 0.45), inset 0 -6px 14px rgba(0, 0, 0, 0.2);
  transition: transform 0.12s, filter 0.2s, box-shadow 0.2s;
}
.mic:hover { transform: scale(1.04); }
.mic:active { transform: scale(0.97); }
.mic:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
.mic-icon { width: 54px; height: 54px; }
.mic-dots { display: none; gap: 6px; }
.mic-dots i { width: 11px; height: 11px; }

.mic.listening {
  background: radial-gradient(circle at 30% 25%, #ff9a9a, #ff4747 55%, #b81f1f);
  animation: pulse 1.3s infinite;
}
/* Waiting for the player to start talking: calm button, a ring that drains. */
.mic.listening.counting { animation: none; background: radial-gradient(circle at 30% 25%, #ffcf8a, #ffb347 55%, #c97a16); }
.mic::after {
  content: "";
  position: absolute; inset: -12px;
  border-radius: 50%;
  background: conic-gradient(var(--amber) calc(var(--left, 0) * 1turn), rgba(255, 255, 255, 0.1) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.mic.counting::after { opacity: 1; }
.mic.busy { cursor: progress; filter: saturate(0.4) brightness(0.8); }
.mic.busy .mic-icon { display: none; }
.mic.busy .mic-dots { display: inline-flex; }
.mic.off { filter: grayscale(1) brightness(0.6); box-shadow: none; }

.hint { margin: 0; font-size: 13px; color: var(--muted); text-align: center; min-height: 1.45em; }
.hint.warn { color: var(--amber); }

.type { display: flex; gap: 8px; width: min(560px, 100%); }
.type input {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.type input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.type button, .ending-actions button {
  padding: 10px 18px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.type button:hover, .ending-actions button:hover { border-color: var(--accent); }
.type button:disabled, .type input:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- ending ---------- */

.ending {
  position: absolute; inset: 0; z-index: 5;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(10, 6, 14, 0.78);
  backdrop-filter: blur(6px);
  animation: fade 0.3s ease-out;
}
.ending[hidden] { display: none; }

.ending-card {
  width: min(460px, 100%);
  padding: 28px 26px 24px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 4px solid var(--tier, var(--accent));
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: rise 0.35s ease-out;
}
.ending-card.win { --tier: var(--good); }
.ending-card.meh { --tier: var(--amber); }
.ending-card.lose { --tier: var(--bad); }
.ending-emoji { font-size: 64px; line-height: 1.1; }
.ending-card h2 { margin: 8px 0 10px; font: 700 26px/1.15 Georgia, serif; color: var(--tier); }
.ending-blurb { margin: 0 0 14px; color: #e6d9ee; }
.ending-score { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.ending-score strong { color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ending-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.ending-actions .primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }

/* ---------- cast ---------- */

.cast {
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px 18px 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.cast h2 {
  margin: 6px 0 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.cast-list { display: flex; flex-direction: column; gap: 10px; }

.card {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 4px 12px;
  width: 100%;
  padding: 12px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.12s, background 0.2s;
}
.card:hover { transform: translateX(-2px); border-color: var(--c); }
.card.active {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, var(--panel));
  box-shadow: 0 0 0 1px var(--c) inset;
}
.card.nudge { animation: nudge 0.5s ease-out; }
.card-emoji {
  grid-row: span 2;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  font-size: 22px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 2px solid var(--c);
}
.card-name { font-weight: 700; }
.card-name small { font-weight: 400; color: var(--muted); }
.card-diff {
  float: right;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--c);
  border: 1px solid color-mix(in srgb, var(--c) 50%, transparent);
}
.card-role { font-size: 13px; color: var(--muted); }
.card-taste { grid-column: 1 / -1; margin-top: 6px; font-size: 12.5px; color: #cdbfd9; }
.card-taste b { font-weight: 600; }
.card-taste .yes { color: var(--good); }
.card-taste .no { color: var(--bad); }

/* ---------- motion ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.2); } }
@keyframes blink { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
@keyframes flash { 0% { opacity: 0; transform: translateY(6px); } 12% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; } }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 71, 71, 0.55), 0 10px 34px rgba(255, 71, 71, 0.45); }
  100% { box-shadow: 0 0 0 30px rgba(255, 71, 71, 0), 0 10px 34px rgba(255, 71, 71, 0.45); }
}
@keyframes nudge { 30% { transform: translateX(-6px); } 60% { transform: translateX(3px); } }

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

/* ---------- narrow screens ---------- */

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .cast { order: -1; min-width: 0; padding: 10px 16px 0; overflow: visible; }
  .cast h2 { margin: 0 0 8px; }
  .cast-list { flex-direction: row; overflow-x: auto; padding-bottom: 6px; }
  .card { flex: none; width: 190px; }
  .card:hover { transform: none; }
  .card-taste { display: none; }
  .stage { padding: 10px 16px 14px; gap: 10px; }
  .topbar h1 { font-size: 22px; }
  .status { gap: 12px; padding: 12px; }
  .avatar { width: 60px; height: 60px; }
  .avatar .face { font-size: 32px; }
  .pips-wrap { display: none; }
  .meter-label { display: none; }
  .mic { width: 100px; height: 100px; }
  .msg { max-width: 88%; }
}
