:root {
  --bg: #0b0d1f;
  --bg2: #12153a;
  --text: #eef0ff;
  --muted: #a6abd6;
  --glass: rgba(255, 255, 255, .06);
  --border: rgba(255, 255, 255, .12);
  --primary: #7c5cff;
  --pink: #ff5ca8;
  --cyan: #2fd6ff;
  --ok: #34d399;
  --bad: #f87171;
  --radius: 20px;
  --grad: linear-gradient(120deg, var(--cyan), var(--primary) 45%, var(--pink));
  --A1: #34d399; --A2: #22c55e; --B1: #38bdf8; --B2: #6366f1; --C1: #c084fc; --C2: #f472b6;
}

* { box-sizing: border-box; }
html { background: #0b0d1f; scroll-behavior: smooth; scroll-padding-top: 72px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overflow-x: clip; }
button, a { -webkit-tap-highlight-color: transparent; }
img, canvas { max-width: 100%; }
h1, h2, h3, p { overflow-wrap: break-word; }
body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(1200px 800px at 10% -10%, var(--bg2), var(--bg));
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: clip;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { line-height: 1.15; margin: 0; }

/* Animated background */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.blob { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .45; animation: float 18s ease-in-out infinite; }
.b1 { width: 480px; height: 480px; background: var(--primary); top: -120px; left: -80px; }
.b2 { width: 420px; height: 420px; background: var(--pink); top: 30%; right: -120px; animation-delay: -6s; }
.b3 { width: 380px; height: 380px; background: var(--cyan); bottom: -140px; left: 30%; animation-delay: -12s; opacity: .3; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(60px, 40px) scale(1.1); }
  66% { transform: translate(-40px, 60px) scale(.95); }
}

.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.glass { background: var(--glass); border: 1px solid var(--border); border-radius: var(--radius); backdrop-filter: blur(14px); }

/* Nav */
.nav {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem clamp(1rem, 4vw, 3rem);
  background: rgba(11, 13, 31, .6); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-size: 1.25rem; font-weight: 600; }
.brand b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--grad); font-weight: 800; color: #fff; }
.nav nav { display: flex; gap: 1.5rem; }
.nav nav a { color: var(--muted); font-size: .95rem; transition: color .2s; }
.nav nav a:hover { color: var(--text); }
.nav-right { display: flex; align-items: center; gap: .8rem; }
.streak { background: var(--glass); border: 1px solid var(--border); border-radius: 999px; padding: .25rem .7rem; font-size: .9rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
  border: 1px solid var(--border); border-radius: 999px; padding: .8rem 1.4rem;
  font: inherit; font-weight: 600; color: var(--text); background: var(--glass);
  transition: transform .15s, box-shadow .2s, background .2s;
}
.btn:hover { transform: translateY(-2px); }
.btn.primary { background: var(--grad); border: none; box-shadow: 0 10px 30px -10px var(--primary); }
.btn.primary:hover { box-shadow: 0 14px 40px -8px var(--pink); }
.btn.ghost:hover { background: rgba(255, 255, 255, .12); }
.btn.small { padding: .4rem .9rem; font-size: .85rem; }
.btn.icon { padding: .6rem 1rem; font-size: .9rem; }

