:root {
  color-scheme: light dark;
  --bg: #f5f7f5;
  --surface: #ffffff;
  --text: #202e29;
  --muted: #66756e;
  --line: #dce5df;
  --accent: #3949ab;
  --accent-soft: #e6f1eb;
  --green: #196345;
  --green-soft: #e8f3eb;
  --red: #ab3d3d;
  --red-soft: #fbeeed;
  --shadow: 0 12px 40px #203b2910, 0 2px 5px #203b2905;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--bg); color: var(--text); display: flex; flex-direction: column; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; -webkit-tap-highlight-color: transparent; touch-action: manipulation; min-height: 48px; }
button, .flashcard { -webkit-user-select: none; user-select: none; }
button:focus-visible, main:focus-visible { outline: 3px solid var(--accent); outline-offset: 5px; }
button:disabled { cursor: default; opacity: .5; }
button:hover:not(:disabled) { filter: brightness(.97); }
button:active:not(:disabled) { scale: .985; }
[hidden] { display: none !important; }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(36px, 5vw, 52px); font-weight: 700; letter-spacing: -1.8px; margin-bottom: 14px; }
h2 { font-size: 24px; letter-spacing: -.6px; }
p { line-height: 1.6; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.app-header { width: 100%; padding: max(24px, env(safe-area-inset-top)) max(32px, env(safe-area-inset-right)) 20px max(32px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 12px; align-items: center; font-size: 20px; font-weight: 650; background: transparent; padding: 0; letter-spacing: -.5px; }
.brand img { border-radius: 11px; }
.icon-button { width: 48px; height: 48px; display: inline-flex; align-items: center; justify-content: center; background: transparent; border-radius: 14px; }
.icon-button:hover { background: var(--accent-soft); }
main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 56px 40px 28px; outline: none; }
.home-intro { margin-bottom: 38px; }
.eyebrow { color: var(--accent); font-size: 12px; letter-spacing: 2px; font-weight: 700; margin-bottom: 20px; }
.subtitle { font-size: 20px; color: var(--muted); margin: 0; }
.deck-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 28px; }
.deck-shell { min-width: 0; }
.deck-button { width: 100%; text-align: left; background: var(--surface); padding: 32px; border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); transition: transform .2s, box-shadow .2s; }
.deck-button:hover { transform: translateY(-3px); box-shadow: 0 18px 45px #203b2918; }
.deck-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.deck-emoji { font-size: 36px; width: 70px; height: 70px; background: var(--accent-soft); display: grid; place-items: center; border-radius: 20px; }
.pill { font-size: 13px; padding: 8px 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 50px; }
.deck-button h2 { font-size: 28px; margin-bottom: 10px; }
.deck-description { font-size: 17px; color: var(--muted); margin-bottom: 32px; }
.deck-bottom { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 22px; font-weight: 650; color: var(--accent); }
.deck-bottom svg { width: 22px; }
.mastery { display: grid; grid-template-columns: repeat(3, 1fr); padding: 24px 8px; gap: 12px; text-align: center; }
.mastery strong { display: block; font-size: 25px; font-weight: 650; margin-bottom: 8px; }
.mastery span { display: block; font-size: 13px; color: var(--muted); }
.mastery .known strong { color: var(--green); }
.mastery .missed strong { color: var(--red); }
.home-note { text-align: center; color: var(--muted); margin: 38px 0 0; font-size: 15px; }
.app-footer { padding: 18px 24px max(24px, env(safe-area-inset-bottom)); color: var(--muted); display: flex; gap: 16px; justify-content: center; align-items: center; flex-wrap: wrap; font-size: 12px; }
#offline-status::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 8px; border-radius: 50%; background: var(--accent); vertical-align: middle; }
#update-button { background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 8px 16px; font-size: 14px; }
main.study-main { padding-top: 24px; max-width: 1060px; display: flex; flex-direction: column; }
.study-heading { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 14px; margin-bottom: 22px; }
.study-heading h1 { font-size: 23px; letter-spacing: -.7px; text-align: center; margin: 0; }
.study-heading p { text-align: center; font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.progress-heading { display: flex; align-items: center; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
#progress-count { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }
progress { appearance: none; -webkit-appearance: none; width: 100%; height: 5px; border: none; border-radius: 9px; overflow: hidden; background: var(--line); }
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 9px; transition: width .2s; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 9px; }
.card-area { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-top: 26px; }
.flashcard { width: 100%; height: clamp(300px, 43vh, 530px); height: clamp(300px, 43dvh, 530px); perspective: 1600px; background: transparent; padding: 0; border-radius: 30px; text-align: center; transition: opacity .16s, transform .16s; }
.card-inner { display: block; position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .45s cubic-bezier(.25,.65,.2,1); }
.flashcard.flipped .card-inner { transform: rotateY(180deg); }
.card-face { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px; background: var(--surface); border: 1px solid var(--line); border-radius: 30px; box-shadow: var(--shadow); backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.card-back { transform: rotateY(180deg); background: var(--accent-soft); border-color: var(--accent); }
.card-label { position: absolute; top: 30px; font-size: 11px; letter-spacing: 2px; font-weight: 700; color: var(--muted); }
.card-text { font-size: clamp(30px, 4.5vw, 48px); font-weight: 600; letter-spacing: -1px; line-height: 1.3; max-width: 680px; text-wrap: pretty; }
.card-back .card-text { font-size: clamp(38px, 5.5vw, 62px); color: var(--accent); }
.card-hint { position: absolute; bottom: 30px; color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.card-hint svg { width: 18px; height: 18px; }
.flashcard.leaving { opacity: 0; transform: translateY(-10px); }
.grading-space { min-height: 116px; display: flex; justify-content: center; align-items: center; padding-top: 24px; }
.grading { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; width: min(100%, 600px); animation: appear .2s ease-out; }
.grade-button { min-height: 74px; border-radius: 20px; display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 20px; font-weight: 650; border: 1px solid; }
.grade-button svg { width: 28px; height: 28px; stroke-width: 2.5; }
.grade-missed { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red) 22%, transparent); }
.grade-known { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 22%, transparent); }
.study-tip { text-align: center; font-size: 14px; color: var(--muted); margin: 10px 0 0; }
.results { max-width: 650px; margin: 30px auto; text-align: center; }
.result-symbol { width: 88px; height: 88px; border-radius: 28px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin: 0 auto 26px; }
.result-symbol svg { width: 42px; height: 42px; stroke-width: 2; }
.results h1 { font-size: 44px; }
.results-card { padding: 32px; background: var(--surface); border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); margin: 32px 0; }
.percentage { display: block; color: var(--accent); font-size: 66px; font-weight: 700; letter-spacing: -3px; margin-bottom: 6px; }
.results-stats { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); margin-top: 24px; padding-top: 24px; }
.results-stats strong { display: block; font-size: 30px; margin-bottom: 6px; }
.results-stats span { font-size: 15px; color: var(--muted); }
.results-stats .known strong { color: var(--green); }
.results-stats .missed strong { color: var(--red); }
.result-actions { display: flex; flex-direction: column; gap: 12px; }
.primary, .secondary, .danger { min-height: 56px; border-radius: 16px; padding: 16px 24px; font-size: 17px; font-weight: 600; }
.primary { color: #fff; background: var(--accent); }
.secondary { background: var(--surface); border: 1px solid var(--line); }
.danger { background: var(--red-soft); color: var(--red); border: 1px solid var(--red); }
.text-button { background: transparent; color: var(--muted); padding: 12px 24px; font-size: 16px; border-radius: 12px; }
dialog { width: min(460px, calc(100% - 32px)); padding: 28px; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); }
dialog::backdrop { background: #10271b70; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.dialog-heading h2 { margin: 0; }
.dialog-actions { display: flex; flex-direction: column; gap: 12px; margin: 24px 0 16px; }
.small { font-size: 13px; margin-bottom: 0; }
.muted { color: var(--muted); }
.notice { position: fixed; bottom: 16px; left: 16px; right: 16px; max-width: 700px; margin: auto; background: var(--red-soft); color: var(--red); border: 1px solid var(--red); border-radius: 16px; padding: 18px; z-index: 10; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@keyframes appear { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (min-width: 760px) { .home-intro { margin-top: 20px; } .deck-grid:has(.deck-shell:only-child) { max-width: 660px; } }
@media (max-width: 600px) {
  .app-header { padding: max(16px, env(safe-area-inset-top)) 20px 12px; }
  main { padding: 32px 20px 20px; }
  main.study-main { padding: 18px 20px; }
  .deck-button { padding: 24px; }
  .deck-button h2 { font-size: 24px; }
  .study-heading { gap: 6px; }
  .study-heading h1 { font-size: 19px; }
  .card-face { padding: 32px 24px; }
  .card-label { top: 22px; }
  .card-hint { bottom: 22px; }
  .grade-button { font-size: 18px; }
  .grading { gap: 12px; }
  .results { margin-top: 0; }
}
@media (orientation: landscape) and (max-height: 850px) {
  .app-header { padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: 10px; }
  main.study-main { padding-top: 12px; }
  .study-heading { margin-bottom: 12px; }
  .card-area { padding-top: 16px; }
  .flashcard { height: clamp(230px, 40dvh, 370px); }
  .grading-space { min-height: 96px; padding-top: 18px; }
  .grade-button { min-height: 64px; }
  .study-tip { margin-top: 0; }
  .app-footer { padding-top: 10px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141d1b; --surface: #1d2925; --text: #edf4ef; --muted: #a8b8af; --line: #36473e; --accent: #8ad2b5; --accent-soft: #233d33; --green: #9cddae; --green-soft: #243e2e; --red: #f3abab; --red-soft: #432b2b; --shadow: 0 12px 40px #00000020; }
  .primary { color: #102b20; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (prefers-contrast: more) {
  :root { --muted: #34473c; --line: #657c6c; }
  .card-face, .deck-button, .grade-button { border-width: 2px; }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark) { :root { --muted: #d7e8dc; --line: #a4bfad; } }

.audio-controls { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.audio-controls[hidden] { display: none; }

.workshop h1 { font-size: clamp(30px, 4vw, 44px); }
.workshop .text-button { margin-bottom: 24px; }
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.lesson-tile { padding: 24px; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; display: flex; flex-direction: column; gap: 16px; }
.lesson-tile .eyebrow { margin: 0; }
.lesson-tile strong { font-size: 20px; }
.lesson-tile > span:last-child { color: var(--muted); }
.workshop-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 28px; margin-top: 24px; }
.workshop label { display: block; font-weight: 650; margin: 12px 0; }
.workshop select, #python-editor { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 14px; font: inherit; margin-bottom: 16px; }
#python-editor { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 16px; line-height: 1.6; resize: vertical; tab-size: 4; }
.code-example, .code-output { white-space: pre-wrap; overflow-wrap: anywhere; font: 16px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); padding: 18px; border-radius: 12px; }
.code-output { min-height: 90px; max-height: 360px; overflow: auto; }
.workshop-actions { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 600px) { .workshop-panel { padding: 18px; } }
