/* Soft-bound study room: tactile surfaces, distinctive type, meaningful motion. */
:root, :root[data-theme="dark"] {
  --font-body: 'Afacad Flux', system-ui, sans-serif;
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-serif: 'Literata', Georgia, serif;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow-card: 0 1px 0 rgba(255,255,255,.045) inset, 0 12px 34px rgba(0,0,0,.16);
  --shadow-lift: 0 1px 0 rgba(255,255,255,.07) inset, 0 18px 46px rgba(0,0,0,.24);
  --t-pop: 180ms;
  --ease-pop: cubic-bezier(.2,.9,.25,1.25);
  --ease-soft: cubic-bezier(.2,.75,.25,1);
}
:root[data-theme="day"] {
  --shadow-card: 0 1px 0 rgba(255,255,255,.88) inset, 0 9px 26px rgba(92,61,54,.09), 0 2px 5px rgba(92,61,54,.06);
  --shadow-lift: 0 1px 0 #fff inset, 0 17px 38px rgba(92,61,54,.14), 0 3px 8px rgba(92,61,54,.07);
}

body { font-family: var(--font-body); font-size: 16px; font-variation-settings: 'wght' 440; letter-spacing: -.005em; overflow-x: hidden; }
h1, h2, h3, .brand { font-family: var(--font-display); font-weight: 650; letter-spacing: -.045em; }
.prompt, .answer, .transcript-section p, .reader-note { font-family: var(--font-serif); }
.lede { font-size: 16px; }
.mobile-brand { display: none; }
.skip { min-height: 44px; }
.quiet-link { display: inline-flex; align-items: center; min-height: 44px; }

.panel, .big-card, .hero-card, .source-card, .face {
  border-color: color-mix(in srgb, var(--line2) 88%, white 12%);
  background: linear-gradient(145deg, color-mix(in srgb, var(--panel) 94%, white 6%), var(--panel));
  box-shadow: var(--shadow-card);
}
.panel, .big-card, .hero-card { border-radius: var(--radius); }
.source-card { border-radius: 19px; transition: transform var(--t-pop) var(--ease-soft), border-color var(--t-pop), box-shadow var(--t-pop); }
.source-card:hover { transform: translateY(-5px) rotate(-.18deg); box-shadow: var(--shadow-lift); }
.source-card:active { transform: translateY(-1px) scale(.99); }
.source-card h3 { font-weight: 620; letter-spacing: -.035em; }

.btn, .icon-btn, .cmd-btn, .chip, .tab, .rate, .option, .switch {
  transition: transform var(--t-pop) var(--ease-pop), background-color var(--t-pop), border-color var(--t-pop), box-shadow var(--t-pop), color var(--t-pop);
}
.btn, .icon-btn, .cmd-btn { min-height: 44px; border-radius: 14px; font-weight: 620; }
.btn-primary, .btn-gold { box-shadow: 0 1px 0 rgba(255,255,255,.22) inset, 0 8px 20px color-mix(in srgb, var(--cy) 28%, transparent); }
.btn:hover, .icon-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); }
.btn:active, .icon-btn:active, .cmd-btn:active, .chip:active, .tab:active, .option:active, .rate:active { transform: scale(.965); }
.input, .textarea, .select { min-height: 48px; border-radius: 14px; font-family: var(--font-body); }
.input:focus, .textarea:focus, .select:focus { box-shadow: 0 0 0 4px var(--cy-dim); }
.switch { position: relative; width: 56px; height: 44px; border: 0; border-radius: 22px; background: transparent !important; }
.switch::before { content: ''; position: absolute; inset: 7px 0; border: 1px solid var(--line); border-radius: 17px; background: var(--panel2); transition: background-color var(--t-pop), border-color var(--t-pop); }
.switch::after { width: 20px; height: 20px; top: 11px; left: 4px; box-shadow: 0 2px 5px rgba(0,0,0,.2); }
.switch[aria-checked="true"]::before { border-color: var(--cy-text); background: var(--cy-dim); }
.switch[aria-checked="true"]::after { transform: translateX(28px); }
.chip { min-height: 44px; }