/* Hero */
.hero {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 3rem; align-items: center;
  max-width: 1200px; margin: 0 auto; padding: clamp(3rem, 8vw, 6rem) clamp(1rem, 4vw, 3rem) 3rem;
}
.pill { display: inline-block; padding: .35rem .9rem; border-radius: 999px; background: var(--glass); border: 1px solid var(--border); color: var(--muted); font-size: .9rem; margin-bottom: 1.2rem; }
.hero h1 { font-size: clamp(2.4rem, 5.5vw, 4.2rem); font-weight: 800; letter-spacing: -.02em; }
#rotator { display: inline-block; transition: opacity .35s, transform .35s; }
#rotator.out { opacity: 0; transform: translateY(12px); }
.lead { color: var(--muted); font-size: 1.15rem; max-width: 34rem; margin: 1.2rem 0 2rem; }
.cta { display: flex; gap: 1rem; flex-wrap: wrap; }
.stats { display: flex; gap: 2.2rem; margin-top: 2.8rem; flex-wrap: wrap; }
.stats b { display: block; font-size: 1.9rem; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stats span { color: var(--muted); font-size: .85rem; }

/* Flashcard */
.hero-card { perspective: 1200px; }
.flip {
  position: relative; height: 320px; cursor: pointer; outline: none;
  transform-style: preserve-3d; transition: transform .7s cubic-bezier(.2, .8, .2, 1);
}
.flip.flipped { transform: rotateY(180deg); }
.flip:focus-visible .face { box-shadow: 0 0 0 3px var(--cyan); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden;
  display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: .6rem;
  padding: 2rem; border-radius: 28px; border: 1px solid var(--border);
  background: linear-gradient(160deg, rgba(124, 92, 255, .25), rgba(255, 92, 168, .12)), var(--glass);
  backdrop-filter: blur(18px); box-shadow: 0 30px 80px -30px rgba(124, 92, 255, .6);
}
.face.back { transform: rotateY(180deg); background: linear-gradient(160deg, rgba(47, 214, 255, .2), rgba(124, 92, 255, .18)), var(--glass); }
.face h2 { font-size: clamp(2.2rem, 4vw, 3.2rem); font-weight: 800; }
.ipa { color: var(--muted); font-size: 1.2rem; margin: 0; font-family: "Lucida Sans Unicode", "Segoe UI", sans-serif; }
.def { font-size: 1.25rem; margin: 0; }
.example { color: var(--muted); font-style: italic; margin: 0; }
.hint { color: var(--muted); font-size: .85rem; margin: .5rem 0 0; opacity: .8; }
.tag { font-size: .75rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.badge { display: inline-block; padding: .2rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: rgba(255, 255, 255, .1); border: 1px solid var(--border); }
.badge.level { color: #0b0d1f; border: none; }
.card-actions { display: flex; justify-content: center; gap: .8rem; margin-top: 1.2rem; }

/* Skills strip */
.skills { display: flex; flex-wrap: wrap; justify-content: center; gap: .8rem; max-width: 1200px; margin: 0 auto; padding: 1rem; }
.skill { display: flex; align-items: center; gap: .5rem; padding: .55rem 1.1rem; border-radius: 999px; background: var(--glass); border: 1px solid var(--border); color: var(--muted); }
.skill span { font-size: 1.2rem; }

/* Sections */
.section { max-width: 1200px; margin: 0 auto; padding: 4rem clamp(1rem, 4vw, 3rem) 1rem; }
.section-head { margin-bottom: 2rem; }
.section-head.row { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.section-head h2 { font-size: clamp(1.8rem, 3.5vw, 2.5rem); }
.section-head p { color: var(--muted); margin: .4rem 0 0; }

/* Levels */
.levels { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1rem; }
.level-card {
  position: relative; padding: 1.4rem 1.1rem; border-radius: var(--radius); cursor: pointer; text-align: left;
  background: var(--glass); border: 1px solid var(--border); color: var(--text); font: inherit;
  transition: transform .2s, border-color .2s, box-shadow .2s; overflow: hidden;
}
.level-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: var(--c); }
.level-card:hover { transform: translateY(-4px); box-shadow: 0 20px 40px -20px var(--c); }
.level-card.active { border-color: var(--c); box-shadow: 0 0 0 1px var(--c), 0 20px 40px -20px var(--c); }
.level-card b { font-size: 1.8rem; color: var(--c); display: block; }
.level-card h3 { font-size: 1rem; margin: .2rem 0 .4rem; }
.level-card p { color: var(--muted); font-size: .82rem; margin: 0; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { padding: .4rem .9rem; border-radius: 999px; border: 1px solid var(--border); background: var(--glass); color: var(--muted); cursor: pointer; font: inherit; font-size: .88rem; transition: all .2s; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--grad); color: #fff; border-color: transparent; }

/* Lessons */
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(270px, 100%), 1fr)); gap: 1.2rem; }
.lesson {
  display: flex; flex-direction: column; gap: .7rem; padding: 1.5rem; cursor: pointer;
  border-radius: var(--radius); background: var(--glass); border: 1px solid var(--border);
  transition: transform .2s, box-shadow .2s, border-color .2s; animation: rise .5s both;
}
.lesson:hover { transform: translateY(-5px); border-color: rgba(255, 255, 255, .25); box-shadow: 0 25px 50px -25px var(--primary); }
.lesson .top { display: flex; justify-content: space-between; align-items: center; }
.lesson .emoji { font-size: 1.8rem; }
.lesson h3 { font-size: 1.15rem; }
.lesson p { color: var(--muted); margin: 0; font-size: .92rem; flex: 1; }
.lesson .go { color: var(--cyan); font-weight: 600; font-size: .9rem; }
.empty { color: var(--muted); grid-column: 1 / -1; text-align: center; padding: 2rem; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }

/* Quiz */
.quiz { padding: 2rem; max-width: 760px; margin: 0 auto; }
.quiz-top { display: flex; justify-content: space-between; }
.quiz-def { font-size: 1.4rem; margin: 1rem 0 1.5rem; min-height: 4rem; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.option {
  padding: 1rem; border-radius: 14px; border: 1px solid var(--border); background: rgba(255, 255, 255, .04);
  color: var(--text); font: inherit; font-size: 1.05rem; font-weight: 600; cursor: pointer; transition: all .2s;
}
.option:hover:not(:disabled) { background: rgba(124, 92, 255, .2); border-color: var(--primary); }
.option.correct { background: rgba(52, 211, 153, .2); border-color: var(--ok); }
.option.wrong { background: rgba(248, 113, 113, .2); border-color: var(--bad); animation: shake .4s; }
.option:disabled { cursor: default; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.quiz-bottom { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 1.4rem; min-height: 3rem; }
.feedback { margin: 0; font-weight: 600; }

/* Dictionary */
.search { display: flex; align-items: center; gap: .8rem; padding: .4rem 1.2rem; max-width: 640px; margin: 0 auto 2rem; }
.search input { flex: 1; background: none; border: none; outline: none; color: var(--text); font: inherit; font-size: 1.1rem; padding: .8rem 0; }
.words { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 1rem; }
.word { padding: 1.3rem; border-radius: var(--radius); background: var(--glass); border: 1px solid var(--border); animation: rise .4s both; }
.word .head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.word h3 { font-size: 1.2rem; }
.word .ipa { font-size: .95rem; }
.word p { margin: .4rem 0 0; font-size: .92rem; }
.word .example { font-size: .88rem; }
.speak { background: none; border: none; cursor: pointer; font-size: 1.1rem; padding: .2rem; border-radius: 8px; }
.speak:hover { background: rgba(255, 255, 255, .1); }

/* Modal */
dialog {
  width: min(720px, 92vw); max-height: 86vh; padding: 0; border: 1px solid var(--border); border-radius: 24px;
  background: #15183d; color: var(--text); box-shadow: 0 40px 120px -20px rgba(0, 0, 0, .8);
}
dialog::backdrop { background: rgba(5, 6, 20, .7); backdrop-filter: blur(6px); }
dialog[open] { animation: pop .3s cubic-bezier(.2, .8, .2, 1); }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(10px); } }
dialog article { position: relative; padding: 2.2rem; }
.close { position: absolute; top: 1rem; right: 1rem; background: var(--glass); border: 1px solid var(--border); color: var(--text); border-radius: 50%; width: 36px; height: 36px; cursor: pointer; }
.modal-meta { display: flex; gap: .5rem; margin: .8rem 0 1.4rem; }
.modal-content { background: rgba(255, 255, 255, .04); border-left: 3px solid var(--primary); padding: 1rem 1.3rem; border-radius: 0 14px 14px 0; }
.modal-content p { margin: .5rem 0; }
dialog h4 { margin: 1.8rem 0 .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-size: .8rem; }
dialog .words { grid-template-columns: 1fr 1fr; }

/* Footer & toast */
.footer { text-align: center; color: var(--muted); padding: 4rem 1rem 2rem; font-size: .9rem; }
.footer a { color: var(--cyan); }
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translate(-50%, 150%);
  background: #1d2150; border: 1px solid var(--border); padding: .8rem 1.4rem; border-radius: 999px;
  transition: transform .35s cubic-bezier(.2, .8, .2, 1), visibility .35s; z-index: 50; visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }

