:root {
  /* Sunset over the court: night purple, orange-gold light, graffiti teal. */
  --bg: #1a0f2e;
  --bg2: #241539;
  --card: #2e1c48;
  --card-d: #170c28;
  --line: #4a3170;
  --text: #fff;
  --dim: #c2a9e0;
  --yellow: #ffc21a;
  --yellow-d: #c98a00;
  --orange: #ff7a1a;
  --orange-d: #c24d00;
  --green: #3ee07a;
  --green-d: #1fa552;
  --red: #ff4f6a;
  --red-d: #c42340;
  --cyan: #29c7d0;
  --cyan-d: #138a92;
  --purple: #9a5cff;
  --purple-d: #6131c9;
  --pink: #ff4f9a;
  --display: 'Lilita One', 'Fredoka', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Fredoka', system-ui, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(130% 45% at 50% 0%, #6a2a5e 0%, #3a1a4e 35%, var(--bg) 75%);
  background-attachment: fixed;
  color: var(--text);
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }
button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.en { direction: ltr; unicode-bidi: isolate; }
.hidden { display: none !important; }

#app {
  max-width: 480px; margin: 0 auto; min-height: 100%;
  padding: calc(var(--safe-top) + 12px) 18px calc(var(--safe-bottom) + 20px);
  display: flex; flex-direction: column; gap: 14px;
}

/* ---------- splash ---------- */
.splash {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  transition: opacity .45s, visibility .45s;
}
.splash img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; }
.splash-load { position: absolute; left: 25%; right: 25%; bottom: calc(var(--safe-bottom) + 34px); height: 8px; border-radius: 9px; background: rgba(0,0,0,.45); overflow: hidden; }
.splash-load i { display: block; height: 100%; width: 40%; border-radius: 9px; background: var(--yellow); animation: load 1s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-120%); } to { transform: translateX(260%); } }
.splash.gone { opacity: 0; visibility: hidden; }
@keyframes bob { 50% { transform: translateY(-12px) rotate(-4deg); } }

