/* Futuristic theme for the Calculus II assistant.
   Loads after style.css and only overrides it. Pure CSS animation; the small
   futuristic.js adds the floating symbols and the typewriter.
   The light theme (data-theme="light") is left exactly as style.css defines it. */

@font-face {
  font-family: "Inter";
  src: url("static/fonts/inter-latin-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Space Grotesk";
  src: url("static/fonts/space-grotesk-latin-var.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --fx-navy: #081222;
  --fx-blue: #2c5bd0;
  --fx-purple: #7552d6;
  --fx-ease: cubic-bezier(0.22, 0.8, 0.24, 1);
  --fx-glass: rgba(16, 29, 54, 0.62);
  --fx-glass-edge: rgba(127, 148, 224, 0.2);
  --fx-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 10px 30px rgba(4, 10, 24, 0.55),
    0 2px 24px rgba(44, 91, 208, 0.12);
  --font-heading: "Space Grotesk", "Inter", system-ui, sans-serif;
}

/* ---- Dark palette (default theme only) -------------------------------- */
:root:not([data-theme="light"]) {
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --on-purple: #9272de;
  --on-purple-dark: #7552d6;
  --on-purple-deep: #ede9fe;
  --on-purple-soft: rgba(117, 82, 214, 0.16);
  --on-purple-mid: rgba(117, 82, 214, 0.34);
  --ask: #2c5bd0;
  --ink: #dde4f5;
  --muted: #93a2c4;
  --line: rgba(127, 148, 224, 0.16);
  --desk: #081222;
  --page: rgba(16, 29, 54, 0.66);
  --card: #13213d;
  --sidebar: #0b1730;
  --bar: transparent;
  --bar-ink: #e9eefb;
}

:root:not([data-theme="light"]) body {
  background:
    radial-gradient(900px 520px at 12% -8%, rgba(44, 91, 208, 0.14), transparent 60%),
    radial-gradient(760px 480px at 100% 0%, rgba(117, 82, 214, 0.13), transparent 60%),
    radial-gradient(900px 600px at 50% 120%, rgba(31, 67, 179, 0.14), transparent 60%),
    #081222;
  background-attachment: fixed;
}

@supports (height: 100dvh) {
  body,
  .app-shell,
  .sidebar {
    height: 100dvh;
    min-height: 100dvh;
  }
}

h1,
h2,
h3,
.welcome__title,
.sidebar-header h2,
.appbar__titles h1 {
  font-family: var(--font-heading);
  letter-spacing: -0.01em;
}

/* ---- Header ----------------------------------------------------------- */
:root:not([data-theme="light"]) .appbar {
  background: linear-gradient(100deg, #0a1a36 0%, #151a4a 45%, #22185a 70%, #0a1a36 100%);
  background-size: 220% 100%;
  animation: fxShift 18s linear infinite;
  border-bottom: 1px solid var(--fx-glass-edge);
  box-shadow: 0 8px 28px rgba(4, 10, 24, 0.45);
  overflow: hidden;
}

/* Slow drifting light specks in the header. */
:root:not([data-theme="light"]) .appbar::before,
:root:not([data-theme="light"]) .appbar::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-repeat: repeat-x;
  opacity: 0.55;
}

:root:not([data-theme="light"]) .appbar::before {
  background-image:
    radial-gradient(1.5px 1.5px at 20px 14px, rgba(143, 168, 238, 0.9), transparent 60%),
    radial-gradient(1px 1px at 90px 34px, rgba(168, 151, 230, 0.9), transparent 60%),
    radial-gradient(1.5px 1.5px at 150px 22px, rgba(143, 168, 238, 0.7), transparent 60%);
  background-size: 180px 48px;
  animation: fxDrift 40s linear infinite;
}

:root:not([data-theme="light"]) .appbar::after {
  background-image:
    radial-gradient(1px 1px at 40px 30px, rgba(255, 255, 255, 0.8), transparent 60%),
    radial-gradient(2px 2px at 120px 10px, rgba(117, 82, 214, 0.8), transparent 60%);
  background-size: 260px 48px;
  animation: fxDrift 70s linear infinite reverse;
}

.appbar > * {
  position: relative;
  z-index: 1;
}

.appbar__logo {
  filter: drop-shadow(0 0 8px rgba(79, 123, 224, 0.55));
}

.appbar__titles h1 {
  font-weight: 700;
  background: linear-gradient(90deg, #8fa8ee, #a897e6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.appbar__icon,
.appbar__button {
  transition: background 0.3s ease, transform 0.3s var(--fx-ease);
}

.appbar__icon:hover {
  transform: translateY(-1px);
}

/* ---- Sidebar ---------------------------------------------------------- */
:root:not([data-theme="light"]) .sidebar {
  background: linear-gradient(180deg, rgba(11, 23, 48, 0.96), rgba(12, 18, 42, 0.96));
  border-right: 1px solid var(--fx-glass-edge);
}

@media (min-width: 901px) {
  .sidebar {
    transition: width 0.35s var(--fx-ease), min-width 0.35s var(--fx-ease), border-color 0.35s ease;
  }
}

@media (max-width: 900px) {
  .sidebar {
    transition: left 0.35s var(--fx-ease), box-shadow 0.35s ease;
  }

  .sidebar.is-open {
    box-shadow: 10px 0 40px rgba(4, 10, 24, 0.6), 0 0 30px rgba(44, 91, 208, 0.15);
  }
}

.sidebar-backdrop {
  background: rgba(4, 10, 24, 0.6);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fxFade 0.3s ease both;
}

/* ---- Main surface ----------------------------------------------------- */
.desk {
  animation: fxDeskIn 0.7s var(--fx-ease) both;
}

:root:not([data-theme="light"]) .notebook__page {
  background: var(--fx-glass);
  border: 1px solid var(--fx-glass-edge);
  border-radius: 16px;
  box-shadow: var(--fx-shadow);
}

@media (min-width: 641px) {
  :root:not([data-theme="light"]) .notebook__page {
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    backdrop-filter: blur(12px) saturate(140%);
  }
}

.transcript {
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

/* ---- Chat messages ---------------------------------------------------- */
.bubble {
  animation: fxSlideUp 0.45s var(--fx-ease) both;
}

.bubble--user {
  background: linear-gradient(135deg, #1f43b3 0%, #2c5bd0 55%, #4a47c4 100%);
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 8px 22px rgba(31, 67, 179, 0.35), 0 1px 0 rgba(255, 255, 255, 0.18) inset;
  animation-name: fxSlideRight;
}

:root:not([data-theme="light"]) .answer-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--fx-glass-edge);
  border-left: 3px solid var(--fx-purple);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(4, 10, 24, 0.4);
}

/* Formulas flash a soft glow once when they are drawn. */
.answer-card .katex,
.question-preview .katex {
  animation: fxMathGlow 1.8s ease-out 1 both;
}

/* ---- Typing indicator -------------------------------------------------- */
.thinking .dot,
.typing-indicator .dot {
  width: 8px;
  height: 8px;
  background: linear-gradient(135deg, var(--fx-blue), var(--fx-purple));
  box-shadow: 0 0 10px rgba(74, 71, 196, 0.8);
  animation: fxPulseDot 1.2s infinite ease-in-out;
}

.thinking {
  animation: fxFade 0.3s ease both;
}

/* ---- Welcome cards ------------------------------------------------------ */
.welcome__title {
  font-weight: 700;
  background: linear-gradient(90deg, #8fa8ee 0%, #a897e6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

:root:not([data-theme="light"]) .suggestion {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--fx-glass-edge);
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
  transition: transform 0.3s var(--fx-ease), box-shadow 0.3s ease, border-color 0.3s ease,
    background 0.3s ease;
  animation: fxSlideUp 0.6s var(--fx-ease) both;
}

.suggestion:nth-child(1) { animation-delay: 0.05s; }
.suggestion:nth-child(2) { animation-delay: 0.12s; }
.suggestion:nth-child(3) { animation-delay: 0.19s; }
.suggestion:nth-child(4) { animation-delay: 0.26s; }

:root:not([data-theme="light"]) .suggestion:hover,
:root:not([data-theme="light"]) .suggestion:focus-visible {
  transform: translateY(-5px);
  background: rgba(74, 71, 196, 0.1);
  border-color: rgba(117, 82, 214, 0.75);
  box-shadow: 0 14px 34px rgba(44, 91, 208, 0.28), 0 0 0 1px rgba(117, 82, 214, 0.35),
    0 0 24px rgba(117, 82, 214, 0.25);
  outline: none;
}

.suggestion:active {
  transform: translateY(-1px) scale(0.99);
}

.suggestion__id {
  color: #8fa8ee;
  font-family: var(--font-heading);
  font-weight: 600;
}

/* ---- Composer ----------------------------------------------------------- */
:root:not([data-theme="light"]) .composer {
  background: rgba(10, 22, 40, 0.55);
  border-top: 1px solid var(--fx-glass-edge);
}

:root:not([data-theme="light"]) #question {
  background: rgba(8, 17, 34, 0.7);
  color: var(--ink);
  border: 1px solid var(--fx-glass-edge);
  border-radius: 12px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#question:focus {
  outline: none;
  border-color: rgba(79, 123, 224, 0.8);
  box-shadow: 0 0 0 3px rgba(44, 91, 208, 0.25), 0 0 22px rgba(44, 91, 208, 0.2);
}

#ask-button {
  background: linear-gradient(135deg, #2c5bd0, #4a47c4 60%, #7552d6);
  color: #fff;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
  transition: transform 0.3s var(--fx-ease), filter 0.3s ease;
  animation: fxPulseGlow 2.6s ease-in-out infinite;
}

#ask-button:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.12);
}

#ask-button:disabled {
  animation: none;
  opacity: 0.55;
}

.math-key,
.math-category,
.math-keyboard-toggle {
  transition: transform 0.2s var(--fx-ease), background 0.3s ease, border-color 0.3s ease,
    box-shadow 0.3s ease;
}

.math-key:hover,
.math-category:hover,
.math-keyboard-toggle:hover {
  transform: translateY(-2px);
  border-color: rgba(117, 82, 214, 0.6);
  box-shadow: 0 6px 16px rgba(44, 91, 208, 0.25);
}

.math-palette {
  animation: fxSlideUp 0.3s var(--fx-ease) both;
}

/* ---- Powered-by badge ---------------------------------------------------- */
.fx-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  margin: 0.55rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.85;
}

.fx-badge__icon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--fx-blue);
  border-right-color: var(--fx-purple);
  box-shadow: 0 0 8px rgba(74, 71, 196, 0.7);
  animation: spin 2.4s linear infinite;
}

