:root {
  --bg: #f4f2fb;
  --card: #ffffff;
  --ink: #1d1b2e;
  --muted: #6b6880;
  --line: #e6e3f2;
  --primary: #6c4cf5;
  --primary-2: #8b6dff;
  --primary-soft: #ece7ff;
  --good: #1fb57a;
  --good-soft: #dcf7ea;
  --bad: #ef4d5f;
  --bad-soft: #fde3e6;
  --fire: #ff8a1f;
  --gold: #f5b400;
  --shadow: 0 6px 20px rgba(60, 40, 140, .08);
  --radius: 20px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131220;
    --card: #1e1c30;
    --ink: #f1effa;
    --muted: #a29fb8;
    --line: #302d48;
    --primary: #8b6dff;
    --primary-2: #a48cff;
    --primary-soft: #2c2650;
    --good-soft: #143a2c;
    --bad-soft: #43202a;
    --shadow: 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Heebo", "Arial Hebrew", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.en { direction: ltr; unicode-bidi: isolate; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}
body.ingame #app { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* ---------- nav ---------- */
#nav {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#nav button {
  flex: 1; max-width: 130px; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--muted); font-weight: 600;
}
#nav button span { font-size: 22px; filter: grayscale(1); opacity: .6; transition: .2s; }
#nav button.on { color: var(--primary); }
#nav button.on span { filter: none; opacity: 1; transform: scale(1.1); }

