:root {
  --ink: #151A2E;
  --slate: #232A45;
  --signal: #5EE6C4;
  --alert: #FF7A59;
  --amber: #F0B942;
  --paper: #EDEFF5;
  --muted: #8A90AC;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: 'Inter', sans-serif;
  overflow-x: hidden;
}

h1, h2, h3, .brand {
  font-family: 'Fraunces', serif;
  font-weight: 600;
}

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

.navbar { border-bottom: 1px solid var(--slate); position: relative; }
.navbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  gap: 1rem;
}
.brand { font-size: 1.25rem; white-space: nowrap; }
.brand span { color: var(--signal); }
.nav-links { display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; }
.nav-links a {
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: rgba(237,239,245,0.8);
}
.nav-links a:hover { background: var(--slate); color: var(--paper); }
.nav-links a.active {
  background: var(--signal);
  color: var(--ink);
  font-weight: 600;
}

.nav-dropdown { position: relative; }
.nav-dropdown-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: rgba(237,239,245,0.8);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
}
.nav-dropdown-toggle:hover { background: var(--slate); color: var(--paper); }
.nav-dropdown-toggle.active { background: var(--signal); color: var(--ink); font-weight: 600; }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.35rem;
  background: var(--ink);
  border: 1px solid var(--slate);
  border-radius: 0.6rem;
  padding: 0.4rem;
  min-width: 190px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.45);
  z-index: 30;
  flex-direction: column;
  gap: 0.1rem;
}
.nav-dropdown-menu a {
  display: block;
  padding: 0.5rem 0.65rem;
  border-radius: 0.4rem;
  font-size: 0.875rem;
  white-space: nowrap;
}
.nav-dropdown.open .nav-dropdown-menu { display: flex; }

.nav-user { display: flex; align-items: center; gap: 0.75rem; }
.nav-user-mobile { display: none; }
.user-name { font-size: 0.875rem; color: var(--muted); }
.link-button {
  background: none; border: none; cursor: pointer;
  color: var(--alert); font-weight: 500; font-size: 0.875rem;
  padding: 0.5rem 0.75rem; border-radius: 0.5rem;
}
.link-button:hover { background: var(--slate); }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.5rem;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--paper);
  border-radius: 2px;
}
.nav-toggle:hover { background: var(--slate); }

@media (max-width: 800px) {
  .nav-toggle { display: flex; }
  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--ink);
    border-bottom: 1px solid var(--slate);
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem;
    gap: 0.25rem;
    z-index: 20;
  }
  .nav-links.open { display: flex; }
  .nav-links a { width: 100%; }
  .nav-user-desktop { display: none; }
  .nav-user-mobile {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0.75rem 0.25rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--slate);
  }

  /* On mobile there's no room for a floating popover, and touch users can't hover —
     dropdown groups just render as permanently-expanded, indented sections instead,
     with their toggle button becoming a plain non-interactive section label. */
  .nav-dropdown-toggle {
    width: 100%;
    text-align: left;
    pointer-events: none;
    background: none !important;
    color: var(--muted) !important;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.6rem 0.75rem 0.2rem;
  }
  .nav-dropdown-menu {
    display: flex !important;
    position: static;
    flex-direction: column;
    background: none;
    border: none;
    box-shadow: none;
    padding: 0 0 0 0.5rem;
    margin-top: 0;
  }
  .nav-dropdown-menu a { width: 100%; }
}

.page { max-width: 1100px; margin: 0 auto; padding: 2.5rem 1.5rem; }
.page-narrow {
  max-width: 640px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  position: relative;
}

.page-auth { position: relative; }

/* Constellation backdrop for the auth flow (Login/Register/password/verify pages) and
   every signed-in app page (.page-auth, set in _Layout.cshtml) -- both otherwise sit on
   a flat --ink fill with nothing to soften it. The public Landing/ComingSoon pages are
   deliberately excluded: they already have their own hero gradient treatment.
   Star layers are tiled (small background-size, repeating) rather than a handful of
   hand-placed percentage points -- at real viewport sizes a dozen fixed points read as
   almost nothing; tiling keeps density consistent regardless of window size. */