/* ---- Login landing -------------------------------------------------------- */
.access-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  max-width: none;
  margin: 0;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #dde4f5;
  background:
    radial-gradient(900px 560px at 15% 10%, rgba(44, 91, 208, 0.18), transparent 60%),
    radial-gradient(800px 540px at 90% 90%, rgba(117, 82, 214, 0.18), transparent 60%),
    linear-gradient(160deg, #060e1d 0%, #081222 55%, #0d1233 100%);
  border: 0;
  border-radius: 0;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.7s ease, visibility 0s linear 0s;
  animation: fxFade 0.9s ease both;
}

/* app.js toggles [hidden]; fading instead of disappearing gives the dissolve. */
.access-gate[hidden] {
  display: flex !important;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.7s ease, visibility 0s linear 0.7s;
}

.access-gate[hidden] * {
  animation-play-state: paused !important;
}

.fx-symbols {
  position: absolute;
  inset: 0;
  overflow: hidden;
  perspective: 700px;
  pointer-events: none;
}

.fx-sym {
  position: absolute;
  left: var(--x);
  bottom: -12vh;
  font-family: var(--font-heading);
  font-size: var(--size);
  color: var(--tint);
  opacity: 0;
  text-shadow: 0 0 14px var(--tint);
  will-change: transform, opacity;
  animation: fxFloat var(--dur) linear var(--delay) infinite;
}