/* ---------- generic ---------- */
h1 { font-size: 26px; margin: 4px 0 16px; }
h2 { font-size: 19px; margin: 24px 0 12px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack > * + * { margin-top: 12px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 54px; padding: 12px 18px;
  border-radius: 16px; font-weight: 700; font-size: 17px;
  background: var(--primary); color: #fff;
  box-shadow: 0 4px 0 #4f33c9;
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #4f33c9; }
.btn.ghost { background: var(--card); color: var(--primary); box-shadow: 0 3px 0 var(--line); border: 2px solid var(--line); }
.btn.good { background: var(--good); box-shadow: 0 4px 0 #148a5b; }
.btn.bad { background: var(--bad); box-shadow: 0 4px 0 #c22f40; }
.btn:disabled { opacity: .45; pointer-events: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; background: var(--card);
  box-shadow: var(--shadow); font-weight: 700; font-size: 15px;
}

.bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary-2), var(--primary)); transition: width .4s; }
[dir=rtl] .bar > i { background: linear-gradient(270deg, var(--primary-2), var(--primary)); }

#toast {
  position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 50; background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px;
  font-weight: 700; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
  animation: drop .3s ease-out;
}
@keyframes drop { from { transform: translate(-50%, -20px); opacity: 0; } }
@keyframes pop { 0% { transform: scale(.85); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.pop { animation: pop .35s ease-out; }
.shake { animation: shake .35s; }

/* ---------- login ---------- */
.login { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; }
.logo { width: 84px; height: 84px; border-radius: 24px; margin: 0 auto 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; font-size: 38px; font-weight: 800; box-shadow: var(--shadow); }
.login h1 { text-align: center; margin-bottom: 4px; }
.tabs2 { display: flex; background: var(--line); border-radius: 14px; padding: 4px; margin: 20px 0 14px; }
.tabs2 button { flex: 1; padding: 10px; border-radius: 11px; font-weight: 700; color: var(--muted); }
.tabs2 button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field input, .search {
  width: 100%; height: 52px; padding: 0 14px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--card); outline: none;
}
.field input:focus, .search:focus { border-color: var(--primary); }
.err { color: var(--bad); font-weight: 600; min-height: 22px; margin: 4px 0 8px; }

/* ---------- home ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.topbar .chips { display: flex; gap: 8px; }
.hello { font-size: 22px; font-weight: 800; }
.goal { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 96px; height: 96px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; }
.goal h3 { margin: 0 0 4px; font-size: 18px; }
.cta {
  width: 100%; margin-top: 16px; padding: 20px; border-radius: 22px; text-align: right;
  background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff;
  box-shadow: 0 6px 0 #4f33c9; display: flex; align-items: center; gap: 14px;
}
.cta:active { transform: translateY(4px); box-shadow: 0 2px 0 #4f33c9; }
.cta .play { width: 56px; height: 56px; border-radius: 50%; background: rgba(255,255,255,.22); display: grid; place-items: center; font-size: 24px; flex: none; }
.cta strong { font-size: 21px; display: block; }
.cta small { opacity: .9; font-size: 14px; }
.cta.done { background: linear-gradient(135deg, #2fd08f, var(--good)); box-shadow: 0 6px 0 #148a5b; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.stat { background: var(--card); border-radius: 18px; padding: 14px 8px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.level { margin-top: 16px; }
.level .spread { margin-bottom: 8px; }

/* ---------- games list ---------- */
.games { display: grid; gap: 12px; }
.game {
  display: flex; align-items: center; gap: 14px; text-align: right; width: 100%;
  background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.game:active { transform: scale(.98); }
.game .ic { width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center; font-size: 30px; flex: none; }
.game h3 { margin: 0; font-size: 18px; }
.game p { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.game .best { font-size: 12px; font-weight: 700; color: var(--primary); margin-top: 4px; }

/* ---------- words ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.filters button { white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--card); font-weight: 600; font-size: 14px; box-shadow: var(--shadow); }
.filters button.on { background: var(--primary); color: #fff; }
.topic { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); margin-top: 10px; overflow: hidden; }
.topic > button { width: 100%; padding: 14px 16px; display: flex; align-items: center; gap: 12px; text-align: right; }
.topic .em { font-size: 26px; }
.topic .grow { flex: 1; }
.topic .bar { height: 6px; margin-top: 6px; }
.wlist { border-top: 1px solid var(--line); }
.witem { display: flex; align-items: center; gap: 10px; padding: 11px 16px; width: 100%; text-align: right; border-bottom: 1px solid var(--line); }
.witem:last-child { border-bottom: 0; }
.witem .en { font-weight: 700; min-width: 0; }
.witem .he { color: var(--muted); flex: 1; text-align: left; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--line); }
.dot.s1, .dot.s2 { background: var(--fire); }
.dot.s3, .dot.s4 { background: var(--primary); }
.dot.s5 { background: var(--good); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(15, 10, 40, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--card); width: 100%; max-width: 520px; border-radius: 26px 26px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); } }

/* ---------- word display ---------- */
.big-em { font-size: 64px; text-align: center; line-height: 1.1; }
.big-word { font-size: 38px; font-weight: 800; text-align: center; margin: 6px 0 2px; word-break: break-word; }
.pron { text-align: center; color: var(--muted); font-size: 15px; }
.pos { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 700; }
.he-big { font-size: 28px; font-weight: 800; text-align: center; margin: 10px 0; }
.example { background: var(--bg); border-radius: 14px; padding: 12px 14px; margin-top: 12px; }
.example .en { font-weight: 600; display: block; text-align: left; }
.example .tr { color: var(--muted); font-size: 14px; display: block; margin-top: 2px; }
.speak { width: 54px; height: 54px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 24px; display: inline-grid; place-items: center; flex: none; }
.speak:active { transform: scale(.92); }
.center { text-align: center; }

/* ---------- game screen ---------- */
.ghead { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.ghead .x { width: 40px; height: 40px; border-radius: 12px; font-size: 22px; color: var(--muted); flex: none; }
.ghead .bar { flex: 1; height: 14px; }
.ghead .score { font-weight: 800; min-width: 44px; text-align: left; }
.stage-title { text-align: center; font-weight: 800; color: var(--primary); font-size: 14px; letter-spacing: .3px; margin-bottom: 6px; }
.qcard { background: var(--card); border-radius: 24px; box-shadow: var(--shadow); padding: 26px 18px; text-align: center; margin-bottom: 18px; }
.qcard .prompt { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.qword { font-size: 34px; font-weight: 800; }
.opts { display: grid; gap: 10px; }
.opt {
  width: 100%; min-height: 58px; padding: 12px 16px; border-radius: 16px; background: var(--card);
  border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line); font-size: 19px; font-weight: 700;
}
.opt:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.opt.right { background: var(--good-soft); border-color: var(--good); box-shadow: 0 3px 0 var(--good); }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); box-shadow: 0 3px 0 var(--bad); }
.locked .opt { pointer-events: none; }

.feedback {
  position: fixed; inset: auto 0 0 0; z-index: 30; padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  border-radius: 24px 24px 0 0; animation: up .25s ease-out;
}
.feedback .in { max-width: 520px; margin: 0 auto; }
.feedback.ok { background: var(--good-soft); }
.feedback.no { background: var(--bad-soft); }
.feedback h3 { margin: 0 0 6px; font-size: 20px; }
.feedback.ok h3 { color: var(--good); }
.feedback.no h3 { color: var(--bad); }
.feedback .ans { font-size: 18px; font-weight: 700; margin-bottom: 12px; }

.listen-btn { width: 120px; height: 120px; border-radius: 50%; font-size: 52px; background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; box-shadow: 0 6px 0 #4f33c9; }
.listen-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #4f33c9; }
.slow { margin-top: 12px; font-weight: 700; color: var(--primary); }

.spell-input { width: 100%; height: 60px; border-radius: 16px; border: 2px solid var(--line); background: var(--card); font-size: 24px; text-align: center; font-weight: 700; outline: none; }
.spell-input:focus { border-color: var(--primary); }
.hintline { margin: 10px 0 14px; display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; direction: ltr; }
.hintline i { font-style: normal; width: 22px; border-bottom: 3px solid var(--line); text-align: center; font-weight: 800; font-size: 18px; }
.hintline i.sp { border-color: transparent; }

/* flashcard */
.flip { perspective: 1200px; height: 340px; margin-bottom: 18px; cursor: pointer; }
.flip .inner { position: relative; width: 100%; height: 100%; transition: transform .5s; transform-style: preserve-3d; }
.flip.on .inner { transform: rotateY(180deg); }
.flip .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: var(--card); border-radius: 24px; box-shadow: var(--shadow); padding: 22px; display: flex; flex-direction: column; justify-content: center; }
.flip .back { transform: rotateY(180deg); }
.tap-hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* memory */
.mem-info { display: flex; justify-content: space-around; margin-bottom: 14px; font-weight: 700; }
.mem { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mem.c4 { grid-template-columns: repeat(4, 1fr); }
.mcard { perspective: 800px; aspect-ratio: 3 / 3.6; }
.mcard .inner { position: relative; width: 100%; height: 100%; transition: transform .4s; transform-style: preserve-3d; }
.mcard.open .inner, .mcard.done .inner { transform: rotateY(180deg); }
.mcard .face { position: absolute; inset: 0; border-radius: 16px; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: grid; place-items: center; padding: 6px; text-align: center; font-weight: 800; word-break: break-word; }
.mcard .front { background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; font-size: 28px; box-shadow: 0 4px 0 #4f33c9; }
.mcard .back { transform: rotateY(180deg); background: var(--card); border: 2px solid var(--line); font-size: 16px; line-height: 1.2; }
.mcard .back.isen { color: var(--primary); }
.mcard.done .back { background: var(--good-soft); border-color: var(--good); }
.mcard.miss .back { background: var(--bad-soft); border-color: var(--bad); }

/* quick round */
.timer { height: 14px; flex: 1; border-radius: 999px; background: var(--line); overflow: hidden; }
.timer i { display: block; height: 100%; background: var(--fire); border-radius: inherit; }
.combo { text-align: center; font-weight: 800; color: var(--fire); min-height: 24px; margin-bottom: 6px; }
.flash-ok { animation: okflash .5s; }
.flash-no { animation: noflash .5s; }
@keyframes okflash { 30% { background: var(--good-soft); } }
@keyframes noflash { 30% { background: var(--bad-soft); } }

/* summary */
.summary { text-align: center; padding-top: 30px; }
.summary .trophy { font-size: 80px; animation: pop .6s; }
.summary .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 22px 0; }

/* profile */
.set { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.set:last-child { border-bottom: 0; }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; }
.seg button { padding: 7px 12px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.switch { width: 52px; height: 32px; border-radius: 999px; background: var(--line); position: relative; transition: .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; right: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on { background: var(--good); }
.switch.on::after { right: 23px; }
input[type=range] { width: 140px; accent-color: var(--primary); }
.empty { text-align: center; padding: 30px 10px; }
.empty .e { font-size: 54px; }