.study-hero {
  border-radius: 26px;
  background: radial-gradient(circle at 88% 18%, color-mix(in srgb, var(--cy-text) 14%, transparent), transparent 31%), linear-gradient(135deg, color-mix(in srgb, var(--panel2) 96%, var(--cy) 4%), var(--panel));
  box-shadow: var(--shadow-card);
}
.study-hero h2 { font-weight: 650; letter-spacing: -.055em; }
.study-hero h2 em { font-family: var(--font-serif); font-weight: 520; letter-spacing: -.045em; }
.hero-folio { animation: folio-breathe 5.5s ease-in-out infinite; transform-origin: 50% 70%; }
.folio-star { animation: star-wink 2.8s ease-in-out infinite; transform-origin: center; }
.rhythm-panel { border-radius: 22px; box-shadow: var(--shadow-card); background: linear-gradient(160deg, color-mix(in srgb, var(--panel) 94%, white 6%), var(--panel)); }
.rhythm i { transform-origin: bottom; animation: rhythm-rise .48s var(--ease-soft) both; }
.rhythm i:nth-child(2) { animation-delay: 45ms; }.rhythm i:nth-child(3) { animation-delay: 90ms; }
.rhythm i:nth-child(4) { animation-delay: 135ms; }.rhythm i:nth-child(5) { animation-delay: 180ms; }
.rhythm i:nth-child(6) { animation-delay: 225ms; }.rhythm i:nth-child(7) { animation-delay: 270ms; }
.return-dot { animation: due-pulse 2.7s ease-out infinite; }
.return-status.is-clear .return-dot { animation: none; }
.companion-trigger { border-radius: 16px; box-shadow: var(--shadow-card); }
.companion-trigger .pixel-me { animation: companion-idle 4.2s ease-in-out infinite; transform-origin: 50% 100%; }

.study-stats { gap: 12px; border: 0; padding-bottom: 0; }
.study-stats > div { min-width: 0; padding: 17px 18px; border: 1px solid var(--line2) !important; border-radius: 17px; background: color-mix(in srgb, var(--panel) 96%, white 4%); box-shadow: 0 1px 0 rgba(255,255,255,.035) inset; }
.study-stats b { font-family: var(--font-display); font-weight: 680; letter-spacing: -.05em; }
.stat-label { color: var(--ink3); }

.face { border-radius: 24px; box-shadow: var(--shadow-card); }
.face-body .prompt { font-family: var(--font-serif); font-weight: 520; letter-spacing: -.035em; }
.face-body .answer { font-family: var(--font-serif); }
.option { min-height: 56px; border-radius: 15px; font-weight: 570; }
.option:hover:not(:disabled) { transform: translateX(4px); }
.rate { min-height: 54px; border-radius: 14px; }
.review-progress { height: 8px; background: var(--panel-sunk); border: 1px solid var(--line2); }
.review-progress i { background: linear-gradient(90deg, var(--cy2), var(--cy-text)); transition: width .65s var(--ease-soft); }
.feedback-correct .face.front { animation: correct-pop .58s var(--ease-pop); }
.feedback-wrong .face.front { animation: wrong-shake .48s ease-out; }
.option.correct { animation: answer-glow .62s ease-out; }

.toast { border-radius: 15px; box-shadow: var(--shadow-lift); animation: toast-arrive .42s var(--ease-pop); }
.feedback-burst { position: fixed; width: 1px; height: 1px; pointer-events: none; z-index: 1100; }
.feedback-burst i { --distance: 48px; position: absolute; width: 7px; height: 7px; left: -3px; top: -3px; border-radius: 2px; background: var(--mint); box-shadow: 0 0 10px color-mix(in srgb, var(--mint) 55%, transparent); animation: burst-spark .7s var(--ease-soft) forwards; }
.feedback-burst.error i { background: var(--rose); box-shadow: 0 0 10px color-mix(in srgb, var(--rose) 55%, transparent); }
.feedback-burst i:nth-child(even) { --distance: 64px; width: 5px; height: 10px; }

.route-stage:not(.route-ready) .screen > * { opacity: 0; transform: translateY(12px); }
.route-stage.route-ready .screen > * { animation: route-reveal .5s var(--ease-soft) both; }
.route-stage.route-ready .screen > *:nth-child(2) { animation-delay: 55ms; }
.route-stage.route-ready .screen > *:nth-child(3) { animation-delay: 100ms; }
.route-stage.route-ready .screen > *:nth-child(4) { animation-delay: 145ms; }
.route-stage.route-ready .screen > *:nth-child(5) { animation-delay: 190ms; }
.route-stage.route-ready .screen > *:nth-child(n+6) { animation-delay: 225ms; }

