/* app/css/components.css — Reader Cards, Step-Reveal, Search & Drawer
   Neo-brutalist redesign: brutal tokens, 2.5px ink outlines, hard shadows. */

.hero-eyebrow {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent-amber);
  margin-bottom: 6px;
}

.hero-title {
  font-size: 1.65rem;
  line-height: 1.22;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--ink);
  color: var(--on-ink);
  font-weight: 800;
  font-size: 16px;
  min-height: 48px;
  padding: 11px 18px;
  border-radius: var(--radius-sm, 6px);
  border: var(--rule, 2.5px) solid var(--ink);
  box-shadow: var(--shadow-sm, 4px 4px 0 var(--ink));
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  box-sizing: border-box;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}

.btn-primary:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--ink);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 800;
  font-size: 16px;
  min-height: 48px;
  padding: 11px 18px;
  border-radius: var(--radius-sm, 6px);
  border: var(--rule, 2.5px) solid var(--ink);
  box-shadow: var(--shadow-sm, 4px 4px 0 var(--ink));
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  box-sizing: border-box;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}

.btn-secondary:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--ink);
}

/* Menu Grid */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.menu-tile {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 122px;
  transition:
    transform 260ms var(--ease-spring),
    background-color 240ms var(--ease-out-expo),
    border-color 240ms var(--ease-out-expo),
    box-shadow 260ms var(--ease-out-expo);
}

.menu-tile:hover {
  border-color: var(--border-strong);
  background: var(--bg-surface);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.menu-tile:active {
  transform: scale(0.98);
}

.tile-tag {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 10px;
  color: var(--ink);
  border: 1.5px solid var(--ink);
}

.tag-amber {
  background: var(--fill-butter);
  color: var(--ink);
}
.tag-teal {
  background: var(--fill-sky);
  color: var(--ink);
}
.tag-emerald {
  background: var(--fill-sage);
  color: var(--ink);
}

.tile-title {
  font-size: 1.08rem;
  font-weight: 700;
  margin: 0 0 4px;
}

.tile-desc {
  font-size: 0.84rem;
  color: var(--text-secondary);
  margin: 0;
}

/* Chapter Select Cards & Unit Nodes */
.chapter-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  transition: background-color 260ms var(--ease-out-expo), border-color 260ms var(--ease-out-expo), box-shadow 260ms var(--ease-out-expo);
}

.chapter-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-amber);
}

.chapter-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 2px 0 4px;
}

/* Reader Navigation Pills */
.unit-nav-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 0 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
  scrollbar-width: none;
}

.unit-nav-bar::-webkit-scrollbar {
  display: none;
}

.unit-pill {
  appearance: none;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition:
    transform 220ms var(--ease-spring),
    background-color 220ms var(--ease-out-expo),
    border-color 220ms var(--ease-out-expo),
    color 220ms var(--ease-out-expo),
    box-shadow 220ms var(--ease-out-expo);
}

.unit-pill:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.unit-pill:active {
  transform: scale(0.95);
}

.unit-pill.active {
  background: var(--ink);
  color: var(--on-ink);
  border-color: var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}

/* Section & Theory Blocks */
.reader-section {
  margin-bottom: 36px;
}

