/* ============================================================
   Math Worksheet Builder — Styles
   Palette: 4 accent colors (excluding black/white)
     --accent:     #2563eb  (blue — primary)
     --accent-alt: #1e40af  (dark blue — hover/active)
     --success:    #16a34a  (green — toggle on)
     --muted:      #94a3b8  (slate — disabled/secondary)
   ============================================================ */

:root {
  --accent: #2563eb;
  --accent-alt: #1e40af;
  --success: #16a34a;
  --muted: #94a3b8;

  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
}

/* ---- Reset & Base ---- */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- Site Nav ---- */

.site-nav {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-nav-link {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.site-nav-link:hover {
  text-decoration: underline;
}

.site-nav-link.active {
  color: var(--text);
  text-decoration: none;
  cursor: default;
}

/* ---- Container ---- */

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 32px 20px 48px;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
  text-align: center;
}

.site-subtitle {
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--text-secondary);
  text-align: center;
  margin: 0 0 28px;
}

/* ---- Home Title ---- */

.home-title {
  color: var(--accent);
}

/* ---- Brand Header ---- */

.brand-header {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-align: center;
  margin-bottom: 0;
}

.brand-support-link {
  display: block;
  text-align: center;
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: underline;
  margin-bottom: 8px;
}

/* ---- Subject Grid (Home Page) ---- */

.subject-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  max-width: 400px;
  margin: 0 auto;
}

.subject-btn {
  min-height: 80px;
  font-size: 1.25rem;
  font-weight: 700;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.subject-coming-soon {
  background: var(--muted);
  cursor: not-allowed;
}

.subject-coming-soon:hover {
  background: var(--muted);
}

.coming-soon-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0.85;
}

@media (max-width: 400px) {
  .subject-grid {
    gap: 12px;
  }

  .subject-btn {
    min-height: 64px;
    font-size: 1.1rem;
  }
}

/* ---- Fieldset / Legend ---- */

fieldset {
  border: none;
  margin-bottom: 28px;
}

legend {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ---- Operation Notice ---- */

@keyframes operation-notice-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.operation-notice {
  color: var(--text-secondary);
  text-align: center;
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 12px;
  animation: operation-notice-pulse 2s ease-in-out infinite;
}

.operation-notice.hidden {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .operation-notice {
    animation: none;
  }
}

/* ---- Card Row ---- */

.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* ---- Card (radio wrapper) ---- */

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  min-width: 100px;
  min-height: 72px;
  padding: 16px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
}

.card:hover {
  border-color: var(--accent);
}

.card:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card.selected {
  border-color: var(--accent);
  background: #eff6ff;
  box-shadow: 0 0 0 1px var(--accent);
}

/* Hide the native radio/checkbox but keep it accessible */
.card input[type="radio"],
.card input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.card-label {
  font-size: 1rem;
  font-weight: 600;
  pointer-events: none;
}

.card-range {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
  pointer-events: none;
}

/* ---- Factor Range Row ---- */

.factor-range-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  font-size: 0.95rem;
  font-weight: 500;
}

.factor-range-row input[type="number"] {
  width: 64px;
  padding: 8px 10px;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
  min-height: 40px;
  transition: border-color 0.15s ease;
}

.factor-range-row input[type="number"]:focus {
  border-color: var(--accent);
  outline: none;
}

/* ---- Options Group ---- */

.options-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---- Toggle Row ---- */

.toggle-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  min-height: 44px;
  user-select: none;
  -webkit-user-select: none;
}

.toggle-status {
  font-weight: 400;
  color: var(--text-secondary);
  min-width: 24px;
}

/* Hide native checkbox */
.toggle-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* Track */
.toggle-track {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
  background: var(--muted);
  border-radius: 14px;
  transition: background-color 0.2s ease;
}

/* Thumb */
.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Checked state */
.toggle-label input[type="checkbox"]:checked ~ .toggle-track {
  background: var(--success);
}

.toggle-label input[type="checkbox"]:checked ~ .toggle-track .toggle-thumb {
  transform: translateX(20px);
}