@keyframes route-reveal { from { opacity: 0; transform: translateY(12px) scale(.992); } to { opacity: 1; transform: none; } }
@keyframes folio-breathe { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-7px) rotate(1deg); } }
@keyframes star-wink { 0%,100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.18); } }
@keyframes rhythm-rise { from { transform: scaleY(.1); opacity: .25; } to { transform: scaleY(1); opacity: 1; } }
@keyframes due-pulse { 0%,55%,100% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--cy-text) 13%, transparent); } 72% { box-shadow: 0 0 0 9px transparent; } }
@keyframes companion-idle { 0%,86%,100% { transform: translateY(0) rotate(0); } 91% { transform: translateY(-3px) rotate(-2deg); } 96% { transform: translateY(0) rotate(2deg); } }
@keyframes correct-pop { 0% { transform: scale(1); } 38% { transform: scale(1.018) rotate(.2deg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--mint) 45%, transparent), var(--shadow-lift); } 100% { transform: scale(1); } }
@keyframes wrong-shake { 0%,100% { transform: translateX(0); } 22% { transform: translateX(-7px) rotate(-.25deg); } 44% { transform: translateX(6px) rotate(.2deg); } 66% { transform: translateX(-3px); } 84% { transform: translateX(2px); } }
@keyframes answer-glow { 0% { box-shadow: 0 0 0 transparent; } 45% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--mint) 25%, transparent); } 100% { box-shadow: 0 0 0 transparent; } }
@keyframes toast-arrive { from { opacity: 0; transform: translateY(16px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes burst-spark { 0% { opacity: 1; transform: rotate(var(--turn)) translate(0) rotate(calc(-1 * var(--turn))) scale(1); } 100% { opacity: 0; transform: rotate(var(--turn)) translate(var(--distance)) rotate(calc(-1 * var(--turn))) scale(.25); } }

@media (max-width: 599px) {
  body { font-size: 15px; }
  .topbar { width: 100%; min-height: 72px; padding: max(10px, env(safe-area-inset-top)) 16px 10px; gap: 10px; }
  .topbar .caption, .topbar .presence-wrap, #theme-toggle, #btn-cmd { display: none; }
  .companion-trigger { width: 48px; height: 48px; padding: 2px; flex: none; }
  .mobile-brand { display: grid; line-height: 1; min-width: 0; }
  .mobile-brand b { font-family: var(--font-display); font-size: 17px; font-weight: 720; letter-spacing: -.045em; }
  .mobile-brand small { margin-top: 5px; color: var(--ink3); font: 9px/1 var(--font-mono); letter-spacing: .06em; text-transform: uppercase; }
  .topbar-actions { margin-left: auto; gap: 7px; }
  .topbar-actions .icon-btn { width: 44px; height: 44px; min-width: 44px; border: 1px solid var(--line2); border-radius: 14px; background: var(--panel); }
  .return-status { min-width: 58px; min-height: 44px; padding: 7px 10px; border: 1px solid var(--line2); border-radius: 14px; background: var(--panel); gap: 7px; }
  .return-status > span:last-child { display: grid; }
  .return-status b { max-width: 42px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
  .return-status small { display: none; }
  .return-dot { width: 7px; height: 7px; }

  main.view { padding: 22px 16px calc(104px + env(safe-area-inset-bottom)); }
  .screen, .study-home { gap: 20px; }
  .study-welcome { align-items: center; }
  .study-welcome h1 { font-size: clamp(30px, 9vw, 36px); line-height: 1.02; margin-top: 8px; }
  .study-hero { min-height: 285px; padding: 23px 21px; border-radius: 24px; }
  .study-hero h2 { max-width: 8.5em; font-size: clamp(34px, 10.5vw, 41px); line-height: .99; margin: 18px 0 15px; }
  .study-hero p { max-width: 31ch; font-size: 13px; line-height: 1.55; }
  .study-hero .hero-actions { gap: 9px; margin-top: 22px; }
  .study-hero .hero-actions .btn { flex: 0 1 auto; }
  .hero-folio { width: 142px; right: -36px; top: 18px; opacity: .11; }
  .rhythm-panel { border-radius: 20px; padding: 18px; }
  .study-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .study-stats > div, .study-stats > div:nth-child(even) { padding: 15px 14px; border: 1px solid var(--line2); }
  .study-stats b { font-size: 29px; }
  .study-stats small { display: block; margin: 5px 0 0; font-size: 10px; }
  .stat-label { margin-bottom: 5px; }

  .tabbar { inset: auto 10px max(8px, env(safe-area-inset-bottom)); width: calc(100% - 20px); height: 72px; padding: 7px 8px; border-radius: 22px; box-shadow: 0 14px 38px rgba(0,0,0,.34), 0 1px 0 rgba(255,255,255,.06) inset; }
  .tabbar .nav-list { grid-template-columns: 1fr 1fr 60px 1fr 1fr; }
  .nav-item { min-width: 44px; min-height: 56px; border-radius: 13px; }
  .nav-item span { font-size: 10px; }
  .fab { width: 52px; height: 52px; border-radius: 17px; box-shadow: 0 9px 22px color-mix(in srgb, var(--cy) 40%, transparent), 0 1px 0 rgba(255,255,255,.24) inset; }
  .fab:active { transform: translate(-50%, -50%) scale(.92); }

  .panel { padding: 20px 18px; border-radius: 20px; }
  .screen-head { gap: 12px; }
  .screen-head h1, .source-reader-head h1 { font-size: 34px; }
  .source-card { border-radius: 18px; grid-template-columns: 91px minmax(0,1fr); }
  .source-cover { min-height: 162px; }
  .source-card-body { padding: 15px; }
  .source-card h3 { font-size: 19px; }

  .review-head { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
  .review-head .eyebrow { grid-column: 1 / 3; grid-row: 1; align-self: center; width: auto; }
  .review-count { grid-column: 3; grid-row: 1; justify-self: end; margin: 0; }
  .review-progress { grid-column: 1 / -1; grid-row: 2; width: 100%; }
  .review-left, .review-head .spacer { display: none; }
  .review-head .btn { min-width: 44px; min-height: 44px; width: 100%; justify-content: center; }
  #focus-review { grid-column: 1; grid-row: 3; }
  #undo-btn { grid-column: 2; grid-row: 3; }
  #stop-review { grid-column: 3; grid-row: 3; }
  .review-grid { gap: 14px; }
  .face { min-height: min(490px, calc(100dvh - 225px)); padding: 21px 18px; border-radius: 22px; }
  .face-body .prompt, .review-focus .face-body .prompt { font-size: clamp(24px, 7vw, 29px); line-height: 1.25; }
  .face-body .prompt.q { font-size: clamp(20px, 5.8vw, 24px); }
  .option { min-height: 54px; padding: 12px; font-size: 14px; }
  .option .t { font-size: 15px; }
  .rating-row { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
  .rate { min-height: 58px; padding: 10px 8px; }
  .review-focus main.view { padding: max(18px, env(safe-area-inset-top)) 14px 28px; }
  body:has(.review-grid) main.view { padding-bottom: 26px; }
  body:has(.review-grid) .tabbar { display: none; }

  .settings-grid { gap: 14px; }
  .settings-grid .setting { gap: 14px; padding: 15px 0; }
  .setting .name { font-size: 15px; font-weight: 650; }
  .setting .desc { font-size: 13px; line-height: 1.45; }
  .setting .btn-sm { min-height: 44px; }
  .inline-setting, .inline-setting.wide, .range-row { width: 100%; }
  .inline-setting .input, .inline-setting.wide .input { width: 0; min-width: 0; flex: 1; }
  .reminder-time { width: 132px; }
  .reminder-intro { gap: 13px; padding: 15px; border-radius: 17px; }
  .phone-install { padding: 15px; border-radius: 16px; }
  .install-app-row { gap: 12px; }
  .install-app-row img { width: 52px; height: 52px; border-radius: 12px; }
  .toast-host { left: 12px; right: 12px; bottom: calc(94px + env(safe-area-inset-bottom)); max-width: none; }
}

@media (max-width: 370px) {
  .mobile-brand small { display: none; }
  .return-status { min-width: 44px; padding: 7px; }
  .return-status > span:last-child { display: none; }
  .study-hero .hero-actions .btn { width: 100%; justify-content: center; }
  .tabbar { left: 6px; right: 6px; width: calc(100% - 12px); }
  .nav-item span { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .route-stage.route-ready .screen > *, .hero-folio, .folio-star, .rhythm i, .return-dot, .companion-trigger .pixel-me, .feedback-correct .face.front, .feedback-wrong .face.front, .option.correct, .toast, .feedback-burst i { animation: none !important; }
  .feedback-burst { display: none !important; }
}
:root.rm .route-stage.route-ready .screen > *, :root.rm .hero-folio, :root.rm .folio-star, :root.rm .rhythm i, :root.rm .return-dot, :root.rm .companion-trigger .pixel-me, :root.rm .feedback-correct .face.front, :root.rm .feedback-wrong .face.front, :root.rm .option.correct, :root.rm .toast, :root.rm .feedback-burst i { animation: none !important; }
:root.rm .feedback-burst { display: none !important; }