.section-heading {
  font-size: 1.32rem;
  font-weight: 800;
  letter-spacing: -0.015em;
  margin: 28px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.prose-block p {
  margin: 0 0 14px;
}

.prose-block h3,
.prose-block h4 {
  margin: 22px 0 10px;
  font-size: 1.08rem;
  color: var(--heading-accent, var(--accent-amber));
}

/* Theorem & Definition Cards */
.theorem-card {
  background: var(--fill-sand, #e8d6b2);
  border: var(--rule, 2.5px) solid var(--ink);
  border-radius: var(--radius, 7px);
  box-shadow: var(--shadow-sm, 4px 4px 0 var(--ink));
  padding: 18px 20px;
  margin: 22px 0;
  color: var(--ink);
}

.definition-card {
  background: var(--fill-sky, #bfd2dd);
  border: var(--rule, 2.5px) solid var(--ink);
  border-radius: var(--radius, 7px);
  box-shadow: var(--shadow-sm, 4px 4px 0 var(--ink));
  padding: 18px 20px;
  margin: 22px 0;
  color: var(--ink);
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-kicker {
  font-family: var(--font-display, inherit);
  font-size: 1.15rem;
  font-weight: 850;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.definition-card .card-kicker {
  color: var(--ink);
}

.definition-body p,
.theorem-statement p,
.proof-drawer p,
.step-item p,
.callout-body p {
  margin: 0 0 10px;
}

.definition-body p:last-child,
.theorem-statement p:last-child,
.proof-drawer p:last-child,
.step-item p:last-child,
.callout-body p:last-child {
  margin-bottom: 0;
}

/* Blockquotes: margin 12px 0, padding 4px 0 4px 12px, border-left 3px solid var(--ink) */
blockquote.md-quote,
.md-quote {
  margin: 12px 0;
  padding: 4px 0 4px 12px;
  border-left: 3px solid var(--ink);
}

.md-quote p {
  margin: 4px 0;
}

.md-quote p:first-child {
  margin-top: 0;
}

.md-quote p:last-child {
  margin-bottom: 0;
}

.prose-block ul,
.prose-block ol,
.definition-body ul,
.definition-body ol,
.theorem-statement ul,
.theorem-statement ol,
.proof-drawer ul,
.proof-drawer ol,
.step-item ul,
.step-item ol,
.callout-body ul,
.callout-body ol {
  margin: 8px 0 12px;
  padding-left: 20px;
}

.definition-body ul:last-child,
.definition-body ol:last-child,
.theorem-statement ul:last-child,
.theorem-statement ol:last-child,
.step-item ul:last-child,
.step-item ol:last-child,
.callout-body ul:last-child,
.callout-body ol:last-child {
  margin-bottom: 0;
}

.prose-block li,
.definition-body li,
.theorem-statement li,
.proof-drawer li,
.step-item li,
.callout-body li {
  margin-bottom: 10px;
  line-height: 1.6;
}

.prose-block li:last-child,
.definition-body li:last-child,
.theorem-statement li:last-child,
.proof-drawer li:last-child,
.step-item li:last-child,
.callout-body li:last-child {
  margin-bottom: 0;
}

/* Nested lists in content: small top margin, normal indent, readable at 390 px */
.prose-block li > ul,
.prose-block li > ol,
.definition-body li > ul,
.definition-body li > ol,
.theorem-statement li > ul,
.theorem-statement li > ol,
.proof-drawer li > ul,
.proof-drawer li > ol,
.step-item li > ul,
.step-item li > ol,
.callout-body li > ul,
.callout-body li > ol,
li > ul,
li > ol {
  margin: 6px 0 4px;
  padding-left: 18px;
}

li > ul > li,
li > ol > li {
  margin-bottom: 6px;
}

.prose-block li > .math-block,
.definition-body li > .math-block,
.theorem-statement li > .math-block,
.step-item li > .math-block {
  margin: 6px 0 4px;
}

.proof-toggle-btn {
  appearance: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition:
    transform 220ms var(--ease-spring),
    background-color 220ms var(--ease-out-expo),
    border-color 220ms var(--ease-out-expo),
    color 220ms var(--ease-out-expo),
    box-shadow 220ms var(--ease-out-expo);
}

.proof-toggle-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.proof-toggle-btn:active {
  transform: scale(0.95);
}

.proof-toggle-btn.is-open {
  background: var(--accent-amber-soft);
  border-color: var(--accent-amber-border);
  color: var(--accent-amber);
}

.proof-drawer {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-strong);
}

/* Worked Example & IOE Interactive Step-Reveal Card */
.example-card {
  background: var(--paper);
  border: var(--rule, 2.5px) solid var(--ink);
  border-radius: var(--radius, 7px);
  padding: 20px;
  margin: 22px 0;
  box-shadow: var(--shadow, 7px 7px 0 var(--ink));
  color: var(--ink);
}

.example-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.example-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--paper-2);
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}

.example-badge.ioe-badge {
  background: var(--fill-butter);
  color: var(--ink);
  border-color: var(--ink);
}

/* Past-question label: the question number is the loudest thing on the card. */
.example-badge.ioe-badge {
  padding: 0;
  gap: 0;
  overflow: hidden;
  flex-wrap: wrap;
}
.ioe-qno {
  background: var(--ink);
  color: var(--paper);
  font-size: 20px;
  font-weight: 800;
  text-transform: none;
  letter-spacing: 0.01em;
  padding: 6px 12px;
  line-height: 1.1;
}
.ioe-meta {
  padding: 6px 10px;
  font-size: 13px;
}

.example-prompt {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.35;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 16px;
  color: var(--ink);
}

.step-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.step-item {
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm, 6px);
  padding: 14px 16px;
  min-width: 0;
  overflow-x: auto;
  color: var(--ink);
}

/* Jump Bridge Explanation Card inside a Step */
.jump-card {
  background: var(--fill-mint, #c3dcc9);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm, 6px);
  box-shadow: 2px 2px 0 var(--ink);
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 0.95rem;
  color: var(--ink);
}

.jump-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.jump-badge {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--fill-sky);
  color: var(--ink);
  border: 1.5px solid var(--ink);
}

.jump-title {
  color: var(--text-primary);
  font-size: 0.9rem;
}

/* Callouts & Textbook Errata */
.callout {
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin: 14px 0;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
}

.callout-erratum {
  background: var(--fill-rose, #e6c3bb);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm, 6px);
  box-shadow: 2px 2px 0 var(--ink);
  color: var(--ink);
}

.callout-title {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.86rem;
  margin-bottom: 6px;
  color: var(--ink);
}

.callout-erratum .callout-title {
  color: var(--ink);
}

/* Final Answer Highlight Box */
.answer-box {
  background: var(--fill-butter, #efe2a6);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm, 6px);
  box-shadow: 2px 2px 0 var(--ink);
  padding: 14px 16px;
  margin-top: 14px;
  min-width: 0;
  overflow-x: auto;
  color: var(--ink);
}

.answer-label {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 4px;
}

/* Step Reveal Control Bar */
.step-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 2px solid var(--ink);
}

.step-controls-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
}

/* Exercise Question + Final Book Answer Cards */
.exercise-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 16px 0;
}

