/* Study Buddy styles. Four looks, chosen in Settings. No animations unless "Celebrate" is on in Settings
   (and never when the phone asks for reduced motion). Nothing ever flashes. */
:root, [data-theme="blue"] {
  --bg: #F5F7FA; --surface: #FFFFFF; --text: #1C2733; --muted: #52606D; --line: #E1E6EC;
  --control: #C9D3DD; --soft: #E6EEF6; --soft-text: #3E4C59; --soft-line: #D3DFEB; --chip: #EEF2F6;
  --accent: #2F5F8F; --on-accent: #FFFFFF;
  --ok: #1F6F5C; --ok-bg: #E3F2EC; --warn: #A3321C; --warn-border: #C0432B; --warn-bg: #FDECE8;
  --font: "Atkinson Hyperlegible", system-ui, -apple-system, sans-serif; --r: 14px; --r-big: 18px;
}
[data-theme="sage"] {
  --bg: #F7F4EC; --surface: #FFFDF8; --text: #2B2A26; --muted: #5E5B52; --line: #E8E2D4;
  --control: #D3CBB8; --soft: #E7EFE6; --soft-text: #45443D; --soft-line: #D2DFD0; --chip: #F1ECE0;
  --accent: #3F6B55; --on-accent: #FFFFFF;
  --font: "Nunito", system-ui, -apple-system, sans-serif; --r: 22px; --r-big: 26px;
}
[data-theme="night"] {
  --bg: #141A24; --surface: #1E2633; --text: #E6EAF0; --muted: #A3AFBF; --line: #2C3646;
  --control: #3A4659; --soft: #23304A; --soft-text: #C3CCD8; --soft-line: #34405A; --chip: #2A3445;
  --accent: #A9C1FF; --on-accent: #141A24;
  --ok: #6FCFB0; --ok-bg: #17352E; --warn: #FF9C8A; --warn-border: #FF9C8A; --warn-bg: #3B2420;
  --font: "Lexend", system-ui, -apple-system, sans-serif;
}
[data-theme="peach"] {
  --bg: #FFF4EE; --surface: #FFFFFF; --text: #2E2220; --muted: #6A5550; --line: #F0DDD3;
  --control: #DDC3B8; --soft: #FCE3DA; --soft-text: #4A3733; --soft-line: #F3CFC2; --chip: #FBEAE3;
  --accent: #A63D57; --on-accent: #FFFFFF;
  --font: "Atkinson Hyperlegible", system-ui, -apple-system, sans-serif; --r: 18px; --r-big: 22px;
}
[data-size="large"] { font-size: 112%; }
[data-size="xlarge"] { font-size: 125%; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
html { -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; }
*, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
html:not([data-celebrate="on"]) *, html:not([data-celebrate="on"]) *::before, html:not([data-celebrate="on"]) *::after { animation: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; } }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topbar {
  position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) 12px 0;
}
.topbar-inner { height: 60px; display: grid; grid-template-columns: 108px 1fr 108px; align-items: center; max-width: 640px; margin: 0 auto; }
.brand { text-align: center; font-weight: 700; color: var(--accent); font-size: 1.05rem; }
.topbar .right { text-align: right; color: var(--muted); font-size: 0.9rem; }
.icon-btn {
  min-height: 44px; min-width: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--control);
  background: var(--surface); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 1rem;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-only { padding: 0; width: 44px; justify-content: center; }

main { max-width: 640px; margin: 0 auto; padding: 24px 20px calc(40px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 20px; }
h1 { margin: 0; font-size: 1.75rem; line-height: 1.25; }
h1:focus { outline: none; }
h2 { margin: 0; font-size: 1.15rem; }
p { margin: 0; line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 0.95rem; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-big); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.panel.soft { background: var(--soft); border-color: var(--soft-line); color: var(--soft-text); }
.panel.soft strong, .panel.soft .title { color: var(--text); }
.title { font-size: 1.15rem; font-weight: 700; }

.btn {
  min-height: 52px; border-radius: var(--r); border: 2px solid transparent; padding: 0 18px; font-size: 1.05rem; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-align: center; width: 100%;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.secondary { background: var(--surface); border-color: var(--control); color: var(--text); }
.btn.outline { background: var(--surface); border-color: var(--accent); color: var(--accent); }
.btn.link { background: transparent; color: var(--muted); text-decoration: underline; font-weight: 400; min-height: 44px; }
.btn.small { min-height: 44px; width: auto; font-size: 0.95rem; }

label { font-size: 0.95rem; color: var(--muted); }
input[type="search"] {
  width: 100%; height: 54px; border-radius: var(--r); border: 2px solid var(--control); padding: 0 16px; font-size: 1.1rem;
  background: var(--surface); color: var(--text); -webkit-appearance: none; appearance: none;
}
input[type="search"]::placeholder { color: var(--muted); }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-big); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.list-item {
  width: 100%; min-height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px;
  background: transparent; border: 0; text-align: left; cursor: pointer; font-size: 1.05rem; color: var(--text);
}
.list-item .sub { display: block; color: var(--muted); font-size: 0.9rem; margin-top: 2px; }
.list-item .chev { color: var(--muted); flex-shrink: 0; }
.score-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; font-size: 1.02rem; }
.score-row span:last-child { color: var(--muted); white-space: nowrap; }
.soft-list { background: var(--soft); border-color: var(--soft-line); }
.soft-list > * + * { border-top-color: var(--soft-line); }

.tag { display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--soft-text); margin-left: 6px; vertical-align: 2px; white-space: nowrap; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg button { min-height: 48px; border-radius: 12px; border: 2px solid var(--control); background: var(--surface); cursor: pointer; font-size: 1rem; }
.seg button[aria-pressed="true"] { border-color: var(--accent); background: var(--soft); font-weight: 700; color: var(--text); }

