:root {
  --sidebar: 260px;
  --bg: #f7f8fa;
  --paper: #ffffff;
  --text: #20242a;
  --muted: #667085;
  --line: #d9dee7;
  --soft: #f0f3f7;
  --accent: #2f5f8f;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  font-size: 16px;
}

/* Floating Sidebar Toggle Button */
.sidebar-toggle {
  position: fixed;
  top: 12px;
  left: 206px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #ffffff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  z-index: 35;
  transition: left 0.22s ease, background 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-toggle:hover {
  background: var(--soft);
}

/* Sidebar navigation */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar);
  background: #ffffff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 25;
  transition: transform 0.22s ease;
  -webkit-overflow-scrolling: touch;
}

.sidebar-header {
  position: sticky;
  top: 0;
  background: #ffffff;
  z-index: 2;
  border-bottom: 1px solid var(--line);
  padding: 14px 12px;
  min-height: 54px;
  display: flex;
  align-items: center;
}

.site-title {
  font-weight: 750;
  font-size: 15px;
  margin: 0;
  padding-right: 48px;
}

/* Timer in Sidebar */
.timer-container {
  margin: 10px 12px 6px;
  text-align: center;
}

.test-timer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  font-weight: 750;
  font-size: 14.5px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  margin: 0;
}

.test-timer.timer-overtime {
  border-color: #f59e0b;
  color: #b45309;
  background: #fffbeb;
}

.timer-subtext {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
  margin-top: 4px;
}

.test-timer.timer-stopped {
  background: #f0fdf4;
  border-color: #86efac;
  color: #15803d;
}

.sidebar-body {
  padding: 10px 12px 28px;
}

/* Complete Collapse Behavior: NO white bar remains */
body.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  border-right: none;
}

body.sidebar-collapsed .sidebar-toggle {
  left: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
}

/* Navigation groups */
.nav-group {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 0 0 10px;
  background: #ffffff;
  overflow: hidden;
}

.nav-group summary {
  cursor: pointer;
  list-style: none;
  font-weight: 750;
  padding: 12px;
  background: var(--soft);
  user-select: none;
}

.nav-group summary::-webkit-details-marker {
  display: none;
}

.nav-links {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 10px;
}

.nav-links a {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 650;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.nav-links a:hover {
  filter: brightness(0.96);
}

/* Sidebar question status colors for Test */
.nav-links a.state-unanswered {
  background: #ffffff;
  border-color: var(--line);
  color: var(--text);
}

.nav-links a.state-answered {
  background: #dcfce7;
  border-color: #22c55e;
  color: #15803d;
}

.nav-links a.state-correct {
  background: #dcfce7 !important;
  border-color: #22c55e !important;
  color: #15803d !important;
}

.nav-links a.state-incorrect {
  background: #fee2e2 !important;
  border-color: #ef4444 !important;
  color: #b91c1c !important;
}

.nav-links a.state-flagged {
  background: #ffedd5 !important;
  border-color: #f97316 !important;
  color: #c2410c !important;
}

/* Sidebar rating status colors for Study Guide */
.nav-links a.state-red {
  background: #fee2e2;
  border-color: #ef4444;
  color: #991b1b;
}

.nav-links a.state-yellow {
  background: #fef9c3;
  border-color: #eab308;
  color: #854d0e;
}

.nav-links a.state-green {
  background: #dcfce7;
  border-color: #22c55e;
  color: #15803d;
}

/* Main Content */
.main {
  margin-left: var(--sidebar);
  padding: 32px 28px 64px;
  transition: margin-left 0.22s ease;
}

body.sidebar-collapsed .main {
  margin-left: 0;
  padding-left: 64px;
}

.content {
  width: min(900px, 100%);
  margin: 0 auto;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
  margin: 0 0 8px;
}

h2 {
  font-size: 24px;
  margin: 44px 0 18px;
}

h3 {
  font-size: 18px;
  margin: 0;
}

h4 {
  font-size: 16px;
  margin: 18px 0 7px;
}

p {
  margin: 8px 0;
}

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

.unit {
  scroll-margin-top: 18px;
}

.card,
.guide-section {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  margin: 0 0 22px;
  scroll-margin-top: 18px;
}

/* Card Header with Question Title, Autosave Indicator & Flag Button */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--soft);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Autosave Indicator */
.save-indicator {
  font-size: 13px;
  font-weight: 650;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid transparent;
  color: #64748b;
  background: #f1f5f9;
  transition: all 0.2s ease;
}