.exercise-card {
  background: var(--paper);
  border: var(--rule, 2.5px) solid var(--ink);
  border-radius: var(--radius-sm, 6px);
  box-shadow: var(--shadow-sm, 4px 4px 0 var(--ink));
  padding: 16px 18px;
  color: var(--ink);
}

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

.exercise-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.exercise-qnum {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  min-width: 32px;
  padding-top: 2px;
}

.exercise-prompt {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.solution-box {
  margin-top: 12px;
  padding: 14px;
  background: var(--accent-amber-soft);
  border: 1px solid var(--accent-amber-border);
  border-radius: 10px;
  min-width: 0;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  margin: 14px 0;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle, rgba(128, 128, 128, 0.4)) transparent;
  background-image:
    linear-gradient(to left, var(--paper), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.28), transparent);
  background-repeat: no-repeat;
  background-position: right center, right center;
  background-size: 36px 100%, 16px 100%;
  background-attachment: local, scroll;
}

[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .table-wrap {
  background-image:
    linear-gradient(to left, var(--paper), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.75), transparent);
}

.table-wrap::-webkit-scrollbar {
  height: 6px;
}

.table-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-subtle, rgba(128, 128, 128, 0.4));
  border-radius: 3px;
}

.math-table,
.prose-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.math-table th,
.math-table td,
.prose-table th,
.prose-table td {
  border: 1.5px solid var(--ink);
  padding: 9px 12px;
  text-align: left;
  min-width: 7em;
  max-width: 16em;
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
}

.math-table th code,
.math-table td code,
.prose-table th code,
.prose-table td code,
.math-table a,
.prose-table a {
  overflow-wrap: anywhere;
  word-break: break-all;
}

.math-table th,
.prose-table th {
  background: var(--paper-2);
  font-weight: 700;
  color: var(--ink);
}

/* Contextual IOE Exam Checkpoint Card */
.ioe-checkpoint-banner {
  background: var(--subject-accent-soft);
  border: 1.5px solid var(--accent-teal-border);
  border-radius: var(--radius-xl);
  padding: 22px 24px;
  margin: 30px 0 16px;
  box-shadow: var(--shadow-card);
  transition: transform 260ms var(--ease-spring), box-shadow 260ms var(--ease-out-expo);
}

/* Slide-Up Checkpoint Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.drawer-sheet {
  width: 100%;
  max-width: 740px;
  max-height: 88dvh;
  background: var(--bg-canvas);
  border-top: 1px solid var(--border-strong);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-drawer);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer-handle {
  display: none;
  width: 42px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 999px;
  margin: 10px auto 4px;
  flex-shrink: 0;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-body {
  padding: 20px 22px 36px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Figures & Tables */
