:root {
  --ff-primary: #2b6cb0;
  --ff-primary-dark: #234e7d;
  --ff-success: #22c55e;
  --ff-success-dark: #16a34a;
  --ff-accent: #f59e0b;
  --ff-bg: #f7f9fc;
  --ff-surface: #ffffff;
  --ff-text: #1f2937;
  --ff-muted: #6b7280;
  --ff-border: #e5e7eb;
  --ff-radius: 16px;
  --ff-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
  --ff-bg: #0f172a;
  --ff-surface: #1e293b;
  --ff-text: #e2e8f0;
  --ff-muted: #94a3b8;
  --ff-border: #334155;
  --ff-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

html {
  font-size: 15px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--ff-bg);
  color: var(--ff-text);
  margin-bottom: 60px;
}

h1, h2, h3, h4, h5, h6, .navbar-brand {
  font-weight: 800;
}

html {
  position: relative;
  min-height: 100%;
}

/* Cards: rounded, soft shadow */
.card {
  background-color: var(--ff-surface);
  color: var(--ff-text);
  border: 1px solid var(--ff-border);
  border-radius: var(--ff-radius);
  box-shadow: var(--ff-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.1);
}

.card-header {
  background-color: transparent;
  border-bottom: 1px solid var(--ff-border);
  font-weight: 700;
}