.page-narrow::before,
.page-auth::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1.7px 1.7px at 15% 40%, rgba(237,239,245,0.75) 0, transparent 100%) 0 0/130px 130px,
    radial-gradient(1.4px 1.4px at 65% 65%, rgba(237,239,245,0.6) 0, transparent 100%) 40px 60px/160px 160px,
    radial-gradient(1.9px 1.9px at 40% 15%, rgba(237,239,245,0.65) 0, transparent 100%) 90px 20px/200px 200px,
    radial-gradient(1.5px 1.5px at 75% 25%, rgba(237,239,245,0.55) 0, transparent 100%) 20px 100px/180px 180px,
    radial-gradient(ellipse 640px 420px at 18% 10%, rgba(94,230,196,0.18), transparent 70%) no-repeat,
    radial-gradient(ellipse 520px 380px at 88% 82%, rgba(240,185,66,0.13), transparent 70%) no-repeat,
    var(--ink);
}

.card {
  background: var(--slate);
  border-radius: 1rem;
  padding: 1.5rem;
}

.card-link { display: block; transition: box-shadow 0.15s; }
.card-link:hover { box-shadow: 0 0 0 1px rgba(94,230,196,0.5); }

/* For cards where the link is only part of the card (e.g. actions sit below it) --
   the hover highlight belongs on the whole .card, not just the linked portion, or it
   renders as a stray box hugging just that inner element. */
.card:has(> .card-link-inner) { transition: box-shadow 0.15s; }
.card:has(> .card-link-inner):hover { box-shadow: 0 0 0 1px rgba(94,230,196,0.5); }
.card-link-inner { display: block; text-decoration: none; }

.muted { color: var(--muted); }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 700px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

form.form-card {
  background: var(--slate);
  border-radius: 1rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 480px;
}

label { display: block; font-size: 0.875rem; color: var(--muted); margin-bottom: 0.25rem; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
  width: 100%;
  background: var(--ink);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  color: var(--paper);
  font-family: inherit;
  font-size: 0.95rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--signal);
  outline-offset: 1px;
  border-color: var(--signal);
}

.password-field { position: relative; }
.password-field input { padding-right: 2.5rem; }
.password-toggle {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  line-height: 1;
  color: var(--muted);
  display: flex;
  align-items: center;
  border-radius: 0.4rem;
}
.password-toggle svg { display: block; width: 18px; height: 18px; }
.password-toggle:hover { color: var(--paper); background: rgba(255,255,255,0.08); }
.password-toggle.showing { color: var(--signal); }

.btn-primary {
  background: var(--signal);
  color: var(--ink);
  font-weight: 600;
  border: none;
  border-radius: 0.5rem;
  padding: 0.65rem 1.25rem;
  cursor: pointer;
  font-size: 0.95rem;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: var(--paper);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 0.5rem;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.alert { border-radius: 0.5rem; padding: 0.65rem 0.9rem; font-size: 0.9rem; margin-bottom: 1rem; }
.alert-error { background: rgba(255,122,89,0.12); color: var(--alert); }
.alert-success { background: rgba(94,230,196,0.12); color: var(--signal); }
.alert-info { background: rgba(255,255,255,0.05); color: var(--muted); }

.option-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 0.75rem; border-radius: 0.5rem; border: 1px solid rgba(255,255,255,0.1); margin-bottom: 0.5rem; }
.option-row.selected { border-color: var(--signal); background: rgba(94,230,196,0.08); }
.option-row.correct { border-color: var(--signal); background: rgba(94,230,196,0.08); }
.option-row.incorrect { border-color: var(--alert); background: rgba(255,122,89,0.08); }

.question-block { background: var(--slate); border-radius: 0.75rem; padding: 1.25rem; margin-bottom: 1.25rem; }

.timer-badge {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.25rem;
  background: var(--slate);
  color: var(--signal);
  padding: 0.4rem 0.9rem;
  border-radius: 0.5rem;
  min-width: 4.5rem;
  text-align: center;
}
.timer-badge.timer-warning { color: var(--alert); }
.timer-badge.timer-expired { color: var(--alert); background: rgba(255,122,89,0.12); }