.math-figure {
  margin: 18px 0;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  text-align: center;
}

.math-figure img,
.math-figure svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 10px;
}

.math-figure figcaption {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Search Input */
.search-bar {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.96rem;
  margin-bottom: 16px;
  transition: border-color 220ms var(--ease-out-expo), box-shadow 220ms var(--ease-out-expo), background-color 220ms var(--ease-out-expo);
}

.search-bar:focus {
  outline: none;
  border-color: var(--accent-amber);
  box-shadow: 0 0 0 3px var(--accent-amber-soft);
}

/* ==========================================================================
   Mobile Responsive Tier (Phones <= 600px)
   ========================================================================== */
@media (max-width: 600px) {
  
  .hero-title {
    font-size: 1.38rem;
    line-height: 1.25;
  }
  
  
  

  /* Grid & Chapter Cards */
  .menu-tile {
    padding: 14px 13px;
    min-height: 108px;
  }
  .tile-title {
    font-size: 0.98rem;
  }
  .tile-desc {
    font-size: 0.78rem;
  }
  .chapter-card {
    padding: 16px 14px;
    margin-bottom: 14px;
  }
  .chapter-title {
    font-size: 1.1rem;
  }

  /* Reader Section Headings & Cards */
  .section-heading {
    font-size: 1.18rem;
    margin: 22px 0 12px;
  }
  .theorem-card,
  .definition-card {
    padding: 13px 14px;
    margin: 14px 0;
  }
  .card-kicker {
    font-size: 0.9rem;
  }

  /* Worked Examples & IOE Step-Reveal Cards */
  .example-card {
    padding: 14px 13px;
    margin: 16px 0;
  }
  .example-top {
    flex-wrap: wrap;
    gap: 8px;
  }
  .example-prompt {
    font-size: 0.96rem;
    padding-bottom: 11px;
    margin-bottom: 11px;
  }
  .step-item {
    padding: 10px 10px;
  }
  .jump-card {
    padding: 10px 12px;
    font-size: 0.88rem;
  }
  .callout {
    padding: 11px 13px;
    margin: 12px 0;
  }
  .solution-box {
    padding: 10px 10px;
  }
  .answer-box {
    padding: 12px 13px;
    margin-top: 12px;
  }

  /* Exercise Question Cards & Full Width Prompts */
  .exercise-card {
    padding: 13px 14px;
  }
  .exercise-row {
    flex-wrap: wrap;
    gap: 10px;
  }
  .exercise-qnum {
    min-width: 26px;
    font-size: 0.82rem;
  }
  .exercise-prompt {
    flex: 1 1 calc(100% - 38px);
    min-width: 0;
    font-size: 0.93rem;
  }
  .exercise-actions {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-subtle);
  }
  .exercise-actions .proof-toggle-btn {
    flex: 1;
    justify-content: center;
    min-height: 36px;
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  /* Tables & Figures */
  .prose-table th,
  .prose-table td,
  .math-table th,
  .math-table td {
    padding: 7px 9px;
    font-size: 0.84rem;
  }
  .math-figure {
    padding: 12px;
    margin: 14px 0;
  }

  /* Checkpoint Drawer */
  .drawer-sheet {
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
  }
  .drawer-handle {
    display: block;
  }
  .drawer-header {
    padding: 12px 16px;
  }
  .drawer-body {
    padding: 14px 12px 28px;
  }
}

/* Medium Phones and Narrower (<= 560px) */
@media (max-width: 560px) {
  .exercises-section > div:first-child {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .exercises-section > div:first-child > div:last-child {
    width: 100%;
    display: flex;
    gap: 8px;
  }
  .exercises-section > div:first-child > div:last-child .proof-toggle-btn {
    flex: 1;
    justify-content: center;
    min-height: 38px;
    font-size: 0.8rem;
  }
}

/* Compact Mobile Phones (<= 480px) */
@media (max-width: 480px) {
  .step-item {
    padding: 8px 8px;
  }
  .step-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .step-controls-left {
    width: 100%;
    display: flex;
    gap: 8px;
  }
  .step-controls-left .btn-primary {
    flex: 1 1 11rem;
    min-width: 0;
    min-height: 48px;
    padding: 10px 12px;
    font-size: 0.95rem;
  }
  .step-controls-left .btn-secondary {
    min-height: 48px;
    padding: 10px 12px;
    font-size: 0.95rem;
  }
  .step-controls .icon-btn.js-reset-steps {
    width: 100%;
    justify-content: center;
    min-height: 48px;
  }
}

/* Narrow Compact Mobile Phones (<= 360px) */
@media (max-width: 360px) {
  .menu-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

/* ==========================================================================
   Authentication, Lockdown & Session Concurrency System
   ========================================================================== */

.account-btn {
  padding: 4px 8px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
}

.account-pill {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--accent-amber);
  cursor: pointer;
  transition: transform 200ms ease, opacity 200ms ease, box-shadow 200ms ease;
}

.account-pill:hover {
  border-color: var(--accent-amber);
}

.account-pill.pill-unlocked {
  color: var(--ink);
  border: 1.5px solid var(--ink);
  background: var(--fill-sage);
}

.account-pill.pill-expired {
  color: var(--ink);
  border: 1.5px solid var(--ink);
  background: var(--fill-rose);
}

.auth-card {
  max-width: 440px;
  width: 90%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 24px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  position: relative;
}

.auth-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.auth-title {
  margin: 0;
  font-size: 1.3rem;
  color: var(--text-primary);
}

.auth-sub {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 0 0 16px;
}

.form-label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 200ms ease;
}

.form-input:focus {
  border-color: var(--accent-amber);
  box-shadow: 0 0 0 2px var(--accent-amber-soft);
}

.btn-block {
  width: 100%;
}

.auth-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #ff8b8b;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.86rem;
  margin-bottom: 14px;
}

