:root {
  color-scheme: dark;
  --bg: #101113;
  --panel: rgba(31, 31, 34, 0.82);
  --panel-solid: #1f1f22;
  --panel-soft: rgba(255, 255, 255, 0.055);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f0ea;
  --muted: #b8aea4;
  --accent: #d98578;
  --accent-2: #7fc2b4;
  --user: #2c3840;
  --assistant: #302624;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.36);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 16%, rgba(127, 194, 180, 0.16), transparent 26%),
    linear-gradient(180deg, rgba(9, 10, 14, 0.28), rgba(9, 10, 14, 0.78)),
    url("assets/starry-sky-bg.png") center / cover fixed,
    var(--bg);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: flex;
  justify-content: center;
  width: min(980px, calc(100vw - 32px));
  max-width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  align-items: stretch;
  overflow-x: hidden;
}

.companion-panel,
.settings-panel {
  border: 1px solid var(--line);
  background: rgba(24, 23, 29, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.companion-panel {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  width: min(860px, 100%);
  min-width: 0;
  min-height: calc(100vh - 64px);
  border-radius: 8px;
  overflow: hidden;
}

.topbar,
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: linear-gradient(145deg, #d98578, #7fc2b4);
  color: #171516;
  font-weight: 800;
  font-size: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-2);
  font-size: 11px;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 20px;
}

.identity-note {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(127, 194, 180, 0.24);
  border-radius: 999px;
  color: #9be0d2;
  background: rgba(127, 194, 180, 0.1);
  font-size: 12px;
  white-space: nowrap;
}

.icon-button,
.voice-button,
.speech-toggle,
.stop-button,
.send-button,
.save-button,
.danger-button,
.quick-prompt {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.icon-button:hover,
.voice-button:hover,
.speech-toggle:hover,
.quick-prompt:hover {
  transform: translateY(-1px);
  border-color: rgba(245, 240, 234, 0.26);
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  font-size: 22px;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  scroll-behavior: smooth;
  scrollbar-color: rgba(217, 133, 120, 0.56) rgba(255, 255, 255, 0.06);
  scrollbar-width: thin;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.08)),
    rgba(12, 12, 17, 0.12);
}

.chat-log::-webkit-scrollbar,
.settings-panel::-webkit-scrollbar {
  width: 9px;
}

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

.chat-log::-webkit-scrollbar-thumb,
.settings-panel::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(217, 133, 120, 0.58);
  background-clip: padding-box;
}

.chat-log::-webkit-scrollbar-thumb:hover,
.settings-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(217, 133, 120, 0.78);
  background-clip: padding-box;
}

.welcome-panel {
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(217, 133, 120, 0.13), rgba(127, 194, 180, 0.12)),
    rgba(255, 255, 255, 0.04);
}

.welcome-panel h2 {
  font-size: 24px;
}

.welcome-panel p {
  max-width: 620px;
  margin: 0;
  color: rgba(245, 240, 234, 0.78);
  line-height: 1.7;
}

.welcome-kicker {
  color: var(--accent-2) !important;
  font-size: 12px;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.quick-prompt {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--text);
  background: rgba(16, 17, 19, 0.34);
}

.message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 100%;
  min-width: 0;
}

.message.user {
  justify-content: flex-end;
  align-items: flex-end;
}

.bubble {
  max-width: min(82%, 560px);
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.72;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.assistant .bubble {
  background: rgba(48, 38, 36, 0.88);
}

.user .bubble {
  background: rgba(44, 56, 64, 0.92);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
  padding: 0 4px;
  color: rgba(245, 240, 234, 0.48);
  font-size: 11px;
  line-height: 1.2;
}

.delete-message-button {
  min-height: 22px;
  padding: 0 7px;
  border-color: rgba(217, 133, 120, 0.28);
  border-radius: 7px;
  color: rgba(245, 240, 234, 0.56);
  font-size: 11px;
  opacity: 1;
  transition: color 0.16s ease, border-color 0.16s ease;
}

.delete-message-button:hover {
  border-color: rgba(217, 133, 120, 0.75);
  color: var(--text);
}

@media (hover: none) {
  .delete-message-button {
    opacity: 1;
  }
}

.image-bubble {
  display: grid;
  gap: 10px;
  max-width: min(86%, 520px);
  min-width: 0;
  overflow: hidden;
}

.image-bubble img {
  display: block;
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.24);
  cursor: zoom-in;
  transition: transform 160ms ease, border-color 160ms ease;
}