/* Buttons: bold, rounded, playful press effect */
.btn {
  border-radius: 999px;
  font-weight: 700;
  padding: 0.5rem 1.25rem;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn:active {
  transform: translateY(2px);
}

.btn-primary {
  background-color: var(--ff-primary);
  border-color: var(--ff-primary);
}

.btn-primary:hover {
  background-color: var(--ff-primary-dark);
  border-color: var(--ff-primary-dark);
}

.btn-success {
  background-color: var(--ff-success);
  border-color: var(--ff-success);
  box-shadow: 0 4px 0 var(--ff-success-dark);
}

.btn-success:hover {
  background-color: var(--ff-success-dark);
  border-color: var(--ff-success-dark);
}

/* Navbar */
.navbar {
  background-color: var(--ff-surface) !important;
  border-bottom: 1px solid var(--ff-border) !important;
}

.navbar .nav-link {
  color: var(--ff-text) !important;
  font-weight: 700;
}

.navbar .nav-link:hover {
  color: var(--ff-primary) !important;
}

/* Tables */
.table {
  color: var(--ff-text);
}

/* Animated exercise feedback */
@keyframes ff-pop {
  0% { transform: scale(0.96); }
  60% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

@keyframes ff-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.feedback.alert-success {
  animation: ff-pop 0.3s ease;
}

.feedback.alert-danger {
  animation: ff-shake 0.4s ease;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

/* Landing page helpers */
.text-ff-success {
  color: var(--ff-success);
}

.text-accent {
  color: var(--ff-accent) !important;
}

.hero-mascot {
  max-width: 260px;
  width: 100%;
}

.feature-icon {
  font-size: 2.5rem;
  line-height: 1;
}

/* Achievement badge icons */
.badge-icon {
  font-size: 2rem;
  line-height: 1;
}

/* Reading summary score ring */
.reading-score-ring {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(#e5e7eb 0deg, #e5e7eb 360deg);
  flex: 0 0 auto;
}

.reading-score-inner {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--ff-surface);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Navbar dropdown themed for dark mode */
.dropdown-menu {
  background-color: var(--ff-surface);
  border-color: var(--ff-border);
  box-shadow: var(--ff-shadow);
}

.dropdown-item {
  color: var(--ff-text);
}

.dropdown-item:hover, .dropdown-item:focus {
  background-color: var(--ff-bg);
  color: var(--ff-primary);
}

/* =====================================================================
   Mobile usability polish
   - Larger, finger-friendly tap targets (min ~44px per Apple HIG)
   - Roomier collapsed navbar so the menu is easy to read and tap
   - Comfortable form controls and buttons on small screens
   ===================================================================== */

/* Prevent iOS from auto-zooming when focusing inputs (needs >=16px). */
.form-control,
.form-select {
  font-size: 1rem;
}

/* Brand a touch bigger and clearer on phones. */
.navbar-brand {
  font-size: 1.25rem;
}

/* Make the hamburger button a proper tap target. */
.navbar-toggler {
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
}

.navbar-toggler:focus {
  box-shadow: 0 0 0 0.2rem rgba(43, 108, 176, 0.35);
}

@media (max-width: 575.98px) {
  /* Collapsed menu: give each link a generous, easy-to-tap row. */
  .navbar .navbar-nav .nav-link {
    padding: 0.75rem 0.25rem;
    font-size: 1.05rem;
    border-radius: 10px;
  }

  .navbar .navbar-nav .nav-link:hover,
  .navbar .navbar-nav .nav-link:focus {
    background-color: var(--ff-bg);
  }

  /* Dropdown items inside the collapsed menu: bigger rows + clear indent. */
  .navbar .dropdown-menu {
    border: none;
    box-shadow: none;
    padding-left: 0.5rem;
  }

  .navbar .dropdown-item {
    padding: 0.7rem 0.5rem;
    font-size: 1.02rem;
    white-space: normal;
  }

  /* Space out the theme toggle + login area when stacked. */
  #themeToggle {
    margin: 0.5rem 0.25rem 0.25rem 0.25rem !important;
    padding: 0.5rem 0.9rem;
  }

  /* Buttons and links should be comfortable to tap. */
  .btn {
    padding: 0.6rem 1.25rem;
  }

  /* Stacked action buttons get full width for easy tapping. */
  .btn-block-sm {
    display: block;
    width: 100%;
  }

  /* Headings: trim slightly so they don't dominate small screens. */
  h1, .h1 { font-size: 1.6rem; }
  h2, .h2 { font-size: 1.35rem; }
  h3, .h3 { font-size: 1.2rem; }

  /* Tables scroll horizontally instead of squishing. */
  .table-responsive-sm {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Ensure anything interactive has a minimum comfortable hit area. */
.nav-link,
.dropdown-item {
  min-height: 44px;
  display: flex;
  align-items: center;
}

.btn {
  min-height: 44px;
}

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .card,
  .btn,
  .feedback.alert-success,
  .feedback.alert-danger {
    transition: none;
    animation: none;
  }
}

/* ---------------------------------------------------------------------
   Stacked tables on phones
   Turns a wide comparison table (e.g. Gramática) into readable stacked
   cards on narrow screens, using each cell's data-label as a heading.
   On >=576px it stays a normal table.
   --------------------------------------------------------------------- */
@media (max-width: 575.98px) {
  .ff-stack-table thead {
    display: none;
  }

  .ff-stack-table,
  .ff-stack-table tbody,
  .ff-stack-table tr,
  .ff-stack-table td {
    display: block;
    width: 100%;
  }

  .ff-stack-table tr {
    margin-bottom: 0.9rem;
    border: 1px solid var(--ff-border);
    border-radius: 12px;
    overflow: hidden;
    background-color: var(--ff-surface);
  }

  .ff-stack-table td {
    border: none;
    border-bottom: 1px solid var(--ff-border);
    padding: 0.6rem 0.85rem;
  }

  .ff-stack-table td:last-child {
    border-bottom: none;
  }

  .ff-stack-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--ff-muted);
    margin-bottom: 0.15rem;
  }
}

/* ---------------------------------------------------------------------
   Navbar layout (global so it also styles the login partial)
   Desktop: single centered row, no text wrapping.
   Mobile: menu + actions stack cleanly.
   --------------------------------------------------------------------- */

/* Ensure the hamburger toggler is always visible, even in dark mode. */
.ff-navbar .navbar-toggler {
  border: 1px solid rgba(0, 0, 0, 0.2);
  padding: 0.35rem 0.55rem;
}

/* Uniform, compact nav action buttons for a consistent look and good fit. */
.ff-navbar {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.ff-navbar .container {
  align-items: center;
}

.ff-nav-actions .btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 999px;
  line-height: 1.2;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ff-nav-actions #themeToggle {
  padding: 0.35rem 0.6rem;
}

.ff-navbar .navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2843, 108, 176, 1%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

@media (min-width: 1200px) {
  .ff-navbar #mainNav {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
  }

  .ff-navbar .navbar-nav {
    flex-direction: row;
    align-items: center;
  }

  .ff-navbar .nav-link {
    white-space: nowrap;
  }

  /* Right-side actions: one centered row. */
  .ff-nav-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.5rem;
    margin-left: auto;
  }

  /* The login partial is its own <ul>; lay it out inline and centered. */
  .ff-nav-actions .navbar-nav {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .ff-nav-actions .nav-item {
    display: flex;
    align-items: center;
    margin: 0;
  }

  .ff-nav-actions .nav-item .btn {
    margin: 0;
  }

  .ff-nav-actions .nav-link {
    white-space: nowrap;
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
  }
}