.auth-toggle-row {
  margin-top: 16px;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent-amber);
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
  font-size: 0.88rem;
}

.account-summary-box {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.acc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.acc-row:last-child {
  border-bottom: none;
}

.acc-label {
  font-size: 0.86rem;
  color: var(--text-secondary);
}

.acc-val {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-primary);
}

.acc-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  border: 1.5px solid var(--ink);
}

.badge-mobile {
  background: var(--fill-sky);
  color: var(--ink);
  border: 1.5px solid var(--ink);
}

.badge-desktop {
  background: var(--fill-sand);
  color: var(--ink);
  border: 1.5px solid var(--ink);
}

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

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

.concurrency-note {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  line-height: 1.45;
  background: rgba(229, 169, 60, 0.06);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(229, 169, 60, 0.2);
}

.evict-card {
  max-width: 420px;
  text-align: center;
  padding: 28px 24px;
}

/* Google Sign-In Button & Divider */
.btn-google {
  background: #ffffff;
  color: #1f2937;
  border: 1px solid #d1d5db;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 180ms ease, transform 180ms ease;
  width: 100%;
}

.btn-google:hover {
  background: #f3f4f6;
}

.btn-google:active {
  transform: scale(0.98);
}

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 16px 0;
  color: var(--text-tertiary);
  font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border-subtle);
}

.auth-divider span {
  padding: 0 10px;
}

.badge-status {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--ink);
  border: 1.5px solid var(--ink);
}

.badge-status.active {
  background: var(--fill-sage);
  color: var(--ink);
  border: 1.5px solid var(--ink);
}

.badge-status.building {
  background: var(--fill-butter);
  color: var(--ink);
  border: 1.5px solid var(--ink);
}

.badge-status.pending {
  background: var(--paper-2);
  color: var(--ink-2);
  border: 1.5px dashed var(--ink);
}


/* Typical exam marks for a worked-example pattern (@marks N) */
.marks-pill {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  color: var(--ink);
  background: var(--fill-butter);
  border: 1.5px solid var(--ink);
}

/* ==========================================================================
   Global Cross-Subject Search Sheet
   ========================================================================== */

.search-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.search-sheet {
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  height: 85vh;
  background: var(--paper);
  border: var(--rule, 2.5px) solid var(--ink);
  border-bottom: none;
  border-radius: var(--radius, 7px) var(--radius, 7px) 0 0;
  box-shadow: 0 -7px 0 var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
}

.search-sheet-header {
  padding: 18px 20px 14px;
  background: var(--paper);
  border-bottom: var(--rule, 2.5px) solid var(--ink);
  flex-shrink: 0;
}

.search-sheet-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 8px;
}

.search-input-wrap {
  width: 100%;
  position: relative;
}

