:root {
  --bg: #0a0910;
  --bg-soft: #14121c;
  --surface: rgba(20, 18, 28, 0.78);
  --surface-strong: rgba(28, 25, 39, 0.9);
  --surface-light: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.1);
  --line-soft: rgba(255, 255, 255, 0.05);
  --text: #f7f2ee;
  --muted: #b7a99d;
  --accent: #ff8a5b;
  --accent-strong: #ff6432;
  --accent-glow: rgba(255, 120, 77, 0.28);
  --gold: #ffd49d;
  --danger: #ff5f6d;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 18px 48px rgba(0, 0, 0, 0.24);
  --radius-xl: 30px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --vvh: 100dvh;
}

* {
  box-sizing: border-box;
}

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

body {
  position: relative;
  overflow-x: hidden;
  color: var(--text);
  font-family: "Avenir Next", "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 131, 88, 0.14), transparent 26%),
    radial-gradient(circle at 85% 18%, rgba(255, 214, 157, 0.12), transparent 22%),
    linear-gradient(180deg, #0b0911 0%, #120f1a 28%, #16121c 100%);
}

.app-shell {
  position: relative;
  width: min(1180px, calc(100% - 20px));
  margin: 0 auto;
  padding: 18px 0 110px;
}

.hidden-top-meta {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.bg-orb,
.bg-grid {
  pointer-events: none;
  position: fixed;
  inset: auto;
  z-index: 0;
}

.bg-orb {
  width: 44vw;
  height: 44vw;
  max-width: 420px;
  max-height: 420px;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.32;
}

.orb-a {
  top: -110px;
  left: -80px;
  background: radial-gradient(circle, rgba(255, 111, 67, 0.55), transparent 68%);
}

.orb-b {
  right: -100px;
  bottom: 120px;
  background: radial-gradient(circle, rgba(255, 209, 137, 0.4), transparent 70%);
}

.bg-grid {
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.65), transparent 86%);
}

.app-header,
.hero-panel,
.mini-panel,
.status-panel,
.preview-card,
.form-panel,
.progress-card,
.chat-stage-card,
.identity-card,
.health-card,
.composer-card,
.debug-card,
.avatar-card {
  position: relative;
  z-index: 1;
}

.app-header {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.brand-block,
.status-panel,
.hero-panel,
.mini-panel,
.form-panel,
.preview-card,
.progress-card,
.chat-stage-card,
.identity-card,
.health-card,
.composer-card,
.debug-card,
.avatar-card {
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-block {
  padding: 22px 20px;
  border-radius: var(--radius-xl);
}

.brand-chip,
.section-tag,
.status-label,
.field span,
.inline-field span,
.selected-human span,
.health-card span,
.identity-copy span,
.mini-panel span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

.form-panel .field span {
  font-size: 13px;
  letter-spacing: 0.12em;
}

.brand-chip,
.section-tag {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 212, 157, 0.18);
  background: rgba(255, 212, 157, 0.08);
}

.brand-block h1,
.hero-copy h2 {
  margin: 14px 0 0;
  font-size: clamp(32px, 8vw, 52px);
  line-height: 0.96;
  letter-spacing: -0.04em;
}

.brand-copy,
.hero-copy p,
.debug-card small,
.overlay-tip,
.preview-head span,
.progress-card p,
.mini-panel span,
.avatar-card .avatar-meta,
#voiceHintLabel,
.identity-copy span,
.health-card span {
  color: var(--muted);
}

.brand-copy {
  max-width: 560px;
  margin: 14px 0 0;
  font-size: 15px;
  line-height: 1.75;
}

.status-panel {
  display: grid;
  gap: 6px;
  padding: 18px;
  border-radius: 24px;
}

.status-panel strong {
  font-size: 18px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.tab-panel[data-tab-panel="avatars"].active {
  min-height: calc(100vh - 96px);
}

.view-stack {
  display: grid;
  gap: 16px;
}

#avatarSelectView {
  min-height: calc(100vh - 120px);
  grid-template-rows: auto 1fr auto;
}

.select-hero {
  margin-bottom: 6px;
}

.select-hero .hero-copy p.select-hero-copy {
  max-width: 420px;
  font-size: 13px;
  line-height: 1.65;
}

.select-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 9, 14, 0.56);
  backdrop-filter: blur(12px);
}