.image-bubble img:hover,
.image-bubble img:focus-visible {
  border-color: rgba(127, 194, 180, 0.72);
  outline: none;
  transform: translateY(-1px);
}

.image-bubble p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.artifact-bubble {
  display: grid;
  gap: 10px;
  max-width: min(520px, 100%);
  min-width: 0;
  overflow: hidden;
}

.artifact-bubble strong {
  font-size: 17px;
}

.artifact-bubble span {
  color: var(--muted);
  font-size: 13px;
  word-break: break-all;
}

.artifact-bubble button {
  justify-self: start;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(127, 194, 180, 0.32);
  border-radius: 8px;
  color: var(--text);
  background: rgba(127, 194, 180, 0.16);
  cursor: pointer;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  padding: 20px;
  background: rgba(5, 6, 9, 0.88);
  backdrop-filter: blur(18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.image-viewer.open {
  opacity: 1;
  pointer-events: auto;
}

.image-viewer-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.image-viewer-toolbar .secondary-button {
  width: auto;
  min-width: 112px;
  margin: 0;
  padding: 0 14px;
}

.image-viewer img {
  align-self: center;
  justify-self: center;
  max-width: min(96vw, 1280px);
  max-height: calc(100vh - 100px);
  object-fit: contain;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.56);
}

body.viewer-open {
  overflow: hidden;
}

.attachment-tray {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px 0;
  background: rgba(20, 20, 22, 0.88);
}

.attachment-tray.has-attachments {
  display: flex;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 32px;
  padding: 0 8px 0 10px;
  border: 1px solid rgba(127, 194, 180, 0.28);
  border-radius: 8px;
  color: rgba(245, 240, 234, 0.82);
  background: rgba(127, 194, 180, 0.1);
  font-size: 12px;
}

.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip button {
  min-height: 24px;
  padding: 0 7px;
  border: 1px solid rgba(217, 133, 120, 0.4);
  border-radius: 7px;
  color: var(--text);
  background: rgba(217, 133, 120, 0.16);
  cursor: pointer;
}

.composer {
  display: grid;
  grid-template-columns: 54px 48px 58px 1fr 68px 76px;
  gap: 10px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  background: rgba(20, 20, 22, 0.88);
  min-width: 0;
  overflow-x: hidden;
}

.voice-button {
  position: relative;
  display: grid;
  width: 54px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  overflow: hidden;
}

.speech-toggle {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  font-size: 18px;
}

.upload-button {
  height: 48px;
  border: 1px solid rgba(127, 194, 180, 0.28);
  border-radius: 8px;
  color: var(--text);
  background: rgba(127, 194, 180, 0.12);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.upload-button:hover {
  border-color: rgba(127, 194, 180, 0.62);
  background: rgba(127, 194, 180, 0.2);
}

.stop-button {
  height: 48px;
  border: 1px solid rgba(217, 133, 120, 0.42);
  border-radius: 8px;
  color: #1b1211;
  background: rgba(217, 133, 120, 0.9);
  font-weight: 800;
}

.stop-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  color: rgba(245, 240, 234, 0.5);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
}

.speech-toggle.active {
  border-color: rgba(127, 194, 180, 0.45);
  background: rgba(127, 194, 180, 0.16);
}

.speech-toggle:not(.active) {
  color: rgba(245, 240, 234, 0.52);
  background: rgba(255, 255, 255, 0.045);
}

.voice-ring {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: rgba(127, 194, 180, 0.18);
}

.mic-symbol {
  position: relative;
}

.voice-button.listening .voice-ring {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.28);
    background: rgba(217, 133, 120, 0.28);
  }
}