/* Focus ring on the track when checkbox is focused */
.toggle-label input[type="checkbox"]:focus-visible ~ .toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Disabled toggle */
.toggle-label.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toggle-label.disabled .toggle-track {
  background: var(--muted);
}

.toggle-label.disabled input[type="checkbox"]:checked ~ .toggle-track {
  background: var(--muted);
}

/* Note text beneath toggle */
.toggle-note {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-left: 0;
  min-height: 0;
}

/* ---- Number Input Row ---- */

.number-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.number-row label {
  font-size: 0.95rem;
  font-weight: 500;
}

.number-row input[type="number"] {
  width: 120px;
  padding: 10px 12px;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease;
  min-height: 44px;
}

.number-row input[type="number"]:focus {
  border-color: var(--accent);
  outline: none;
}

.number-row input[type="number"]:invalid {
  border-color: #dc2626;
  background: #fef2f2;
}

/* ---- Action Section ---- */

/* ---- Math Page Sections ---- */

.math-section {
  margin-top: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}

.math-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 16px 20px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-align: left;
}

.math-section-toggle:hover {
  background: var(--bg);
}

.math-section-toggle-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.math-section-thumb {
  width: 120px;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.math-section-arrow {
  font-size: 0.8rem;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.math-section-toggle[aria-expanded="true"] .math-section-arrow {
  transform: rotate(90deg);
}

.math-section-body {
  padding: 0 20px 20px;
}

.premade-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.premade-btn {
  font-size: 0.9rem;
  padding: 12px 10px;
}

.flash-section-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.math-bottom-actions {
  margin-top: 24px;
}

@media (max-width: 480px) {
  .premade-grid {
    grid-template-columns: 1fr;
  }
}

.action-section {
  margin-top: 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.math-section-body .action-section {
  margin-top: 16px;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 16px 24px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  min-height: 52px;
}

.btn-primary:hover {
  background: var(--accent-alt);
}

button#show-worksheet-btn:disabled,
button#flash-card-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  transition: all 0.2s ease;
}

/* ---- Experimental Label ---- */

.action-experimental {
  margin-top: 12px;
}

.experimental-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 4px;
}

/* ---- Responsive ---- */

/* Tablet and up (768px+) — already good by default */

/* Phone (<768px) — single-column cards, no overflow */
@media (max-width: 767px) {
  .container {
    padding: 20px 16px 40px;
  }

  h1 {
    font-size: 1.4rem;
    margin-bottom: 20px;
  }

  .card-row {
    gap: 8px;
  }

  .card {
    min-width: 0;
    flex: 1 1 0;
    padding: 12px 8px;
    min-height: 56px;
  }

  .card-label {
    font-size: 0.85rem;
  }

  .card-range {
    font-size: 0.7rem;
  }
}

/* Very small screens */
@media (max-width: 400px) {
  .card-group .card-row {
    flex-wrap: wrap;
  }

  .card-group .card-row .card {
    flex: 1 1 calc(50% - 6px);
    min-width: calc(50% - 6px);
  }
}

/* ---- Worksheet View ---- */

.worksheet-container {
  max-width: 960px;
}

/* ---- Toolbar ---- */

.worksheet-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.btn-secondary {
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  min-height: 44px;
}

.btn-secondary:hover {
  background: #eff6ff;
}

.btn-secondary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Problems Grid ---- */

.problems-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, max-content));
  gap: 32px 20px;
  justify-content: center;
}

/* ---- Problem Block ---- */

.problem {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  aspect-ratio: 1;
}

.problem-number {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.6;
  flex-shrink: 0;
}

.problem-content {
  font-family: "Courier New", Courier, "Liberation Mono", monospace;
  font-size: 1.25rem;
  text-align: right;
  min-width: 5ch;
  flex: 0 0 auto;
}

.problem-num1 {
  text-align: right;
}

.problem-num2 {
  text-align: right;
}

.problem-operator {
  float: left;
}

