:root {
  --bg: #040912;
  --panel: rgba(10, 16, 30, 0.82);
  --panel-strong: rgba(12, 19, 34, 0.94);
  --line: rgba(102, 185, 255, 0.18);
  --text: #f1f5fb;
  --muted: #95a3b8;
  --accent: #62d0ff;
  --accent-2: #7caeff;
  --accent-3: #345dff;
  --danger: #ff718d;
  --success: #6dffb2;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  overflow: hidden;

  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  background:
    radial-gradient(circle at 20% 20%, rgba(35, 117, 255, 0.16), transparent 32%),
    radial-gradient(circle at 78% 12%, rgba(92, 65, 255, 0.18), transparent 34%),
    radial-gradient(circle at 50% 100%, rgba(0, 210, 255, 0.08), transparent 38%),
    linear-gradient(135deg, #06131f 0%, #090c17 48%, #121536 100%);

  display: grid;
  place-items: center;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  height: min(760px, calc(100dvh - 56px));
  min-height: 0;
  margin: 0 auto;
  padding: 0;

  display: grid;
  grid-template-columns: minmax(320px, 0.98fr) minmax(360px, 1.02fr);
  gap: clamp(16px, 2vw, 24px);
  align-items: stretch;
  overflow: hidden;

  transform: translateY(10px);
}

.stage-card,
.chat-card {
  position: relative;
  width: 100%;
  min-width: 0;
  height: min(760px, calc(100dvh - 84px));
  min-height: 620px;
  max-height: 820px;
  border: 1px solid var(--line);
  border-radius: 0px;
  background: linear-gradient(145deg, rgba(11, 18, 33, 0.84), rgba(4, 8, 17, 0.92));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.stage-card::before,
.chat-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, rgba(255,255,255,0.06), transparent 24%, transparent 70%, rgba(98,208,255,0.08));
}

.stage-card {
  display: flex;
  flex-direction: column;
  padding: clamp(18px, 2.2vw, 26px);
}

.chat-card {
  display: flex;
  flex-direction: column;
  padding: clamp(18px, 2.2vw, 24px);
}

.topbar,
.chat-head {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chat-head {
  flex: 0 0 auto;
  margin-bottom: 8px;
}

.eyebrow {
  color: var(--accent);
  letter-spacing: 0.18em;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 5px 0 0;
  line-height: 1;
}

h1 {
  font-size: clamp(28px, 4vw, 48px);
}

h2 {
  font-size: 30px;
}

.badge {
  border: 1px solid rgba(98,208,255,0.28);
  color: var(--accent);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 800;
  background: rgba(98,208,255,0.08);
  text-transform: uppercase;
}

.badge.warn {
  color: #ffd166;
  border-color: rgba(255,209,102,0.35);
  background: rgba(255,209,102,0.08);
}

.badge.good {
  color: var(--success);
  border-color: rgba(109,255,178,0.35);
  background: rgba(109,255,178,0.08);
}

.hidden-badge {
  display: none;
}

.avatar-wrap,
.avatar-wrap-tall {
  position: relative;
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  margin-top: 0;
  border-radius: 0px;
  overflow: hidden;
  border: 1px solid rgba(98,208,255,0.14);
  background:
    linear-gradient(rgba(98,208,255,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(98,208,255,0.04) 1px, transparent 1px),
    radial-gradient(circle at 50% 35%, rgba(74,165,255,0.16), transparent 36%),
    radial-gradient(circle at 50% 100%, rgba(63, 96, 255, 0.10), transparent 46%),
    #030915;
  background-size: 100% 100%, 42px 42px, 100% 100%, 100% 100%, 100% 100%;
}

#avatarCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.scanline {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.018), rgba(255,255,255,0.018) 1px, transparent 1px, transparent 4px);
  mix-blend-mode: screen;
}

.status-orbit {
  position: absolute;
  left: 50%;
  top: 51%;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(98,208,255,0.12);
  border-radius: 50%;
  pointer-events: none;
}

.status-orbit-a {
  width: 430px;
  height: 430px;
  animation: spin 18s linear infinite;
}

.status-orbit-b {
  width: 520px;
  height: 320px;
  animation: spinReverse 24s linear infinite;
}

body[data-quality="low"] .status-orbit {
  display: none;
}

body[data-quality="low"] .scanline {
  opacity: 0.34;
}

@keyframes spin {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes spinReverse {
  from { transform: translate(-50%, -50%) rotate(360deg); }
  to { transform: translate(-50%, -50%) rotate(0deg); }
}

.app-state,
.meter-row,
.meter,
.voice-select,
#voiceSelect,
#qualitySelect {
  display: none;
}

.meter-row {
  align-items: start;
  grid-template-columns: repeat(3, 1fr);
}

.meter {
  border: 1px solid rgba(98,208,255,0.14);
  border-radius: 18px;
  padding: 14px;
  background: rgba(4, 10, 20, 0.62);
}

.meter span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .14em;
  font-weight: 800;
}

