/* RateMySpanish — "quiet productivity" UI: left-sidebar app shell, neutral
   greys, one restrained indigo accent, thin dividers, document-like content.
   Inspired by Notion / Linear. */

:root {
  --content-bg: #ffffff;
  --sidebar-bg: #fafafa;
  --fg: #1f2328;
  --muted: #6b7280;
  --faint: #9aa0a6;
  --line: #ececef;
  --line-soft: #f3f3f5;
  --accent: #5b5bd6;        /* indigo */
  --accent-hover: #4d4dc7;
  --accent-soft: #eeeefc;
  --good: #2f9e6b;
  --bad: #d6455b;
  --radius: 10px;
  --radius-lg: 14px;
  --content-max: 900px;
  --sidebar-w: 256px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--content-bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 1.5rem; letter-spacing: -0.01em; }
h3 { font-size: 1.02rem; }

/* ---------- App shell ---------- */
body.app { display: flex; align-items: stretch; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0.85rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
  padding: 0.2rem 0.5rem 0.9rem;
}
.sidebar .brand:hover { text-decoration: none; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.93rem;
  font-weight: 500;
}
.side-nav a:hover { background: rgba(0, 0, 0, 0.045); color: var(--fg); text-decoration: none; }
.side-nav a.active { background: var(--accent-soft); color: var(--accent); }
.side-nav a.active svg { color: var(--accent); }
.side-nav svg { width: 18px; height: 18px; flex: none; color: var(--faint); }

.side-user {
  margin-top: auto;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
}
.side-user .who { color: var(--fg); font-weight: 500; word-break: break-all; }
.side-user .meta { margin: 0.25rem 0 0.55rem; display: flex; align-items: center; gap: 0.4rem; }
.level-chip {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  padding: 0.08rem 0.4rem;
  border-radius: 6px;
}

/* ---------- Content ---------- */
.content { flex: 1; min-width: 0; }
.container {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 2.4rem 2rem 4rem;
}

/* Guest (logged-out) pages: centered, no sidebar. */
body.guest { min-height: 100vh; }
.guest-brand {
  display: block;
  text-align: center;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--fg);
  padding: 2.2rem 0 0;
}
.guest-brand:hover { text-decoration: none; }
body.guest .container { max-width: 440px; padding-top: 1.5rem; }

/* ---------- Flash ---------- */
.flash {
  max-width: var(--content-max);
  margin: 1.5rem auto -0.5rem;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  font-size: 0.92rem;
}
.flash-notice { background: var(--accent-soft); color: var(--accent-hover); }
.flash-alert { background: #fdecec; color: #a3271f; }

/* ---------- Cards ---------- */
.card {
  background: var(--content-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.3rem 1.5rem;
  margin-bottom: 1.25rem;
}
.card h2 { margin-top: 0; }
.card h3 { margin-top: 0; }

/* The English prompt the student must translate */
.prompt {
  font-size: 1.5rem;
  line-height: 1.35;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ---------- Buttons ---------- */
button, .btn, input[type="submit"] {
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  transition: background 0.12s ease, border-color 0.12s ease;
}
button:hover, .btn:hover, input[type="submit"]:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  text-decoration: none;
}
.btn-secondary {
  background: var(--content-bg);
  color: var(--fg);
  border: 1px solid var(--line);
}
.btn-secondary:hover { background: var(--line-soft); border-color: var(--line); color: var(--fg); }
.btn.small, .btn-secondary.small, button.small, input.small[type="submit"] {
  padding: 0.3rem 0.7rem;
  font-size: 0.84rem;
}
.link-button {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  font-size: 0.88rem;
}
.link-button:hover { background: none; color: var(--fg); text-decoration: underline; }

.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; align-items: center; }

/* Practice-assignment chooser */
.assignee-picker {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  margin: 1rem 0 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.assignee-picker legend { padding: 0 0.3rem; }
.assignee-picker label { display: flex; align-items: center; gap: 0.5rem; margin: 0; color: var(--fg); font-size: 0.95rem; }
.assignee-picker input[type="radio"] { width: auto; }

/* ---------- Forms ---------- */
form .field { margin-bottom: 1rem; }
label { display: block; font-size: 0.88rem; color: var(--muted); margin-bottom: 0.35rem; }
input[type="text"], input[type="email"], input[type="password"],
select, textarea {
  width: 100%;
  font: inherit;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--fg);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 7rem; resize: vertical; }

.muted { color: var(--muted); }
.small { font-size: 0.88rem; }

/* ---------- Rating stars ---------- */
.rating { font-size: 1.05rem; letter-spacing: 1px; }
.rating .on { color: var(--accent); }
.rating .off { color: var(--line); }

/* ---------- Overall competence rating ---------- */
.overall-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.overall-score { font-size: 2.1rem; line-height: 1; font-weight: 700; letter-spacing: -0.02em; margin: 0.3rem 0 0; }
.overall-score .muted { font-size: 1rem; font-weight: 500; }
.overall-meta { text-align: right; flex: none; }
.meter { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 0.95rem; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.3s ease; }

/* Colour the score and meter by competence band. */
.band-good { color: var(--good); }
.band-good.meter-fill { background: var(--good); }
.band-ok { color: #c2861a; }
.band-ok.meter-fill { background: #d99a2b; }
.band-low { color: var(--bad); }
.band-low.meter-fill { background: var(--bad); }

/* ---------- Markdown feedback ---------- */
.feedback h1, .feedback h2, .feedback h3 { font-size: 1rem; margin: 0.8rem 0 0.3rem; }
.feedback ul { margin: 0.3rem 0 0.8rem; padding-left: 1.2rem; }
.feedback code { background: var(--accent-soft); padding: 0.1rem 0.3rem; border-radius: 4px; }

/* ---------- Lists ---------- */
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 0.8rem 0; border-bottom: 1px solid var(--line-soft); }
.list li:last-child { border-bottom: none; }
.term { font-weight: 600; }

/* ---------- Badges ---------- */
.badge {
  font-size: 0.76rem;
  color: var(--muted);
  background: var(--line-soft);
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
}

/* ---------- Spinner ---------- */
.thinking { color: var(--muted); font-style: italic; }
.loading {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-style: italic;
}
.spinner {
  display: inline-block;
  width: 1.05em;
  height: 1.05em;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: pulse 1.2s ease-in-out infinite; }
  @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
}
button[disabled], input[type="submit"][disabled] { opacity: 0.6; cursor: progress; }

/* ---------- Auth ---------- */
.auth { max-width: 400px; margin: 1.5rem auto; }

/* ---------- Focus tree ---------- */
.focus-category { margin-bottom: 1.6rem; }
.focus-category h3 {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--faint);
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.4rem;
  margin-bottom: 0.4rem;
}
.focus-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line-soft);
}
.focus-item .badge { margin-left: auto; }
.focus-children { margin-left: 1rem; padding-left: 0.4rem; border-left: 2px solid var(--line-soft); }
.disabled-focus { opacity: 0.55; }