.save-indicator.saved {
  color: #15803d;
  background: #dcfce7;
  border-color: #bbf7d0;
}

.save-indicator.saving {
  color: #b45309;
  background: #fef3c7;
  border-color: #fde68a;
}

/* Flag Button */
.flag-btn {
  font-size: 13px;
  font-weight: 650;
  padding: 4px 12px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.flag-btn:hover {
  background: var(--soft);
}

.flag-btn.flagged {
  background: #ffedd5;
  border-color: #f97316;
  color: #c2410c;
  font-weight: 700;
}

/* In-Page Answer Review Box (Shown Post-Submit) */
.answer-review-box {
  display: none;
  margin-top: 18px;
  padding: 16px;
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 9px;
  color: #14532d;
}

.answer-review-box.visible {
  display: block;
}

.answer-review-box h4 {
  margin: 0 0 8px;
  color: #15803d;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.answer-review-box .solution-text {
  font-size: 14px;
  line-height: 1.5;
  margin: 4px 0;
}

/* Completion Banner */
.completion-banner {
  display: none;
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 24px;
}

.completion-banner.visible {
  display: block;
}

.completion-banner h2 {
  margin: 0 0 6px;
  color: #15803d;
  font-size: 22px;
}

.score-badge {
  display: inline-block;
  font-size: 16px;
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 20px;
  background: #ffffff;
  border: 2px solid #22c55e;
  color: #15803d;
  margin: 6px 0 10px;
}

.completion-banner p {
  margin: 4px 0;
  color: #166534;
}

.completion-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

/* Graded Input Feedback */
.input-correct {
  border-color: #22c55e !important;
  background-color: #f0fdf4 !important;
}

.input-incorrect {
  border-color: #ef4444 !important;
  background-color: #fef2f2 !important;
}

/* Study Guide Understanding Rating Gauge */
.understanding-gauge {
  margin: 18px 0 6px;
  padding: 12px 14px;
  background: var(--soft);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.gauge-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.gauge-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.gauge-btn {
  font-size: 13px;
  font-weight: 650;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  background: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.gauge-btn:hover {
  filter: brightness(0.96);
}

.gauge-btn.selected[data-val="red"] {
  background: #fee2e2;
  border-color: #ef4444;
  color: #991b1b;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.gauge-btn.selected[data-val="yellow"] {
  background: #fef9c3;
  border-color: #eab308;
  color: #854d0e;
  box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.2);
}

.gauge-btn.selected[data-val="green"] {
  background: #dcfce7;
  border-color: #22c55e;
  color: #15803d;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

/* Study Guide Module Check-Yourself Disclosure */
.module-answer {
  margin: 12px 0 8px;
}

.module-answer summary {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  background: #ffffff;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s ease;
}

.module-answer summary:hover {
  background: var(--soft);
}

.module-answer summary::-webkit-details-marker {
  display: none;
}

.module-answer-box {
  margin-top: 8px;
  padding: 10px 14px;
  background: #f8fafc;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  font-weight: 600;
  color: #1e293b;
}

/* Standard Content & Components */
.part {
  margin: 18px 0 0;
}

.math {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  white-space: pre-wrap;
}

.answer,
.answer-line,
.answer-work {
  width: 100%;
  border: 1.5px solid #aab3c0;
  border-radius: 8px;
  background: #ffffff;
  font: inherit;
  color: var(--text);
  padding: 11px 12px;
}

.answer-line {
  min-height: 48px;
}

.answer {
  min-height: 82px;
  resize: vertical;
}

.answer-work {
  min-height: 160px;
  resize: vertical;
}

.answer:focus,
.answer-line:focus,
.answer-work:focus,
.inline-input:focus {
  outline: 3px solid rgba(47, 95, 143, 0.12);
  border-color: var(--accent);
}

.inline-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.inline-input {
  width: 120px;
  min-height: 44px;
  border: 1.5px solid #aab3c0;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}

.inline-input.small {
  width: 80px;
}

/* Place Value Chart */
.pv-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(92px, 1fr));
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-top: 10px;
}

.pv-grid div {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 6px;
  text-align: center;
  font-size: 13px;
}

.pv-grid div:nth-child(6n) {
  border-right: 0;
}

.pv-grid input {
  width: 100%;
  min-width: 0;
  min-height: 52px;
  border: 0;
  text-align: center;
  font-size: 18px;
}

/* Models */
.model {
  display: grid;
  margin: 14px 0;
  max-width: 600px;
}

.model.two {
  grid-template-columns: 4fr 1fr;
}

.model.four {
  grid-template-columns: 5fr 3fr 2fr 1.5fr;
}

.model .label {
  text-align: center;
  font-weight: 700;
  padding: 5px;
}

.model .box {
  border: 1.5px solid #7f8b99;
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.model .box + .box {
  border-left: 0;
}

.stack {
  display: inline-block;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
  margin: 7px 0 10px;
  white-space: pre;
}

.example {
  background: #fafbfc;
  border-left: 4px solid #b9c5d2;
  padding: 12px 14px;
  margin: 10px 0;
  border-radius: 4px 8px 8px 4px;
}

/* Actions & Buttons */
.test-actions-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 36px 0 12px;
}

.btn-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

.submit-test-btn {
  border: 0;
  border-radius: 10px;
  background: #16a34a;
  color: #ffffff;
  font: inherit;
  font-weight: 750;
  padding: 14px 26px;
  min-width: 220px;
  min-height: 50px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.25);
}

.submit-test-btn:hover {
  background: #15803d;
}

.submit-test-btn:disabled {
  background: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
}

.copy-ai-btn {
  border: 1.5px solid #2563eb;
  border-radius: 10px;
  background: #eff6ff;
  color: #1d4ed8;
  font: inherit;
  font-weight: 750;
  padding: 13px 22px;
  min-height: 50px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  transition: background 0.15s ease;
}

.copy-ai-btn:hover {
  background: #dbeafe;
}

.print-button {
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-weight: 750;
  padding: 13px 22px;
  min-width: 180px;
  min-height: 50px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.print-button:hover {
  background: var(--soft);
}

/* Authentication Modal / Lock Overlay */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-modal {
  background: #ffffff;
  border-radius: 16px;
  padding: 36px 32px;
  width: min(450px, 100%);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.auth-modal h2 {
  margin: 0 0 10px;
  font-size: 24px;
}

.auth-modal p {
  color: var(--muted);
  font-size: 15px;
  margin: 0 0 22px;
}

.auth-input {
  width: 100%;
  font-size: 18px;
  text-align: center;
  letter-spacing: 2px;
  padding: 14px;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  margin-bottom: 14px;
  font-family: inherit;
}

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

.auth-btn {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #ffffff;
  font-size: 16px;
  font-weight: 750;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.auth-btn:hover {
  opacity: 0.92;
}

.auth-btn.btn-cancel {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  margin-top: 8px;
}

.auth-btn.btn-cancel:hover {
  background: var(--soft);
}

.auth-error {
  color: #dc2626;
  font-size: 14px;
  font-weight: 600;
  margin-top: 8px;
  display: none;
}

/* Toast Notification */
.toast-msg {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1e293b;
  color: #ffffff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 15px;
  font-weight: 650;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.toast-msg.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Responsive */
@media (max-width: 700px) {
  :root {
    --sidebar: 240px;
  }
  .main {
    padding: 24px 18px 52px;
  }
  body.sidebar-collapsed .main {
    padding-left: 56px;
  }
  h1 {
    font-size: 26px;
  }
}

/* Clean Print Output */
@media print {
  @page {
    size: letter;
    margin: 0.5in;
  }
  body {
    background: #ffffff;
  }
  .sidebar,
  .sidebar-toggle,
  .auth-overlay,
  .toast-msg,
  .test-actions-bar,
  .card-actions,
  .understanding-gauge,
  .completion-actions {
    display: none !important;
  }
  .main {
    margin-left: 0 !important;
    padding: 0 !important;
  }
  body.sidebar-collapsed .main {
    padding-left: 0 !important;
  }
  .content {
    width: 100%;
    max-width: none;
  }
  .card {
    break-inside: avoid-page;
    page-break-inside: avoid;
  }
  .unit + .unit {
    break-before: page;
    page-break-before: always;
  }
  .answer-review-box {
    border: 1px solid #777777 !important;
    background: #f8fafc !important;
    color: #000000 !important;
  }
  input,
  textarea {
    border: 1px solid #777777 !important;
    background: #ffffff !important;
    color: #000000 !important;
  }
}
