:root {
  color-scheme: dark;
  --bg-0: #030416;
  --bg-1: #08153b;
  --bg-2: #24105c;
  --panel: rgba(14, 18, 47, 0.74);
  --panel-strong: rgba(20, 25, 62, 0.92);
  --line: rgba(160, 190, 255, 0.24);
  --line-hot: rgba(252, 206, 87, 0.72);
  --ink: #f4f7ff;
  --muted: #aab7df;
  --cyan: #50e7ff;
  --violet: #9b63ff;
  --magenta: #ff5dd6;
  --yellow: #ffd84d;
  --red: #ff3d68;
  --green: #63f2b3;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.52);
  --mic-level: 0;
  --mic-glow: 14px;
  --mic-inner-glow: 12px;
  --mic-inset-a: 9px;
  --mic-inset-b: 16px;
  --mic-alpha: 0.32;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(132deg, var(--bg-0) 0%, var(--bg-1) 44%, var(--bg-2) 72%, #070622 100%);
  overflow: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  opacity: 0.42;
  background-image:
    radial-gradient(circle, rgba(255, 255, 255, 0.72) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(80, 231, 255, 0.58) 0 1px, transparent 1.6px);
  background-position: 0 0, 38px 64px;
  background-size: 142px 142px, 216px 216px;
  animation: star-drift 26s linear infinite;
}

body::after {
  opacity: 0.2;
  background:
    linear-gradient(90deg, transparent 0 48px, rgba(80, 231, 255, 0.18) 49px, transparent 50px),
    linear-gradient(0deg, transparent 0 48px, rgba(155, 99, 255, 0.14) 49px, transparent 50px);
  background-size: 96px 96px;
  mask-image: linear-gradient(to bottom, transparent, #000 16%, #000 82%, transparent);
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100vh;
  padding: clamp(12px, 2.6vw, 32px);
  display: grid;
  place-items: center;
}

.experience-grid {
  width: min(1360px, 100%);
  height: min(820px, calc(100vh - clamp(24px, 5.2vw, 64px)));
  max-height: calc(100vh - clamp(24px, 5.2vw, 64px));
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(380px, 1.05fr);
  gap: clamp(14px, 2vw, 26px);
  align-items: stretch;
  
}

.robot-panel,
.control-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(150deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.025)),
    var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.robot-panel {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.robot-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(80, 231, 255, 0.08), transparent 38%, rgba(255, 61, 104, 0.05) 72%, transparent),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 8px);
  mix-blend-mode: screen;
  pointer-events: none;
}

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

.status-stack {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 2;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(6, 8, 26, 0.72);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(14px);
}

#statusText {
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.state-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 16px rgba(170, 183, 223, 0.48);
}

.state-dot.live {
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(99, 242, 179, 0.14), 0 0 24px rgba(99, 242, 179, 0.9);
}

.state-dot.busy {
  background: var(--yellow);
  box-shadow: 0 0 0 5px rgba(255, 216, 77, 0.14), 0 0 24px rgba(255, 216, 77, 0.86);
}

.control-panel {
  height: 100%;
  min-height: 0;
  padding: clamp(12px, 1.8vw, 20px);
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  gap: 14px;
  overflow: hidden;
}