.problem-rule {
  border-bottom: 2px solid var(--text);
  margin: 4px 0 8px;
}

.problem-answer {
  text-align: right;
  color: var(--accent);
  font-weight: 600;
  min-height: 1.6em;
  visibility: visible;
}

.problem-answer.hidden {
  visibility: hidden;
}

/* ---- Responsive: Worksheet Grid ---- */

@media (max-width: 767px) {
  .problems-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, max-content));
    gap: 12px;
  }

  .worksheet-toolbar {
    gap: 8px;
  }

  .btn-secondary {
    padding: 8px 14px;
    font-size: 0.85rem;
  }
}

@media (max-width: 400px) {
  .problems-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

/* ---- Flash Card Empty Message ---- */

.fc-empty-msg {
  font-size: 0.9rem;
  color: #dc2626;
  font-weight: 500;
  text-align: center;
}

/* ---- Flash Card Modal ---- */

.fc-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fc-modal-container {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  padding: 32px 28px 28px;
  min-width: 280px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.fc-modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fc-modal-close:hover {
  color: var(--text);
}

.fc-modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.fc-modal-btn {
  width: 100%;
  padding: 14px 24px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 10px;
  min-height: 52px;
  cursor: pointer;
  border: none;
  text-align: center;
}

.fc-modal-btn-disabled {
  background: var(--muted);
  color: #fff;
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.fc-modal-btn-disabled:hover {
  background: var(--muted);
}

/* ---- Flash Card Complete Modal ---- */

.fc-complete-modal {
  text-align: center;
  padding: 40px 32px 32px;
}

.fc-complete-text {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text);
}

/* ---- Flash Card View ---- */

.fc-view {
  max-width: 680px;
}

.fc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.fc-progress {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.fc-card {
  font-family: "Courier New", Courier, "Liberation Mono", monospace;
  font-size: 3.5rem;
  text-align: right;
  display: inline-block;
  min-width: 4ch;
  margin: 0 auto 32px;
  padding: 32px 48px 24px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
}

.fc-card-wrapper {
  text-align: center;
}

.fc-num1 {
  text-align: right;
}

.fc-num2 {
  text-align: right;
}

.fc-operator {
  float: left;
}

.fc-rule {
  border-bottom: 3px solid var(--text);
  margin: 8px 0 8px;
}

.fc-answer {
  text-align: right;
  color: var(--accent);
  font-weight: 600;
  min-height: 1.2em;
  visibility: visible;
}

.fc-answer.hidden {
  visibility: hidden;
}

.fc-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  max-width: 320px;
  margin: 0 auto;
}

.fc-action-btn {
  flex: 1;
}

.fc-skip-btn {
  flex: 0 0 auto;
  min-width: 52px;
  font-size: 1.2rem;
  font-weight: 700;
}

/* ---- Flash Card Responsive ---- */

@media (max-width: 767px) {
  .fc-card {
    font-size: 2.5rem;
    padding: 28px 32px;
  }
}

/* ---- Print Styles ---- */

@media print {
  body {
    background: #fff;
    min-height: 0;
  }

  .site-nav,
  .worksheet-toolbar {
    display: none;
  }

  #home {
    display: none !important;
  }

  #config {
    display: none !important;
  }

  .operation-notice {
    display: none !important;
  }

  #worksheet {
    display: block !important;
  }

  .container,
  .worksheet-container {
    padding: 0;
    margin: 0;
    max-width: none;
  }

  .problem {
    border: none;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .problems-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, max-content));
    gap: 60px 16px;
  }

  #flash-card-view {
    display: none !important;
  }

  .fc-modal-backdrop {
    display: none !important;
  }

  /* Answer visibility in print respects the current toggle state.
     Answers hidden by JS (visibility:hidden) stay hidden; answers shown stay shown. */

  #spelling-grade-select {
    display: none !important;
  }

  #spelling-view {
    display: none !important;
  }

  #spelling-complete {
    display: none !important;
  }
}

/* ============================================================
   Spelling Words Mode
   ============================================================ */