.fx-glow {
  position: absolute;
  width: 46vmax;
  height: 46vmax;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.22;
  pointer-events: none;
}

.fx-glow--a {
  background: #2c5bd0;
  left: -14vmax;
  top: -16vmax;
  animation: fxBlob 16s ease-in-out infinite alternate;
}

.fx-glow--b {
  background: #7552d6;
  right: -16vmax;
  bottom: -18vmax;
  animation: fxBlob 20s ease-in-out infinite alternate-reverse;
}

.fx-card {
  position: relative;
  z-index: 2;
  width: min(26rem, 100%);
  padding: 2.1rem 1.8rem 1.6rem;
  text-align: center;
  background: rgba(16, 29, 54, 0.5);
  border: 1px solid rgba(127, 148, 224, 0.28);
  border-radius: 20px;
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  backdrop-filter: blur(14px) saturate(150%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.08) inset,
    0 24px 60px rgba(2, 6, 18, 0.65),
    0 0 50px rgba(44, 91, 208, 0.18),
    0 0 90px rgba(117, 82, 214, 0.12);
  transform: translateY(0) scale(1);
  filter: blur(0);
  transition: transform 0.7s var(--fx-ease), filter 0.7s ease;
  animation: fxCardIn 1s var(--fx-ease) 0.1s both, fxCardGlow 5s ease-in-out 1.2s infinite;
}

