:root {
  color-scheme: dark;
  font-family: "Manrope", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: #080808;
  --glass-bg: rgba(15, 15, 20, 0.6);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-highlight: rgba(255, 255, 255, 0.18);
  --text-primary: rgba(255, 255, 255, 0.95);
  --text-secondary: rgba(255, 255, 255, 0.7);
  --accent: #6d8dff;
  --accent-strong: #8ca9ff;
  --danger: #ff6d8f;
  --warning: #ffd76a;
  --chat-width: min(960px, 92vw);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  /* Deeper night sky gradient base */
  background: linear-gradient(to bottom, #050814 0%, #020205 100%);
  overflow: hidden;
}

/* Main star container */
.background {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  /* Static star layer using repeating gradients for randomness */
  background-image:
    radial-gradient(circle at 15% 18%, rgba(255, 255, 255, 0.7) 0.5px, transparent 1px),
    radial-gradient(circle at 35% 45%, rgba(255, 255, 255, 0.6) 0.5px, transparent 1px),
    radial-gradient(circle at 85% 85%, rgba(255, 255, 255, 0.6) 0.5px, transparent 1px),
    radial-gradient(circle at 55% 25%, rgba(255, 255, 255, 0.5) 1px, transparent 1.5px),
    radial-gradient(circle at 75% 55%, rgba(255, 255, 255, 0.5) 1px, transparent 1.5px),
    radial-gradient(circle at 15% 65%, rgba(255, 255, 255, 0.5) 0.5px, transparent 1px);
  background-size: 500px 500px;
  background-repeat: repeat;
  opacity: 0.8;
}

/* Deep subtle nebulas behind the stars */
.background::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(80, 110, 230, 0.12), transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(120, 90, 220, 0.08), transparent 50%);
  filter: blur(120px);
  z-index: -1;
}

/* Twinkling star layer on top */
.background::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 25% 30%, white 1px, transparent 2px),
    radial-gradient(circle at 80% 20%, white 0.5px, transparent 1px),
    radial-gradient(circle at 40% 75%, white 1px, transparent 2.5px),
    radial-gradient(circle at 70% 90%, white 0.5px, transparent 1px);
  background-size: 600px 600px;
  background-repeat: repeat;
  animation: twinkle 5s ease-in-out infinite alternate;
}

@keyframes twinkle {
  0% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.8; }
  100% { opacity: 0.4; transform: scale(1.02); }
}

.app-shell {
  position: relative;
  display: grid;
  gap: 18px;
  width: var(--chat-width);
  height: min(880px, 92vh);
  grid-template-rows: auto 1fr auto auto;
  z-index: 1;
  padding: 18px;
}

.glass-panel {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(18px) saturate(140%);
  border-radius: 24px;
  box-shadow:
    inset 0 1px 0 var(--glass-highlight),
    0 30px 80px rgba(0, 0, 0, 0.45);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  position: relative;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.model-selector {
  position: relative;
  display: inline-flex;
  width: 192px;
}

.model-trigger {
  appearance: none;
  border: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 0 44px 0 16px;
  height: 38px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  backdrop-filter: blur(14px) saturate(150%);
}

.model-trigger:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(109, 141, 255, 0.15);
}

.model-trigger:not(:disabled):hover {
  border-color: rgba(255, 255, 255, 0.24);
}

.model-selector[data-open="1"] .model-trigger {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(109, 141, 255, 0.15);
}

.model-selector[data-disabled="1"] .model-trigger,
.model-trigger:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.model-trigger-label {
  pointer-events: none;
}

.model-trigger .selector-caret {
  position: absolute;
  right: 16px;
  width: 12px;
  height: 12px;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.2));
  clip-path: polygon(50% 65%, 0 20%, 100% 20%);
  opacity: 0.8;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.model-selector[data-open="1"] .model-trigger .selector-caret {
  transform: rotate(180deg);
  opacity: 1;
}

