:root {
  color-scheme: dark;
  --bg: #050912;
  --ink: #f5f3ef;
  --muted: #98a3b6;
  --panel: #0c1320;
  --panel-strong: #182236;
  --line: #202b3c;
  --accent: #efff4a;
  --accent-strong: #f4ff82;
  --warn: #ef6a50;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

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

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  height: 100dvh;
  min-height: 0;
  padding: 28px;
  overflow: hidden;
}

.settings-button {
  position: fixed;
  z-index: 30;
  top: 22px;
  right: 22px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--accent-strong);
  cursor: pointer;
}

.settings-button:hover,
.settings-button:focus-visible {
  outline: 0;
  border-color: var(--accent);
  background: var(--panel-strong);
}

.settings-glyph {
  position: relative;
  width: 22px;
  height: 16px;
  background:
    linear-gradient(currentColor, currentColor) 0 2px / 22px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 0 7px / 22px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 0 12px / 22px 2px no-repeat;
}

.settings-glyph::before,
.settings-glyph::after {
  position: absolute;
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.settings-glyph::before {
  top: 0;
  left: 4px;
}

.settings-glyph::after {
  right: 5px;
  bottom: 2px;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 36px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
}

.avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(360px, 42vw, 500px);
  aspect-ratio: 1;
  margin-block: -16px 8px;
}

.avatar-ring {
  position: absolute;
  inset: 2%;
  border: 1px solid rgba(239, 255, 74, 0.28);
  border-radius: 50%;
  background: var(--panel);
}

.avatar-core {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  width: 82%;
  aspect-ratio: 1;
  border: 2px solid rgba(239, 255, 74, 0.35);
  border-radius: 50%;
  background: var(--panel-strong);
  box-shadow: none;
}

.avatar-core img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.avatar-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.avatar.model-loaded .avatar-canvas {
  opacity: 1;
}

.avatar.model-loaded {
  width: clamp(360px, 42vw, 500px);
  margin-block: -16px 8px;
}

.avatar.model-loaded .voice-glow {
  display: none;
}

.avatar.model-loaded .avatar-core {
  overflow: hidden;
  width: 82%;
  border: 2px solid rgba(239, 255, 74, 0.35);
  border-radius: 50%;
  background: var(--panel-strong);
  box-shadow: none;
}

.avatar.model-loaded .avatar-fallback {
  opacity: 0;
}

.avatar-fallback {
  transition: opacity 0.35s ease;
}

.avatar-shine {
  display: none;
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 22%, rgba(255, 255, 255, 0.4), transparent 26%),
    linear-gradient(155deg, rgba(255, 255, 255, 0.28), transparent 42%);
  pointer-events: none;
}

.voice-glow {
  position: absolute;
  inset: auto 28% 13% 28%;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 250, 243, 0.82);
  box-shadow:
    0 0 18px rgba(255, 250, 243, 0.7),
    0 0 34px rgba(14, 107, 93, 0.42);
  opacity: 0;
  transform: translateY(8px) scaleX(0.72);
}

.avatar.speaking .avatar-ring {
  animation: pulse 1.2s ease-in-out infinite;
}

.avatar.speaking .avatar-core {
  animation: avatarTalk 1.08s ease-in-out infinite;
}

.avatar.model-loaded.speaking .avatar-core {
  animation: none;
}

.avatar.model-loaded.speaking .avatar-ring {
  animation: idleSpin 10s linear infinite;
}

.avatar.speaking .voice-glow {
  animation: voiceGlow 0.56s ease-in-out infinite;
}

.status-line {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
  color: var(--muted);
  font-size: 0.95rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: none;
}

.dot.ready {
  background: var(--accent);
  box-shadow: none;
}

.conversation {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 860px);
  min-height: 72px;
  margin: 26px 0;
  padding-right: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.message {
  max-width: 82%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  color: #090d12;
  border-color: transparent;
  background: var(--accent);
}

.message.assistant {
  align-self: flex-start;
  background: var(--panel);
}

.composer {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 10px;
  width: min(100%, 860px);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.icon-button,
.send-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  display: grid;
  place-items: center;
  background: var(--panel-strong);
}

.icon-button[aria-pressed="true"] {
  background: #36442a;
}

.mic-icon {
  width: 18px;
  height: 26px;
  border: 2px solid var(--accent-strong);
  border-radius: 14px;
  position: relative;
}

.mic-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 18px;
  height: 10px;
  border-bottom: 2px solid var(--accent-strong);
  border-left: 2px solid var(--accent-strong);
  border-right: 2px solid var(--accent-strong);
  border-radius: 0 0 12px 12px;
  transform: translateX(-50%);
}

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

.send-button {
  padding-inline: 18px;
  color: #090d12;
  background: var(--accent);
}

.send-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.composer textarea {
  min-height: 44px;
  max-height: 160px;
  padding: 11px 12px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
}

.control-panel {
  display: none;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  position: fixed;
  z-index: 25;
  top: 78px;
  right: 28px;
  bottom: 28px;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 106px);
  overflow-y: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.app-shell.settings-open .control-panel {
  display: flex;
}

.panel-block {
  display: grid;
  gap: 8px;
}