/* Dissolve: the card shrinks and blurs away as the page fades. */
.access-gate[hidden] .fx-card {
  transform: translateY(-18px) scale(0.92);
  filter: blur(12px);
}

.fx-card__logo {
  width: 84px;
  height: 84px;
  object-fit: contain;
  margin: 0 auto 0.9rem;
  display: block;
  filter: drop-shadow(0 0 14px rgba(79, 123, 224, 0.75)) drop-shadow(0 0 28px rgba(117, 82, 214, 0.4));
  animation: fxLogoGlow 4s ease-in-out infinite;
}

.access-gate .fx-card__title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: clamp(2.1rem, 8vw, 2.9rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #2c5bd0 0%, #7552d6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.fx-card__subtitle {
  margin: 0.45rem 0 1.5rem;
  min-height: 1.4em;
  font-size: 0.98rem;
  letter-spacing: 0.04em;
  color: #a3b2d4;
}

.fx-caret {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: -0.15em;
  background: #8fa8ee;
  animation: fxBlink 1s steps(1) infinite;
}

.access-gate label {
  font-size: 0.82rem;
  color: #93a2c4;
  margin-bottom: 0.6rem;
}

.access-gate input {
  width: 100%;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 1rem;
  text-align: center;
  letter-spacing: 0.12em;
  color: #e9eefb;
  background: rgba(6, 14, 29, 0.6);
  border: 1px solid rgba(127, 148, 224, 0.28);
  border-radius: 12px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.access-gate input::placeholder {
  letter-spacing: 0.04em;
  color: #6f82a8;
}

.access-gate input:focus {
  outline: none;
  border-color: rgba(79, 123, 224, 0.9);
  box-shadow: 0 0 0 3px rgba(44, 91, 208, 0.28), 0 0 26px rgba(44, 91, 208, 0.3);
}

.fx-enter {
  width: 100%;
  padding: 0.85rem 1rem;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, #2c5bd0 0%, #4a47c4 55%, #7552d6 100%);
  border: 0;
  border-radius: 12px;
  transition: transform 0.3s var(--fx-ease), filter 0.3s ease;
  animation: fxPulseGlow 2.4s ease-in-out infinite;
}

.fx-enter:hover {
  transform: translateY(-2px);
  filter: brightness(1.12);
}

.fx-enter:active {
  transform: translateY(0) scale(0.985);
}

.access-gate__error {
  margin: 0.7rem 0 0;
  min-height: 1.2rem;
  font-size: 0.88rem;
  color: #fca5a5;
}

/* ---- Feedback dialog ------------------------------------------------------- */
.feedback-dialog {
  border: 1px solid var(--fx-glass-edge);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(2, 6, 18, 0.6);
}

.feedback-dialog::backdrop {
  background: rgba(4, 10, 24, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* ---- Mobile ------------------------------------------------------------------ */
@media (max-width: 640px) {
  .desk {
    padding: 0.5rem 0.4rem 0;
  }

  :root:not([data-theme="light"]) .notebook__page {
    border-radius: 14px;
    background: rgba(14, 26, 50, 0.9);
  }

  .transcript {
    padding: 0.9rem 0.75rem 0.4rem;
  }

  .composer {
    padding: 0.6rem 0.7rem calc(10px + env(safe-area-inset-bottom, 0px));
  }

  /* 16px keeps iOS from zooming the page when the field is focused. */
  #question,
  .access-gate input {
    font-size: 16px;
  }

  .fx-card {
    padding: 1.7rem 1.3rem 1.3rem;
    border-radius: 18px;
    background: rgba(16, 29, 54, 0.72);
  }

  .fx-card__logo {
    width: 70px;
    height: 70px;
  }

  .fx-glow {
    filter: blur(60px);
    opacity: 0.18;
  }

  .fx-badge {
    font-size: 0.68rem;
  }

  .suggestion:hover {
    transform: none;
  }
}

@media (max-height: 520px) {
  .fx-card__logo {
    display: none;
  }
}

/* ---- Keyframes ----------------------------------------------------------------- */
@keyframes fxFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fxDeskIn {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

@keyframes fxSlideUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@keyframes fxSlideRight {
  from { opacity: 0; transform: translateX(22px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes fxCardIn {
  from { opacity: 0; transform: translateY(26px) scale(0.96); filter: blur(8px); }
  to { opacity: 1; transform: none; filter: blur(0); }
}

@keyframes fxCardGlow {
  0%, 100% { border-color: rgba(127, 148, 224, 0.28); }
  50% { border-color: rgba(146, 114, 222, 0.55); }
}

@keyframes fxLogoGlow {
  0%, 100% { filter: drop-shadow(0 0 12px rgba(79, 123, 224, 0.6)) drop-shadow(0 0 22px rgba(117, 82, 214, 0.3)); }
  50% { filter: drop-shadow(0 0 20px rgba(79, 123, 224, 0.95)) drop-shadow(0 0 36px rgba(117, 82, 214, 0.55)); }
}

@keyframes fxPulseGlow {
  0%, 100% { box-shadow: 0 6px 18px rgba(44, 91, 208, 0.35), 0 0 0 0 rgba(74, 71, 196, 0.45); }
  50% { box-shadow: 0 8px 26px rgba(74, 71, 196, 0.55), 0 0 0 8px rgba(74, 71, 196, 0); }
}

@keyframes fxPulseDot {
  0%, 80%, 100% { transform: scale(0.55); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

@keyframes fxMathGlow {
  0% { text-shadow: 0 0 16px rgba(79, 123, 224, 0.95), 0 0 30px rgba(117, 82, 214, 0.7); color: #c9d6f6; }
  100% { text-shadow: 0 0 0 rgba(79, 123, 224, 0); color: inherit; }
}

@keyframes fxFloat {
  0% { transform: translate3d(0, 0, -250px) rotateZ(var(--rot)) scale(0.7); opacity: 0; }
  12% { opacity: var(--alpha); }
  88% { opacity: var(--alpha); }
  100% { transform: translate3d(var(--drift), -118vh, 220px) rotateZ(calc(var(--rot) + 40deg)) scale(1.1); opacity: 0; }
}

@keyframes fxBlob {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(8vmax, 6vmax, 0) scale(1.15); }
}

@keyframes fxShift {
  from { background-position: 0% 0; }
  to { background-position: 220% 0; }
}

@keyframes fxDrift {
  from { background-position: 0 0; }
  to { background-position: 520px 0; }
}

@keyframes fxBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ---- Respect reduced-motion settings -------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .fx-symbols,
  .fx-glow {
    display: none;
  }
}