.model-options {
  list-style: none;
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: 100%;
  margin: 0;
  padding: 8px;
  border-radius: 14px;
  background: rgba(15, 15, 20, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(18px) saturate(160%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 24px 50px rgba(0, 0, 0, 0.55);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px) scale(0.97);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    visibility 0.18s ease;
  z-index: 100;
}

.model-selector[data-open="1"] .model-options {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.model-option {
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.model-option + .model-option {
  margin-top: 6px;
}

.model-option.is-active {
  background: rgba(109, 141, 255, 0.16);
  color: var(--text-primary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.model-option:hover {
  background: rgba(109, 141, 255, 0.28);
  color: var(--text-primary);
}

.model-option:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(109, 141, 255, 0.3);
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 16px;
}

.status-badge {
  min-width: 180px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--warning);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.2s ease, border-color 0.2s ease;
}

.status-badge:not(:empty),
.status-badge[data-loading] {
  opacity: 0.92;
}

.status-badge[data-loading] {
  border-color: rgba(255, 255, 255, 0.24);
}

.status-badge .spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: rgba(255, 255, 255, 0.75);
  animation: spin 0.8s linear infinite;
}

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

.status-disclaimer {
  padding: 12px 20px;
  color: var(--warning);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  background: rgba(20, 18, 8, 0.6);
  border: 1px solid rgba(255, 215, 106, 0.32);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 16px 40px rgba(0, 0, 0, 0.4);
}

.chat-pane {
  position: relative;
  overflow: hidden;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message-list::-webkit-scrollbar {
  width: 6px;
}

.message-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
}

.message {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.message .avatar {
  flex: 0 0 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
}

.message .bubble {
  flex: 1;
  position: relative;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 20px 24px;
  padding-right: 132px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.message.is-pending .bubble {
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.16);
}

.message-controls {
  position: absolute;
  top: 14px;
  right: 16px;
  display: flex;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.message.is-pending .message-controls {
  display: none;
}

.message:hover .message-controls,
.message:focus-within .message-controls {
  opacity: 1;
}

.control-button {
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(11, 14, 22, 0.6);
  color: var(--text-secondary);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-button:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.3);
}

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

.message .sender {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.message .content {
  font-size: 1rem;
  line-height: 1.58;
  color: var(--text-primary);
  white-space: normal;
  word-break: break-word;
}

.message.is-pending .content {
  display: flex;
  align-items: center;
  min-height: 24px;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

.message .content p {
  margin: 0 0 0.8rem;
}

.message .content h1,
.message .content h2,
.message .content h3,
.message .content h4,
.message .content h5,
.message .content h6 {
  margin: 1.2rem 0 0.66rem;
  line-height: 1.25;
}

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

.message .content pre {
  margin: 12px 0;
  padding: 16px;
  border-radius: 14px;
  background: rgba(12, 14, 20, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.05);
  overflow-x: auto;
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
}

.message .content code {
  background: rgba(255, 255, 255, 0.06);
  padding: 0 6px;
  border-radius: 8px;
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
}

.message .content pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}

.message .content a {
  color: var(--accent-strong);
  text-decoration: none;
}

.message .content a:hover {
  text-decoration: underline;
}

.message .content ul,
.message .content ol {
  margin: 12px 0;
  padding-left: 24px;
}

.message .content blockquote {
  margin: 12px 0;
  padding-left: 16px;
  border-left: 3px solid rgba(109, 141, 255, 0.3);
  color: var(--text-secondary);
}

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.35;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.composer {
  padding: 18px 20px;
}

#chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
}

#prompt {
  width: 100%;
  resize: none;
  overflow: hidden;
  font-size: 1rem;
  line-height: 1.5;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(17, 17, 22, 0.6);
  color: var(--text-primary);
  min-height: 48px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#prompt:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: none;
}

button {
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.primary-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 28px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.15), rgba(14, 20, 36, 0.2));
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  backdrop-filter: blur(14px) saturate(160%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 12px 26px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  z-index: 0;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    border-color 0.18s ease;
}

.primary-button::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.4), transparent 55%),
    linear-gradient(135deg, rgba(109, 141, 255, 0.42), rgba(140, 169, 255, 0.18));
  mix-blend-mode: screen;
  opacity: 0.8;
  z-index: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.primary-button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(109, 141, 255, 0.65), rgba(140, 169, 255, 0.2));
  opacity: 0.25;
  z-index: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.primary-button span {
  position: relative;
  z-index: 1;
}

.primary-button:not(:disabled):hover {
  border-color: rgba(109, 141, 255, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 18px 32px rgba(21, 36, 84, 0.55);
}

.primary-button:not(:disabled):hover::after {
  opacity: 0.4;
}

.primary-button:not(:disabled):hover::before {
  opacity: 1;
}

.primary-button:not(:disabled):active {
  transform: scale(0.97);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    0 12px 24px rgba(12, 18, 36, 0.5);
}

.primary-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.ghost-button {
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
}

.ghost-button:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.35);
}

.access-shell {
  position: relative;
  z-index: 1;
  width: min(520px, 94vw);
}

.access-card {
  padding: 32px 36px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
  align-items: stretch;
}

.access-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.access-title {
  margin: 0;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}

.access-subtitle {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.access-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.access-input {
  width: 100%;
  padding: 14px 18px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(16, 17, 26, 0.65);
  color: var(--text-primary);
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.access-input::placeholder {
  color: rgba(255, 255, 255, 0.38);
}

.access-input:focus {
  outline: none;
  border-color: rgba(109, 141, 255, 0.6);
  box-shadow: 0 0 0 4px rgba(109, 141, 255, 0.16);
  background: rgba(18, 20, 32, 0.78);
}

.access-status {
  min-height: 24px;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--text-secondary);
  transition: color 0.2s ease, opacity 0.2s ease;
  opacity: 0.85;
}

.access-status[data-state="success"] {
  color: #8de1c6;
  opacity: 1;
}

.access-status[data-state="error"] {
  color: var(--danger);
  opacity: 1;
}

.access-status[data-state="warning"] {
  color: var(--warning);
  opacity: 1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 768px) {
  .app-shell {
    height: 100vh;
    width: 100vw;
    padding: 16px;
    gap: 14px;
  }

  .app-header,
  .composer {
    padding: 16px;
  }

  .chat-pane {
    padding: 18px;
  }

  .message .bubble {
    padding: 18px 18px;
    padding-right: 108px;
  }

  .control-button {
    font-size: 0.65rem;
    padding: 4px 8px;
  }

  .access-card {
    padding: 28px 26px;
    gap: 16px;
  }

  .access-title {
    font-size: 1.7rem;
  }

  .access-subtitle {
    font-size: 0.92rem;
  }
}

/* Global modal (announcement) */
.site-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
}

.site-modal {
  width: min(92vw, 760px);
  padding: 28px 26px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(15, 15, 20, 0.78);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 30px 80px rgba(0, 0, 0, 0.6);
}

.site-modal-title {
  margin: 0 0 10px;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}

.site-modal-body {
  margin: 0 0 16px;
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text-primary);
}

.site-modal-actions {
  display: flex;
  justify-content: flex-end;
}

.site-modal-close {
  min-width: 120px;
}