.search-sheet-input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: var(--radius-sm, 6px);
  border: 2px solid var(--ink);
  background: var(--paper-2);
  color: var(--ink);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
}

.search-sheet-input:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--ink);
}

.search-close-btn {
  min-height: 48px;
  padding: 0 14px;
  font-weight: 800;
  font-size: 14px;
}

.search-results-listbox {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px 32px;
  -webkit-overflow-scrolling: touch;
}

.search-subject-group {
  margin-bottom: 20px;
}

.search-subject-group:last-child {
  margin-bottom: 0;
}

.search-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm, 6px);
}

.search-group-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.search-group-count {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

.search-result-option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 14px;
  margin-bottom: 6px;
  border-radius: var(--radius-sm, 6px);
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: transform 120ms var(--ease);
}

.search-result-option:hover,
.search-result-option.is-active {
  background: var(--ink);
  color: var(--on-ink);
  transform: translateX(3px);
}

.search-result-option:hover .b-stamp,
.search-result-option.is-active .b-stamp {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
}

.search-kind-stamp {
  flex-shrink: 0;
}

.search-result-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.search-result-arrow {
  flex-shrink: 0;
  font-weight: 800;
  font-size: 18px;
}

.search-empty-state {
  padding: 32px 16px;
  text-align: center;
  font-size: 15px;
  color: var(--ink-2);
}

/* Upcoming Exams Card & Set Exam Dates Modal */
.upcoming-exams-card {
  border-color: var(--accent-amber-border);
  margin-top: 8px;
}

.upcoming-exams-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.upcoming-exams-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upcoming-exam-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--subject-accent, var(--accent-amber));
  font-size: 0.92rem;
  font-weight: 600;
}

.upcoming-exam-icon {
  color: var(--subject-accent, var(--accent-amber));
  font-size: 1.1rem;
  flex-shrink: 0;
}

.upcoming-exam-text {
  flex: 1;
  min-width: 0;
}

.exam-empty-row {
  display: flex;
  justify-content: flex-end;
  margin-top: -12px;
  margin-bottom: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1050;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 22px 20px;
  box-shadow: var(--shadow-drawer);
}

.exam-dates-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.exam-dates-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.exam-date-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.exam-date-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.exam-date-field .form-input {
  width: auto;
  min-width: 150px;
  padding: 6px 10px;
  font-size: 0.86rem;
}

.exam-dates-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 480px) {
  
  .search-sheet-header {
    padding: 12px 12px 10px;
  }
  .search-results-listbox {
    padding: 10px 10px 24px;
  }
  .exam-date-field {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .exam-date-field .form-input {
    width: 100%;
  }
}

/* "Mark as complete" on worked examples and exercises: a topic reaches 100 % only when all are marked */
.complete-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}
.complete-btn {
  min-height: 48px;
  min-width: 11rem;
  justify-content: center;
}
.complete-btn.is-done {
  background: var(--ink);
  color: var(--on-ink);
}

/* Completed worked example folded into a one-line bar (components.js, owner 2026-11-10).
   Hover (mouse) shows "Click to expand"; touch screens always show "Tap to expand". */