.select-loading-card {
  min-width: min(280px, calc(100vw - 48px));
  display: grid;
  gap: 12px;
  justify-items: center;
  padding: 24px 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  background:
    radial-gradient(circle at top, rgba(255, 177, 118, 0.16), transparent 42%),
    linear-gradient(145deg, rgba(28, 24, 38, 0.95), rgba(16, 14, 23, 0.95));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  text-align: center;
}

.select-loading-card strong {
  font-size: 18px;
  color: #fff7f1;
}

.select-loading-card p {
  margin: 0;
  color: rgba(255, 245, 238, 0.72);
  font-size: 13px;
  line-height: 1.6;
}

.select-loading-spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: #ffab68;
  animation: spin 0.8s linear infinite;
}

.tab-launch-button {
  min-height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(135deg, #ffc06f, #ff8457);
  color: #160f0e;
  font-weight: 700;
  box-shadow: 0 14px 28px rgba(255, 132, 87, 0.32);
}

.select-footer-action {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 12;
  display: grid;
  justify-items: center;
  width: min(320px, calc(100vw - 40px));
  margin-top: 4px;
  padding: 0;
}

.select-footer-action .tab-launch-button {
  width: min(220px, calc(100% - 36px));
  min-height: 54px;
  border-radius: 20px;
}

.hero-panel {
  display: grid;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at top right, rgba(255, 138, 91, 0.22), transparent 34%),
    linear-gradient(145deg, rgba(30, 26, 40, 0.92), rgba(16, 14, 23, 0.92));
}

.create-hero {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
}

.hero-copy p {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.65;
}

.hero-icon-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  justify-self: start;
}

.hero-actions,
.button-row,
.stage-actions,
.health-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

.form-panel .button-row {
  grid-template-columns: 1fr;
}

.hidden-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.create-footer-action {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 12;
  display: grid;
  justify-items: center;
  width: min(320px, calc(100vw - 40px));
  padding: 0;
}

.create-footer-action .tab-launch-button {
  width: min(220px, calc(100% - 36px));
  min-height: 54px;
  border-radius: 20px;
}

.create-busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(9, 8, 13, 0.44);
  backdrop-filter: blur(12px);
}

.create-busy-card {
  min-width: min(280px, calc(100vw - 48px));
  padding: 24px 22px;
  border-radius: 24px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    radial-gradient(circle at top, rgba(255, 170, 102, 0.18), transparent 46%),
    linear-gradient(180deg, rgba(29, 24, 39, 0.96), rgba(14, 12, 21, 0.96));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
}

.create-busy-card strong {
  display: block;
  margin-top: 16px;
  font-size: 16px;
  line-height: 1.5;
}

.create-busy-spinner {
  width: 38px;
  height: 38px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: #ffab68;
  animation: spin 0.8s linear infinite;
}

.overview-strip {
  display: grid;
  gap: 12px;
}

.mini-panel {
  min-height: 108px;
  padding: 16px;
  border-radius: 22px;
}

.mini-panel strong {
  display: block;
  margin-top: 18px;
  font-size: 18px;
  line-height: 1.35;
}

.avatar-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  align-content: start;
}

.avatar-card {
  overflow: hidden;
  border-radius: 26px;
  cursor: pointer;
  align-self: start;
  transition:
    transform 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.avatar-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 138, 91, 0.36);
}

.avatar-card.selected {
  border-color: rgba(255, 138, 91, 0.72);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.32),
    0 0 0 1px rgba(255, 138, 91, 0.26);
}

