.app-page {
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--paper-deep);
}

.app-header {
  position: relative;
  z-index: 80;
  height: 64px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.app-nav { display: flex; align-items: stretch; height: 100%; gap: 26px; color: var(--muted); font-size: 13px; }
.app-nav a { position: relative; display: flex; align-items: center; text-decoration: none; }
.app-nav a[aria-current="page"] { color: var(--ink); font-weight: 700; }
.app-nav a[aria-current="page"]::after { content: ""; position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: var(--green); }
.app-header .header-actions { justify-self: end; }

.utility-button, .sidebar-close {
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 11px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}
.library-toggle { display: inline-flex; }

.app-layout {
  position: relative;
  height: calc(100dvh - 64px);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  overflow: hidden;
  transition: grid-template-columns 220ms var(--ease-out);
}
.app-layout.is-library-collapsed { grid-template-columns: 0 minmax(0, 1fr); }

.app-sidebar {
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 22px 18px 18px;
  overflow: hidden;
  background: var(--paper);
  border-right: 1px solid var(--line);
  transform: translateX(0);
  transition: opacity 160ms ease, transform 220ms var(--ease-out);
}
.app-layout.is-library-collapsed .app-sidebar { opacity: 0; transform: translateX(-18px); pointer-events: none; }
.sidebar-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.sidebar-heading .section-kicker { margin-bottom: 5px; }
.sidebar-heading h1 { margin: 0; font-family: Georgia, serif; font-size: 28px; font-weight: 500; letter-spacing: -.035em; }
.sidebar-close { display: inline-flex; padding: 0; border-radius: 10px; }

.app-sidebar .session-stats { margin-bottom: 14px; }
.app-sidebar .session-stats div { flex: 1; min-width: 0; padding: 9px 11px; }
.app-sidebar .session-stats strong { font-size: 15px; }
.saved-progress { margin: -3px 0 12px; padding: 10px 11px; background: var(--paper-deep); border-radius: 10px; }
.saved-progress > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.saved-progress > div { display: grid; grid-template-columns: auto 1fr auto 1fr; align-items: baseline; gap: 4px; }
.saved-progress strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.saved-progress small { color: var(--muted); font-size: 9px; }
.sidebar-filters { margin-bottom: 12px; }
.app-sidebar .segmented-control { width: 100%; }
.app-sidebar .filter-chip { flex: 1; padding-inline: 5px; }
.sidebar-filter-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 8px; }
.app-sidebar .select-wrap { margin: 0; }
.app-sidebar .select-wrap select { width: 100%; min-height: 40px; }
.app-sidebar .icon-button { min-height: 40px; }
.app-sidebar .search-field { flex: 0 0 auto; }
.app-sidebar .search-field input { height: 42px; font-size: 13px; }
.app-sidebar .library-meta { flex: 0 0 auto; margin: 10px 0 8px; font-size: 10px; }
.app-sidebar #library-scope { display: block; margin-top: 3px; }
.app-sidebar #library-scope::before { content: none; }

.app-sidebar .question-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: block;
  overflow: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--line);
  scrollbar-width: thin;
}
.app-sidebar .question-item,
.app-sidebar .question-item:nth-child(2n),
.app-sidebar .question-item:nth-child(3n) {
  min-height: 0;
  padding: 13px 8px;
  border-right: 0;
}
.app-sidebar .question-item-top { margin-bottom: 7px; font-size: 9px; }
.app-sidebar .question-item h3 { min-height: 0; margin-bottom: 5px; font-size: 15px; }
.app-sidebar .question-item p { font-size: 10px; }
.app-sidebar .load-more-button { flex: 0 0 auto; min-height: 40px; margin: 12px auto 0; padding-block: 8px; }
.app-sidebar .library-empty { padding: 38px 12px; }

.app-workspace {
  height: 100%;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px;
  scroll-padding: 16px;
}
.mobile-session-bar { display: none; }
.app-workspace .quiz-card {
  width: min(1400px, 100%);
  min-height: 0;
  margin: 0 auto;
  padding: clamp(18px, 2.2vw, 28px);
  border-radius: 16px;
}
.app-workspace .quiz-topline { margin-bottom: 14px; }
.app-workspace .progress-track { margin-bottom: 20px; }
.app-workspace .quiz-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(350px, .8fr);
  gap: clamp(20px, 2.4vw, 34px);
  align-items: start;
}
.app-workspace .question-pane,
.app-workspace .answer-pane { min-width: 0; }
.app-workspace .answer-pane { padding-left: clamp(20px, 2.4vw, 34px); border-left: 1px solid var(--line); }
.app-workspace .question-title { margin-bottom: 16px; font-size: clamp(27px, 3vw, 38px); }
.app-workspace .statement-shell { margin-bottom: 0; }
.app-workspace .problem-statement { max-width: none; }
.statement-fullscreen-open { display: none; }

