:root {
  color-scheme: light dark;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --text: #1d2622;
  --muted: #68716d;
  --border: #dcded9;
  --accent: #275c49;
  --accent-text: #ffffff;
  --soft: #e9eee9;
  --danger-soft: #f6e9e6;
  --warning-soft: #f5eedc;
  --success-soft: #e5f1e9;
  --shadow: 0 18px 45px rgba(28, 38, 34, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; }
.app-shell { width: min(100%, 68rem); min-height: 100vh; margin: 0 auto; padding: clamp(1.25rem, 5vw, 3rem); }
.screen { min-height: calc(100vh - 2.5rem); }
.brand { padding: clamp(2.5rem, 10vh, 6rem) 0 1rem; }
.eyebrow, .label {
  margin: 0 0 .5rem;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 750;
  letter-spacing: .15em;
  text-transform: uppercase;
}
h1, h2, p { overflow-wrap: break-word; }
h1 { margin: 0; font-size: clamp(1.75rem, 7vw, 2.6rem); line-height: 1.12; }
h2 { margin: 0; }
.library-summary { margin-bottom: 1.75rem; color: var(--muted); }
.deck-grid { display: grid; gap: 1rem; }
.deck-card, .question-card, .mixed-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
}
.deck-card { padding: 1.25rem; animation: soft-update 220ms ease both; }
.deck-heading, .study-meta, .study-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.deck-heading h2 { font-size: 1.12rem; }
.deck-total, .mode-label, .study-meta { color: var(--muted); font-size: .9rem; }
.progress-track { height: .4rem; margin: 1rem 0; overflow: hidden; border-radius: 99px; background: var(--soft); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width 180ms ease; }
.counts { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; }
.counts div { padding: .15rem .4rem; text-align: center; border-right: 1px solid var(--border); }
.counts div:last-child { border-right: 0; }
.counts dt { color: var(--muted); font-size: .72rem; }
.counts dd { margin: .2rem 0 0; font-size: 1.08rem; font-weight: 750; }
.selection-count { margin: .8rem 0 0; color: var(--muted); font-size: .78rem; }
.deck-actions, .mixed-actions { display: grid; gap: .6rem; margin-top: 1rem; }
.deck-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mixed-actions { grid-template-columns: 1.3fr 1fr; }
.deck-reset { padding-inline: .7rem; }
.button {
  min-height: 3.25rem;
  padding: .8rem 1rem;
  border: 1px solid transparent;
  border-radius: .8rem;
  cursor: pointer;
  font-weight: 700;
  touch-action: manipulation;
}
.button:focus-visible, .back-button:focus-visible, .question-link:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent), transparent 55%); outline-offset: 3px; }
.button:disabled { cursor: not-allowed; opacity: .5; }
.button-primary { background: var(--accent); color: var(--accent-text); }
.button-secondary { border-color: var(--border); background: transparent; color: var(--text); }
.button:active { transform: scale(.975); }
.text-button {
  display: block;
  min-height: 2.75rem;
  margin: 1.25rem auto 0;
  padding: .6rem .8rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .85rem;
}
.text-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent), transparent 55%); outline-offset: 3px; }
.message { margin: 0 0 1rem; color: var(--muted); }
.mixed-panel { display: grid; gap: 1rem; margin-top: 1rem; padding: clamp(1.25rem, 4vw, 1.75rem); }
.mixed-panel p:last-child { margin: .5rem 0 0; color: var(--muted); line-height: 1.45; }
.mixed-actions { margin: 0; }
.study-header { padding: .5rem 0 2rem; }
.back-button { min-height: 2.75rem; padding: .5rem 0; border: 0; background: transparent; color: var(--accent); cursor: pointer; font-weight: 700; }
.study-meta { font-weight: 750; }
.study-meta span:first-child { color: var(--accent); font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; }
.study-progress { margin: .65rem 0 1.5rem; }
.question-card {
  perspective: 90rem;
  overflow: hidden;
}
.card-inner {
  display: grid;
  min-height: clamp(23rem, 65vh, 38rem);
  transform-style: preserve-3d;
  transition: transform 500ms cubic-bezier(.2, .72, .2, 1);
  -webkit-transform-style: preserve-3d;
}
.card-inner.is-flipped { transform: rotateY(180deg); }
.card-face {
  display: flex;
  grid-area: 1 / 1;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  padding: clamp(1.5rem, 7vw, 3rem);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.card-back {
  max-height: clamp(23rem, 65vh, 38rem);
  justify-content: flex-start;
  overflow-y: auto;
  transform: rotateY(180deg);
  overscroll-behavior: contain;
}
.question-enter { animation: question-enter 220ms ease-out both; }
.screen-enter { animation: screen-enter 200ms ease-out both; }
.question-card h2 { font-size: clamp(1.65rem, 7vw, 2.65rem); line-height: 1.22; }
.answer-panel p:last-child { margin: 0; font-size: clamp(1.08rem, 4vw, 1.3rem); line-height: 1.55; white-space: pre-wrap; }
.study-actions, .rating-actions { margin-top: 1rem; }
.study-actions { display: grid; }
.rating-actions { display: grid; grid-template-columns: .85fr repeat(3, 1fr) .85fr; gap: .55rem; }
.rating-button { padding-inline: .35rem; color: var(--text); }
.navigation-button { padding-inline: .35rem; background: var(--surface); color: var(--accent); }
.navigation-button:disabled { opacity: .38; cursor: default; }
.rating-again { background: var(--danger-soft); border-color: #e8cbc4; }
.rating-almost { background: var(--warning-soft); border-color: #e6d6ab; }
.rating-know { background: var(--success-soft); border-color: #bfdcc8; }
.empty-state { padding: 18vh 1rem 0; text-align: center; }
.empty-state p { margin: .75rem 0 1.5rem; color: var(--muted); line-height: 1.5; }
[hidden] { display: none !important; }

.browse-heading { margin-bottom: 1.5rem; }
.browse-heading .library-summary { margin: .65rem 0 0; }
.selection-toolbar { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: .6rem; margin-bottom: 1rem; }
.question-list { display: grid; gap: .65rem; }
.question-link {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .85rem;
  width: 100%;
  min-height: 3.75rem;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: .9rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 6px 18px rgba(28, 38, 34, .04);
}
.question-checkbox { width: 1.25rem; height: 1.25rem; accent-color: var(--accent); }
.question-link:active { transform: scale(.99); }
.question-number { color: var(--accent); font-size: .75rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.question-copy { line-height: 1.35; }
.question-status {
  padding: .25rem .45rem;
  border-radius: 99px;
  background: var(--soft);
  color: var(--muted);
  font-size: .65rem;
  font-weight: 750;
  text-transform: uppercase;
}
.status-mastered { background: var(--success-soft); color: var(--accent); }
.status-learning { background: var(--warning-soft); }

.reader-tools {
  position: sticky;
  top: .5rem;
  z-index: 5;
  display: grid;
  gap: .75rem;
  margin-bottom: 1.25rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
}
.reader-search {
  width: 100%;
  min-height: 3rem;
  padding: .7rem .85rem;
  border: 1px solid var(--border);
  border-radius: .75rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.audio-buttons { display: grid; grid-template-columns: 1.35fr repeat(4, 1fr); gap: .5rem; }
.audio-buttons .button { min-height: 2.75rem; padding: .55rem .65rem; font-size: .82rem; }
.audio-options { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.1rem; color: var(--muted); font-size: .82rem; }
.audio-options label { display: flex; align-items: center; gap: .4rem; }
.audio-options select { padding: .35rem; border: 1px solid var(--border); border-radius: .45rem; background: var(--surface); color: var(--text); }
.audio-status { margin-left: auto; color: var(--accent); font-weight: 700; }
.reader-list { display: grid; gap: .75rem; padding-bottom: 3rem; }
.reader-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(28, 38, 34, .05);
}
.reader-card[open] { border-color: color-mix(in srgb, var(--accent), var(--border) 45%); }
.reader-card > summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: .8rem;
  padding: 1rem;
  cursor: pointer;
  font-weight: 750;
  line-height: 1.4;
  list-style: none;
}
.reader-card > summary::-webkit-details-marker, .followup-card > summary::-webkit-details-marker { display: none; }
.reader-answer { padding: 0 1rem 1rem 3.4rem; line-height: 1.58; }
.reader-answer > p { margin: 0; }
.followups { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.followups h3 { margin: 0 0 .7rem; color: var(--accent); font-size: .82rem; }
.followup-card { margin-top: .55rem; border-radius: .65rem; background: var(--soft); }
.followup-card summary { padding: .75rem; cursor: pointer; font-weight: 700; list-style: none; }
.followup-card p { margin: 0; padding: 0 .75rem .8rem; color: var(--muted); }
.reader-card.audio-active { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent), transparent 45%); }

@keyframes question-enter {
  from { opacity: 0; transform: translateY(.6rem); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes screen-enter {
  from { opacity: 0; transform: translateY(.35rem); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes soft-update {
  from { opacity: .72; transform: translateY(.2rem); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 42rem) {
  .deck-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mixed-panel { grid-template-columns: 1fr minmax(18rem, .8fr); align-items: center; }
  .screen { min-height: calc(100vh - 6rem); }
}
@media (max-width: 41.99rem) {
  .rating-actions { gap: .32rem; }
  .rating-actions .button { min-height: 3.25rem; padding: .55rem .18rem; font-size: clamp(.66rem, 2.8vw, .82rem); }
  .selection-toolbar { grid-template-columns: 1fr 1fr; }
  .selection-toolbar #study-selected { grid-column: 1 / -1; }
  .audio-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .audio-buttons #listen-all { grid-column: 1 / -1; }
  .audio-status { width: 100%; margin-left: 0; }
  .reader-answer { padding-left: 1rem; }
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816; --surface: #1d2320; --text: #edf1ee; --muted: #aab3ae; --border: #343d38;
    --accent: #79b99f; --accent-text: #102019; --soft: #2c3430; --danger-soft: #3a2825;
    --warning-soft: #393321; --success-soft: #23382c; --shadow: none;
  }
  .rating-again { border-color: #64443d; }
  .rating-almost { border-color: #625735; }
  .rating-know { border-color: #385c46; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