.avatar-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  display: block;
  object-fit: cover;
  object-position: center top;
}

.avatar-card-body {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  justify-content: flex-start;
  padding: 0;
  pointer-events: none;
}

.avatar-card-body strong {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  max-width: min(10ch, calc(100% - 8px));
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(17, 14, 24, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
  font-size: 15px;
  line-height: 1.2;
  word-break: break-word;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 28px 18px;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: 24px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}

.create-layout {
  display: grid;
  gap: 16px;
}

#avatarCreateView {
  min-height: calc(100vh - 120px);
  grid-template-rows: auto 1fr auto;
}

.form-panel,
.preview-card,
.progress-card,
.composer-card,
.chat-stage-card,
.debug-card {
  padding: 18px;
  border-radius: var(--radius-xl);
}

.preview-card-large {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.create-video-card {
  margin-bottom: 8px;
}

.create-video-card .preview-head {
  margin-bottom: 6px;
}

.preview-head,
.progress-head,
.composer-top,
.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-head strong,
.progress-head strong {
  font-size: 18px;
}

.preview-frame {
  margin-top: 8px;
  width: min(132px, 100%);
  aspect-ratio: 3 / 4;
  border-radius: 20px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
  display: grid;
  place-items: center;
}

.preview-frame-large {
  width: min(180px, 100%);
}

.preview-frame-video {
  position: relative;
  width: min(180px, 100%);
  aspect-ratio: 3 / 5;
  margin-inline: auto;
}

.preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.preview-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
  background: #0b0910;
}

.preview-empty {
  display: none;
}

.preview-action-button {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: 84px;
  min-width: 84px;
  min-height: 30px;
  height: 30px;
  border-radius: 14px;
  background: rgba(17, 14, 24, 0.72);
  backdrop-filter: blur(10px);
  font-size: 12px;
  padding: 0 10px;
  line-height: 1;
}

.field {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 15px 16px;
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: rgba(255, 255, 255, 0.34);
}

textarea {
  resize: vertical;
  line-height: 1.65;
  min-height: 124px;
}

input:focus,
textarea:focus {
  border-color: rgba(255, 138, 91, 0.55);
  box-shadow: 0 0 0 4px rgba(255, 138, 91, 0.12);
}

.progress-bar {
  margin-top: 12px;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.progress-bar div {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ffb46e);
  transition: width 0.25s ease;
}

.progress-card p {
  margin: 12px 0 0;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 54px;
  border: 0;
  border-radius: 18px;
  padding: 14px 18px;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    opacity 0.18s ease,
    background 0.18s ease;
}