/* Focus On/Off control rendered as a pill toggle. An enabled row shows an
   "On" button (indigo); a disabled row carries .disabled-focus and an "Off"
   button (grey) — so we can style each state without inspecting the label. */
.focus-item form { margin: 0; }
.focus-item .btn,
.focus-item button {
  border-radius: 999px;
  min-width: 3rem;
  text-align: center;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.focus-item.disabled-focus .btn,
.focus-item.disabled-focus button {
  background: var(--content-bg);
  border-color: var(--line);
  color: var(--muted);
}

/* ---------- Q&A thread ---------- */
.qa { border-top: 1px solid var(--line); margin-top: 1rem; padding-top: 1rem; }
.qa .q { font-weight: 600; }
.qa .a { margin: 0.3rem 0 1rem; }

/* ---------- Instructor comments ---------- */
.comment { background: var(--accent-soft); border-radius: 8px; padding: 0.6rem 0.8rem; margin-bottom: 0.6rem; }
.comment .who { font-size: 0.8rem; color: var(--muted); }

/* ---------- Responsive: sidebar collapses to a top bar ---------- */
@media (max-width: 860px) {
  body.app { flex-direction: column; }
  .sidebar {
    width: auto;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    border-right: none;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    padding: 0.55rem 0.9rem;
  }
  .sidebar .brand { padding: 0 0.5rem 0 0.25rem; white-space: nowrap; }
  .side-nav { flex-direction: row; gap: 2px; }
  .side-nav a span.label { display: none; }
  .side-nav a { padding: 0.5rem; }
  .side-user {
    margin: 0 0 0 auto;
    padding-top: 0;
    border-top: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    white-space: nowrap;
  }
  .side-user .who, .side-user .meta .muted { display: none; }
  .side-user .meta { margin: 0; }
  .container { padding: 1.6rem 1.1rem 3rem; }
}

/* ===================================================================
   Marketing landing page (layout: marketing). Full-width, sales-y.
   =================================================================== */
body.marketing { background: var(--content-bg); }
.marketing main { display: block; }

/* Header */
.m-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.1rem 1.5rem;
}
.m-header .brand { font-weight: 700; font-size: 1.1rem; color: var(--fg); }
.m-header .brand:hover { text-decoration: none; }
.m-nav { margin-left: auto; display: flex; align-items: center; gap: 1.1rem; }
.m-nav-link { color: var(--muted); font-weight: 500; }
.m-nav-link:hover { color: var(--fg); text-decoration: none; }