.panel-block label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.panel-block input,
.panel-block select,
.panel-block textarea {
  padding: 10px 12px;
}

.panel-block textarea {
  resize: vertical;
  line-height: 1.45;
}

.personality-save-button {
  min-height: 42px;
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #090d12;
  cursor: pointer;
}

.personality-save-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.personality-save-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.personality-save-status {
  min-height: 2.8em;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.panel-row {
  display: flex;
  align-items: center;
  min-height: 36px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

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

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.92;
  }

  50% {
    transform: scale(1.04);
    opacity: 1;
  }
}

@keyframes avatarTalk {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(-2px) scale(1.015);
  }
}

@keyframes voiceGlow {
  0%,
  100% {
    opacity: 0.3;
    transform: translateY(8px) scaleX(0.72);
  }

  50% {
    opacity: 1;
    transform: translateY(3px) scaleX(1);
  }
}

@media (max-width: 960px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100dvh;
    padding: 16px;
    overflow: visible;
  }

  .stage {
    height: calc(100dvh - 32px);
    padding: 22px;
  }

  .control-panel {
    order: -1;
  }

  .avatar {
    width: clamp(230px, 54vw, 340px);
  }
}

@media (max-width: 560px) {
  .avatar {
    width: min(78vw, 310px);
  }

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

  .mic-button {
    min-height: 56px;
  }

  .mic-icon {
    width: 22px;
    height: 30px;
  }

  .mic-icon::before {
    width: 22px;
    height: 12px;
  }

  .send-button {
    grid-column: auto;
    min-height: 40px;
    padding-inline: 10px;
    font-size: 0.88rem;
  }

  .message {
    max-width: 100%;
  }
}

html[data-view="embed"] #webSearchButton {
  display: none !important;
}

html[data-view="embed"] body {
  overflow: hidden;
  min-height: 0;
}

html[data-view="embed"] .app-shell {
  height: 100dvh;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

html[data-view="embed"] .stage {
  height: 100%;
  padding: 14px;
  border-radius: 0;
}

html[data-view="embed"] .avatar,
html[data-view="embed"] .avatar.model-loaded {
  flex: 0 0 auto;
  width: 140px;
  margin: 0 0 6px;
}

html[data-view="embed"] .status-line {
  flex: 0 0 auto;
  min-height: 20px;
  font-size: 0.76rem;
}

html[data-view="embed"] .conversation {
  width: 100%;
  min-height: 0;
  margin: 12px 0;
  gap: 8px;
}

html[data-view="embed"] .message {
  max-width: 94%;
  padding: 10px 12px;
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

html[data-view="embed"] .composer {
  grid-template-columns: 56px minmax(0, 1fr) 54px;
  width: 100%;
  gap: 6px;
  padding: 7px;
}

html[data-view="embed"] .mic-button {
  min-height: 54px;
}

html[data-view="embed"] .send-button {
  min-height: 40px;
  padding-inline: 4px;
  font-size: 0.78rem;
}

html[data-view="embed"] .composer textarea {
  align-self: center;
  max-height: 80px;
  padding: 10px 5px;
  font-size: 0.88rem;
}

html:not([data-view="admin"]) .settings-button,
html:not([data-view="admin"]) .control-panel {
  display: none !important;
}

@media (max-height: 450px) {
  html[data-view="embed"] .avatar,
  html[data-view="embed"] .avatar.model-loaded {
    width: 84px;
  }
}

.panel-help {
  margin: 0;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.admin-section { border-block: 1px solid var(--line); padding-block: 16px; }
.admin-section summary { cursor: pointer; font-weight: 700; margin-bottom: 12px; }
.admin-section > * + * { margin-top: 12px; }
.knowledge-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.knowledge-actions button, .knowledge-upload button {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-strong); color: var(--ink); cursor: pointer; font-size: .8rem;
}
.knowledge-actions button:hover, .knowledge-upload button:hover { border-color: var(--accent); }
.knowledge-list { display: grid; gap: 10px; }
.knowledge-source { padding: 12px; border: 1px solid var(--line); border-radius: 6px; overflow-wrap: anywhere; }
.knowledge-source > * + * { margin-top: 8px; }
.knowledge-source strong { display: block; font-size: .88rem; }
.knowledge-upload { padding-top: 12px; border-top: 1px solid var(--line); }
.control-panel button:disabled { opacity: .5; cursor: not-allowed; }
.web-search-button {
  grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-strong); color: var(--ink); cursor: pointer; padding: 8px 14px;
  font-size: .85rem;
}
.web-search-button:hover, .web-search-button:focus-visible { border-color: var(--accent); }
.web-search-button:disabled { opacity: .5; cursor: not-allowed; }
.web-search-message::before { content: 'Internet'; display: block; color: #263000; font-weight: 700; font-size: .7rem; margin-bottom: 4px; }
.web-sources { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); font-size: .78rem; line-height: 1.5; }
.web-sources p { margin: 0 0 6px; color: var(--muted); }
.web-sources a, #webSearchesList a { display: block; overflow-wrap: anywhere; margin-top: 6px; }
.message a, #webSearchesList a { color: var(--accent-strong); }
