:root {
  --bg: #faf6ee;
  --bg-elev: #fffaf0;
  --surface: #ffffff;
  --text: #2b2018;
  --muted: #7a6a5e;
  --line: #ead9c0;
  --accent: #7c3a17;
  --accent-soft: #c2845a;
  --accent-warm: #f1d9a8;
  --green: #4a7c2a;
  --green-soft: #d8e8c4;
  --highlight: #ffeec2;
  --shadow: 0 1px 2px rgba(45, 26, 12, 0.06), 0 8px 24px rgba(45, 26, 12, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino", "Palatino Linotype", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a140e;
    --bg-elev: #221a12;
    --surface: #2a2017;
    --text: #f4ecdb;
    --muted: #b6a48f;
    --line: #3b2d1f;
    --accent: #e2a073;
    --accent-soft: #c2845a;
    --accent-warm: #4a3621;
    --green: #9bc77a;
    --green-soft: #2c3c1c;
    --highlight: #6a4c1f;
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border-bottom: 1px solid var(--line);
  padding: 14px 20px;
  backdrop-filter: saturate(140%) blur(6px);
}
.brand {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 18px;
  justify-content: space-between;
}
.brand-link {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: inherit;
}
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-warm);
  font-size: 28px;
  display: grid; place-items: center;
  font-weight: 600;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.brand-title { font-weight: 700; font-size: 19px; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted); font-size: 13px; }

.topnav {
  display: flex;
  gap: 4px;
  align-items: center;
}
.navlink {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  transition: color .15s ease, background .15s ease;
}
.navlink:hover { color: var(--text); background: var(--accent-warm); }
.navlink.active { color: var(--accent); font-weight: 600; }

#auth-area { margin-left: 6px; }
.auth-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: var(--accent-warm);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  transition: filter .15s ease, transform .15s ease;
}
.auth-chip:hover { filter: brightness(1.05); transform: translateY(-1px); }
.auth-chip.ghost {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.auth-chip.ghost:hover { background: var(--accent-warm); }
.auth-dot {
  width: 8px;
  height: 8px;
  background: #6ec96e;
  border-radius: 50%;
  display: inline-block;
}

/* NIVEAU PICKER (home) */
.niveaus {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.niveau-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  text-decoration: none;
  color: inherit;
  display: flex;
  gap: 14px;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
  position: relative;
  overflow: hidden;
}
.niveau-card:hover { transform: translateY(-2px); border-color: var(--accent-soft); }
.niveau-num {
  font-family: var(--font-serif);
  font-size: 56px;
  font-weight: 700;
  color: var(--accent-warm);
  line-height: 0.95;
  flex-shrink: 0;
  width: 60px;
  text-align: center;
}
.niveau-meta { flex: 1; min-width: 0; }
.niveau-title {
  font-weight: 600;
  font-size: 16px;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}
.niveau-sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}
.niveau-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.niveau-progress .bar {
  flex: 1;
  height: 5px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.niveau-progress .bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-soft), var(--green));
  transition: width .4s ease;
}
.niveau-card.locked { opacity: 0.85; }
.niveau-card.locked .niveau-num { color: var(--line); }
.lock-icon {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 18px;
  opacity: 0.6;
}

/* LOCKED HERO */
.locked-hero {
  text-align: center;
  padding: 48px 16px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.locked-hero .lock-big { font-size: 48px; opacity: 0.5; margin-bottom: 8px; }
.locked-hero h1 {
  font-family: var(--font-serif);
  color: var(--accent);
  font-size: 26px;
  margin: 0 0 8px;
}
.locked-hero p { color: var(--muted); margin: 0 auto 18px; max-width: 380px; }

/* LOGIN / ACCOUNT */
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 420px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.login-card label span { color: var(--muted); }
.login-card input {
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--text);
  outline: none;
  transition: border-color .15s ease;
}
.login-card input:focus { border-color: var(--accent-soft); }
.login-card .btn { align-self: stretch; justify-content: center; }
.login-note { font-size: 12px; color: var(--muted); margin: 0; }
.login-note a { color: var(--accent); text-decoration: none; }

