:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-alt: #f3f4f6;
  --ink: #1a1d23;
  --muted: #667085;
  --border: #e3e6eb;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-ink: #ffffff;
  --accent-soft: #eaf1fe;

  --good: #16a34a;
  --good-soft: #eafaf0;
  --bad: #dc2626;
  --bad-soft: #fdecec;

  --radius: 20px;
  --radius-lg: 26px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05), 0 2px 6px rgba(16,24,40,.06);
  --shadow: 0 4px 10px rgba(16,24,40,.06), 0 16px 32px -10px rgba(16,24,40,.16);
  --font-body: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(900px 520px at 6% -10%, rgba(37,99,235,.09), transparent 55%),
    radial-gradient(760px 520px at 102% 18%, rgba(124,58,237,.07), transparent 52%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255,255,255,.9);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 14px 22px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -.005em;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--ink);
  min-width: 0;
  flex-shrink: 1;
}
.brand-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand .flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(155deg, #4c8cf5, var(--accent));
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 3px 8px -2px rgba(37,99,235,.5);
}
.brand .flag svg { width: 18px; height: 18px; }

.topbar .spacer { flex: 1; }

.icon-btn {
  appearance: none;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .06s ease;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--surface-alt); border-color: #d0d5dd; }
.icon-btn:active { transform: scale(.94); }

/* Unified "where am I" block inside the topbar — one line, same shape on
   every screen, no repeated deck icon (it's already shown in the hero
   banner right below). */