/* Hamburger button (hidden on desktop) */
.menu-btn {
  display: none; width: 44px; height: 44px; padding: 11px 10px; border-radius: 12px; cursor: pointer;
  background: var(--glass); border: 1px solid var(--border); flex-direction: column; justify-content: space-between;
}
.menu-btn span { display: block; height: 2px; border-radius: 2px; background: var(--text); transition: transform .25s, opacity .2s; }
.nav.open .menu-btn span:nth-child(1) { transform: translateY(9px) rotate(45deg); }
.nav.open .menu-btn span:nth-child(2) { opacity: 0; }
.nav.open .menu-btn span:nth-child(3) { transform: translateY(-9px) rotate(-45deg); }
.only-sm { display: none; }

/* Responsive: tablets */
@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; gap: 2.5rem; }
  .hero-card { max-width: 480px; width: 100%; margin: 0 auto; }
  .levels { grid-template-columns: repeat(3, 1fr); }

  .menu-btn { display: flex; }
  .nav nav {
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; gap: 0; padding: .5rem clamp(1rem, 4vw, 3rem) 1rem;
    background: rgba(11, 13, 31, .97); backdrop-filter: blur(16px); border-bottom: 1px solid var(--border);
    transform: translateY(-8px); opacity: 0; visibility: hidden; transition: opacity .2s, transform .2s, visibility .2s;
  }
  .nav.open nav { transform: none; opacity: 1; visibility: visible; }
  .nav nav a { padding: .9rem .2rem; font-size: 1.05rem; border-bottom: 1px solid var(--border); }
  .nav nav a:last-child { border-bottom: none; }
  .only-sm { display: block; }
}

