:root {
  --bg-1: #09040a;
  --bg-2: #170815;
  --bg-3: #2a1020;
  --panel: rgba(13, 15, 22, 0.72);
  --panel-strong: rgba(16, 18, 28, 0.9);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f8f1ec;
  --muted: #beafb8;
  --accent: #ff8f70;
  --accent-2: #ff4d8d;
  --accent-3: #ffd6b3;
  --shadow: 0 30px 100px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(255, 125, 101, 0.22), transparent 24%),
    radial-gradient(circle at 80% 0%, rgba(255, 78, 141, 0.18), transparent 28%),
    radial-gradient(circle at 50% 100%, rgba(108, 52, 153, 0.18), transparent 30%),
    linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 42%, var(--bg-3) 100%);
  color: var(--text);
  font-family: "Manrope", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.35;
  transition: opacity 180ms ease;
}

.ambient {
  position: fixed;
  border-radius: 999px;
  filter: blur(70px);
  pointer-events: none;
  opacity: 0.42;
  transition: opacity 180ms ease;
}

.ambient-a {
  top: -10rem;
  left: -8rem;
  width: 25rem;
  height: 25rem;
  background: rgba(255, 143, 112, 0.25);
}

.ambient-b {
  top: 8rem;
  right: -12rem;
  width: 30rem;
  height: 30rem;
  background: rgba(255, 77, 141, 0.18);
}

.ambient-c {
  bottom: -12rem;
  left: 25%;
  width: 28rem;
  height: 28rem;
  background: rgba(167, 90, 255, 0.16);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0;
  transition: width 180ms ease, padding 180ms ease;
}

.intro-screen,
.chat-screen {
  min-height: calc(100vh - 2rem);
}

.intro-screen {
  display: grid;
  place-items: center;
}

.intro-frame,
.chat-sidebar,
.chat-main {
  backdrop-filter: blur(28px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.intro-frame {
  width: min(780px, 100%);
  padding: 4rem 2rem;
  text-align: center;
  border-radius: 36px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    rgba(18, 16, 23, 0.7);
  animation: rise 700ms ease-out both;
}

.kicker,
.chat-label {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.intro-frame h1,
.chat-sidebar h2,
.chat-header h3 {
  margin: 0;
}

.intro-frame h1 {
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(4.8rem, 14vw, 9.5rem);
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 0.9;
  text-shadow: 0 12px 40px rgba(255, 93, 129, 0.25);
}

.intro-copy,
.sidebar-copy {
  width: min(34rem, 100%);
  margin: 1.2rem auto 0;
  color: var(--muted);
  line-height: 1.8;
}

.primary-button,
.secondary-button,
.chat-form button {
  border: 0;
  cursor: pointer;
  transition:
    transform 180ms ease,
    opacity 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
}

.primary-button {
  margin-top: 2rem;
  min-width: 12rem;
  padding: 1rem 2rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff8f3;
  font: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  box-shadow: 0 24px 60px rgba(255, 77, 141, 0.28);
}

.primary-button:hover,
.secondary-button:hover,
.chat-form button:hover,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.chat-form button:focus-visible {
  transform: translateY(-2px);
}

.primary-button:disabled,
.secondary-button:disabled,
.chat-form button:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

.status-text {
  min-height: 1.5rem;
  margin: 1rem 0 0;
  color: var(--accent-3);
}

.chat-screen {
  display: none;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 1rem;
}

body.mode-chat .intro-screen {
  display: none;
}

body.mode-chat .chat-screen {
  display: grid;
  animation: fade-in 400ms ease-out both;
}

body.immersive-active .ambient,
body.immersive-active::before {
  opacity: 0;
}

body.immersive-active .app-shell {
  width: 100%;
  padding: 0;
}

body.immersive-active .chat-screen {
  grid-template-columns: 1fr;
  gap: 0;
  min-height: 100vh;
}

body.immersive-active .chat-sidebar {
  display: none;
}

body.immersive-active .chat-main {
  min-height: 100vh;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
}

.chat-sidebar {
  padding: 2rem;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    rgba(12, 13, 19, 0.78);
}

.chat-sidebar h2 {
  font-family: "Cormorant Garamond", serif;
  font-size: 3.4rem;
  line-height: 0.95;
}

.secondary-button {
  margin-top: 2rem;
  width: 100%;
  padding: 0.95rem 1.2rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1rem;
  min-height: calc(100vh - 2rem);
  padding: 1rem;
  border-radius: 28px;
  background:
    radial-gradient(circle at top right, rgba(255, 143, 112, 0.1), transparent 24%),
    rgba(10, 11, 17, 0.78);
}

.chat-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.4rem;
}

.chat-header h3 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 700;
}

.chat-status {
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--accent-3);
  font-size: 0.9rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.fullscreen-button {
  margin-top: 0;
  width: auto;
  min-width: 5.2rem;
  padding: 0.7rem 1rem;
  border-radius: 999px;
}

.message-list {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 0.85rem;
  padding: 0.25rem;
}

.message {
  max-width: min(44rem, 100%);
  padding: 1rem 1.1rem;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
  animation: rise 240ms ease-out both;
}

.message.user {
  justify-self: end;
  background: linear-gradient(135deg, rgba(255, 143, 112, 0.22), rgba(255, 77, 141, 0.16));
  border-color: rgba(255, 143, 112, 0.22);
}

.message.assistant {
  justify-self: start;
  background: rgba(255, 255, 255, 0.04);
}

.message-meta {
  margin-bottom: 0.45rem;
  color: var(--accent-3);
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.message-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.1rem 0 0.7rem;
}

.tool-chip {
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--accent-3);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message-body {
  line-height: 1.75;
}

.message-body > :first-child {
  margin-top: 0;
}

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

.message-body p,
.message-body ul,
.message-body ol,
.message-body blockquote {
  margin: 0 0 0.9rem;
}

.message-body ul,
.message-body ol {
  padding-left: 1.3rem;
}

.message-body li + li {
  margin-top: 0.3rem;
}

.message-body a {
  color: var(--accent-3);
}

.message-body blockquote {
  padding-left: 1rem;
  border-left: 2px solid rgba(255, 214, 179, 0.36);
  color: var(--muted);
}

.message-body pre {
  overflow: auto;
  margin: 0 0 0.9rem;
  padding: 0.95rem 1rem;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(0, 0, 0, 0.3);
}

.message-body code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.92em;
}

