:root {
  color-scheme: dark;
  --bg: #08111f;
  --bg-2: #111827;
  --panel: rgba(15, 23, 42, 0.72);
  --panel-strong: rgba(17, 24, 39, 0.9);
  --text: #f8fafc;
  --muted: #aab6cc;
  --line: rgba(255, 255, 255, 0.12);
  --blue: #4f8cff;
  --violet: #8e6cff;
  --silver: #e8ecf6;
  --danger: #ff7a90;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #eef3fb;
  --bg-2: #f8fafc;
  --panel: rgba(255, 255, 255, 0.74);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --text: #101827;
  --muted: #5d687a;
  --line: rgba(15, 23, 42, 0.12);
  --shadow: 0 24px 70px rgba(56, 72, 102, 0.18);
}

* { box-sizing: border-box; }

html { min-height: 100%; scroll-behavior: smooth; }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 16%, rgba(79, 140, 255, 0.32), transparent 30%),
    radial-gradient(circle at 84% 8%, rgba(142, 108, 255, 0.3), transparent 28%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
  color: var(--text);
  font-family: Manrope, ui-sans-serif, sans-serif;
  letter-spacing: 0;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.mentor-home-link {
  color: var(--silver);
  font-size: 0.78rem;
  font-weight: 700;
  left: 24px;
  position: fixed;
  text-decoration: none;
  top: 22px;
  z-index: 20;
}

.mentor-home-link:hover { color: var(--violet); }

.hidden { display: none !important; }
.glass {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(26px);
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: linear-gradient(120deg, rgba(79, 140, 255, 0.12), rgba(142, 108, 255, 0.12), rgba(255, 255, 255, 0.03));
  animation: hueFlow 14s ease-in-out infinite alternate;
}

#particleCanvas { width: 100%; height: 100%; display: block; opacity: 0.5; }

.orb {
  position: absolute;
  width: 34vmax;
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(56px);
  opacity: 0.46;
  animation: floatOrb 12s ease-in-out infinite;
}
.orb-one { left: -12%; top: 14%; background: #356dff; }
.orb-two { right: -10%; top: -12%; background: #8d6bff; animation-delay: -4s; }
.orb-three { left: 42%; bottom: -18%; background: #d8e2ff; animation-delay: -7s; opacity: 0.22; }

.landing {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}

.intro-card {
  width: min(560px, 100%);
  padding: clamp(28px, 5vw, 52px);
  border-radius: 24px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.intro-card::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 23px;
  pointer-events: none;
  background: linear-gradient(145deg, rgba(255,255,255,0.22), transparent 42%, rgba(142,108,255,0.16));
}

.eyebrow, .chat-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(4rem, 14vw, 8rem);
  line-height: 0.9;
}

h2 { margin: 8px 0 0; font-size: clamp(1.25rem, 3vw, 1.8rem); }
.lead { margin: 18px auto 28px; max-width: 460px; color: var(--muted); line-height: 1.65; }

.student-form { display: grid; gap: 16px; text-align: left; }
.field { position: relative; display: grid; gap: 8px; color: var(--muted); font-weight: 700; }
.field svg {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: 21px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  pointer-events: none;
}
.field input, .search-box input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  outline: none;
  color: var(--text);
  background: rgba(255,255,255,0.07);
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}
.field input {
  height: 56px;
  border-radius: 18px;
  padding: 0 18px 0 50px;
}
.field input:focus, .search-box input:focus, textarea:focus {
  border-color: rgba(142, 108, 255, 0.78);
  box-shadow: 0 0 0 5px rgba(142, 108, 255, 0.14);
  background: rgba(255,255,255,0.1);
}
.form-error { min-height: 22px; margin: -4px 0 0; color: var(--danger); font-weight: 700; }

.primary-cta, .new-chat, .send-btn {
  border: 0;
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--violet));
  box-shadow: 0 16px 38px rgba(79, 140, 255, 0.28);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}