.primary-button {
  color: #170f0e;
  background: linear-gradient(135deg, #ffb066, #ff7f55 58%, #ff6238);
  box-shadow: 0 16px 36px var(--accent-glow);
}

.primary-button-wide {
  width: 100%;
}

.secondary-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.ghost-button {
  color: var(--text);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.danger-button {
  color: var(--white);
  background: linear-gradient(135deg, #ff6170, #d83a57);
  box-shadow: 0 16px 34px rgba(216, 58, 87, 0.24);
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

.small {
  min-height: 42px;
  padding: 10px 14px;
}

.chat-stage-card {
  display: grid;
  gap: 16px;
  background:
    radial-gradient(circle at top right, rgba(255, 138, 91, 0.12), transparent 30%),
    linear-gradient(180deg, rgba(25, 21, 34, 0.92), rgba(16, 14, 22, 0.94));
}

.chat-topbar {
  align-items: stretch;
  flex-direction: column;
}

.identity-card,
.health-card {
  border-radius: 24px;
  padding: 14px;
}

.identity-card {
  display: flex;
  align-items: center;
  gap: 14px;
}

.identity-card img {
  width: 70px;
  height: 70px;
  border-radius: 22px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.identity-copy strong,
.health-card strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
}

.health-card-wide {
  display: grid;
  gap: 12px;
}

.health-actions {
  grid-template-columns: 1fr 1fr;
}

.stage-hero {
  position: relative;
}

.stage-shell {
  position: relative;
  padding: 14px;
  border-radius: 36px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    rgba(10, 9, 16, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow);
}

.stage-sheen {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent 24%);
  pointer-events: none;
}

.stage-caption {
  margin-bottom: 10px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
}

.video-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 9 / 16;
  border-radius: 30px;
  background:
    radial-gradient(circle at top, rgba(255, 138, 91, 0.22), transparent 35%),
    linear-gradient(180deg, #17131e, #09080d);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(7, 7, 10, 0.36);
}

.video-overlay.active {
  display: grid;
}

.overlay-stack {
  text-align: center;
}

.overlay-pill {
  display: inline-block;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: #fff7f1;
  font-weight: 700;
  font-size: 24px;
  line-height: 1.2;
  box-shadow: none;
}

.overlay-tip {
  margin: 10px auto 0;
  max-width: 280px;
  line-height: 1.6;
  font-size: 13px;
  color: rgba(255, 245, 238, 0.8);
}

.overlay-stack .primary-button {
  margin-top: 16px;
}

.stage-actions {
  margin-top: 14px;
  grid-template-columns: 1fr 1fr;
}

.composer-card {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.composer-top {
  align-items: flex-start;
  flex-direction: column;
}

.composer-heading strong {
  display: block;
  margin-top: 12px;
  font-size: 22px;
}

.composer-heading p {
  margin: 8px 0 0;
}

.inline-field {
  width: 100%;
  display: grid;
  gap: 8px;
}

.chat-history {
  display: grid;
  gap: 10px;
  min-height: 128px;
  margin: 18px 0;
}

.chat-bubble {
  max-width: 88%;
  padding: 13px 15px;
  border-radius: 22px;
  white-space: pre-wrap;
  line-height: 1.62;
}

.chat-bubble.user {
  margin-left: auto;
  color: #1f130f;
  background: linear-gradient(135deg, #ffb066, #ff8754);
  border-bottom-right-radius: 8px;
}

.chat-bubble.assistant {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border-bottom-left-radius: 8px;
}

.chat-bubble.empty {
  max-width: 100%;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.debug-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02)),
    rgba(10, 9, 14, 0.72);
}

.debug-card summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}

.debug-card summary::-webkit-details-marker {
  display: none;
}

.debug-log {
  margin: 14px 0 0;
  min-height: 140px;
  max-height: 240px;
  overflow: auto;
  padding: 14px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.34);
  color: #f9e8db;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 10;
  width: min(720px, calc(100% - 20px));
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 26px;
  background: rgba(12, 10, 18, 0.86);
  box-shadow: 0 24px 58px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(18px);
}

.tabbar,
.tabbar-item {
  display: none !important;
}

.tabbar-item {
  min-height: 58px;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: var(--muted);
}

.tabbar-item.active {
  color: #160f0e;
  background: linear-gradient(135deg, #ffc06f, #ff8457);
  box-shadow: 0 14px 28px rgba(255, 132, 87, 0.32);
}

.hidden {
  display: none !important;
}

@media (max-width: 767px) {
  .app-shell {
    width: calc(100% - 16px);
    padding-top: 14px;
  }

  .brand-block h1,
  .hero-copy h2 {
    font-size: 34px;
  }
}

@media (min-width: 768px) {
  .app-header {
    grid-template-columns: minmax(0, 1fr) 260px;
    align-items: stretch;
  }

  .overview-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .create-layout {
    grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.9fr);
    align-items: start;
  }

  .hero-actions,
  .button-row {
    grid-auto-flow: column;
    justify-content: start;
  }
}

@media (min-width: 980px) {
  .chat-stage-card {
    grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
    gap: 22px;
  }

  .chat-topbar {
    grid-column: 1 / -1;
    flex-direction: row;
  }

  .stage-hero {
    grid-column: 1;
    grid-row: 2 / span 2;
  }

  .composer-card,
  .stage-debug-card {
    grid-column: 2;
  }

  .stage-shell {
    position: sticky;
    top: 20px;
  }
}

body.chat-stage-active {
  overflow: hidden;
}

.chat-tab-panel.active {
  min-height: calc(var(--vvh) - 170px);
  padding: 0;
}

.chat-top-strip {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px 14px;
}

.chat-back-button {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  font-size: 22px;
  box-shadow: none;
}

.chat-stage-screen {
  position: relative;
  min-height: calc(var(--vvh) - 250px);
  border-radius: 34px;
  overflow: hidden;
  background: #09080d;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.42);
}

.chat-stage-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.chat-stage-backdrop video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
  background:
    radial-gradient(circle at top, rgba(255, 138, 91, 0.18), transparent 28%),
    #0c0911;
}

