/* ═══ Kelma — midnight notebook theme ═══ */
:root {
  --ink: #17123b;
  --ink-2: #241d5c;
  --ink-3: #322878;
  --paper: #faf3e3;
  --paper-2: #f3e8cf;
  --coral: #ff6b57;
  --coral-deep: #e04f3c;
  --teal: #2dd4bf;
  --teal-deep: #14a696;
  --gold: #ffc94d;
  --muted: #8f89b8;
  --ok: #34d399;
  --bad: #fb7185;
  --radius: 20px;
  --shadow: 0 10px 30px rgba(10, 6, 40, .45);
  --font-ar: 'Tajawal', system-ui, 'Segoe UI', sans-serif;
  --font-en: 'Fraunces', 'Georgia', serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: var(--font-ar);
  background: var(--ink);
  color: var(--paper);
  min-height: 100vh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
.bg-grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(900px 500px at 85% -5%, rgba(255, 107, 87, .16), transparent 60%),
    radial-gradient(700px 480px at -10% 30%, rgba(45, 212, 191, .12), transparent 60%),
    radial-gradient(600px 600px at 50% 110%, rgba(255, 201, 77, .10), transparent 60%);
}
[dir="ltr"] body, body.en { font-family: var(--font-ar); }
.en-word, [dir="ltr"] { font-family: var(--font-en); }

/* ── top bar ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px;
  background: linear-gradient(to bottom, var(--ink) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 38px; height: 38px; filter: drop-shadow(0 3px 8px rgba(255,107,87,.4)); }
.brand-name { font-weight: 900; font-size: 1.35rem; letter-spacing: .5px; }
.icon-btn {
  background: var(--ink-2); border: 1px solid var(--ink-3); color: var(--paper);
  width: 42px; height: 42px; border-radius: 14px; font-size: 1.1rem; cursor: pointer;
  transition: transform .15s, background .15s;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.small { width: 34px; height: 34px; font-size: .95rem; border-radius: 11px; }

/* ── layout ── */
.app { position: relative; z-index: 1; max-width: 560px; margin: 0 auto; padding: 6px 18px 24px; }
.view { display: none; animation: viewIn .35s cubic-bezier(.2,.9,.3,1); }
.view.active { display: block; }
@keyframes viewIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ── hero ── */
.hero { padding: 18px 2px 8px; }
.hero-kicker {
  color: var(--teal); font-weight: 700; font-size: .85rem; letter-spacing: 1px; margin-bottom: 8px;
}
.hero-title { font-size: 2.05rem; font-weight: 900; line-height: 1.35; }
.hero-sub { color: var(--muted); margin-top: 10px; line-height: 1.9; font-size: .95rem; }

