:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: rgba(18, 18, 18, 0.82);
  --panel-strong: rgba(26, 26, 26, 0.94);
  --text: #f3f0ea;
  --muted: #9d9890;
  --faint: #5e5a54;
  --line: rgba(255, 255, 255, 0.09);
  --accent: #ff6a00;
  --accent-soft: rgba(255, 106, 0, 0.2);
  --danger: #ff4d4d;
  --pointer-x: 50%;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, #070707 0%, #050505 58%, #090603 100%);
  color: var(--text);
  font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: auto 0 0;
  height: 40vh;
  pointer-events: none;
  background:
    radial-gradient(70% 80% at var(--pointer-x) 100%, rgba(255, 106, 0, 0.34), transparent 68%),
    linear-gradient(180deg, transparent, rgba(255, 106, 0, 0.1));
  filter: blur(28px);
  opacity: 0.82;
  transition: background 900ms ease, opacity 600ms ease;
  transform: translateZ(0);
}

body.listening::before {
  opacity: 1;
  background:
    radial-gradient(72% 82% at var(--pointer-x) 100%, rgba(255, 106, 0, 0.52), transparent 70%),
    linear-gradient(180deg, transparent, rgba(255, 106, 0, 0.16));
}

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

button,
select {
  border: 0;
}

button {
  cursor: pointer;
}

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

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
p {
  margin: 0;
}

.topbar {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 72px;
  padding: 16px max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(5, 5, 5, 0.72);
  backdrop-filter: blur(18px);
}

.topbar h1 {
  font-size: 17px;
  font-weight: 700;
}

#status {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

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

.ghost,
.icon-button,
.send,
.queue-controls button {
  min-height: 40px;
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  transition: transform 180ms ease, background 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.ghost {
  display: inline-grid;
  place-items: center;
  padding: 0 14px;
  font-size: 13px;
}

.ghost:hover,
.icon-button:hover,
.queue-controls button:hover {
  background: rgba(255, 255, 255, 0.13);
}

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  height: 100vh;
  padding: 76px 20px 92px;
}

.thread {
  display: grid;
  min-height: 0;
}

.messages {
  width: min(100%, 860px);
  margin: 0 auto;
  overflow-y: auto;
  padding: 24px 0 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.message {
  width: fit-content;
  max-width: min(680px, 88%);
  margin: 0 0 18px;
  animation: message-in 220ms ease-out;
}

.message.user {
  margin-left: auto;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.18);
}

.message.user .message-text {
  color: #17110a;
  border-color: rgba(255, 106, 0, 0.36);
  background: linear-gradient(180deg, #ff7a14, var(--accent));
}

.message.assistant .message-text,
.message.pending .message-text {
  background: rgba(255, 255, 255, 0.055);
}

.message.pending .message-text {
  color: var(--muted);
}

.message.error .message-text {
  color: #ffd4d4;
  border-color: rgba(255, 77, 77, 0.3);
  background: rgba(255, 77, 77, 0.1);
}

.message-meta {
  margin-top: 7px;
  padding: 0 4px;
  color: var(--faint);
  font-size: 12px;
}

.composer {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 118px 52px 58px;
  align-items: center;
  gap: 8px;
  width: min(calc(100% - 32px), 880px);
  min-height: 72px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 26px;
  background: rgba(18, 18, 18, 0.82);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.48), 0 0 0 1px rgba(255, 106, 0, 0.06);
  backdrop-filter: blur(22px);
  transform: translateX(-50%);
}

#message {
  min-height: 48px;
  max-height: 160px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 13px 2px 11px;
  color: var(--text);
  background: transparent;
}

#message::placeholder {
  color: var(--faint);
}

#reasoning {
  height: 52px;
  min-width: 0;
  padding: 0 36px 0 22px;
  border-radius: 999px;
  color: var(--muted);
  outline: 0;
  appearance: none;
  background: rgba(255, 255, 255, 0.07);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 23px) 50%,
    calc(100% - 16px) 50%;
  background-size: 7px 7px, 7px 7px;
  background-repeat: no-repeat;
}

.icon-button,
.send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

#attach {
  font-size: 28px;
  font-weight: 300;
  padding-bottom: 2px;
}

.voice {
  color: #160b03;
  background: var(--accent);
  box-shadow: 0 0 28px rgba(255, 106, 0, 0.28);
}

body.listening .voice {
  animation: pulse 1.25s ease-in-out infinite;
}

.send {
  width: 58px;
  height: 58px;
  padding-bottom: 4px;
  font-size: 25px;
  color: #160b03;
  background: var(--accent);
}

.send:hover,
.voice:hover {
  background: #ff7d1f;
  transform: translateY(-1px);
}

.queue-panel {
  position: fixed;
  z-index: 40;
  top: 88px;
  right: 18px;
  bottom: 104px;
  width: min(420px, calc(100vw - 36px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(14, 14, 14, 0.92);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.54);
  backdrop-filter: blur(22px);
  transform: translateX(calc(100% + 32px));
  transition: transform 260ms ease;
}

.queue-panel.open {
  transform: translateX(0);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
}

.panel-head h2 {
  font-size: 15px;
}

.queue {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  padding-right: 2px;
}

.queue-item {
  display: grid;
  gap: 7px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.055);
}

.queue-item strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.queue-item span,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.queue-controls {
  display: flex;
  gap: 8px;
}

.queue-controls button {
  padding: 0 14px;
}

.queue-controls .secondary {
  color: var(--muted);
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--line);
}

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 86px);
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(18, 18, 18, 0.9);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.login-panel {
  width: min(100%, 380px);
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(18, 18, 18, 0.84);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(22px);
}

.login-panel form {
  display: grid;
  gap: 12px;
}

.login-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-panel input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.login-panel button {
  min-height: 44px;
  border-radius: 999px;
  color: #160b03;
  background: var(--accent);
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 28px rgba(255, 106, 0, 0.28);
  }
  50% {
    box-shadow: 0 0 44px rgba(255, 106, 0, 0.66);
  }
}

@media (max-width: 720px) {
  body {
    overflow: hidden;
  }

  .topbar {
    height: 64px;
    padding-top: 12px;
  }

  .shell {
    padding: 70px 14px 104px;
  }

  .messages {
    padding-top: 14px;
  }

  .message {
    max-width: 92%;
  }

  .composer {
    grid-template-columns: 46px minmax(0, 1fr) 46px 50px;
    width: calc(100% - 20px);
    min-height: 66px;
    border-radius: 24px;
  }

  #reasoning {
    position: absolute;
    right: 94px;
    bottom: calc(100% + 8px);
    width: 82px;
    height: 34px;
    padding: 0 28px 0 14px;
    font-size: 12px;
    background-position:
      calc(100% - 18px) 50%,
      calc(100% - 12px) 50%;
    background-size: 6px 6px, 6px 6px;
    background-color: rgba(18, 18, 18, 0.92);
  }

  .icon-button {
    width: 46px;
    height: 46px;
  }

  .send {
    width: 50px;
    height: 50px;
  }

  .queue-panel {
    inset: 76px 10px 102px;
    width: auto;
  }

  .logout {
    display: none;
  }
}