.stage-gradient {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(8, 7, 12, 0.16) 0%, rgba(8, 7, 12, 0.03) 24%, rgba(8, 7, 12, 0.08) 60%, rgba(8, 7, 12, 0.34) 100%),
    radial-gradient(circle at top right, rgba(255, 138, 91, 0.2), transparent 26%);
  pointer-events: none;
}

.health-card-stage {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03)),
    rgba(16, 14, 23, 0.76);
}

.health-summary {
  min-width: 0;
  display: grid;
  gap: 4px;
  justify-self: start;
  text-align: left;
}

.chat-top-strip .health-summary strong {
  margin-top: 0;
  white-space: nowrap;
}

.chat-top-strip .health-summary span {
  white-space: nowrap;
}

.health-actions-inline {
  width: max-content;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  justify-self: end;
  margin-left: auto;
}

.health-actions-inline .ghost-button {
  min-height: 42px;
  padding: 0 18px;
  border-radius: 16px;
  margin-left: auto;
}

.top-action-button {
  min-height: 42px;
  padding: 0 18px;
  border-radius: 16px;
  font-size: 14px;
  white-space: nowrap;
}

.composer-card-floating {
  position: fixed;
  left: 18px;
  right: 18px;
  width: auto;
  bottom: 92px;
  z-index: 14;
  max-width: none;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.composer-card-floating .field {
  margin-top: 0;
}

.field-tight {
  display: block;
  margin: 0;
}

.chat-history-hidden,
.debug-log-hidden {
  display: none;
}

.hidden-stage-avatar,
.hidden-stage-name {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.field-tight textarea {
  min-height: 28px;
  border-radius: 22px;
  background: rgba(18, 15, 26, 0.24);
  border-color: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  line-height: 1.35;
  padding-right: 64px;
  padding-top: 8px;
  padding-bottom: 8px;
  pointer-events: none;
  user-select: none;
  opacity: 1;
  cursor: default;
}

.field-tight textarea:disabled {
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  opacity: 1;
}

.button-row-inline {
  grid-template-columns: 1fr;
}

.video-overlay-screen {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.speech-float-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}

.stage-telemetry {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  display: none;
  gap: 10px;
  width: min(52vw, 220px);
  pointer-events: none;
}

.stage-telemetry-card {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(16, 14, 23, 0.52);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(12px);
}

.stage-telemetry-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 212, 157, 0.9);
}

.stage-telemetry-card strong {
  color: rgba(255, 247, 241, 0.96);
  font-size: 13px;
  line-height: 1.35;
  word-break: break-word;
}

.stage-telemetry-volume {
  gap: 8px;
}

.stage-telemetry-volume-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stage-volume-bar {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.stage-volume-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(255, 176, 109, 0.9), rgba(255, 109, 76, 0.96));
  box-shadow: 0 0 18px rgba(255, 140, 91, 0.3);
  transition: width 120ms linear;
}