.statement-fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
.statement-fullscreen-overlay[hidden] { display: none; }
.statement-fullscreen-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: calc(env(safe-area-inset-top) + 9px) 16px 9px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.statement-fullscreen-title {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .09em;
  text-transform: uppercase;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.statement-fullscreen-close {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.statement-fullscreen-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}
.app-workspace .pane-label { margin: 0 0 10px; color: var(--green); font-size: 10px; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
.app-workspace .approach-question { margin-bottom: 3px; font-size: clamp(18px, 1.7vw, 22px); }
.app-workspace .question-hint { margin-bottom: 10px; font-size: 10px; }
.app-workspace .options { gap: 7px; }
.app-workspace .option-wrap { display: grid; gap: 5px; }
.app-workspace .option { padding: 11px 13px; border-radius: 11px; }
.app-workspace .option-copy span { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.app-workspace .option-key { width: 30px; height: 30px; }
.app-workspace .concept-chip-wrap {
  position: relative;
  z-index: 1;
  width: fit-content;
  margin-left: 44px;
}
.app-workspace .concept-chip {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 4px 9px;
  color: var(--green);
  background: var(--green-soft);
  border: 1px solid color-mix(in srgb, var(--green) 24%, transparent);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 750;
  line-height: 1.2;
  text-decoration: none;
}
.app-workspace .concept-chip:hover { border-color: var(--green); }
.app-workspace .concept-chip:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.app-workspace .concept-tooltip {
  position: absolute;
  z-index: 30;
  bottom: calc(100% + 9px);
  left: 0;
  width: min(300px, calc(100vw - 40px));
  padding: 13px 14px;
  color: var(--method-text);
  background: var(--method-bg);
  border: 1px solid var(--green);
  border-radius: 12px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, .42);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transform: translateY(5px) scale(.98);
  transform-origin: bottom left;
  visibility: hidden;
  transition: opacity 150ms ease, transform 180ms var(--ease-out), visibility 0s linear 180ms;
}
.app-workspace .concept-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 18px;
  border: 6px solid transparent;
  border-top-color: var(--method-bg);
}
.app-workspace .concept-tooltip-label,
.app-workspace .concept-tooltip-action { display: block; }
.app-workspace .concept-tooltip-label {
  margin-bottom: 5px;
  color: var(--green);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.app-workspace .concept-tooltip pre {
  max-height: 190px;
  margin: 0;
  overflow: auto;
  color: var(--method-text);
  font: 500 10px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}
.app-workspace .concept-tooltip-action { margin-top: 7px; color: var(--method-muted); font-size: 10px; }
.app-workspace .concept-chip-wrap:hover,
.app-workspace .concept-chip-wrap:focus-within { z-index: 35; }
.app-workspace .concept-chip-wrap:hover .concept-tooltip,
.app-workspace .concept-chip-wrap:focus-within .concept-tooltip {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
  transition-delay: 80ms, 80ms, 0s;
}
.app-workspace .feedback { margin-top: 16px; padding-top: 16px; }
.app-workspace .loading-state, .app-workspace .session-summary { min-height: calc(100dvh - 64px - 48px - 72px); }
.library-scrim { display: none; }
.answer-sheet-topbar { display: none; }
.answer-fab { display: none; }
.answer-sheet-scrim { display: none; }

@media (min-width: 1121px) {
  .app-workspace { overflow: hidden; }
  .app-workspace .quiz-card {
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .app-workspace .quiz-topline,
  .app-workspace .progress-track { flex: 0 0 auto; }
  .app-workspace .quiz-columns {
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
    overflow: hidden;
  }
  .app-workspace .question-pane {
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .app-workspace .statement-shell {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .app-workspace .statement-header { flex: 0 0 auto; }
  .app-workspace .problem-statement {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
  .app-workspace .answer-pane {
    min-height: 0;
    padding-right: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
  .app-workspace .loading-state,
  .app-workspace .session-summary { min-height: 0; height: 100%; }
}

@media (max-width: 1120px) {
  .app-workspace .quiz-card { width: min(820px, 100%); }
  .app-workspace .quiz-columns { grid-template-columns: 1fr; gap: 22px; }
  .app-workspace .answer-pane { padding: 22px 0 0; border-top: 1px solid var(--line); border-left: 0; }
}

@media (max-width: 820px) {
  .app-header { grid-template-columns: 1fr auto; height: 60px; padding-inline: 14px; }
  .app-header .app-nav { display: none; }
  .app-header .theme-toggle { min-width: 40px; min-height: 40px; padding-inline: 11px; }
  .app-header .theme-label { display: none; }
  .library-toggle { display: inline-flex; }
  .app-layout { height: calc(100dvh - 60px); grid-template-columns: 1fr; }
  .app-layout.is-library-collapsed { grid-template-columns: 1fr; }
  .app-sidebar {
    position: fixed;
    z-index: 100;
    top: 60px;
    bottom: 0;
    left: 0;
    width: min(92vw, 360px);
    height: auto;
    padding-top: 18px;
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform 220ms var(--ease-out);
    opacity: 1;
  }
  .app-layout.is-library-collapsed .app-sidebar { opacity: 1; transform: translateX(-105%); }
  .app-sidebar.is-open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .library-scrim { position: fixed; z-index: 90; inset: 60px 0 0; width: 100%; height: auto; background: rgba(0,0,0,.52); border: 0; }
  .library-scrim.is-visible { display: block; }
  .app-workspace { padding: 12px; scroll-padding: 12px; }
  .mobile-session-bar { width: min(760px, 100%); display: flex; align-items: end; justify-content: space-between; gap: 14px; margin: 0 auto 12px; }
  .mobile-session-bar .section-kicker { margin-bottom: 4px; }
  .mobile-session-bar h2 { margin: 0; font-family: Georgia, serif; font-size: 22px; font-weight: 500; }
  .mobile-session-bar .session-stats { gap: 6px; }
  .mobile-session-bar .session-stats div { min-width: 60px; padding: 7px 9px; }
  .mobile-session-bar .session-stats span { font-size: 8px; }
  .mobile-session-bar .session-stats strong { font-size: 13px; }
  .app-workspace .quiz-card { padding: 18px; border-radius: 16px; box-shadow: none; }
  .app-workspace .quiz-tags .pill:nth-child(n+4) { display: none; }
  .app-workspace .question-position { white-space: nowrap; }
  .app-workspace .problem-statement { font-size: 17px; line-height: 1.7; overflow: visible; }
  .statement-fullscreen-open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
  }
  .statement-fullscreen-open:hover, .statement-fullscreen-open:focus-visible { color: var(--ink); border-color: var(--ink); }
  .statement-fullscreen-open .ui-icon { width: 14px; height: 14px; }
  .statement-fullscreen-body { font-size: 17px; line-height: 1.7; }
  .statement-fullscreen-body code { font-size: .85em; }
  .app-workspace .problem-statement code { font-size: .85em; }
  .app-workspace .option { grid-template-columns: 32px minmax(0, 1fr); }
  .app-workspace .option-icon { grid-column: 2; width: auto; text-align: left; }
  .app-workspace .feedback { grid-template-columns: 1fr; }
  .app-workspace .next-button { width: 100%; justify-content: space-between; }
  .app-workspace .loading-state, .app-workspace .session-summary { min-height: calc(100dvh - 60px - 24px - 70px); }

  .app-workspace .answer-pane {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 250;
    display: flex;
    flex-direction: column;
    max-height: min(82vh, 640px);
    padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
    background: var(--paper);
    border-top: 0;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -14px 44px rgba(0, 0, 0, .32);
    transform: translateY(100%);
    transition: transform 260ms var(--ease-out);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .app-workspace .answer-pane.is-open { transform: translateY(0); }
  .answer-sheet-topbar {
    position: relative;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    margin-bottom: 4px;
  }
  .answer-sheet-handle { width: 36px; height: 4px; background: var(--line); border-radius: 999px; }
  .answer-sheet-close {
    position: absolute;
    right: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
  }
  .answer-fab:not([hidden]) {
    position: fixed;
    right: 18px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 230;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 13px 20px;
    color: var(--white);
    background: var(--green);
    border: 0;
    border-radius: 999px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .32);
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
  }
  .answer-sheet-scrim.is-visible {
    position: fixed;
    z-index: 240;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, .5);
    border: 0;
  }
}

@media (max-width: 420px) {
  .app-header .brand > span:last-child { display: none; }
  .utility-button span { display: none; }
  .mobile-session-bar h2 { font-size: 19px; }
  .mobile-session-bar .session-stats div { min-width: 54px; }
  .app-workspace { padding: 10px; }
  .app-workspace .quiz-card { padding: 15px; }
  .app-workspace .quiz-topline { align-items: flex-start; }
  .app-workspace .concept-tooltip { left: -44px; width: min(280px, calc(100vw - 36px)); transform-origin: bottom center; }
  .app-workspace .concept-tooltip::after { left: 61px; }
  .app-workspace .problem-statement { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  .app-layout, .app-sidebar { transition: none; }
  .app-workspace .concept-tooltip { transition: none; }
}