/* ---------- buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  border-radius: 18px; font-weight: 600; font-size: 19px; padding: 15px 18px; color: #fff;
  background: var(--green); box-shadow: 0 5px 0 var(--green-d);
  transition: transform .06s, box-shadow .06s;
}
.btn:active, .press:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--green-d); }
.btn.orange { background: var(--orange); box-shadow: 0 5px 0 var(--orange-d); }
.btn.yellow { background: var(--yellow); box-shadow: 0 5px 0 var(--yellow-d); color: #3a2600; }
.btn.purple { background: var(--purple); box-shadow: 0 5px 0 var(--purple-d); }
.btn.cyan { background: var(--cyan); box-shadow: 0 5px 0 var(--cyan-d); color: #04263a; }
.btn.red { background: var(--red); box-shadow: 0 5px 0 var(--red-d); }
.btn.ghost { background: var(--card); box-shadow: 0 5px 0 var(--card-d); }
.btn.small { font-size: 16px; padding: 11px 14px; border-radius: 14px; }
.pill { display: inline-flex; align-items: center; gap: 5px; background: var(--card); border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 15px; }
button.pill { color: var(--dim); }
button.pill:active { background: var(--line); }

/* ---------- home ---------- */
.logo { display: block; width: 78%; max-width: 330px; margin: 0 auto -6px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.45)); }
.topbar { display: flex; align-items: center; justify-content: space-between; }
.hello { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 600; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--orange); display: grid; place-items: center; font-size: 26px; border: 3px solid var(--yellow); overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.level { background: var(--card); border-radius: 18px; padding: 12px 14px; }
.level .row { display: flex; justify-content: space-between; font-size: 14px; color: var(--dim); margin-bottom: 8px; }
.level .row b { color: var(--text); font-weight: 600; }
.bar { height: 12px; border-radius: 99px; background: var(--card-d); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--orange), var(--yellow)); transition: width .6s; }
.hero {
  border-radius: 24px; padding: 18px; position: relative; overflow: hidden;
  background: linear-gradient(135deg, #ff9a1a 0%, #ff5a3d 55%, #e83a7a 100%); box-shadow: 0 6px 0 #9c2a3a;
}
.hero h2 { font-size: 26px; font-weight: 700; text-shadow: 0 2px 0 rgba(120,30,0,.35); }
.hero p { color: #fff3e6; margin: 4px 0 14px; font-size: 15px; }
.hero .big-emoji { position: absolute; left: 14px; top: 8px; font-size: 54px; transform: rotate(-12deg); }
.exam { display: flex; align-items: center; gap: 10px; background: #3d1630; border: 2px solid #ff4f6a66; border-radius: 16px; padding: 10px 12px; font-size: 14px; text-align: start; }
.exam b { font-weight: 600; }
.sec-title { font-size: 15px; color: var(--dim); font-weight: 500; margin-top: 4px; }
.deck { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 18px; padding: 11px 12px; box-shadow: 0 4px 0 var(--card-d); text-align: start; width: 100%; }
.deck:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-d); }
.deck.collection { background: #3d2a12; box-shadow: 0 4px 0 #1f1406; }
.deck .ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; flex: none; }
.deck .info { flex: 1; min-width: 0; }
.deck .name { font-weight: 600; font-size: 16px; }
.deck .meta { font-size: 13px; color: var(--dim); }
.deck .bar { height: 7px; margin-top: 6px; }
.deck .bar > i { background: var(--green); }
.stars { font-size: 14px; white-space: nowrap; }
.stars .off { filter: grayscale(1) brightness(.45); }
.badge { background: var(--yellow); color: #3a2600; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 8px; margin-inline-start: 6px; vertical-align: 2px; }
.empty { text-align: center; color: var(--dim); padding: 40px 10px; line-height: 1.6; }
.empty .big { font-size: 64px; }

/* ---------- sheet ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(8,5,25,.65); animation: fade .2s; }
.sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 21; max-width: 480px; margin: 0 auto;
  background: var(--bg2); border-radius: 30px 30px 0 0;
  padding: 12px 18px calc(var(--safe-bottom) + 22px);
  display: flex; flex-direction: column; gap: 12px; animation: up .25s cubic-bezier(.2,.9,.3,1.2);
  max-height: 90vh; overflow-y: auto;
}
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 4px; }
.sheet h3 { font-size: 22px; font-weight: 700; }
.sheet .sub { color: var(--dim); font-size: 14px; margin-top: -8px; }
.mode { display: flex; align-items: center; gap: 12px; border-radius: 20px; padding: 14px; color: #fff; text-align: start; width: 100%; }
.mode:active { transform: translateY(4px); box-shadow: none !important; }
.mode .ico { width: 50px; height: 50px; border-radius: 16px; background: rgba(255,255,255,.2); display: grid; place-items: center; font-size: 26px; flex: none; }
.mode b { font-size: 18px; font-weight: 600; display: block; }
.mode span { font-size: 13px; opacity: .9; }
.mode .mastery { margin-inline-start: auto; text-align: center; font-size: 12px; flex: none; }
.mode .mastery strong { display: block; font-size: 18px; }
.mode.meaning { background: var(--purple); box-shadow: 0 5px 0 var(--purple-d); }
.mode.spell { background: var(--cyan); box-shadow: 0 5px 0 var(--cyan-d); color: #04263a; }
.mode.exam { background: var(--red); box-shadow: 0 5px 0 var(--red-d); }
.wordchips { display: flex; flex-wrap: wrap; gap: 6px; direction: ltr; }
.wordchips span { background: var(--card); padding: 4px 10px; border-radius: 10px; font-size: 13px; }
.wordchips span.g { background: #1f5a3c; }
.wordchips span.y { background: #5a4a1a; }

/* ---------- play ---------- */
.playtop { display: flex; align-items: center; gap: 10px; }
.quit { font-size: 22px; color: var(--dim); width: 32px; height: 32px; }
.prog { flex: 1; height: 16px; border-radius: 99px; background: var(--card-d); overflow: hidden; }
.prog > i { display: block; height: 100%; background: var(--green); border-radius: 99px; box-shadow: inset 0 -4px 0 rgba(0,0,0,.15); transition: width .3s; }
.prog.spell > i { background: var(--cyan); }
.prog.exam > i { background: var(--red); }
.combo { color: var(--orange); font-weight: 700; font-size: 15px; min-width: 40px; text-align: center; }
.prompt { color: var(--dim); font-size: 16px; text-align: center; }
.wordcard {
  background: var(--card); border-radius: 26px; padding: 22px 16px; text-align: center;
  box-shadow: 0 6px 0 var(--card-d); position: relative; animation: pop .25s;
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.wordcard .w { font-family: var(--display); font-size: 48px; font-weight: 400; letter-spacing: .5px; color: var(--yellow); text-shadow: 0 3px 0 #8a3a00; word-break: break-word; }
.wordcard .note { color: var(--dim); font-size: 14px; margin-top: 4px; }
.speak { position: absolute; top: 12px; left: 12px; width: 42px; height: 42px; border-radius: 12px; background: var(--cyan); display: grid; place-items: center; font-size: 19px; box-shadow: 0 3px 0 var(--cyan-d); }
.listen { display: flex; align-items: center; justify-content: center; gap: 22px; padding: 6px 0; animation: pop .25s; }
.bigspeak { width: 100px; height: 100px; border-radius: 32px; background: var(--cyan); box-shadow: 0 7px 0 var(--cyan-d); display: grid; place-items: center; font-size: 46px; }
.bigspeak:active { transform: translateY(5px); box-shadow: 0 3px 0 var(--cyan-d); }
.bigspeak.talking { animation: pulse .6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.slow { width: 64px; height: 64px; border-radius: 22px; background: var(--card); box-shadow: 0 5px 0 var(--card-d); font-size: 30px; display: grid; place-items: center; }
.field {
  width: 100%; border-radius: 18px; background: #12091f; border: 3px solid var(--line); padding: 13px 16px;
  font-size: 24px; font-weight: 500; font-family: inherit; color: var(--text); outline: none; text-align: center;
}
.field:focus { border-color: var(--orange); }
.field.ok { border-color: var(--green); }
.field.bad { border-color: var(--red); }
.field::placeholder { color: #6e5590; font-size: 18px; }
.hintrow { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.hintrow .pill { font-size: 13px; padding: 7px 12px; }
.hinttext { text-align: center; color: var(--yellow); font-size: 16px; min-height: 1px; }
.blanks { display: flex; gap: 5px; justify-content: center; direction: ltr; flex-wrap: wrap; }
.blanks i { width: 22px; border-bottom: 3px solid var(--line); font-style: normal; text-align: center; font-size: 20px; font-weight: 600; height: 28px; }
.blanks i.sp { border: 0; }

.feedback { border-radius: 22px; padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; animation: pop .2s; }
.feedback.good { background: #123d2a; }
.feedback.bad { background: #4a1430; }
.fb-head { display: flex; align-items: center; gap: 10px; font-size: 21px; font-weight: 700; line-height: 1.2; }
.fb-head .xp { white-space: nowrap; }
.fb-head .ic { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; flex: none; }
.fb-head .xp { margin-inline-start: auto; color: var(--yellow); font-size: 19px; }
.good .fb-head { color: var(--green); } .good .ic { background: var(--green); color: #0d3b22; }
.bad .fb-head { color: var(--red); } .bad .ic { background: var(--red); color: #44142a; }
.fb-text { font-size: 15px; color: #dfffe9; line-height: 1.45; }
.bad .fb-text { color: #ffd9df; }
.fb-actions { display: flex; gap: 8px; }
.fb-actions .btn { flex: 1; }
.override { color: #ffb3c0; font-size: 13px; text-decoration: underline; align-self: center; }
.diff { display: flex; gap: 4px; justify-content: center; direction: ltr; flex-wrap: wrap; }
.diff span { min-width: 28px; height: 38px; padding: 0 4px; border-radius: 10px; display: grid; place-items: center; font-size: 21px; font-weight: 700; }
.diff .ok { background: #1f5a3c; color: #bdfdd3; }
.diff .wrong, .diff .missing { background: var(--red); color: #fff; }
.diff .extra { color: var(--red); text-decoration: line-through; min-width: 14px; font-size: 17px; }
.diff .space { min-width: 12px; background: none; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.xp-fly { position: fixed; z-index: 30; left: 50%; top: 40%; transform: translateX(-50%); font-weight: 700; font-size: 34px; color: var(--yellow); text-shadow: 0 3px 0 #7a4b00; pointer-events: none; animation: fly .9s forwards; }
@keyframes fly { from { opacity: 1; transform: translate(-50%, 0) scale(.8); } 30% { transform: translate(-50%, -20px) scale(1.15); } to { opacity: 0; transform: translate(-50%, -90px) scale(1); } }

/* ---------- results ---------- */
.res-head { text-align: center; margin-top: 12px; }
.res-head .trophy { font-size: 80px; line-height: 1; animation: bob 1.4s ease-in-out infinite; }
.res-head h2 { font-size: 30px; font-weight: 700; color: var(--yellow); text-shadow: 0 3px 0 #8a3a00; margin-top: 6px; }
.res-head p { color: var(--dim); }
.res-stars { font-size: 46px; text-align: center; letter-spacing: 4px; }
.res-stars span { display: inline-block; animation: starpop .4s backwards; }
.res-stars span:nth-child(2) { animation-delay: .2s; } .res-stars span:nth-child(3) { animation-delay: .4s; }
.res-stars .off { filter: grayscale(1) brightness(.4); }
@keyframes starpop { from { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.3); } }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { border-radius: 16px; padding: 10px 6px; text-align: center; border: 3px solid; }
.stat small { display: block; font-size: 12px; font-weight: 600; }
.stat b { font-size: 24px; font-family: var(--display); font-weight: 400; }
.stat.y { border-color: var(--yellow); color: var(--yellow); }
.stat.g { border-color: var(--green); color: var(--green); }
.stat.o { border-color: var(--orange); color: var(--orange); }
.review-list { background: var(--card); border-radius: 18px; padding: 12px 14px; }
.review-list h4 { font-size: 14px; color: var(--dim); font-weight: 500; margin-bottom: 6px; }
.rv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 16px; }
.rv:first-of-type { border-top: 0; }
.rv .yours { color: #ff9aaa; font-size: 13px; text-decoration: line-through; }
.spacer { flex: 1; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 9px; height: 15px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
.toast { position: fixed; bottom: calc(var(--safe-bottom) + 18px); left: 50%; transform: translateX(-50%); background: var(--card); padding: 10px 16px; border-radius: 14px; font-size: 14px; z-index: 60; }

/* ---------- install guide ---------- */
.install { background: #12091f; border: 2px dashed var(--yellow); border-radius: 18px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; }
.install b { font-weight: 600; }
.install > b:first-child { color: var(--yellow); font-size: 17px; }
.install ol { padding-inline-start: 20px; display: flex; flex-direction: column; gap: 5px; line-height: 1.4; color: #f0e6ff; }
.install-later { align-self: flex-start; color: var(--dim); font-size: 13px; text-decoration: underline; }

/* ---------- next quiz ---------- */
.exam-card { width: 100%; text-align: start; background: #3a1a3a; border: 2px solid #ff4f6a88; border-radius: 20px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 4px 0 #1f0b20; }
.exam-card:active { transform: translateY(3px); box-shadow: 0 1px 0 #1f0b20; }
.exam-card.urgent { border-color: var(--red); background: #4a1430; }
.exam-top { display: flex; justify-content: space-between; align-items: center; }
.exam-label { font-size: 13px; font-weight: 600; color: #ff9aaa; }
.exam-when { font-size: 13px; font-weight: 700; color: #1a0f2e; background: var(--yellow); border-radius: 99px; padding: 2px 10px; }
.exam-card.urgent .exam-when { background: var(--red); color: #fff; }
.exam-name { font-size: 20px; font-weight: 700; }
.exam-meta { font-size: 13px; color: var(--dim); }
.exam-card .bar { height: 8px; margin-top: 4px; }

/* ---------- stages ---------- */
.path { display: flex; flex-direction: column; gap: 10px; }
.mode.learn { background: var(--yellow); box-shadow: 0 5px 0 var(--yellow-d); color: #3a2600; }
.mode .ico { position: relative; }
.mode .num { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%; background: #1a0f2e; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; border: 2px solid rgba(255,255,255,.7); }
.mode .num.done { background: var(--green); color: #0d3b22; border-color: #fff; }
.mode.next { outline: 3px solid #fff; outline-offset: 3px; }
.next-tag { display: inline-block; font-style: normal; font-size: 11px; font-weight: 700; background: #fff; color: #1a0f2e; border-radius: 8px; padding: 1px 7px; margin-bottom: 3px; }
.prog.learn > i { background: var(--yellow); }

/* ---------- learn: flash card ---------- */
.flash { perspective: 1000px; width: 100%; height: 230px; animation: pop .25s; }
.flash-inner { position: relative; width: 100%; height: 100%; transition: transform .5s cubic-bezier(.3,1.3,.5,1); transform-style: preserve-3d; }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; border-radius: 26px; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 18px; }
.face.front { background: var(--card); box-shadow: 0 6px 0 var(--card-d); }
.face.back { background: linear-gradient(135deg, #ff9a1a, #e83a7a); box-shadow: 0 6px 0 #9c2a3a; transform: rotateY(180deg); }
.face .w { font-family: var(--display); font-size: 48px; color: var(--yellow); text-shadow: 0 3px 0 #8a3a00; word-break: break-word; text-align: center; }
.face .tap { color: var(--dim); font-size: 14px; }
.face .w-small { font-family: var(--display); font-size: 24px; color: #fff3e6; }
.face .he { font-size: 34px; font-weight: 700; text-align: center; line-height: 1.25; }
.face .note { font-size: 15px; color: #fff3e6; }
.say-again { align-self: center; }
.path .mode { padding: 10px 12px; }
.path .mode .ico { width: 44px; height: 44px; font-size: 22px; border-radius: 14px; }
.path .mode b { font-size: 17px; }
.path .mode span { font-size: 12.5px; }