.meter strong {
  display: block;
  margin-top: 5px;
  color: var(--text);
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quality-select {
  width: 100%;
  margin-top: 5px;
  height: 24px;
  border: 1px solid rgba(98,208,255,0.18);
  border-radius: 10px;
  color: var(--text);
  background: rgba(0,0,0,0.28);
  font-weight: 800;
  outline: none;
}

.voice-select {
  margin-top: 7px;
  font-size: 11px;
  height: 25px;
}

.range-input {
  width: 100%;
  margin-top: 8px;
  accent-color: #62d0ff;
}

.mini-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.chat-log {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  min-height: 0;
  margin: 12px 0 14px;
  padding-right: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.chat-log::-webkit-scrollbar {
  width: 8px;
}

.chat-log::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.03);
  border-radius: 999px;
}

.chat-log::-webkit-scrollbar-thumb {
  background: rgba(98,208,255,0.24);
  border-radius: 999px;
}

.msg {
  margin: 0 0 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  animation: messageIn 0.22s ease-out both;
}

.msg.user {
  align-items: flex-end;
}

.msg.user .bubble {
  border-bottom-right-radius: 10px;
}

.msg.assistant .bubble {
  border-bottom-left-radius: 10px;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg.assistant .bubble:empty,
.msg.system .bubble:empty,
.bubble:empty {
  display: none;
}

.bubble {
  max-width: min(88%, 590px);
  border: 1px solid rgba(255,255,255,0.075);
  border-radius: 18px;
  padding: 12px 15px;
  line-height: 1.52;
  color: rgba(245, 249, 255, 0.96);
  background: rgba(255,255,255,0.04);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow:
    0 12px 34px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255,255,255,0.035);
  backdrop-filter: blur(10px);
}

.user .bubble {
  color: rgba(245, 250, 255, 0.98);
  background:
    linear-gradient(135deg, rgba(74,165,255,0.24), rgba(70,111,255,0.22)),
    rgba(15, 34, 68, 0.72);
  border-color: rgba(98,208,255,0.28);
  box-shadow:
    0 14px 36px rgba(32, 92, 190, 0.20),
    inset 0 1px 0 rgba(255,255,255,0.06);
}

.assistant .bubble {
  color: rgba(244, 248, 255, 0.96);
  background:
    linear-gradient(145deg, rgba(8, 14, 27, 0.92), rgba(4, 9, 18, 0.86));
  border-color: rgba(255,255,255,0.07);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255,255,255,0.035);
}

.meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.msg.assistant .meta,
.msg.system .meta {
  display: none;
}

.composer {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 50px;
  gap: 10px;
  align-items: center;
  width: 100%;
}

.composer input {
  min-width: 0;
}

.composer input#messageInput {
  width: 100%;
}

input {
  height: 50px;
  border: 1px solid rgba(98,208,255,0.2);
  background: rgba(0,0,0,0.28);
  border-radius: 16px;
  color: var(--text);
  padding: 0 15px;
  outline: none;
  font-size: 15px;
}

input:focus {
  border-color: rgba(98,208,255,0.55);
  box-shadow: 0 0 0 4px rgba(98,208,255,0.08);
}

button {
  font: inherit;
  cursor: pointer;
}

.circle-btn,
.send-btn,
.ghost-btn {
  border: 1px solid rgba(98,208,255,0.22);
  color: var(--text);
  background: rgba(98,208,255,0.08);
  border-radius: 16px;
  height: 50px;
  font-weight: 800;
}

.circle-btn {
  width: 48px;
  font-size: 19px;
}

.circle-btn.recording {
  background: rgba(255,107,145,0.18);
  border-color: rgba(255,107,145,0.55);
}