.chat-window {
  height: 55vh;
  min-height: 320px;
  overflow-y: auto;
  background: var(--slate);
  border-radius: 0.75rem;
  padding: 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.chat-empty {
  margin: auto;
  font-size: 0.9rem;
  text-align: center;
}
.chat-bubble {
  max-width: 75%;
  padding: 0.65rem 0.9rem;
  border-radius: 0.75rem;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  box-sizing: border-box;
}
.chat-bubble-user {
  align-self: flex-end;
  background: var(--signal);
  color: var(--ink);
  border-bottom-right-radius: 0.2rem;
}
.chat-bubble-assistant {
  align-self: flex-start;
  background: rgba(255,255,255,0.06);
  color: var(--paper);
  border-bottom-left-radius: 0.2rem;
  /* Overrides .chat-bubble's pre-wrap: that rule preserves a student's own typed
     line breaks (set via .textContent, no HTML), but an assistant reply is rendered
     as real HTML by renderAiContent (marked.js) — marked's own <p>/<ol>/<li> tags
     already carry the correct spacing, and pre-wrap was additionally preserving the
     literal newline characters marked.js inserts between those tags for readability,
     rendering as a large blank line after every single paragraph/list item. */
  white-space: normal;
}
.chat-bubble-thinking { opacity: 0.6; font-style: italic; }

.chat-input-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  /* The textarea/button themselves are opaque, but the row's own gap/padding wasn't --
     without this, the page-wide constellation background (.page-auth::before) showed through
     right between them. Slate + radius makes the row read as a continuous panel with
     .chat-window directly above it, matching VoiceDoubt's single-card input area. */
  background: var(--slate);
  border-radius: 0.75rem;
  padding: 0.75rem;
}
.chat-input-row textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  background: var(--ink);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  color: var(--paper);
  font-family: inherit;
  font-size: 0.95rem;
}
.chat-input-row textarea:focus {
  outline: 2px solid var(--signal);
  outline-offset: 1px;
  border-color: var(--signal);
}
@media (max-width: 700px) {
  .chat-bubble { max-width: 90%; }
}

.weakness-row { margin-bottom: 1.1rem; }
.weakness-row-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
}
.weakness-row-name { font-weight: 500; }
.weakness-row-meta { color: var(--muted); font-size: 0.78rem; }
.weakness-bar-track {
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.weakness-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
}
.weakness-bar-fill.weak { background: var(--alert); }
.weakness-bar-fill.medium { background: var(--amber); }
.weakness-bar-fill.strong { background: var(--signal); }
.weakness-bar-fill.untried { background: var(--muted); opacity: 0.4; }

.weakness-badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.weakness-badge.weak { background: rgba(255,122,89,0.15); color: var(--alert); }
.weakness-badge.medium { background: rgba(240,185,66,0.15); color: var(--amber); }
.weakness-badge.strong { background: rgba(94,230,196,0.15); color: var(--signal); }
.weakness-badge.untried { background: rgba(138,144,172,0.15); color: var(--muted); }

.subject-weakness-group { margin-bottom: 2rem; }

.plan-task {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.9rem;
  border-radius: 0.65rem;
  background: var(--slate);
  margin-bottom: 0.6rem;
}
.plan-task.completed { opacity: 0.55; }
.plan-task.completed .plan-task-topic { text-decoration: line-through; }
.plan-task input[type=checkbox] {
  margin-top: 0.2rem;
  width: 18px;
  height: 18px;
  accent-color: var(--signal);
  cursor: pointer;
  flex-shrink: 0;
}
.plan-task-body { flex: 1; }
.plan-task-topic { font-weight: 600; font-size: 0.95rem; }
.plan-task-reason { color: var(--muted); font-size: 0.83rem; margin-top: 0.15rem; }
.plan-task-minutes {
  font-size: 0.75rem;
  color: var(--signal);
  font-weight: 600;
  white-space: nowrap;
}