/* Keep the header from overflowing on phones (the "Get started" button was
   getting clipped off the right edge). Drop the redundant "Sign in" link
   (also in the hero + footer) and tighten spacing so brand + language + CTA fit. */
@media (max-width: 820px) {
  .m-header { padding: 0.9rem 1rem; gap: 0.5rem; }
  .m-header .brand { font-size: 1.05rem; white-space: nowrap; }
  .m-nav { gap: 0.55rem; }
  .m-nav .m-nav-link { display: none; }
  .m-nav .btn { flex: none; white-space: nowrap; padding: 0.45rem 0.8rem; }
}
@media (max-width: 380px) {
  /* Smallest phones: also drop the language pill so the CTA is never clipped. */
  .m-header .locale-switcher { display: none; }
}

/* Shared section rhythm */
.marketing main > section { max-width: 1080px; margin: 0 auto; padding: 0 1.5rem; }
.section-title { text-align: center; font-size: 1.7rem; margin: 0 0 2rem; letter-spacing: -0.02em; }
.btn-lg { padding: 0.7rem 1.4rem; font-size: 1.02rem; border-radius: 10px; }

/* Hero */
.hero {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 3rem;
  align-items: center;
  padding-top: 3.5rem !important;
  padding-bottom: 4rem !important;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 0.8rem;
}
.hero h1 {
  font-size: 3rem;
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin: 0 0 1rem;
}
.lede { font-size: 1.18rem; color: var(--muted); margin: 0 0 1.6rem; max-width: 36ch; }
.lede strong { color: var(--fg); }
.hero-cta { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 0.9rem; }

/* Hero demo card */
.demo-card { position: relative; box-shadow: 0 18px 50px -24px rgba(31, 35, 40, 0.35); }

/* Grading spinner: overlays the card while the Turbo frame is busy. */
.demo-busy { display: none; }
turbo-frame[busy] .demo-busy {
  display: flex; align-items: center; justify-content: center; gap: 0.6rem;
  position: absolute; inset: 0; border-radius: inherit;
  background: rgba(255, 255, 255, 0.82);
  font-weight: 600; color: var(--accent);
}
.spinner {
  width: 22px; height: 22px; flex: none; border-radius: 50%;
  border: 2.5px solid var(--accent-soft); border-top-color: var(--accent);
  animation: demo-spin 0.7s linear infinite;
}
@keyframes demo-spin { to { transform: rotate(360deg); } }
.demo-answer {
  margin: 0.9rem 0;
  padding: 0.7rem 0.85rem;
  background: var(--accent-soft);
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 500;
}
.demo-grade { display: flex; align-items: center; gap: 0.6rem; }
.demo-score { font-weight: 700; font-size: 1.1rem; }
.demo-fb { margin: 0.7rem 0 0; }

/* Interactive demo form */
.demo-card form { margin: 0.7rem 0 0.3rem; }
.demo-controls { margin-bottom: 0.5rem; }
.demo-region, .demo-input {
  font: inherit; border: 1px solid var(--line); border-radius: 8px; background: var(--content-bg);
}
.demo-region { padding: 0.35rem 0.5rem; }
.demo-input { width: 100%; padding: 0.6rem 0.7rem; resize: vertical; margin-bottom: 0.6rem; }
.demo-input:focus, .demo-region:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.demo-cta { margin-top: 1.2rem; padding-top: 1.1rem; border-top: 1px solid var(--line); }
.demo-cta p { margin: 0 0 1rem; line-height: 1.45; }
.demo-cta .btn { display: block; width: 100%; text-align: center; }
.demo-again { display: block; margin: 0.9rem 0 0; }

/* Feature grid */
.features { padding-top: 2rem !important; padding-bottom: 3rem !important; }
.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.1rem;
}
.feature {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.3rem 1.4rem;
  background: var(--content-bg);
}
.feature-icon {
  width: 2.1rem; height: 2.1rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 9px; font-weight: 700; margin-bottom: 0.7rem;
}
.feature h3 { margin: 0 0 0.35rem; }
.feature p { margin: 0; color: var(--muted); }
.feature strong { color: var(--fg); }

/* Steps */
.steps { padding-top: 2rem !important; padding-bottom: 3rem !important; }
.step-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.step-list li { display: flex; gap: 0.9rem; align-items: flex-start; }
.step-n {
  flex: none;
  width: 2rem; height: 2rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700;
}
.step-list h3 { margin: 0.1rem 0 0.3rem; }
.step-list p { margin: 0; color: var(--muted); }

