:root {
  color-scheme: dark;
  --bg: #09050c;
  --bg2: #120916;
  --panel: rgba(26, 14, 32, 0.84);
  --panel-strong: rgba(31, 17, 39, 0.96);
  --text: #fff7fb;
  --muted: #cbbacc;
  --dim: #9b879d;
  --line: rgba(255, 214, 243, 0.17);
  --left: #ff77bd;
  --left-soft: rgba(255, 119, 189, 0.16);
  --right: #79dcff;
  --right-soft: rgba(121, 220, 255, 0.15);
  --gold: #ffd36e;
  --green: #61e7a3;
  --red: #ff6f91;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.48);
  --radius: 28px;
  --small-radius: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 14% 0%, rgba(255, 119, 189, 0.24), transparent 33rem),
    radial-gradient(circle at 85% 8%, rgba(121, 220, 255, 0.20), transparent 35rem),
    radial-gradient(circle at 60% 95%, rgba(255, 211, 110, 0.11), transparent 28rem),
    linear-gradient(135deg, #050307 0%, #120916 48%, #070b16 100%);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.app-shell {
  width: min(1540px, 100%);
  margin: 0 auto;
  padding: 26px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 400px);
  gap: 18px;
  margin-bottom: 18px;
}

.hero-copy,
.status-card,
.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero-copy {
  min-height: 245px;
  border-radius: var(--radius);
  padding: clamp(26px, 4vw, 50px);
  position: relative;
  overflow: hidden;
}

.hero-copy::after {
  content: "";
  position: absolute;
  right: -80px;
  bottom: -170px;
  width: 420px;
  height: 420px;
  background:
    radial-gradient(circle, rgba(255, 119, 189, 0.28), transparent 55%),
    radial-gradient(circle at 65% 40%, rgba(121, 220, 255, 0.25), transparent 45%);
  pointer-events: none;
}

.eyebrow,
.kicker {
  margin: 0 0 7px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.75rem;
  font-weight: 900;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  margin: 6px 0 12px;
  max-width: 980px;
  font-size: clamp(2.55rem, 6vw, 6.5rem);
  line-height: 0.92;
  letter-spacing: -0.075em;
}

h2 {
  margin-bottom: 0;
  font-size: 1.22rem;
  letter-spacing: -0.02em;
}

.lede {
  max-width: 850px;
  margin-bottom: 28px;
  color: var(--muted);
  font-size: clamp(1.03rem, 1.9vw, 1.28rem);
  line-height: 1.56;
}

.hero-actions,
.button-row,
.preset-grid,
.room-meta {
  display: flex;
  gap: 10px;
  align-items: center;
}

.wrap {
  flex-wrap: wrap;
}

.primary,
.secondary,
.ghost,
.tiny,
.chip {
  color: var(--text);
  border-radius: 999px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, opacity 160ms ease;
}

.primary:hover,
.secondary:hover,
.ghost:hover,
.tiny:hover,
.chip:hover {
  transform: translateY(-1px);
}

.primary {
  padding: 13px 20px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--left), #a879ff 55%, var(--right));
}

.small-primary {
  padding: 11px 16px;
}

.secondary,
.ghost,
.tiny,
.chip {
  background: rgba(15, 8, 20, 0.72);
  border: 1px solid var(--line);
}

.secondary,
.ghost {
  padding: 12px 16px;
  color: var(--muted);
}

.ghost {
  background: rgba(8, 5, 12, 0.44);
}