/* Responsive: phones */
@media (max-width: 600px) {
  :root { --radius: 16px; }
  .hide-sm { display: none !important; }
  .nav { padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top)); }
  .brand { font-size: 1.1rem; }

  .hero { padding: 2rem 1rem 1.5rem; gap: 2rem; }
  .pill { font-size: .8rem; }
  .lead { font-size: 1.02rem; margin: 1rem 0 1.5rem; }
  .cta { flex-direction: column; }
  .cta .btn { justify-content: center; width: 100%; }
  .stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin-top: 2rem; }
  .stats > div { background: var(--glass); border: 1px solid var(--border); border-radius: 14px; padding: .7rem .9rem; }
  .stats b { font-size: 1.5rem; }

  .flip { height: 280px; }
  .face { padding: 1.4rem; border-radius: 22px; }
  .def { font-size: 1.05rem; }
  .card-actions .btn { flex: 1; justify-content: center; }

  .skills { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; padding: .5rem 1rem; }
  .skills::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
  .skill { flex: none; }

  .section { padding: 2.5rem 1rem .5rem; }
  .section-head { margin-bottom: 1.3rem; }
  .levels { grid-template-columns: repeat(2, 1fr); gap: .7rem; }
  .level-card { padding: 1rem .9rem; }
  .level-card b { font-size: 1.5rem; }

  /* Filter chips scroll sideways instead of stacking many lines */
  .section-head.row { flex-direction: column; align-items: stretch; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -1rem; padding: 0 1rem .3rem; }
  .chip { flex: none; }

  .lesson { padding: 1.2rem; }
  .quiz { padding: 1.2rem; }
  .quiz-def { font-size: 1.15rem; min-height: 3rem; }
  .options { grid-template-columns: 1fr; }
  .option { padding: .9rem; }
  .quiz-bottom { flex-direction: column; align-items: stretch; }
  .quiz-bottom .btn { justify-content: center; }

  .search { padding: .2rem 1rem; }
  .search input { font-size: 16px; } /* >=16px prevents iOS zoom on focus */

  /* Lesson dialog becomes a full-screen sheet */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; border: none; }
  dialog article { padding: 1.4rem 1rem calc(2rem + env(safe-area-inset-bottom)); }
  dialog .words { grid-template-columns: 1fr; }

  .toast { width: max-content; max-width: calc(100vw - 2rem); text-align: center; border-radius: 16px; bottom: calc(1rem + env(safe-area-inset-bottom)); }
  .footer { padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }
}