.topbar-title {
  font-weight: 700;
  font-size: .98rem;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-title.clickable { cursor: pointer; padding: 6px 10px; margin: -6px -10px; border-radius: 10px; transition: background .15s ease; }
.topbar-title.clickable:hover { background: var(--surface-alt); }

/* User menu: one avatar button, everything else tucked in a dropdown. */
.user-menu { position: relative; flex-shrink: 0; }
.avatar-btn {
  appearance: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(155deg, #343a46, var(--ink));
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.user-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px;
  min-width: 170px;
  z-index: 20;
}
.user-dropdown-name {
  padding: 6px 10px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: .9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-dropdown-item {
  appearance: none;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: .9rem;
  font-weight: 600;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}
.user-dropdown-item:hover { background: var(--bad-soft); color: #991b1b; }
.user-dropdown-item svg { width: 16px; height: 16px; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 14px;
  font-family: var(--font-body);
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: transform .06s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn:hover { background: var(--surface-alt); border-color: #d0d5dd; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(155deg, #3b82f6, var(--accent)); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 10px -2px rgba(37,99,235,.5); }
.btn.primary:hover { background: linear-gradient(155deg, #3b82f6, var(--accent-hover)); border-color: var(--accent-hover); }
.btn.ghost { background: var(--surface-alt); border-color: var(--border); color: var(--muted); }
.btn.ghost:hover { background: #e9ebef; border-color: #d0d5dd; }
.btn.small { padding: 7px 11px; font-size: .8rem; }
.btn:disabled { opacity: .4; cursor: default; }

main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 30px 20px 70px; display: flex; flex-direction: column; }

/* The quiz screen centers its single active exercise vertically instead
   of leaving a dead gap below a short card on tall viewports. */
.quiz-screen {
  flex: 1;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* ---------- Auth ---------- */
.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 140px);
  padding: 20px 0;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
}
.auth-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: linear-gradient(155deg, #4c8cf5, var(--accent));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px -4px rgba(37,99,235,.5);
}
.auth-icon svg { width: 26px; height: 26px; }
.auth-card h1 { font-weight: 700; font-size: 1.35rem; margin: 0 0 6px; letter-spacing: -.01em; }
.auth-sub { color: var(--muted); font-size: .88rem; margin: 0 0 18px; line-height: 1.4; }
.auth-card label { text-align: left; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 0 6px; }
.auth-card input {
  width: 100%;
  padding: 13px 15px;
  font-size: 1rem;
  font-family: var(--font-body);
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--surface-alt);
}
.auth-card input:focus { outline: none; background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.auth-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bad-soft);
  color: #991b1b;
  font-size: .85rem;
  font-weight: 600;
  text-align: left;
}
.auth-submit { width: 100%; justify-content: center; margin-top: 18px; padding: 12px; font-size: .98rem; }
.auth-switch { margin: 14px auto 0; }

/* ---------- Home: deck grid ---------- */
.hero-panel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: linear-gradient(135deg, #4c8cf5, var(--accent-hover));
  border-radius: var(--radius-lg);
  padding: 30px 32px;
  margin-bottom: 26px;
  box-shadow: 0 16px 36px -14px rgba(37,99,235,.5);
  overflow: hidden;
}
.hero-panel::before {
  content: "";
  position: absolute;
  top: -50%; right: -6%;
  width: 280px; height: 280px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
}
.hero-panel::after {
  content: "";
  position: absolute;
  bottom: -70%; right: 22%;
  width: 180px; height: 180px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
}
.hero-panel-text { position: relative; min-width: 0; }
.hero-panel-text h1 { font-weight: 800; font-size: 1.85rem; margin: 0 0 8px; letter-spacing: -.015em; color: #fff; }
.hero-panel-text p { color: rgba(255,255,255,.88); margin: 0; font-size: .95rem; max-width: 42ch; line-height: 1.5; }
.hero-panel-stat { position: relative; text-align: center; flex-shrink: 0; }
.hero-panel-stat .n { font-size: 2.2rem; font-weight: 900; color: #fff; line-height: 1; letter-spacing: -.02em; }
.hero-panel-stat .n small { font-size: 1.1rem; font-weight: 800; margin-left: 1px; }
.hero-panel-stat .l { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.85); margin-top: 6px; font-weight: 700; }

.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.deck-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .16s cubic-bezier(.2,.8,.3,1.1), box-shadow .2s ease, border-color .15s ease;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}
.deck-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--deck-color, var(--accent)) 35%, var(--border)); }
.deck-card:hover .deck-icon { transform: scale(1.07) rotate(-3deg); }
.deck-card:hover .deck-card-pattern { opacity: .25; transform: translateY(-50%) rotate(-4deg) scale(1.04); }

.deck-card-pattern {
  position: absolute;
  top: 50%;
  right: -22px;
  width: 132px;
  height: 132px;
  color: var(--deck-color, var(--accent));
  opacity: .16;
  pointer-events: none;
  transform: translateY(-50%) rotate(-8deg);
  transition: opacity .2s ease, transform .2s ease;
}
.deck-card-pattern svg { width: 100%; height: 100%; stroke-width: 1; }
.deck-card-top, .deck-card-progress, .deck-card > p, .deck-card .meta {
  position: relative;
  z-index: 1;
  padding-right: 48px;
}

.deck-icon {
  width: 50px;
  height: 50px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--deck-color, var(--accent));
  background-image: linear-gradient(155deg, rgba(255,255,255,.32), transparent 60%);
  color: #fff;
  box-shadow: 0 6px 14px -4px var(--deck-color, var(--accent));
  flex-shrink: 0;
  transition: transform .2s cubic-bezier(.2,.8,.3,1.1);
}
.deck-icon svg { width: 25px; height: 25px; }

.deck-card-top { display: flex; align-items: center; gap: 12px; }
.deck-card-top h3 { flex: 1; min-width: 0; }
.deck-card h3 { margin: 0; font-weight: 800; font-size: 1.12rem; letter-spacing: -.01em; }
.deck-card p {
  margin: 0;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.45;
  flex: 1;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.deck-card .meta { display: flex; justify-content: space-between; align-items: center; font-size: .78rem; color: var(--muted); font-weight: 600; }

.deck-card-progress { display: flex; align-items: center; gap: 10px; }
.deck-card-progress .progress-bar { flex: 1; height: 7px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; }
.deck-card-progress .progress-bar > span {
  display: block;
  height: 100%;
  background: var(--deck-color, var(--accent));
  border-radius: 999px;
  transition: width .4s ease;
}
.deck-card-progress .progress-pct { font-size: .78rem; font-weight: 800; color: var(--deck-color, var(--accent)); flex-shrink: 0; min-width: 32px; text-align: left; }
.deck-card-progress.mastered .progress-bar > span { background: #d97706; }
.deck-card-progress.mastered .progress-pct { color: #b45309; }

/* ---------- Deck menu: choose an exercise ---------- */
/* A bold solid panel, deliberately built like the home screen's hero —
   NOT like the white mode/rules cards below it, since this one isn't
   clickable and shouldn't look like one of the buttons. */
.deck-hero {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--deck-color, var(--accent)) 100%, #fff 15%), color-mix(in srgb, var(--deck-color, var(--accent)) 80%, #000 15%));
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  margin-bottom: 22px;
  box-shadow: 0 14px 30px -12px var(--deck-color, var(--accent));
  cursor: default;
  overflow: hidden;
}
.deck-hero::before {
  content: "";
  position: absolute;
  top: -55%; right: -8%;
  width: 230px; height: 230px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
}
.deck-hero::after {
  content: "";
  position: absolute;
  bottom: -75%; right: 20%;
  width: 150px; height: 150px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
}
.deck-hero-icon {
  position: relative;
  z-index: 1;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.deck-hero-icon svg { width: 25px; height: 25px; }
.deck-hero-text { position: relative; z-index: 1; flex: 1; min-width: 0; }
.deck-hero-text h1 { margin: 0 0 4px; font-size: 1.25rem; font-weight: 800; letter-spacing: -.01em; color: #fff; }
.deck-hero-text p { margin: 0; color: rgba(255,255,255,.88); font-size: .85rem; line-height: 1.4; }
.deck-hero-stat { position: relative; z-index: 1; text-align: center; flex-shrink: 0; }
.deck-hero-stat .n { font-size: 1.7rem; font-weight: 900; color: #fff; line-height: 1; letter-spacing: -.02em; }
.deck-hero-stat .n small { font-size: .9rem; font-weight: 800; margin-left: 1px; }
.deck-hero-stat .l { font-size: .65rem; text-transform: uppercase; letter-spacing: .07em; color: rgba(255,255,255,.85); margin-top: 5px; font-weight: 700; }

.mode-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mode-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform .14s ease, box-shadow .2s ease, border-color .15s ease;
}
.mode-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: color-mix(in srgb, var(--mode-color, var(--accent)) 35%, var(--border));
}
.mode-card:hover .deck-card-pattern { opacity: .2; }
.mode-card-icon {
  position: relative;
  z-index: 1;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--mode-color, var(--accent));
  background-image: linear-gradient(155deg, rgba(255,255,255,.25), transparent 60%);
  color: #fff;
  box-shadow: 0 4px 10px -3px var(--mode-color, var(--accent));
}
.mode-card-icon svg { width: 21px; height: 21px; }
.mode-card-text { position: relative; z-index: 1; flex: 1; min-width: 0; padding-right: 36px; }
.mode-card-text h3 { margin: 0 0 2px; font-size: 1rem; font-weight: 700; }
.mode-card-text p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.4; }
.mode-card-arrow { position: relative; z-index: 1; color: #b0b6c2; flex-shrink: 0; display: flex; }
.mode-card-arrow svg { width: 18px; height: 18px; }
.mode-card:hover .mode-card-arrow { color: var(--mode-color, var(--accent)); }

.mode-card .deck-card-pattern { top: 50%; right: -26px; width: 92px; height: 92px; opacity: .11; color: var(--mode-color, var(--accent)); }

.card-stage {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.stage-top { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; color: var(--muted); font-weight: 600; }
.stage-top b { color: var(--ink); }
.stage-tools { display: flex; gap: 6px; }
.icon-btn.tiny { width: 28px; height: 28px; border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn.tiny:hover { background: var(--surface-alt); border-color: var(--border); color: var(--ink); }
.icon-btn.tiny svg { width: 15px; height: 15px; }

/* Flashcard */
.flashcard {
  flex: 1;
  border: none;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 22px;
  cursor: pointer;
  min-height: 160px;
  background: var(--surface-alt);
  box-shadow: inset 0 1px 2px rgba(16,24,40,.05);
  transition: background .15s ease, transform .1s ease;
}
.flashcard:active { transform: scale(.99); }
.flashcard:hover { background: var(--accent-soft); }
.flashcard .main { font-size: 1.55rem; font-weight: 700; }
.flashcard .sub { margin-top: 10px; color: var(--muted); font-size: .95rem; }
.flashcard .hint { margin-top: 16px; color: #94a0b3; font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 5px; }
.flashcard .hint svg { width: 14px; height: 14px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* Multiple choice */
.mc-question { text-align: center; }
.mc-question .prompt { font-size: 1.3rem; font-weight: 700; margin-bottom: 6px; }
.mc-question .direction { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
.mc-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 560px) { .mc-options { grid-template-columns: 1fr; } }
.mc-option {
  border: 2px solid transparent;
  background: var(--surface-alt);
  border-radius: 14px;
  padding: 15px 18px;
  text-align: left;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  transition: border-color .12s ease, background .12s ease, transform .08s ease, box-shadow .12s ease;
}
.mc-option:hover { background: var(--surface); border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.mc-option.correct { background: var(--good-soft); border-color: var(--good); color: #166534; }
.mc-option.wrong { background: var(--bad-soft); border-color: var(--bad); color: #991b1b; }
.mc-option.disabled { pointer-events: none; }

/* Type-it / recall */
.type-prompt { text-align: center; font-size: 1.25rem; font-weight: 700; }
.type-sub { text-align: center; color: var(--muted); font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.type-input {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  display: block;
  padding: 14px 18px;
  font-size: 1.05rem;
  font-family: var(--font-body);
  font-weight: 600;
  border-radius: 14px;
  border: 2px solid transparent;
  background: var(--surface-alt);
}
.type-input:focus { outline: none; background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.feedback {
  text-align: center;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: .95rem;
  font-weight: 700;
}
.feedback.correct { background: var(--good-soft); color: #166534; }
.feedback.wrong { background: var(--bad-soft); color: #991b1b; }
.feedback .answer { font-weight: 700; font-size: 1.05rem; display: block; margin-top: 5px; }
.feedback .rule { margin-top: 7px; color: var(--muted); font-size: .85rem; font-weight: 500; }

/* Conjugation table drill */
.conj-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 520px; margin: 0 auto; width: 100%; }
@media (max-width: 560px) { .conj-grid { grid-template-columns: 1fr; } }
.conj-row { display: flex; align-items: center; gap: 8px; }
.conj-row label { width: 150px; flex-shrink: 0; color: var(--muted); font-size: .83rem; font-weight: 600; }
.conj-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--surface-alt);
  font-size: .95rem;
  font-weight: 600;
  font-family: var(--font-body);
}
.conj-row input:focus { outline: none; background: var(--surface); border-color: var(--accent); }
.conj-row input.correct { background: var(--good-soft); border-color: var(--good); }
.conj-row input.wrong { background: var(--bad-soft); border-color: var(--bad); }

.session-stats {
  display: flex;
  gap: 18px;
  justify-content: center;
  font-size: .85rem;
  color: var(--muted);
}
.session-stats b { color: var(--ink); }

.notes-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  font-size: .88rem;
  line-height: 1.55;
  margin-top: 18px;
}
.notes-box h4 { margin: 0 0 9px; font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 800; display: flex; align-items: center; gap: 6px; }
.notes-box h4 svg { width: 14px; height: 14px; color: var(--accent); }
.notes-box ul { margin: 0; padding-left: 20px; }
.notes-box li { margin-bottom: 5px; }
.notes-box li::marker { color: var(--accent); }

/* ---------- Rules card (opens the rules modal) ---------- */
.rules-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
  margin-bottom: 16px;
  overflow: hidden;
  transition: transform .14s ease, box-shadow .2s ease, border-color .15s ease;
}
.rules-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.rules-card:hover .deck-card-pattern { opacity: .2; }
.rules-card .deck-card-pattern { top: 50%; right: -26px; width: 92px; height: 92px; opacity: .11; color: var(--accent); }
.rules-card-icon {
  position: relative;
  z-index: 1;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.rules-card-icon svg { width: 21px; height: 21px; }

/* ---------- Rules modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(16,24,40,.52);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: modal-fade .15s ease;
}
.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
  animation: modal-pop .16s cubic-bezier(.2,.8,.3,1.1);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal-header h4 { margin: 0; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 800; display: flex; align-items: center; gap: 7px; }
.modal-header h4 svg { width: 15px; height: 15px; color: var(--accent); }
.modal-list { margin: 0; padding-left: 20px; font-size: .94rem; line-height: 1.65; color: var(--ink); }
.modal-list li { margin-bottom: 9px; }
.modal-list li::marker { color: var(--accent); font-weight: 700; }

@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop { from { opacity: 0; transform: scale(.95) translateY(6px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.empty-state { text-align: center; color: var(--muted); padding: 50px 10px; margin: auto; }
.empty-state .big-emoji { font-size: 2.2rem; display: block; margin-bottom: 10px; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .topbar { padding: 12px 16px; gap: 10px; }
  .topbar .brand { font-size: 1rem; gap: 8px; }
  .icon-btn { width: 38px; height: 38px; }
  .topbar-title { font-size: .92rem; max-width: 48vw; }
  .avatar-btn { width: 38px; height: 38px; }

  main { padding: 18px 16px 64px; }

  .hero-panel { flex-direction: column; align-items: flex-start; gap: 18px; padding: 24px 22px; margin-bottom: 20px; }
  .hero-panel-text h1 { font-size: 1.45rem; }
  .hero-panel-text p { font-size: .88rem; }
  .hero-panel-stat { align-self: flex-start; text-align: left; }
  .hero-panel-stat .n { font-size: 1.9rem; }

  .deck-grid { grid-template-columns: 1fr; gap: 14px; }
  .deck-card { padding: 18px; gap: 10px; }
  .deck-icon { width: 44px; height: 44px; border-radius: 12px; }
  .deck-icon svg { width: 23px; height: 23px; }
  .deck-card h3 { font-size: 1.05rem; }
  .deck-card p { font-size: .85rem; }

  .deck-hero { padding: 20px; gap: 14px; margin-bottom: 18px; }
  .deck-hero-text h1 { font-size: 1.1rem; }
  .deck-hero-text p { font-size: .82rem; }
  .deck-hero-stat .n { font-size: 1.4rem; }

  .mode-grid { gap: 12px; }
  .mode-card { padding: 16px; gap: 14px; }
  .mode-card-text h3 { font-size: 1.05rem; }
  .mode-card-text p { font-size: .85rem; }

  .card-stage { padding: 22px 18px; min-height: 0; gap: 18px; border-radius: 16px; }
  .flashcard { padding: 32px 18px; min-height: 150px; }
  .flashcard .main { font-size: 1.4rem; }

  .mc-question .prompt, .type-prompt { font-size: 1.22rem; }
  .mc-option { padding: 15px 16px; font-size: .96rem; }

  .row { gap: 10px; }
  .row .btn:not(.small) { flex: 1 1 160px; justify-content: center; }
  .btn { padding: 13px 18px; font-size: .92rem; min-height: 48px; }
  .btn.small { padding: 10px 14px; min-height: 40px; }

  .conj-row { flex-direction: column; align-items: stretch; gap: 4px; }
  .conj-row label { width: auto; }
  .conj-row input { width: 100%; min-height: 44px; }

  .notes-box { padding: 16px; }
}

@media (max-width: 380px) {
  .topbar-title { max-width: 40vw; }
}