/* ── stat chips ── */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 20px 0 16px; }
.stat-chip {
  position: relative; background: var(--ink-2); border: 1px solid var(--ink-3);
  border-radius: var(--radius); padding: 14px 12px 12px; overflow: hidden;
}
.stat-num { display: block; font-size: 1.7rem; font-weight: 900; color: var(--gold); line-height: 1.1; }
.stat-label { display: block; font-size: .72rem; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.stat-emoji { position: absolute; top: 8px; inset-inline-end: 10px; font-size: 1rem; opacity: .85; }

/* ── CTA ── */
.cta {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; border: none; cursor: pointer;
  background: linear-gradient(120deg, var(--coral), var(--coral-deep));
  color: #fff; border-radius: var(--radius); padding: 16px 20px;
  font-family: var(--font-ar); font-weight: 800; font-size: 1.15rem;
  box-shadow: 0 8px 24px rgba(224, 79, 60, .4);
  transition: transform .15s, box-shadow .15s;
}
.cta:active { transform: translateY(2px) scale(.99); box-shadow: 0 3px 10px rgba(224,79,60,.35); }
.cta-sub { font-size: .75rem; font-weight: 500; opacity: .85; flex: 1; text-align: start; }
.cta-arrow { font-size: 1.3rem; }
.cta.small-cta { width: auto; padding: 10px 22px; font-size: 1rem; }
.cta:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.ghost-btn {
  background: transparent; border: 1.5px dashed var(--ink-3); color: var(--paper);
  border-radius: 14px; padding: 12px 18px; font-family: var(--font-ar);
  font-weight: 700; font-size: .95rem; cursor: pointer; transition: border-color .2s, background .2s;
}
.ghost-btn:hover { border-color: var(--teal); }
.ghost-btn.wide { width: 100%; margin: 12px 0; }
.ghost-btn.danger { color: var(--bad); border-color: rgba(251,113,133,.4); }

/* ── word of the day ── */
.wotd {
  margin: 22px 0 6px; background: var(--paper); color: var(--ink);
  border-radius: 26px; padding: 22px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.wotd::before {
  content: ''; position: absolute; inset-inline-end: -30px; top: -30px;
  width: 130px; height: 130px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,107,87,.25), transparent 70%);
}
.wotd-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.wotd-badge {
  background: var(--ink); color: var(--gold); font-size: .75rem; font-weight: 800;
  padding: 5px 12px; border-radius: 999px;
}
.wotd .icon-btn { background: var(--paper-2); border-color: #e5d6b8; color: var(--ink); }
.wotd-word { font-family: var(--font-en); font-size: 2.2rem; font-weight: 900; letter-spacing: .5px; }
.wotd-pos { font-family: var(--font-en); font-style: italic; color: #8a7a52; font-size: .9rem; margin-top: 2px; }
.wotd-ar { font-size: 1.25rem; font-weight: 800; margin-top: 10px; color: var(--coral-deep); }
.wotd-ex { font-family: var(--font-en); margin-top: 14px; font-size: 1rem; line-height: 1.6; }
.wotd-exar { color: #6d6146; margin-top: 6px; font-size: .92rem; line-height: 1.8; }

/* ── sections ── */
.home-section { margin-top: 26px; }
.section-title { font-size: 1.15rem; font-weight: 800; margin-bottom: 12px; }
.section-title.big { font-size: 1.5rem; margin-bottom: 10px; }
.muted { color: var(--muted); line-height: 1.9; }
.muted.tiny { font-size: .8rem; }
.center { text-align: center; }

/* ── week chart ── */
.week-chart {
  display: flex; align-items: flex-end; gap: 8px; height: 110px;
  background: var(--ink-2); border: 1px solid var(--ink-3);
  border-radius: var(--radius); padding: 14px 14px 10px;
}
.week-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.week-bar {
  width: 100%; max-width: 30px; border-radius: 8px 8px 4px 4px; min-height: 5px;
  background: linear-gradient(to top, var(--teal-deep), var(--teal));
  transition: height .5s cubic-bezier(.2,.9,.3,1);
}
.week-bar.empty { background: var(--ink-3); }
.week-bar.today { background: linear-gradient(to top, var(--coral-deep), var(--coral)); }
.week-day { font-size: .68rem; color: var(--muted); }

/* ── decks ── */
.deck-list { display: flex; flex-direction: column; gap: 10px; }
.deck-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--ink-2); border: 1px solid var(--ink-3); border-radius: var(--radius); padding: 14px 16px;
}
.deck-emoji { font-size: 1.6rem; }
.deck-info { flex: 1; }
.deck-name { font-weight: 800; font-size: 1rem; }
.deck-en { font-family: var(--font-en); color: var(--muted); font-size: .78rem; font-style: italic; }
.deck-bar { height: 7px; background: var(--ink-3); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.deck-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--gold), var(--coral)); }
.deck-count { font-size: .8rem; color: var(--muted); white-space: nowrap; }

/* ── study setup ── */
.study-setup { padding-top: 8px; }
.setup-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 18px 0; }
.setup-row label { font-weight: 700; }
select {
  background: var(--ink-2); color: var(--paper); border: 1px solid var(--ink-3);
  border-radius: 12px; padding: 10px 16px; font-family: var(--font-ar); font-size: 1rem; font-weight: 700;
}
.seg { display: flex; background: var(--ink-2); border: 1px solid var(--ink-3); border-radius: 14px; padding: 4px; gap: 4px; }
.seg-btn {
  background: transparent; border: none; color: var(--muted); font-family: var(--font-ar);
  font-weight: 700; font-size: .9rem; padding: 9px 16px; border-radius: 10px; cursor: pointer;
  transition: background .2s, color .2s;
}
.seg-btn.active { background: var(--teal-deep); color: #fff; }

/* ── session ── */
.session-progress { display: flex; align-items: center; gap: 12px; margin: 14px 0 18px; }
.session-bar { flex: 1; height: 8px; background: var(--ink-2); border-radius: 99px; overflow: hidden; }
.session-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--teal), var(--gold)); border-radius: 99px; transition: width .4s; }
.session-count { font-size: .85rem; color: var(--muted); font-weight: 700; min-width: 52px; text-align: center; }