/* ---- Spelling Grade Selection ---- */

.spelling-grade-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 28px;
  color: var(--text);
}

/* ---- Voice Selection Dropdown ---- */

.voice-select-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 480px;
  margin: 0 auto 28px;
}

.voice-select-label {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.voice-select {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  font-weight: 500;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
  cursor: pointer;
  transition: border-color 0.15s ease;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.voice-select:focus {
  border-color: var(--accent);
  outline: none;
}

.voice-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  color: var(--text-secondary);
}

.spelling-grade-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-width: 480px;
  margin: 0 auto 28px;
}

.spelling-grade-btn {
  min-height: 52px;
  min-width: 44px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 10px;
  padding: 14px 12px;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.spelling-grade-btn:hover {
  background: var(--accent-alt);
  transform: translateY(-1px);
}

.spelling-grade-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.spelling-grade-nav {
  text-align: center;
  margin-top: 8px;
}

.spelling-grade-nav .btn-secondary {
  min-height: 44px;
}

/* ---- Spelling Toolbar ---- */

.spelling-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

/* ---- Spelling Progress ---- */

.spelling-progress {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.spelling-grade-label {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
}

/* ---- Spelling TTS Buttons ---- */

.spelling-tts-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.spelling-tts-btn {
  flex: 1 1 0;
  min-height: 52px;
  min-width: 44px;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 14px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.spelling-tts-btn:hover {
  background: var(--accent-alt);
}

.spelling-tts-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Spelling Input Row ---- */

.spelling-input-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  max-width: 400px;
  margin: 0 auto;
}

.spelling-input {
  flex: 1;
  padding: 12px 16px;
  font-size: 1.1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 48px;
  transition: border-color 0.15s ease;
}

.spelling-input:focus {
  border-color: var(--accent);
  outline: none;
}

.spelling-input-row .btn-primary {
  flex: 0 0 auto;
  width: auto;
  min-width: 80px;
  min-height: 48px;
}

/* ---- Spelling Feedback ---- */

.spelling-feedback {
  text-align: center;
  margin-top: 16px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 500;
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* ---- Spelling Summary / Completion View ---- */

.spelling-summary {
  text-align: center;
  padding: 48px 20px;
}

.spelling-score-text {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 32px;
}

.spelling-summary-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 320px;
  margin: 0 auto;
}

/* ---- Spelling Feedback: Correct ---- */

.feedback-correct {
  color: #28a745;
  background: #d4edda;
  border-color: #c3e6cb;
}

/* ---- Spelling Correction Row ---- */

.spelling-correction-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 400px;
  margin: 16px auto 0;
}

.spelling-correction-row .spelling-input {
  width: 100%;
}

.spelling-correction-row .btn-primary {
  width: 100%;
}

.spelling-correction-row .btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Spelling Review Panel ---- */

.spelling-review {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px;
}

.spelling-review-title {
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
  color: var(--text);
}

.spelling-review-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.spelling-review-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.spelling-review-word {
  font-weight: 600;
}

.spelling-review-correct {
  color: #28a745;
  font-weight: 600;
}

.spelling-review-incorrect {
  color: #dc3545;
  font-weight: 500;
}

.spelling-review-label {
  font-weight: 600;
}

.spelling-review-answer {
  font-weight: 400;
  font-style: italic;
}

.spelling-review-nav {
  text-align: center;
}

/* ---- Spelling Responsive ---- */

@media (max-width: 767px) {
  .spelling-grade-title {
    font-size: 1.25rem;
    margin-bottom: 20px;
  }

  .spelling-grade-buttons {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .spelling-grade-btn {
    font-size: 0.95rem;
    padding: 12px 10px;
    min-height: 48px;
  }

  .spelling-tts-buttons {
    gap: 8px;
  }

  .spelling-tts-btn {
    font-size: 0.95rem;
    padding: 12px 12px;
    min-height: 48px;
  }

  .spelling-score-text {
    font-size: 1.25rem;
  }
}

@media (max-width: 400px) {
  .spelling-grade-buttons {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .spelling-tts-buttons {
    flex-direction: column;
  }

  .spelling-tts-btn {
    min-height: 48px;
  }
}

/* ============================================================
   Multiplayer Flash Card Mode
   ============================================================ */

/* ---- Waiting View ---- */

.mp-waiting-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 24px;
  color: var(--text);
}

.mp-qr-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

#mp-qr-code {
  display: inline-block;
}

.mp-waiting-msg {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ---- Grade Controls (Correct / Incorrect) ---- */

.mp-grade-controls {
  display: flex;
  justify-content: center;
  gap: 16px;
  max-width: 400px;
  margin: 0 auto;
}

.mp-grade-btn {
  flex: 1;
  min-height: 56px;
  font-size: 1.15rem;
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.mp-correct-btn {
  background: var(--success);
}

.mp-correct-btn:hover {
  background: #15803d;
}

.mp-incorrect-btn {
  background: #dc2626;
}

.mp-incorrect-btn:hover {
  background: #b91c1c;
}

.mp-grade-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Student Status ---- */

.mp-student-status {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 16px;
}

/* ---- Results View ---- */

.mp-results-summary {
  text-align: center;
  padding: 48px 20px;
}

.mp-results-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

.mp-results-score {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 32px;
}

.mp-results-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 320px;
  margin: 0 auto;
}

.mp-no-incorrect {
  font-size: 1rem;
  font-weight: 500;
  color: var(--success);
  text-align: center;
}

/* ---- Review View ---- */

.mp-review-toolbar {
  margin-bottom: 16px;
}

.mp-review-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

.mp-review-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mp-review-card {
  font-family: "Courier New", Courier, "Liberation Mono", monospace;
  font-size: 1.25rem;
  padding: 16px 20px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  text-align: center;
}

/* ---- Multiplayer Responsive ---- */

@media (max-width: 767px) {
  .mp-waiting-title {
    font-size: 1.25rem;
  }

  .mp-grade-controls {
    gap: 12px;
  }

  .mp-grade-btn {
    font-size: 1rem;
    min-height: 52px;
  }

  .mp-results-title {
    font-size: 1.25rem;
  }

  .mp-results-score {
    font-size: 1.1rem;
  }
}

/* ---- Teacher Code Entry Modal ---- */

.tc-modal-heading {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.tc-code-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.3em;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 52px;
  transition: border-color 0.15s ease;
}

.tc-code-input:focus {
  border-color: var(--accent);
  outline: none;
}

.tc-code-input::placeholder {
  color: var(--muted);
  letter-spacing: 0.3em;
}

.tc-error {
  font-size: 0.9rem;
  color: #dc2626;
  font-weight: 500;
  text-align: center;
  min-height: 0;
}

.tc-error:empty {
  display: none;
}

/* ---- Teacher Waiting View: Join Code Display ---- */

.mp-code-label {
  text-align: center;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.mp-join-code {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: var(--text);
  margin-bottom: 24px;
}

/* ---- End Session Button Row ---- */

.mp-end-session-row {
  text-align: center;
  margin-top: 24px;
}

.mp-end-session-row .btn-destructive {
  width: auto;
  min-width: 160px;
}

/* ---- Destructive Button Variants ---- */

.btn-destructive {
  color: #dc2626;
  border-color: #dc2626;
}

.btn-destructive:hover {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #b91c1c;
}

.btn-destructive-fill {
  background: #dc2626;
  color: #fff;
  border: none;
}

.btn-destructive-fill:hover {
  background: #b91c1c;
}

.btn-destructive-fill:disabled {
  background: var(--muted);
  cursor: not-allowed;
}

/* ---- End Session Modal ---- */

.end-session-modal {
  text-align: center;
  padding: 32px 28px 28px;
}

.end-session-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.end-session-error {
  font-size: 0.9rem;
  font-weight: 500;
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
}

/* ---- Toast Notifications ---- */

.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.toast.toast-fade-out {
  opacity: 0;
}

/* ---- Support nudge ---- */
.support-nudge {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e0e0e0;
  text-align: center;
  font-size: 0.85rem;
  color: #666;
}

.support-nudge p {
  margin: 0 0 0.5rem 0;
}

.support-nudge a {
  color: #2563eb;
  text-decoration: underline;
  font-weight: 600;
}

/* ---- Print: hide multiplayer views ---- */

@media print {
  #mp-waiting-view,
  #mp-teacher-card-view,
  #mp-student-card-view,
  #mp-results-view,
  #mp-review-view {
    display: none !important;
  }

  #end-session-backdrop,
  #session-ended-backdrop,
  .toast-container {
    display: none !important;
  }
}

/* ============================================================
   Geography Quiz Mode
   ============================================================ */

/* ---- Quiz Container ---- */

.geo-quiz-container {
  max-width: 800px;
}

/* ---- Setup Controls ---- */

.geo-setup-controls {
  max-width: 360px;
  margin: 0 auto;
}

.geo-category-fieldset {
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 16px 0;
}

.geo-category-fieldset legend {
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0 6px;
}

.geo-category-fieldset .geo-checkboxes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 0;
}

.geo-checkbox-label {
  display: block;
  font-size: 0.9rem;
  cursor: pointer;
}

.geo-checkbox-label input {
  margin-right: 4px;
}

/* ---- Map Container ---- */

.geo-map-container {
  width: 100%;
  margin: 0 auto 20px;
  text-align: center;
}

.geo-map-container svg {
  width: 100%;
  height: auto;
  max-height: 400px;
}

/* ---- State Paths ---- */

.geo-state {
  fill: #dde4ec;
  stroke: #fff;
  stroke-width: 1;
  transition: fill 0.2s ease;
}

.geo-state:hover {
  fill: #c4d0e0;
}

.geo-state-active {
  fill: #93b5e8;
  stroke: var(--accent);
  stroke-width: 2.5;
}

/* ---- Markers ---- */

.geo-marker-capital {
  fill: #f59e0b;
  stroke: #92400e;
  stroke-width: 1;
}

.geo-marker-city {
  fill: #dc2626;
  stroke: #7f1d1d;
  stroke-width: 1;
}

/* ---- Question Text ---- */

.geo-question-text {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
  min-height: 1.5em;
}

.geo-help-text {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted, #888);
  margin-bottom: 8px;
  font-style: italic;
}

/* ---- Answer Row ---- */

.geo-answer-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  max-width: 400px;
  margin: 0 auto;
  padding: 0 12px;
  box-sizing: border-box;
}