.tiny {
  padding: 8px 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.chip {
  padding: 8px 11px;
  color: var(--muted);
  font-size: 0.87rem;
}

.danger {
  border-color: rgba(255, 111, 145, 0.35);
  color: #ffd0dc;
}

.status-card {
  border-radius: var(--radius);
  min-height: 180px;
  padding: 26px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.status-card strong,
.status-card span:not(.status-dot) {
  display: block;
}

.status-card strong {
  margin-bottom: 7px;
}

.status-card span:not(.status-dot) {
  color: var(--muted);
  line-height: 1.45;
}

.status-dot {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 0 0 8px rgba(255, 211, 110, 0.13);
}

.status-dot.live {
  background: var(--green);
  box-shadow: 0 0 0 8px rgba(97, 231, 163, 0.13);
}

.status-dot.error {
  background: var(--red);
  box-shadow: 0 0 0 8px rgba(255, 111, 145, 0.13);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(310px, 420px) minmax(420px, 1fr);
  grid-template-areas:
    "setup cast room"
    "bridge bridge room";
  gap: 18px;
  align-items: start;
}

.panel {
  border-radius: var(--radius);
  overflow: hidden;
}

.setup-panel { grid-area: setup; }
.characters-panel { grid-area: cast; }
.room-panel { grid-area: room; }
.bridge-panel { grid-area: bridge; }

.setup-panel,
.characters-panel,
.bridge-panel {
  padding: 22px;
}

.panel-head,
.room-head,
.character-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-head {
  margin-bottom: 18px;
}

.room-panel {
  min-height: 760px;
  max-height: calc(100vh - 52px);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 18px;
}

.room-head {
  padding: 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(26, 14, 32, 0.92);
  z-index: 2;
}

.room-meta {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.room-meta span,
.mode-badge,
.side-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(8, 5, 12, 0.48);
  padding: 7px 10px;
  font-size: 0.8rem;
  font-weight: 850;
}

#nextSpeakerPill {
  border-color: rgba(255, 211, 110, 0.25);
  color: #ffe5a6;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 15px;
}

.field span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.field.mini {
  flex: 1 1 auto;
  margin-bottom: 0;
}

input,
textarea,
select {
  width: 100%;
  color: var(--text);
  background: rgba(6, 3, 9, 0.56);
  border: 1px solid rgba(255, 214, 243, 0.18);
  border-radius: 17px;
  outline: none;
  padding: 12px 13px;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

select {
  appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(255, 211, 110, 0.62);
  box-shadow: 0 0 0 4px rgba(255, 211, 110, 0.12);
  background: rgba(6, 3, 9, 0.76);
}

.preset-grid {
  flex-wrap: wrap;
  margin: -3px 0 18px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
  margin-top: 18px;
}

.compact {
  margin-bottom: 0;
}

.export-row {
  margin-top: 18px;
}

.character-editor {
  border: 1px solid var(--line);
  border-radius: var(--small-radius);
  background: rgba(8, 5, 12, 0.42);
  padding: 16px;
  margin-bottom: 14px;
}

.ziva-editor {
  border-color: rgba(255, 119, 189, 0.25);
}

.elior-editor {
  border-color: rgba(121, 220, 255, 0.25);
}

.side-pill.left {
  border-color: rgba(255, 119, 189, 0.4);
  color: #ffc5e2;
}

.side-pill.right {
  border-color: rgba(121, 220, 255, 0.4);
  color: #c7f2ff;
}

.transcript {
  flex: 1 1 auto;
  overflow: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.empty-state {
  margin: auto;
  max-width: 430px;
  color: var(--muted);
  text-align: center;
  padding: 30px;
}

.empty-icon {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  border-radius: 26px;
  font-size: 2rem;
  background: linear-gradient(135deg, rgba(255, 119, 189, 0.24), rgba(121, 220, 255, 0.18));
}

.message {
  max-width: min(84%, 720px);
  display: grid;
  gap: 7px;
}

.message.left {
  align-self: flex-start;
}

.message.right {
  align-self: flex-end;
}

.message.director {
  align-self: center;
  max-width: min(92%, 780px);
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--dim);
  font-size: 0.85rem;
  font-weight: 900;
}

.message.right .message-header {
  justify-content: flex-end;
}

.avatar {
  width: 27px;
  height: 27px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #210d22;
  background: var(--left);
  font-size: 0.74rem;
  font-weight: 950;
}

.message.right .avatar {
  background: var(--right);
  color: #07151d;
}

.message.director .avatar {
  background: var(--gold);
  color: #1d1306;
}

.bubble {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #fff6fb;
  line-height: 1.55;
  padding: 15px 16px;
  border: 1px solid var(--line);
  background: rgba(8, 5, 12, 0.67);
}

.message.left .bubble {
  border-radius: 8px 23px 23px 23px;
  border-color: rgba(255, 119, 189, 0.25);
  background: linear-gradient(135deg, var(--left-soft), rgba(8, 5, 12, 0.72));
}

.message.right .bubble {
  border-radius: 23px 8px 23px 23px;
  border-color: rgba(121, 220, 255, 0.25);
  background: linear-gradient(135deg, rgba(8, 5, 12, 0.72), var(--right-soft));
}

.message.director .bubble {
  border-radius: 999px;
  border-color: rgba(255, 211, 110, 0.3);
  background: rgba(255, 211, 110, 0.09);
  color: #ffe7a8;
  text-align: center;
  font-size: 0.95rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 211, 110, 0.25);
  color: #ffe7a8;
  font-size: 0.73rem;
}

.thinking .bubble::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  animation: dots 1.1s infinite steps(4, end);
}

.bridge-copy {
  color: var(--muted);
  line-height: 1.48;
  margin-bottom: 17px;
}

#manualPromptOutput {
  min-height: 220px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 5, 12, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
  100% { content: ""; }
}

@media (max-width: 1220px) {
  .hero,
  .main-grid {
    grid-template-columns: 1fr;
  }

  .main-grid {
    grid-template-areas:
      "setup"
      "cast"
      "room"
      "bridge";
  }

  .room-panel {
    position: static;
    max-height: none;
    min-height: 620px;
  }
}

@media (max-width: 660px) {
  .app-shell {
    padding: 14px;
  }

  .hero-copy,
  .setup-panel,
  .characters-panel,
  .bridge-panel,
  .room-head,
  .transcript {
    padding: 18px;
  }

  .hero-actions,
  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  .primary,
  .secondary,
  .ghost {
    width: 100%;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
  }

  .message.director .bubble {
    border-radius: 22px;
  }
}