.account-status {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.status-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.status-row .lbl { color: var(--muted); font-size: 13px; }
.status-row .val { font-weight: 600; }
.status-row .val.good { color: var(--green); }

/* Subscription plans */
.plans {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.plan-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease;
  font: inherit;
  color: var(--text);
  position: relative;
}
.plan-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.plan-interval {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.plan-amount {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}
.plan-badge {
  margin-top: 8px;
  font-size: 11px;
  background: var(--accent-warm);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 999px;
  display: inline-block;
  font-weight: 600;
}
.plan-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
  text-align: center;
}

/* MAIN */
main {
  flex: 1;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

/* HOME — lessons grid */
.hero {
  margin-bottom: 22px;
}
.hero h1 {
  font-family: var(--font-serif);
  font-size: 30px;
  margin: 0 0 8px 0;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.hero p {
  color: var(--muted);
  margin: 0;
  font-size: 15px;
}
.overall-progress {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.overall-progress .bar {
  flex: 1;
  height: 6px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.overall-progress .bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-soft), var(--green));
  transition: width .4s ease;
}

.lessons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.lesson-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
  position: relative;
  overflow: hidden;
}
.lesson-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-soft);
}
.lesson-card .num {
  font-family: var(--font-serif);
  font-size: 50px;
  font-weight: 600;
  color: var(--accent-warm);
  line-height: 1;
  position: absolute;
  right: 12px;
  top: 8px;
  user-select: none;
}
.lesson-card .cat {
  font-weight: 600;
  font-size: 16px;
  color: var(--accent);
  z-index: 1;
  padding-right: 50px;
}
.lesson-card .meta {
  font-size: 13px;
  color: var(--muted);
  z-index: 1;
}
.lesson-card .progress {
  margin-top: 4px;
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  z-index: 1;
}
.lesson-card .progress > span {
  display: block;
  height: 100%;
  background: var(--green);
  transition: width .4s ease;
}
.lesson-card.completed { background: var(--green-soft); border-color: var(--green); }
.lesson-card.completed .cat { color: var(--green); }