.topic-strip {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border: 1px solid rgba(80, 231, 255, 0.24);
  border-radius: 8px;
  color: var(--muted);
  background:
    linear-gradient(90deg, rgba(80, 231, 255, 0.12), rgba(155, 99, 255, 0.08), rgba(255, 216, 77, 0.08));
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.topic-strip span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-strip span:last-child {
  flex: 0 0 auto;
  color: #10121f;
  padding: 5px 8px;
  border-radius: 7px;
  background: var(--yellow);
}

.emotion-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.emotion-button,
.primary-button,
.ghost-button,
.replay-button {
  appearance: none;
  border: 1px solid rgba(160, 190, 255, 0.24);
  color: var(--ink);
  background: rgba(9, 13, 38, 0.66);
  cursor: pointer;
  transition: transform 170ms ease, border-color 170ms ease, background 170ms ease, box-shadow 170ms ease;
}

.emotion-button {
  min-width: 0;
  min-height: 54px;
  padding: 8px 6px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 800;
}

.emotion-button:hover,
.primary-button:hover,
.ghost-button:hover,
.replay-button:hover {
  transform: translateY(-1px);
  border-color: rgba(80, 231, 255, 0.72);
  box-shadow: 0 12px 34px rgba(80, 231, 255, 0.15);
}

.emotion-button:active,
.primary-button:active,
.ghost-button:active,
.replay-button:active {
  transform: translateY(0);
}

.emotion-button.is-active {
  border-color: var(--line-hot);
  background:
    linear-gradient(145deg, rgba(255, 216, 77, 0.18), rgba(155, 99, 255, 0.18)),
    rgba(9, 13, 38, 0.88);
  box-shadow: inset 0 0 28px rgba(255, 216, 77, 0.11), 0 14px 36px rgba(155, 99, 255, 0.18);
}

.emotion-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  box-shadow: 0 0 18px currentColor;
}

.emotion-dot.neutral {
  color: var(--cyan);
  background: var(--cyan);
}

.emotion-dot.happy {
  color: var(--yellow);
  background: var(--yellow);
}

.emotion-dot.curious {
  color: var(--magenta);
  background: var(--magenta);
}

.emotion-dot.serious {
  color: var(--red);
  background: var(--red);
}

.emotion-dot.surprised {
  color: #ffffff;
  background: #ffffff;
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.primary-button,
.ghost-button {
  min-width: 0;
  min-height: 48px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  font-weight: 900;
}

.primary-button {
  color: #04111e;
  border-color: rgba(255, 255, 255, 0.5);
  background: linear-gradient(135deg, var(--cyan), #9dffef 52%, var(--yellow));
}

.ghost-button.warning {
  border-color: rgba(255, 216, 77, 0.42);
  background: linear-gradient(145deg, rgba(255, 216, 77, 0.16), rgba(9, 13, 38, 0.78));
}

.ghost-button.danger {
  border-color: rgba(255, 61, 104, 0.46);
  background: linear-gradient(145deg, rgba(255, 61, 104, 0.15), rgba(9, 13, 38, 0.78));
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

.button-icon {
  width: 18px;
  display: inline-grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
}

.access-panel {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(92px, auto) minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(160, 190, 255, 0.22);
  border-radius: 8px;
  background: rgba(5, 9, 29, 0.52);
}

.access-panel[hidden] {
  display: none;
}

.access-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.access-input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(160, 190, 255, 0.3);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(3, 4, 22, 0.72);
  outline: none;
  font: inherit;
  font-size: 14px;
}

.access-input:focus {
  border-color: rgba(80, 231, 255, 0.76);
  box-shadow: 0 0 0 3px rgba(80, 231, 255, 0.14);
}

.access-button,
.access-logout {
  min-height: 42px;
  padding: 0 10px;
}

.access-message {
  grid-column: 2 / -1;
  min-height: 16px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
}

.access-message[data-state="ok"] {
  color: var(--green);
}

.access-message[data-state="error"] {
  color: var(--red);
}

.chat-log {
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  padding: 12px;
  border: 1px solid rgba(160, 190, 255, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(5, 9, 29, 0.78), rgba(12, 15, 45, 0.88)),
    repeating-linear-gradient(90deg, rgba(80, 231, 255, 0.03) 0 1px, transparent 1px 36px);
  scroll-behavior: smooth;
}

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

.chat-log::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.04);
}

.chat-log::-webkit-scrollbar-thumb {
  background: linear-gradient(var(--cyan), var(--violet));
  border-radius: 8px;
}

.message {
  width: min(720px, 96%);
  margin: 0 0 12px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: message-enter 360ms cubic-bezier(0.2, 0.85, 0.22, 1.15) both;
}

.message:last-child {
  margin-bottom: 0;
}

.message.user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.message.bot,
.message.system {
  margin-right: auto;
}

.avatar {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  color: var(--cyan);
  background: rgba(10, 16, 44, 0.9);
  box-shadow: 0 0 28px rgba(80, 231, 255, 0.18);
}