.primary-cta { height: 60px; border-radius: 20px; font-weight: 900; font-size: 1.05rem; }
.primary-cta:hover, .new-chat:hover, .send-btn:hover { transform: translateY(-2px); box-shadow: 0 24px 52px rgba(79, 140, 255, 0.38); }

.chat-app {
  height: 100vh;
  display: grid;
  grid-template-columns: 312px 1fr;
  gap: 18px;
  padding: 18px;
}

.sidebar {
  border-radius: 24px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: transform 0.3s ease, width 0.3s ease, opacity 0.3s ease;
}
.chat-app.sidebar-collapsed { grid-template-columns: 0 1fr; }
.chat-app.sidebar-collapsed .sidebar { transform: translateX(-115%); opacity: 0; pointer-events: none; }

.sidebar-head, .chat-header, .profile, .message-top, .composer { display: flex; align-items: center; }
.sidebar-head { justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; }
.icon-btn, .tool-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.07);
  color: var(--text);
  transition: transform 0.2s ease, background 0.2s ease;
}
.icon-btn:hover, .tool-btn:hover { transform: translateY(-1px); background: rgba(255,255,255,0.12); }
.new-chat { min-height: 48px; margin: 20px 0 16px; border-radius: 17px; font-weight: 900; }

.search-box { display: grid; gap: 8px; color: var(--muted); font-size: 0.82rem; font-weight: 800; }
.search-box input { height: 42px; border-radius: 14px; padding: 0 14px; }
.recent-title { margin: 22px 0 10px; color: var(--muted); font-size: 0.8rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.12em; }
.chat-list { display: grid; gap: 8px; overflow: auto; min-height: 0; padding-right: 2px; }
.chat-item {
  display: grid;
  grid-template-columns: 1fr 34px;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 6px 6px 6px 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--text);
  background: transparent;
}
.chat-item.active, .chat-item:hover { border-color: var(--line); background: rgba(255,255,255,0.08); }
.chat-select {
  min-width: 0;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.delete-chat { width: 32px; height: 32px; border-radius: 10px; border: 0; color: var(--muted); background: transparent; }
.delete-chat:hover { color: var(--danger); background: rgba(255, 122, 144, 0.12); }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; padding-top: 16px; }
.side-action {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: rgba(255,255,255,0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
}
.profile { gap: 12px; padding: 12px; border-radius: 16px; background: rgba(255,255,255,0.07); }
.avatar { width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; font-weight: 900; background: var(--silver); color: #172033; }
.profile span { display: block; color: var(--muted); font-size: 0.82rem; }

.main-panel { min-width: 0; height: 100%; display: grid; grid-template-rows: auto 1fr auto auto auto; gap: 14px; }
.chat-header { justify-content: space-between; min-height: 72px; padding: 14px 18px; border-radius: 22px; }
.chat-header h2 { margin: 2px 0 0; font-size: 1.2rem; }
.messages {
  overflow: auto;
  padding: clamp(8px, 2vw, 24px);
  scroll-behavior: smooth;
}
.empty-state { max-width: 760px; margin: 7vh auto 20px; text-align: center; animation: riseIn 0.55s ease both; }
.empty-state h3 { margin: 0 0 10px; font-size: clamp(2rem, 5vw, 4.5rem); font-family: "Playfair Display", Georgia, serif; }
.empty-state p { margin: 0 auto; max-width: 560px; color: var(--muted); line-height: 1.65; }

.message {
  width: min(860px, 100%);
  margin: 0 auto 18px;
  animation: riseIn 0.34s ease both;
}
.message.user { display: flex; justify-content: flex-end; }
.bubble {
  max-width: min(760px, 92%);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.08);
  line-height: 1.65;
}
.user .bubble { background: linear-gradient(135deg, rgba(79,140,255,0.92), rgba(142,108,255,0.9)); color: white; }
.message-top { justify-content: space-between; gap: 12px; margin-bottom: 8px; color: var(--muted); font-size: 0.78rem; font-weight: 800; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 8px 0 8px 22px; padding: 0; }
.code-wrap { overflow: hidden; margin: 12px 0; border: 1px solid var(--line); border-radius: 16px; background: #111827; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; color: #cbd5e1; background: rgba(255,255,255,0.06); font-size: 0.78rem; }
.copy-code, .regenerate {
  border: 1px solid var(--line);
  border-radius: 10px;
  color: inherit;
  background: rgba(255,255,255,0.08);
  padding: 5px 9px;
}
pre { margin: 0; padding: 14px; overflow: auto; color: #e5e7eb; }
code { font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.9rem; }
.token-key { color: #9cdcfe; }
.token-string { color: #ce9178; }
.token-comment { color: #6a9955; }
.token-number { color: #b5cea8; }

.typing { display: flex; gap: 6px; align-items: center; min-height: 26px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: pulseDot 1s ease-in-out infinite; }
.typing span:nth-child(2) { animation-delay: 0.16s; }
.typing span:nth-child(3) { animation-delay: 0.32s; }

.suggestions {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 0 10px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.suggestions button {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(18px);
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.suggestions button:hover { transform: translateY(-3px); border-color: rgba(142,108,255,0.45); background: rgba(255,255,255,0.13); }

.composer {
  position: relative;
  width: min(980px, calc(100% - 20px));
  margin: 0 auto;
  gap: 10px;
  padding: 12px 14px 30px;
  border-radius: 24px;
}
textarea {
  min-height: 50px;
  max-height: 190px;
  resize: none;
  border-radius: 18px;
  padding: 14px 16px;
}
.send-btn { width: 50px; height: 50px; border-radius: 17px; flex: 0 0 auto; }
.char-counter { position: absolute; right: 22px; bottom: 8px; color: var(--muted); font-size: 0.76rem; }
footer { padding: 0 16px 10px; color: var(--muted); text-align: center; font-size: 0.78rem; }

.drawer-backdrop { display: none; }
.mobile-only { display: none; }

@keyframes hueFlow { to { filter: hue-rotate(24deg) saturate(1.08); } }
@keyframes floatOrb { 50% { transform: translate3d(8%, -5%, 0) scale(1.08); } }
@keyframes riseIn { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulseDot { 50% { opacity: 0.35; transform: translateY(-4px); } }

.reveal { animation: riseIn 0.7s ease both; }

@media (max-width: 980px) {
  .chat-app { grid-template-columns: 1fr; padding: 10px; }
  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 10px auto 10px 10px;
    width: min(320px, calc(100vw - 34px));
    transform: translateX(-115%);
  }
  .sidebar.open { transform: translateX(0); opacity: 1; pointer-events: auto; }
  .drawer-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgba(3, 7, 18, 0.58);
    backdrop-filter: blur(8px);
  }
  .mobile-only { display: inline-grid; }
  #collapseSidebar { display: none; }
  .suggestions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .landing { padding: 18px; }
  .intro-card { padding: 26px 18px; }
  .chat-header { min-height: 64px; }
  .chat-header h2 { font-size: 1rem; }
  .messages { padding: 6px 2px; }
  .bubble { max-width: 96%; }
  .suggestions { grid-template-columns: 1fr; max-height: 150px; overflow: auto; }
  .composer { width: calc(100% - 4px); gap: 7px; padding: 10px 10px 30px; }
  .tool-btn { width: 40px; height: 40px; }
  .send-btn { width: 44px; height: 44px; }
}
.install-app {
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.11);
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  margin: 0.35rem 0 1.2rem;
  padding: 0.65rem 0.95rem;
}

.download-options {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 4px 0 10px;
}

.download-options .install-app {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0;
  padding: 0.8rem 0.65rem;
}

.download-options .install-app small {
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 600;
}

.install-hint {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
  margin: 0 0 1rem;
  min-height: 1.2em;
}

.chat-header .install-app {
  margin: 0 0 0 auto;
}

@media (max-width: 620px) {
  .download-options { grid-template-columns: 1fr; }
  .chat-header .header-install { display: none; }
}

.install-app:hover {
  background: rgba(255, 255, 255, 0.19);
}