.flashcard {
  min-height: 320px; border-radius: 20px; border: 1px solid var(--control); background: var(--surface); padding: 28px 22px;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 16px; text-align: center; cursor: pointer; width: 100%;
}
.flashcard .side { font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.flashcard .front { font-size: 1.6rem; line-height: 1.35; font-weight: 700; }
.flashcard .back { font-size: 1.2rem; line-height: 1.5; font-weight: 700; }

.option {
  min-height: 58px; border-radius: var(--r); border: 2px solid var(--control); background: var(--surface); width: 100%;
  display: flex; align-items: center; gap: 14px; padding: 10px 16px; text-align: left; cursor: pointer; font-size: 1.08rem; color: var(--text);
}
.option .letter { width: 32px; height: 32px; border-radius: 16px; background: var(--chip); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.95rem; flex-shrink: 0; }
.option .txt { flex: 1; }
.option .mark { font-size: 0.85rem; font-weight: 700; }
.option.correct { border-color: var(--ok); background: var(--ok-bg); }
.option.correct .mark { color: var(--ok); }
.option.wrong { border-color: var(--warn-border); background: var(--warn-bg); }
.option.wrong .mark { color: var(--warn); }
.option.dim { opacity: 0.6; }
.option[disabled] { cursor: default; }

.dots { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; }
.dots span { height: 10px; border-radius: 5px; background: var(--control); }
.dots span.on { background: var(--accent); }

.swatches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.swatch { min-height: 64px; border-radius: 14px; border: 2px solid var(--control); padding: 10px 12px; text-align: left; cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 1rem; }
.swatch[aria-pressed="true"] { border-color: var(--accent); border-width: 3px; font-weight: 700; }
.swatch .chip { width: 28px; height: 28px; border-radius: 14px; flex-shrink: 0; border: 1px solid rgba(0,0,0,.15); }

/* Big, clear feedback after a quiz answer */
.fb { display: flex; gap: 14px; align-items: center; padding: 18px; border-radius: var(--r-big); border: 3px solid; }
.fb svg { width: 48px; height: 48px; flex-shrink: 0; }
.fb .big { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.fb.ok { border-color: var(--ok); background: var(--ok-bg); }
.fb.ok .big, .fb.ok svg { color: var(--ok); }
.fb.no { border-color: var(--warn-border); background: var(--warn-bg); }
.fb.no .big, .fb.no svg { color: var(--warn); }
.fb .why { color: var(--text); margin-top: 6px; line-height: 1.5; }
@keyframes pop { 0% { transform: scale(0.6); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
html[data-celebrate="on"] .fb.ok svg { animation: pop 0.45s ease-out 1; }
@keyframes fall { 0% { transform: translateY(0) rotate(0); opacity: 1; } 100% { transform: translateY(105vh) rotate(200deg); opacity: 0; } }
.confetti span { position: fixed; top: -12px; width: 9px; height: 9px; border-radius: 2px; animation: fall 1.8s ease-in 1 forwards; pointer-events: none; z-index: 5; }

/* End-of-session celebration. Only runs when Celebrate is on (see the rule at the top), a few loops then rests. */
.scene { background: var(--surface); border: 1px solid var(--control); border-radius: var(--r, 16px); padding: 8px 8px 14px; text-align: center; overflow: hidden; }
.scene-svg { width: 100%; max-width: 360px; height: auto; display: block; margin: 0 auto; }
.scene-cap { margin: 4px 0 0; font-weight: 700; font-size: 1.1rem; }
html[data-celebrate="on"] .burst { animation: burstPop 2.2s ease-out 2 both; }
@keyframes burstPop { 0% { opacity: 0; transform-origin: center; } 20% { opacity: 1; } 100% { opacity: 0.15; } }
html[data-celebrate="on"] .burst .ray { animation: rayOut 2.2s ease-out 2 both; }
@keyframes rayOut { 0% { transform: scale(0.3); } 100% { transform: scale(1.25); } }
html[data-celebrate="on"] .balloon { animation: rise 2.6s ease-out 1 both; }
@keyframes rise { 0% { transform: translateY(150px); opacity: 0; } 25% { opacity: 1; } 100% { transform: translateY(0); opacity: 1; } }
html[data-celebrate="on"] .star { animation: starIn 0.8s ease-out 1 both, glow 2.4s ease-in-out 0.8s 3; transform-box: fill-box; transform-origin: center; }
@keyframes starIn { 0% { transform: scale(0); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes glow { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
html[data-celebrate="on"] .heartbeat { animation: glow 2.4s ease-in-out 3; transform-box: fill-box; transform-origin: center; }
html[data-celebrate="on"] .llama { animation: sway 0.9s ease-in-out 6; }
html[data-celebrate="on"] .llama .head { animation: nod 0.45s ease-in-out 12; transform-box: fill-box; transform-origin: 50% 90%; }
html[data-celebrate="on"] .llama .l1 { animation: hop 0.9s ease-in-out 6; }
html[data-celebrate="on"] .llama .l2 { animation: hop 0.9s ease-in-out 0.45s 6; }
html[data-celebrate="on"] .notes { animation: floatUp 3s ease-out 2; }
@keyframes sway { 0%, 100% { transform: translate(160px,170px) rotate(-5deg); } 50% { transform: translate(160px,170px) rotate(5deg); } }
@keyframes nod { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes floatUp { 0% { transform: translateY(14px); opacity: 0; } 30% { opacity: 1; } 100% { transform: translateY(-14px); opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) { .scene *, .scene { animation: none !important; } }

.btn .ic { width: 20px; height: 20px; margin-right: 8px; vertical-align: -4px; flex: none; }
.grid2 .btn { padding: 0 10px; }