.flashcard {
  background: var(--slate);
  border-radius: 1rem;
  padding: 3rem 2rem;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.flashcard-topic {
  font-size: 0.72rem;
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.flashcard-content {
  font-size: 1.3rem;
  font-family: 'Fraunces', serif;
  line-height: 1.45;
}
.flashcard-back {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255,255,255,0.1);
  color: var(--signal);
}

.rating-row { display: flex; gap: 0.75rem; justify-content: center; margin-top: 1.25rem; }
.rating-btn {
  flex: 1;
  max-width: 160px;
  padding: 0.75rem;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.rating-again { background: rgba(255,122,89,0.15); color: var(--alert); }
.rating-good { background: rgba(240,185,66,0.15); color: var(--amber); }
.rating-easy { background: rgba(94,230,196,0.15); color: var(--signal); }
.rating-btn:hover { opacity: 0.85; }
.rating-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.difficulty-badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.difficulty-badge.Easy { background: rgba(94,230,196,0.15); color: var(--signal); }
.difficulty-badge.Medium { background: rgba(240,185,66,0.15); color: var(--amber); }
.difficulty-badge.Hard { background: rgba(255,122,89,0.15); color: var(--alert); }

.lang-toggle { display: flex; gap: 0.5rem; }
.lang-btn {
  flex: 1;
  padding: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}
.lang-btn.active { background: var(--signal); color: var(--ink); border-color: var(--signal); font-weight: 600; }

.mic-button {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: none;
  background: var(--signal);
  font-size: 2rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.mic-button:hover { transform: scale(1.05); }
.mic-button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.mic-button.listening {
  background: var(--alert);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,122,89,0.5); }
  70% { box-shadow: 0 0 0 16px rgba(255,122,89,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,122,89,0); }
}

.voice-question, .voice-answer {
  background: var(--slate);
  border-radius: 0.6rem;
  padding: 0.85rem 1rem;
  margin-bottom: 0.6rem;
}
.voice-answer { border-left: 3px solid var(--signal); }

.text-signal { color: var(--signal); }
.text-alert { color: var(--alert); }

.validation-summary { color: var(--alert); font-size: 0.875rem; margin-bottom: 0.5rem; }
.field-validation-error { color: var(--alert); font-size: 0.8rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid rgba(255,255,255,0.08); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 500; }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--slate); }

/* ---- Tutor avatar ----
   Shared by Voice Doubt and the AI Tutor chat: an original floating-robot design (oval
   body, glowing visor) — not a reproduction of any copyrighted character — that reacts to
   each page's own conversation state via is-listening/is-thinking/is-speaking class
   toggles (see each view's script section for what drives them). */
.tutor-avatar-wrap { display: flex; justify-content: center; margin-bottom: 0.5rem; }
.tutor-avatar { position: relative; width: 120px; height: 110px; }
.tutor-avatar svg {
  width: 100%; height: 100%;
  animation: tutor-float 3.4s ease-in-out infinite;
  filter: drop-shadow(0 10px 18px rgba(0,0,0,0.35));
}
@keyframes tutor-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.tutor-glow-ring {
  position: absolute; inset: -10px; border-radius: 50%;
  background: radial-gradient(circle, rgba(94,230,196,0.25), transparent 70%);
  animation: tutor-pulse 2.6s ease-in-out infinite;
}
@keyframes tutor-pulse { 0%, 100% { transform: scale(0.92); opacity: 0.45; } 50% { transform: scale(1.05); opacity: 0.75; } }

.tutor-eye { transition: fill 0.25s ease; transform-box: fill-box; transform-origin: center; }

/* Listening: quicker float/pulse, brighter eyes. */
.tutor-avatar.is-listening svg { animation-duration: 1.6s; }
.tutor-avatar.is-listening .tutor-glow-ring { animation-duration: 1.1s; background: radial-gradient(circle, rgba(94,230,196,0.45), transparent 70%); }
.tutor-avatar.is-listening .tutor-eye { fill: var(--signal); }

/* Thinking: eyes scan side to side, glow shifts to amber. */
.tutor-avatar.is-thinking .tutor-eyes { animation: tutor-scan 1.2s ease-in-out infinite; }
@keyframes tutor-scan { 0%, 100% { transform: translateX(-4px); } 50% { transform: translateX(4px); } }
.tutor-avatar.is-thinking .tutor-glow-ring { animation-duration: 0.9s; background: radial-gradient(circle, rgba(240,185,66,0.4), transparent 70%); }

/* Speaking: eyes pulse like a talking blink. */
.tutor-avatar.is-speaking .tutor-eye { animation: tutor-talk 0.45s ease-in-out infinite; }
@keyframes tutor-talk { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(0.35); } }
.tutor-avatar.is-speaking .tutor-glow-ring { animation-duration: 0.7s; background: radial-gradient(circle, rgba(94,230,196,0.55), transparent 70%); }

@media (prefers-reduced-motion: reduce) {
  .tutor-avatar svg, .tutor-glow-ring, .tutor-avatar.is-thinking .tutor-eyes, .tutor-avatar.is-speaking .tutor-eye {
    animation: none !important;
  }
}