.message.user .avatar {
  color: var(--yellow);
  box-shadow: 0 0 28px rgba(255, 216, 77, 0.16);
}

.message.system .avatar {
  color: var(--red);
}

.avatar svg,
.replay-button svg {
  width: 20px;
  height: 20px;
  display: block;
}

.message-shell {
  min-width: 0;
  padding: 11px 13px;
  border: 1px solid rgba(160, 190, 255, 0.18);
  border-radius: 8px;
  line-height: 1.45;
  background:
    linear-gradient(145deg, rgba(80, 231, 255, 0.13), rgba(155, 99, 255, 0.08)),
    rgba(12, 17, 48, 0.88);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.24);
}

.message.user .message-shell {
  border-color: rgba(255, 216, 77, 0.26);
  background:
    linear-gradient(145deg, rgba(255, 216, 77, 0.14), rgba(255, 93, 214, 0.08)),
    rgba(18, 17, 48, 0.9);
}

.message.system .message-shell {
  border-color: rgba(255, 61, 104, 0.24);
  color: var(--muted);
  background:
    linear-gradient(145deg, rgba(255, 61, 104, 0.11), rgba(80, 231, 255, 0.06)),
    rgba(12, 17, 48, 0.82);
}

.message-meta {
  min-height: 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.message-title {
  min-width: 0;
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
}

.message strong {
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.openai-metrics {
  color: rgba(244, 247, 255, 0.72);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.message-text {
  display: block;
  overflow-wrap: anywhere;
}

.replay-button {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  display: none;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  color: var(--yellow);
  background: rgba(255, 216, 77, 0.12);
}

body.replay-mode .message.bot.has-audio .replay-button {
  display: inline-grid;
}

.mic-orb {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 5;
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(80, 231, 255, 0.34);
  border-radius: 50%;
  color: var(--ink);
  background:
    linear-gradient(145deg, rgba(80, 231, 255, 0.18), rgba(155, 99, 255, 0.22)),
    rgba(5, 9, 29, 0.9);
  box-shadow:
    0 0 var(--mic-glow) rgba(80, 231, 255, 0.44),
    inset 0 0 var(--mic-inner-glow) rgba(255, 255, 255, 0.08);
}

.mic-orb::before,
.mic-orb::after {
  content: "";
  position: absolute;
  inset: var(--mic-inset-a);
  border: 1px solid rgba(255, 216, 77, 0.3);
  border-radius: 50%;
  opacity: var(--mic-alpha);
}

.mic-orb::after {
  inset: var(--mic-inset-b);
  border-color: rgba(255, 61, 104, 0.3);
}

.mic-icon {
  position: relative;
  width: 12px;
  height: 20px;
  border: 2px solid currentColor;
  border-radius: 8px;
}

.mic-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 18px;
  height: 9px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 9px 9px;
  transform: translateX(-50%);
}

.mic-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -15px;
  width: 2px;
  height: 8px;
  background: currentColor;
  transform: translateX(-50%);
}

#botVoice {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@keyframes star-drift {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(-142px, 142px, 0);
  }
}

@keyframes message-enter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.985);
    filter: blur(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@media (max-width: 940px) {
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app-shell {
    place-items: start center;
  }

  .experience-grid {
    height: auto;
    max-height: none;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .robot-panel {
    height: min(72vh, 560px);
    min-height: min(72vh, 560px);
  }

  .control-panel {
    height: min(620px, calc(100vh - 20px));
    min-height: 520px;
  }
}

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

  .robot-panel {
    height: 420px;
    min-height: 420px;
  }

  .control-panel {
    height: min(620px, calc(100vh - 20px));
    padding: 10px;
    grid-template-rows: auto auto auto auto minmax(300px, 1fr);
  }

  .emotion-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .access-panel {
    grid-template-columns: 1fr;
  }

  .access-message {
    grid-column: 1;
  }

  .message {
    width: 100%;
  }

  .avatar {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
  }

  .mic-orb {
    right: 10px;
    bottom: 10px;
  }
}