.geo-answer-row .spelling-input {
  flex: 1;
  min-width: 0;
}

.geo-answer-row .btn-primary {
  flex: 0 0 auto;
  width: auto;
  min-width: 80px;
  min-height: 48px;
}

/* ---- Feedback ---- */

.geo-feedback {
  text-align: center;
  margin-top: 16px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.geo-feedback-correct {
  color: #15803d;
  background: #dcfce7;
  border: 1px solid #bbf7d0;
}

.geo-feedback-fuzzy {
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fde68a;
}

.geo-feedback-wrong {
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
}

/* ---- Review: fuzzy match ---- */

.geo-review-fuzzy {
  color: #92400e;
  font-weight: 500;
}

/* ---- Mini Map (mobile keyboard overlay) ---- */

.geo-mini-map {
  display: none;
}

.geo-mini-map.visible {
  display: block;
  width: 160px;
  height: 120px;
  margin: 0 auto 8px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border, #ccc);
  border-radius: 8px;
  overflow: hidden;
}

.geo-mini-map svg {
  width: 100%;
  height: 100%;
}

/* ---- Geography Responsive ---- */

@media (max-width: 767px) {
  .geo-question-text {
    font-size: 1.1rem;
  }

  .geo-map-container svg {
    max-height: 280px;
  }
}

/* ---- Print: hide geography views ---- */

@media print {
  #geo-setup,
  #geo-quiz-view,
  #geo-summary-view {
    display: none !important;
  }
}