.circle-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(98,208,255,0.46);
  background: linear-gradient(135deg, rgba(98,208,255,0.28), rgba(70,111,255,0.34));
  box-shadow:
    0 0 0 1px rgba(98,208,255,0.14) inset,
    0 14px 34px rgba(35, 110, 255, 0.25);
}

.send-btn {
  background: linear-gradient(135deg, rgba(74,165,255,0.22), rgba(70,111,255,0.24));
}

.composer .send-btn {
  width: 50px;
  min-width: 50px;
  white-space: nowrap;
}

.send-icon-btn {
  padding: 0;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  letter-spacing: 0;
  background: linear-gradient(135deg, rgba(74,165,255,0.28), rgba(70,111,255,0.32));
  box-shadow:
    0 0 0 1px rgba(98,208,255,0.10) inset,
    0 10px 28px rgba(35, 110, 255, 0.20);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.send-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
  filter: drop-shadow(0 0 6px rgba(98,208,255,0.28));
}

.send-icon-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(98,208,255,0.46);
  background: linear-gradient(135deg, rgba(98,208,255,0.28), rgba(70,111,255,0.34));
  box-shadow:
    0 0 0 1px rgba(98,208,255,0.14) inset,
    0 14px 34px rgba(35, 110, 255, 0.25);
}

.ghost-btn {
  height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  color: rgba(185, 202, 220, 0.72);
  background: rgba(98,208,255,0.055);
  border-color: rgba(98,208,255,0.18);
  font-size: 13px;
  font-weight: 800;
  opacity: 0.78;
  transition: opacity 0.18s ease, border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.ghost-btn:hover {
  opacity: 1;
  transform: translateY(-1px);
  color: rgba(235, 248, 255, 0.92);
  background: rgba(98,208,255,0.09);
  border-color: rgba(98,208,255,0.34);
}

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

.hint {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  margin-top: 18px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
}

@media (max-width: 980px) {
  .shell {
    width: min(760px, calc(100vw - 24px));
    grid-template-columns: 1fr;
    padding: 18px 0 26px;
  }

  .stage-card,
  .chat-card {
    height: auto;
    min-height: 0;
    max-height: none;
  }

  .avatar-wrap,
  .avatar-wrap-tall {
    height: clamp(360px, 62vw, 580px);
    min-height: 360px;
    flex: 0 0 auto;
  }

  .chat-card {
    min-height: 620px;
    max-height: 78dvh;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100vw - 16px, 520px);
    padding: 10px 0 18px;
    gap: 12px;
  }

  .stage-card,
  .chat-card {
    border-radius: 22px;
    padding: 14px;
  }

  .avatar-wrap,
  .avatar-wrap-tall {
    height: 62dvh;
    min-height: 320px;
  }

  .chat-card {
    min-height: 560px;
    max-height: 82dvh;
  }

  .chat-head h2 {
    font-size: 25px;
  }

  .composer {
	  grid-template-columns: 44px minmax(0, 1fr) 44px;
	  gap: 8px;
	}

	.circle-btn {
	  width: 44px;
	}

	.composer .send-btn {
	  width: 44px;
	  min-width: 44px;
	}

	.send-icon {
	  width: 23px;
	  height: 23px;
	}

  .composer .send-btn {
    width: 68px;
    min-width: 68px;
    font-size: 13px;
  }
}


@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    min-height: 100%;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    display: block;
    place-items: initial;
  }

  .shell {
    width: min(100%, calc(100vw - 20px));
    height: auto;
    min-height: 100svh;
    margin: 0 auto;
    padding: 14px 0 18px;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(620px, 1fr);
    gap: 12px;
    transform: none;
    overflow: visible;
  }

  .stage-card {
    min-height: 150px;
    height: 150px;
    padding: 10px;
  }

  .avatar-wrap,
  .avatar-wrap-tall {
    height: 100%;
    min-height: 0;
  }

  .chat-card {
    min-height: 620px;
    height: calc(100svh - 190px);
    max-height: none;
    padding: 20px 16px 14px;
  }

  .chat-head {
    align-items: flex-start;
  }

  .chat-head h2 {
    font-size: 28px;
  }

  .ghost-btn {
    height: 32px;
    padding: 0 12px;
    font-size: 12px;
  }

  .chat-log {
    min-height: 0;
    overflow-y: auto;
  }

  .composer {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 8px;
  }

  .circle-btn,
  .composer .send-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  .send-icon {
    width: 23px;
    height: 23px;
  }

  .hint {
    font-size: 11px;
  }
}