.assistant-speech-overlay {
  position: absolute;
  right: 18px;
  bottom: 154px;
  z-index: 3;
  max-width: min(54%, 240px);
  padding: 12px 14px;
  border-radius: 18px 18px 6px 18px;
  background: rgba(20, 16, 28, 0.62);
  color: rgba(255, 247, 241, 0.96);
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(12px);
  text-align: left;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.speech-float-item {
  position: absolute;
  left: 18px;
  bottom: 120px;
  max-width: min(280px, calc(100% - 36px));
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(20, 16, 28, 0.78);
  color: rgba(255, 247, 241, 0.96);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(10px);
  line-height: 1.5;
  animation: speechFloatUp 2s ease-out forwards;
}

.stage-actions-floating {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 15;
  margin-top: 0;
  width: min(240px, calc(100% - 36px));
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 0;
}

.stage-actions-floating.connected {
  left: 18px;
  right: 18px;
  width: auto;
  transform: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stage-actions-floating .primary-button,
.stage-actions-floating .danger-button {
  width: 100%;
  min-height: 54px;
  border-radius: 20px;
}

.stage-actions-floating .danger-button {
  background: linear-gradient(135deg, #ff8c8d, #d8344c);
  box-shadow: 0 16px 30px rgba(216, 52, 76, 0.34);
}

.sound-toggle-button {
  display: none;
  position: absolute;
  top: -18px;
  right: 10px;
  z-index: 2;
  min-width: 52px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 12px;
  font-size: 12px;
}

@media (max-width: 767px) {
  .app-shell {
    min-height: 100dvh;
    padding-bottom: 188px;
  }

  .chat-tab-panel.active {
    min-height: calc(var(--vvh) - 150px);
  }

  .chat-stage-screen {
    min-height: calc(var(--vvh) - 238px);
    border-radius: 28px;
  }

  .chat-top-strip {
    margin-bottom: 10px;
    padding: 10px 12px;
  }

  .health-summary strong {
    margin-top: 0;
    font-size: 16px;
    white-space: nowrap;
  }

  .overlay-pill {
    font-size: 22px;
  }

  .speech-float-item {
    left: 14px;
    bottom: 116px;
    max-width: min(260px, calc(100% - 28px));
  }

  .assistant-speech-overlay {
    right: 14px;
    bottom: 140px;
    max-width: min(58%, 220px);
    padding: 10px 12px;
  }

  .stage-telemetry {
    top: 14px;
    right: 14px;
    width: min(58vw, 210px);
    gap: 8px;
  }

  .stage-telemetry-card {
    padding: 9px 11px;
    border-radius: 14px;
  }

  .stage-telemetry-card strong {
    font-size: 12px;
  }

  .composer-card-floating {
    left: 14px;
    right: 14px;
    width: auto;
    bottom: 82px;
  }

  .stage-actions-floating {
    width: min(220px, calc(100% - 28px));
    bottom: 14px;
  }

  .stage-actions-floating.connected {
    left: 14px;
    right: 14px;
    width: auto;
  }
}

@media (min-width: 768px) {
  .chat-stage-screen {
    min-height: calc(var(--vvh) - 270px);
  }

  .button-row-inline {
    grid-template-columns: 160px;
    justify-content: end;
  }
}

@media (min-width: 980px) {
  .chat-tab-panel.active {
    min-height: calc(var(--vvh) - 184px);
  }

  .chat-stage-screen {
    min-height: calc(var(--vvh) - 280px);
  }

  .chat-top-strip {
    margin-bottom: 14px;
  }

  .composer-card-floating {
    left: 22px;
    right: 22px;
    width: auto;
    bottom: 100px;
  }

  .stage-actions-floating {
    width: 240px;
    bottom: 22px;
  }

  .stage-actions-floating.connected {
    left: 22px;
    right: 22px;
    width: auto;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes speechFloatUp {
  0% {
    opacity: 0;
    transform: translateY(0);
  }

  12% {
    opacity: 1;
    transform: translateY(-8px);
  }

  100% {
    opacity: 0;
    transform: translateY(-92px);
  }
}