/* Touch devices: no sticky hover lifts, comfortable tap targets */
@media (hover: none) {
  .btn:hover, .lesson:hover, .level-card:hover, .feature:hover { transform: none; }
  .speak { min-width: 40px; min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Vocabulary feature banner */
.feature {
  display: flex; align-items: center; gap: 1.5rem; padding: 1.4rem 1.8rem; margin-bottom: 2rem;
  background: linear-gradient(120deg, rgba(47, 214, 255, .14), rgba(124, 92, 255, .18), rgba(255, 92, 168, .14));
  transition: transform .2s, box-shadow .2s;
}
.feature:hover { transform: translateY(-3px); box-shadow: 0 25px 60px -25px var(--primary); }
.feature-pics { font-size: 2.2rem; letter-spacing: .2rem; white-space: nowrap; }
.feature h3 { font-size: 1.4rem; margin: .2rem 0; }
.feature p { color: var(--muted); margin: 0; }
.feature .btn { margin-left: auto; white-space: nowrap; }
@media (max-width: 720px) { .feature { flex-direction: column; text-align: center; } .feature .btn { margin: 0; } }

/* ---------- Installable app (PWA) ---------- */
.install-btn { padding: .45rem .9rem; }
.install-btn[hidden] { display: none; }
@media (max-width: 400px) { .install-label { display: none; } }

.install-sheet {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 60;
  width: min(440px, calc(100vw - 1.5rem)); display: flex; gap: 1rem; align-items: flex-start;
  padding: 1.1rem 1.2rem; border-radius: 20px; background: #1b1f4d; border: 1px solid var(--border);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .8);
  transform: translate(-50%, 140%); visibility: hidden; transition: transform .35s cubic-bezier(.2, .8, .2, 1), visibility .35s;
}
.install-sheet.show { transform: translate(-50%, 0); visibility: visible; }
.install-sheet img { border-radius: 14px; flex: none; }
.install-sheet ol { margin: .4rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: .92rem; }
.install-sheet ol b { color: var(--text); }
.install-sheet .close { position: absolute; top: .5rem; right: .5rem; width: 32px; height: 32px; }
.ios-share { display: inline-grid; place-items: center; width: 1.4em; height: 1.4em; border: 1px solid var(--muted); border-radius: 5px; font-size: .8em; }

/* Offline badge on the logo */
.is-offline .brand::after {
  content: "offline"; font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  padding: .15rem .45rem; border-radius: 99px; background: #fbbf24; color: #0b0d1f; margin-left: .2rem;
}

/* Running as an installed app: no browser chrome, so respect device edges */
@media (display-mode: standalone) {
  .nav { padding-top: max(.6rem, env(safe-area-inset-top)); }
  body { overscroll-behavior-y: none; }
}