#messageInput,
.field input,
.field select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

#messageInput {
  height: 48px;
  padding: 0 14px;
}

#messageInput:focus,
.field input:focus,
.field select:focus {
  outline: 2px solid rgba(127, 194, 180, 0.24);
  border-color: rgba(127, 194, 180, 0.48);
}

.send-button,
.save-button,
.danger-button,
.secondary-button {
  height: 48px;
  border-radius: 8px;
  background: var(--accent);
  color: #171516;
  font-weight: 800;
}

.settings-panel {
  position: fixed;
  top: 32px;
  right: 32px;
  bottom: 32px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(400px, calc(100vw - 32px));
  min-height: auto;
  max-height: calc(100vh - 64px);
  border-radius: 8px;
  padding-bottom: 18px;
  overflow-y: auto;
  transform: translateX(calc(100% + 48px));
  opacity: 0;
  pointer-events: none;
  transition:
    transform 220ms ease,
    opacity 180ms ease;
}

.settings-panel.open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.field {
  display: grid;
  gap: 7px;
  padding: 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.field-hint {
  color: rgba(245, 240, 234, 0.68);
  line-height: 1.55;
}

.field-hint a {
  color: var(--accent-2);
}

.field input,
.field select {
  height: 42px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.07);
}

.save-button {
  margin: auto 18px 0;
}

.secondary-button {
  margin: 0 18px;
  border: 1px solid var(--line);
  background: rgba(127, 194, 180, 0.18);
  color: var(--text);
}

.danger-button {
  margin: 0 18px;
  border: 1px solid rgba(217, 133, 120, 0.48);
  background: rgba(217, 133, 120, 0.16);
  color: var(--text);
}

.danger-button:hover {
  border-color: rgba(217, 133, 120, 0.86);
  background: rgba(217, 133, 120, 0.26);
}

.status-text {
  min-height: 22px;
  margin: -6px 18px 0;
  color: rgba(245, 240, 234, 0.76);
  font-size: 13px;
  line-height: 1.55;
}

.status-text.error {
  color: #ffb0a8;
}

.status-text.ok {
  color: #9be0d2;
}

@media (max-width: 820px) {
  .app-shell {
    width: 100%;
    padding: 0;
    min-height: 100dvh;
  }

  .companion-panel {
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .topbar {
    padding: 12px 14px;
  }

  .avatar {
    width: 46px;
    height: 46px;
    font-size: 21px;
  }

  h1 {
    font-size: 24px;
  }

  .chat-log {
    gap: 14px;
    padding: 14px 12px 18px;
  }

  .welcome-panel {
    padding: 14px;
  }

  .settings-panel {
    inset: 0;
    width: auto;
    max-height: none;
    min-height: 100dvh;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 180ms ease;
  }

  .settings-panel.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .bubble {
    max-width: 92%;
  }

  .composer {
    grid-template-columns: 52px 52px 74px minmax(64px, 1fr) 76px;
    grid-template-areas:
      "voice speech upload stop send"
      "input input input input input";
    gap: 8px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    background: rgba(16, 16, 18, 0.96);
  }

  .voice-button {
    grid-area: voice;
    width: 52px;
  }

  .speech-toggle {
    grid-area: speech;
    width: 52px;
  }

  .upload-button {
    grid-area: upload;
  }

  .stop-button {
    grid-area: stop;
  }

  .send-button {
    grid-area: send;
  }

  #messageInput {
    grid-area: input;
    height: 54px;
    padding: 0 16px;
    color: #fffaf4;
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    font-size: 16px;
  }

  #messageInput::placeholder {
    color: rgba(245, 240, 234, 0.58);
  }

  .voice-button,
  .speech-toggle,
  .upload-button,
  .stop-button,
  .send-button {
    height: 48px;
    min-width: 0;
  }
}