/* Instructor callout */
.instructors {
  display: flex; align-items: center; gap: 1.5rem;
  margin: 1rem auto 3rem !important;
  background: var(--sidebar-bg);
}
.instructors h2 { margin: 0 0 0.3rem; }
.instructors p { margin: 0; }
.instructors .btn { flex: none; margin-left: auto; }

/* Final CTA */
.final-cta { text-align: center; padding: 3rem 1.5rem 4rem !important; }
.final-cta h2 { font-size: 1.9rem; letter-spacing: -0.02em; margin: 0 0 0.5rem; }
.final-cta p { margin: 0 0 1.4rem; }

/* Footer */
.m-footer {
  border-top: 1px solid var(--line);
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.6rem 1.5rem 2.5rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.m-footer .brand { font-weight: 700; color: var(--fg); }
.m-footer-links { margin-left: auto; display: flex; gap: 1.1rem; }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; gap: 2rem; padding-top: 2.4rem !important; }
  .hero h1 { font-size: 2.3rem; }
  /* Lead with the headline + CTA on mobile; the demo follows (DOM order). */
  .feature-grid { grid-template-columns: 1fr; }
  .step-list { grid-template-columns: 1fr; }
  .instructors { flex-direction: column; align-items: flex-start; }
  .instructors .btn { margin-left: 0; }
}

/* Sticky mobile CTA — keeps the signup ask one tap away through the long page. */
.mobile-cta { display: none; }
@media (max-width: 820px) {
  .mobile-cta {
    display: block;
    position: fixed; left: 0; right: 0; bottom: 0;
    padding: 0.7rem 1rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
    z-index: 50;
    /* Hidden until the hero CTA scrolls out of view (sticky_cta_controller),
       so the first screen isn't two identical buttons stacked. */
    transform: translateY(120%);
    transition: transform 0.25s ease;
  }
  .mobile-cta.is-visible { transform: translateY(0); }
  .mobile-cta .btn { display: block; width: 100%; text-align: center; }
  body.marketing main { padding-bottom: 4rem; }
}

/* ---------- Language switcher (globe pill + popover) ---------- */
.locale-switcher { position: relative; display: inline-block; }

.locale-trigger {
  display: inline-flex; align-items: center; gap: 0.4rem;
  width: auto; max-width: 100%;
  padding: 0.34rem 0.6rem;
  font: inherit; font-size: 0.85rem; color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.locale-trigger:hover { background: var(--sidebar-bg); color: var(--fg); border-color: #e2e2e6; }
.locale-trigger[aria-expanded="true"] { color: var(--fg); border-color: var(--accent); }
.locale-trigger .locale-globe { width: 15px; height: 15px; flex: none; color: var(--faint); }
.locale-trigger .locale-chevron { width: 13px; height: 13px; flex: none; color: var(--faint); }
.locale-trigger .locale-current { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* In the app sidebar the pill spans the column. */
.side-user .locale-switcher { display: block; margin-top: 0.55rem; }
.side-user .locale-trigger { width: 100%; }
.side-user .locale-trigger .locale-current { flex: 1; text-align: left; }

.locale-menu {
  position: absolute; left: 0; z-index: 60;
  min-width: 220px; margin: 0; padding: 0.3rem;
  display: flex; flex-direction: column; gap: 1px;
  background: var(--content-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(17, 18, 20, 0.13);
}
.locale-menu[hidden] { display: none; }
.locale-menu--down { top: calc(100% + 6px); }
.locale-menu--up { bottom: calc(100% + 6px); }

.locale-option {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  width: 100%; padding: 0.46rem 0.6rem;
  font: inherit; font-size: 0.9rem; text-align: left; color: var(--fg);
  background: transparent; border: 0; border-radius: 7px; cursor: pointer;
}
.locale-option:hover { background: var(--line-soft); }
.locale-option:focus-visible { outline: none; background: var(--line-soft); }
.locale-option.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.locale-option .locale-check { width: 15px; height: 15px; flex: none; color: var(--accent); }

/* Right-edge placements: anchor the menu to the right so it stays on-screen. */
.m-nav .locale-menu, body.guest .locale-menu { left: auto; right: 0; }

/* On guest/auth pages, float the switcher to the top-right corner. */
body.guest > .locale-switcher { position: absolute; top: 1rem; right: 1rem; }

/* Inbox — instructor comments on the student's sentences. */
.comment-entry.unread { border-left: 3px solid var(--accent); }
.comment-entry .who { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.unread-tag {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 0.08rem 0.4rem;
  border-radius: 6px;
}
.comment-body { margin: 0.5rem 0; }
.comment-sentence-link { font-weight: 500; }