.example-card {
  scroll-margin-top: calc(var(--topbar-h, 78px) + 12px);
}
.collapsed-hint {
  display: none;
}
.example-card.is-collapsed {
  padding: 12px 16px;
  margin: 12px 0;
  cursor: pointer;
  box-shadow: var(--shadow-sm, 4px 4px 0 var(--ink));
  transition: transform 200ms var(--ease, ease), box-shadow 200ms var(--ease, ease);
  animation: example-fold-in 240ms var(--ease, ease);
}
.example-card.is-collapsed .example-top {
  margin-bottom: 0;
  min-height: 32px;
}
.example-card.is-collapsed .example-prompt,
.example-card.is-collapsed .step-list,
.example-card.is-collapsed .answer-container,
.example-card.is-collapsed .step-controls,
.example-card.is-collapsed .complete-row {
  display: none;
}
.example-card.is-collapsed .collapsed-hint {
  display: inline-flex;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2, var(--text-secondary));
  border: 2px dashed currentColor;
  border-radius: var(--radius-sm, 6px);
  padding: 3px 8px;
}
.collapsed-hint__mouse {
  display: none;
}
@media (hover: hover) and (pointer: fine) {
  .collapsed-hint__mouse {
    display: inline;
  }
  .collapsed-hint__touch {
    display: none;
  }
  .example-card.is-collapsed .collapsed-hint {
    opacity: 0;
    transition: opacity 160ms var(--ease, ease);
  }
  .example-card.is-collapsed:hover .collapsed-hint,
  .example-card.is-collapsed:focus-visible .collapsed-hint {
    opacity: 1;
  }
  .example-card.is-collapsed:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--ink);
  }
}
.example-card.is-collapsed:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}
@keyframes example-fold-in {
  from {
    opacity: 0.4;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .example-card.is-collapsed {
    animation: none;
    transition: none;
  }
}

/* Topic completion counter at the end of a lesson */
.rd-progress {
  margin: 28px 0 8px;
  padding: 14px 16px;
}
.rd-progress p {
  margin: 6px 0 0;
  font-size: 0.95rem;
  color: var(--ink-2);
}
.rd-progress.is-complete {
  background: var(--fill-mint);
}

/* Collapsible group of worked examples / exercises with its own Show-Hide button (owner, 2026-11-07).
   Collapsed by default; the cards stay in the DOM, so marks and the topic counter are unaffected. */
.item-group {
  margin: 18px 0;
}
.item-group__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: var(--rule) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
}
.item-group--exercises .item-group__bar {
  background: var(--fill-sand);
}
.item-group--examples .item-group__bar {
  background: var(--fill-sky);
}
.item-group__label {
  font-size: 0.85rem;
}
.item-group__btn {
  min-height: 48px;
}
.item-group.is-open .item-group__btn {
  background: var(--ink);
  color: var(--on-ink);
}
.item-group__body {
  margin-top: 14px;
}
.item-group__body[hidden] {
  display: none;
}

/* Practice card (owner, 2026-11-09): the worked examples and exercises that end a section, plus the
   "N of M marked complete" counter, in ONE card. Each Show/Hide group is a row; rows are split by a rule. */
.b-card.practice-card {
  margin: 28px 0 22px;
  padding: 0;
}
.practice-card__row {
  padding: 14px 16px;
}
.practice-card__row + .practice-card__row {
  border-top: var(--rule) dashed var(--ink);
}
.practice-card__row:first-child {
  border-radius: var(--radius) var(--radius) 0 0;
}
.practice-card__row--examples {
  background: var(--fill-sky);
}
.practice-card__row--exercises {
  background: var(--fill-sand);
}
.practice-card .prose-block {
  margin: 0 0 10px;
}
.practice-card .prose-block h1,
.practice-card .prose-block h2,
.practice-card .prose-block h3 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.3;
}
.practice-card .item-group {
  margin: 0;
}
.practice-card .item-group__bar {
  padding: 0;
  border: 0;
  background: transparent;
}
.practice-card__foot {
  border-top: var(--rule) solid var(--ink);
  border-radius: 0 0 var(--radius) var(--radius);
}
.practice-card__foot:empty {
  display: none;
}
.practice-card__foot .rd-progress {
  margin: 0;
  padding: 14px 16px;
  border-radius: inherit;
}

/* ── PDF links row & buttons (Neo-brutalist) ───────────────────────── */
.pdf-links-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 20px;
}
.pdf-links-row .b-btn,
.sy-subject__pdf-btn {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  padding: 10px 16px;
  box-sizing: border-box;
}
.sy-subject__actions {
  margin-top: 14px;
}
.practice-card:not(:has(.practice-card__progress)) .practice-card__row:last-child {
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
}

/* Semester picker (Home header) */
.sem-pick { position: relative; display: inline-block; }
.sem-pick__btn { background: none; border: 0; padding: 0; margin: 0; color: inherit; font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: .4em; text-align: left; }
.sem-pick__caret { font-size: .6em; opacity: .7; }
.sem-pick__list { position: absolute; z-index: 30; top: 100%; left: 0; min-width: 12rem; margin: .35rem 0 0; padding: .25rem; list-style: none; background: var(--paper); color: var(--ink); border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.sem-pick__list[hidden] { display: none; }
.sem-pick__list li { padding: .55rem .75rem; cursor: pointer; font-size: 1rem; }
.sem-pick__list li:hover, .sem-pick__list li:focus-visible { background: var(--ink); color: var(--on-ink); outline: none; }
.sem-pick__list small { opacity: .7; margin-left: .4em; }
.sem-pick__empty { margin: 2rem 0; opacity: .75; }