/* LESSON DETAIL */
.crumb {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.crumb a {
  color: var(--muted);
  text-decoration: none;
}
.crumb a:hover { color: var(--text); }

.lesson-head {
  margin-bottom: 18px;
}
.lesson-head h1 {
  font-family: var(--font-serif);
  font-size: 28px;
  margin: 0 0 4px 0;
  color: var(--accent);
  font-weight: 700;
}
.lesson-head .meta {
  color: var(--muted);
  font-size: 14px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.btn:hover { border-color: var(--accent-soft); transform: translateY(-1px); }
.btn.primary {
  background: var(--accent);
  color: var(--accent-warm);
  border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }

/* WORD LIST */
.words {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.word {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 14px;
  align-items: center;
  box-shadow: var(--shadow);
  transition: border-color .15s ease;
}
.word.learned { background: var(--green-soft); border-color: var(--green); }
.word .nl {
  font-family: var(--font-ui);
  font-size: 16px;
  color: var(--text);
}
.word .nl .en {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.word .jv {
  font-family: var(--font-serif);
  font-size: 19px;
  color: var(--accent);
  font-weight: 600;
}
.word .jv .krama {
  display: block;
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
  font-style: italic;
  margin-top: 2px;
}
.word-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.speak {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  padding: 6px 8px;
  border-radius: 8px;
  opacity: 0.4;
  transition: opacity .15s ease, background .15s ease, transform .15s ease;
}
.word:hover .speak,
.speak:focus-visible { opacity: 1; }
.speak:hover { background: var(--accent-warm); opacity: 1; }
.speak.speaking {
  opacity: 1;
  background: var(--accent-warm);
  animation: pulse .6s ease infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.mark-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 14px;
  transition: all .15s ease;
}
.mark-btn:hover { border-color: var(--green); color: var(--green); }
.word.learned .mark-btn { background: var(--green); color: white; border-color: var(--green); }

/* FLASHCARDS */
.fc-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.fc-progress {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.fc-card {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 5/4;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: transform .2s ease;
  font-family: var(--font-serif);
}
.fc-card:hover { transform: translateY(-2px); }
.fc-card .label {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  position: absolute;
  top: 14px;
  left: 18px;
}
.fc-card .lessonpill {
  font-family: var(--font-ui);
  font-size: 11px;
  background: var(--accent-warm);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 999px;
  position: absolute;
  top: 12px;
  right: 14px;
  font-weight: 500;
}
.fc-card .front {
  font-size: 38px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.01em;
}
.fc-card .front .en {
  display: block;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
  margin-top: 6px;
  letter-spacing: 0;
  text-transform: lowercase;
}
.fc-card .back {
  font-size: 32px;
  font-weight: 600;
  color: var(--text);
  margin-top: 16px;
}
.fc-card .back .krama {
  display: block;
  font-size: 17px;
  color: var(--muted);
  font-weight: 400;
  font-style: italic;
  margin-top: 6px;
}
.fc-card .tip {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--muted);
  margin-top: 18px;
}
.fc-card .speak-big {
  margin-top: 14px;
  border: 1px solid var(--line);
  background: var(--accent-warm);
  color: var(--accent);
  padding: 8px 16px;
  border-radius: 999px;
  font: inherit;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.fc-card .speak-big.speaking { animation: pulse .6s ease infinite; }

.fc-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 480px;
}
.fc-controls .btn { flex: 1; justify-content: center; }
.fc-controls .icon-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: grid;
  place-items: center;
  transition: all .15s ease;
}
.fc-controls .icon-btn:hover { border-color: var(--accent-soft); }
.fc-controls .icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.fc-done {
  text-align: center;
  padding: 40px 20px;
}
.fc-done h2 {
  font-family: var(--font-serif);
  color: var(--accent);
  font-size: 28px;
  margin: 0 0 8px 0;
}
.fc-done p { color: var(--muted); margin: 0 0 18px 0; }

/* OEFEN (practice landing) */
.practice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.practice-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.practice-card:hover { transform: translateY(-2px); border-color: var(--accent-soft); }
.practice-card .icon {
  font-size: 28px;
  margin-bottom: 4px;
}
.practice-card .ttl {
  font-weight: 600;
  font-size: 16px;
  color: var(--accent);
}
.practice-card .sub {
  font-size: 13px;
  color: var(--muted);
}

/* ABOUT */
.about {
  font-family: var(--font-serif);
  font-size: 17px;
  max-width: 600px;
}
.about h2 {
  font-family: var(--font-ui);
  font-size: 22px;
  color: var(--accent);
  margin-top: 0;
}
.about h3 { font-family: var(--font-ui); font-size: 16px; color: var(--accent); margin-top: 24px; }

/* FOOTER */
footer {
  border-top: 1px solid var(--line);
  padding: 10px 20px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  gap: 8px;
  flex-wrap: wrap;
}
.footer-links a {
  color: var(--muted);
  text-decoration: none;
  margin: 0 2px;
}
.footer-links a:hover { color: var(--text); }

@media (max-width: 540px) {
  .brand { gap: 10px; flex-wrap: wrap; }
  .topnav { width: 100%; justify-content: flex-start; gap: 0; }
  .word { grid-template-columns: 1fr; gap: 6px; }
  .word .jv { font-size: 18px; }
  .word-actions { justify-content: flex-end; }
  .fc-card .front { font-size: 30px; }
  .fc-card .back { font-size: 26px; }
  .hero h1 { font-size: 24px; }
}

/* Touch devices: speaker buttons are always visible */
@media (hover: none) {
  .speak { opacity: 0.7; }
}