.message-body :not(pre) > code {
  padding: 0.15rem 0.35rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.message-body table {
  width: 100%;
  margin: 0 0 1rem;
  border-collapse: collapse;
}

.message-body th,
.message-body td {
  padding: 0.65rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}

.message-body .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.2rem 0;
}

.message-image {
  display: block;
  max-width: min(18rem, 100%);
  margin: 0 0 0.8rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.8rem;
}

.composer {
  display: grid;
  gap: 0.65rem;
}

.chat-form textarea {
  min-height: 4rem;
  max-height: 12rem;
  resize: none;
  padding: 1.05rem 1.1rem;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--panel-strong);
  color: var(--text);
  font: inherit;
  outline: none;
}

.chat-form textarea:focus {
  border-color: rgba(255, 143, 112, 0.6);
  box-shadow: 0 0 0 4px rgba(255, 143, 112, 0.12);
}

.composer-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.7rem;
  align-content: end;
}

.chat-form button,
.upload-button {
  padding: 0 1.4rem;
  min-height: 3.6rem;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff8f3;
  font: inherit;
  font-weight: 700;
  border: 0;
  display: grid;
  place-items: center;
  text-align: center;
  cursor: pointer;
}

.upload-button {
  background: rgba(255, 255, 255, 0.08);
}

.upload-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.preview-card {
  position: relative;
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
}

.preview-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-remove {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  width: 1.4rem;
  height: 1.4rem;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  cursor: pointer;
}

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

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 1rem, 100%);
    padding: 0.5rem 0;
  }

  .intro-screen,
  .chat-screen {
    min-height: calc(100vh - 1rem);
  }

  .intro-frame {
    padding: 3rem 1.25rem;
    border-radius: 28px;
  }

  .chat-screen {
    grid-template-columns: 1fr;
  }

  .chat-sidebar,
  .chat-main {
    border-radius: 24px;
  }

  .chat-main {
    min-height: auto;
  }

  .chat-header,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .chat-header {
    align-items: start;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .composer-actions {
    grid-template-columns: 1fr 1fr;
  }

  body.immersive-active .chat-screen {
    min-height: 100vh;
  }
}