/* ── flashcard ── */
.flashcard { perspective: 1400px; cursor: pointer; outline: none; }
.flashcard-inner {
  position: relative; width: 100%; min-height: 340px;
  transform-style: preserve-3d; transition: transform .55s cubic-bezier(.35, .1, .25, 1);
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 28px; padding: 26px 24px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 8px;
  box-shadow: var(--shadow);
}
.flash-front { background: linear-gradient(160deg, var(--ink-2), var(--ink-3)); border: 1px solid var(--ink-3); }
.flash-back { background: var(--paper); color: var(--ink); transform: rotateY(180deg); }
.flash-tag {
  position: absolute; top: 16px; inset-inline-start: 16px;
  font-size: .72rem; font-weight: 800; padding: 4px 12px; border-radius: 999px;
  background: rgba(45,212,191,.15); color: var(--teal); border: 1px solid rgba(45,212,191,.3);
}
.flash-tag.tag-review { background: rgba(255,201,77,.15); color: var(--gold); border-color: rgba(255,201,77,.3); }
.flash-speak { position: absolute; top: 14px; inset-inline-end: 14px; }
.flash-word { font-family: var(--font-en); font-size: 2.6rem; font-weight: 900; line-height: 1.15; word-break: break-word; }
.flash-word.small-word { font-size: 1.5rem; color: var(--ink); }
.flash-pos { font-family: var(--font-en); font-style: italic; color: var(--muted); }
.flash-flip-hint { position: absolute; bottom: 18px; font-size: .78rem; color: var(--muted); }
.flash-ar { font-size: 1.5rem; font-weight: 800; color: var(--coral-deep); }
.flash-example { margin-top: 12px; background: var(--paper-2); border-radius: 16px; padding: 14px 16px; width: 100%; }
.flash-ex { font-family: var(--font-en); font-size: .98rem; line-height: 1.55; text-align: start; }
.flash-exar { color: #6d6146; font-size: .88rem; line-height: 1.8; margin-top: 6px; text-align: start; }

/* ── grades ── */
.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 18px; }
.grade {
  border: none; cursor: pointer; border-radius: 16px; padding: 12px 4px 10px;
  font-family: var(--font-ar); font-weight: 800; font-size: .92rem; color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: transform .12s, filter .2s;
}
.grade small { font-size: .66rem; font-weight: 500; opacity: .85; }
.grade:active { transform: scale(.94); }
.g-again { background: #b33a4b; }
.g-hard  { background: #b3762a; }
.g-good  { background: #1f8f6e; }
.g-easy  { background: #2563a8; }

/* ── done screens ── */
.study-done { text-align: center; padding: 46px 12px; }
.done-emoji { font-size: 3.4rem; margin-bottom: 14px; }
.done-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 26px; }

/* ── quiz ── */
.quiz-card { background: var(--ink-2); border: 1px solid var(--ink-3); border-radius: 26px; padding: 24px 20px; }
.quiz-q-label { color: var(--teal); font-weight: 800; font-size: .85rem; }
.quiz-prompt { font-size: 1.7rem; font-weight: 900; margin: 10px 0 20px; line-height: 1.4; word-break: break-word; }
.quiz-prompt[dir="ltr"] { font-family: var(--font-en); }
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-opt {
  background: var(--ink); border: 1.5px solid var(--ink-3); color: var(--paper);
  border-radius: 16px; padding: 14px 18px; font-family: var(--font-ar); font-weight: 700;
  font-size: 1rem; cursor: pointer; text-align: start; transition: border-color .2s, background .2s, transform .12s;
}
.quiz-opt[dir="ltr"] { font-family: var(--font-en); text-align: left; }
.quiz-opt:active { transform: scale(.98); }
.quiz-opt.correct { background: rgba(52,211,153,.15); border-color: var(--ok); color: var(--ok); }
.quiz-opt.wrong { background: rgba(251,113,133,.12); border-color: var(--bad); color: var(--bad); }
.quiz-opt:disabled { cursor: default; opacity: .85; }
.quiz-feedback { min-height: 28px; margin-top: 14px; font-weight: 800; text-align: center; }
.quiz-feedback.ok { color: var(--ok); }
.quiz-feedback.no { color: var(--bad); }

/* ── words view ── */
.words-tools { margin: 14px 0 4px; }
.search-input {
  width: 100%; background: var(--ink-2); border: 1px solid var(--ink-3); color: var(--paper);
  border-radius: 14px; padding: 13px 18px; font-family: var(--font-ar); font-size: 1rem; outline: none;
}
.search-input:focus { border-color: var(--teal); }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 6px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  white-space: nowrap; background: var(--ink-2); border: 1px solid var(--ink-3); color: var(--muted);
  border-radius: 999px; padding: 8px 16px; font-family: var(--font-ar); font-weight: 700;
  font-size: .85rem; cursor: pointer; transition: all .2s;
}
.chip.active { background: var(--gold); border-color: var(--gold); color: var(--ink); }

.add-form { display: flex; flex-direction: column; gap: 10px; background: var(--ink-2); border: 1px solid var(--ink-3); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.add-form input {
  background: var(--ink); border: 1px solid var(--ink-3); color: var(--paper);
  border-radius: 12px; padding: 12px 16px; font-family: var(--font-ar); font-size: .95rem; outline: none;
}
.add-form input:focus { border-color: var(--teal); }
.add-form-actions { display: flex; gap: 10px; align-items: center; }

.word-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.word-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--ink-2); border: 1px solid var(--ink-3); border-radius: 16px; padding: 13px 16px;
}
.word-row .w-en { font-family: var(--font-en); font-weight: 700; font-size: 1.05rem; }
.word-row .w-ar { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.word-row .w-mid { flex: 1; min-width: 0; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.status-dot.new { background: var(--ink-3); }
.status-dot.learning { background: var(--teal); }
.status-dot.review { background: var(--gold); }
.status-dot.mastered { background: var(--ok); }
.word-row .icon-btn { width: 34px; height: 34px; font-size: .9rem; border-radius: 10px; flex-shrink: 0; }
.lvl-badge { font-family: var(--font-en); font-size: .68rem; font-weight: 700; color: var(--muted); border: 1px solid var(--ink-3); border-radius: 6px; padding: 2px 7px; }

/* ── settings ── */
.settings-card { background: var(--ink-2); border: 1px solid var(--ink-3); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.settings-card h3 { font-size: 1rem; margin-bottom: 12px; }
.settings-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.file-label { text-align: center; display: block; }

/* ── bottom nav ── */
.bottomnav {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: rgba(23, 18, 59, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--ink-3);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
}
.nav-btn {
  background: none; border: none; color: var(--muted); font-family: var(--font-ar);
  font-size: .7rem; font-weight: 700; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 12px; border-radius: 14px; transition: color .2s, background .2s;
}
.nav-btn .nav-ico { font-size: 1.25rem; }
.nav-btn.active { color: var(--gold); background: rgba(255, 201, 77, .08); }

/* ── toast ── */
.toast {
  position: fixed; bottom: 96px; inset-inline: 24px; z-index: 50;
  background: var(--paper); color: var(--ink); font-weight: 800; text-align: center;
  border-radius: 14px; padding: 13px 18px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(16px); pointer-events: none;
  transition: opacity .3s, transform .3s;
}
.toast.show { opacity: 1; transform: none; }

.hidden { display: none !important; }

@media (min-width: 520px) {
  .hero-title { font-size: 2.4rem; }
  .flashcard-inner { min-height: 380px; }
}
@media (prefers-reduced-motion: reduce) {
  .flashcard-inner, .view, .session-fill { transition: none; }
}

#wotd-speak-ex, #flash-speak-ex { width: auto; padding: 0 10px; margin-top: 4px; font-size: .8rem; }
