:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --ink: #1d2422;
  --muted: #66706c;
  --line: #e2ded4;
  --brand: #2f5d50;
  --brand-ink: #ffffff;
  --brand-soft: #dfeae5;
  --good: #1f7a4d;
  --good-soft: #dcf0e4;
  --bad: #b8432f;
  --bad-soft: #f8e1dc;
  --warn: #9a6a00;
  --warn-soft: #f6ebcc;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 6px 20px rgba(20, 30, 25, .06);
  --radius: 16px;
  --en: "Source Serif 4", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121615; --surface: #1b2120; --surface-2: #232a28; --ink: #e9eeec; --muted: #9aa5a1; --line: #2e3633;
    --brand: #7fc2a9; --brand-ink: #0f1513; --brand-soft: #1f3530;
    --good: #6fd39c; --good-soft: #173326; --bad: #f08b77; --bad-soft: #3a1f1a; --warn: #e6bf5c; --warn-soft: #352c14;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121615; --surface: #1b2120; --surface-2: #232a28; --ink: #e9eeec; --muted: #9aa5a1; --line: #2e3633;
  --brand: #7fc2a9; --brand-ink: #0f1513; --brand-soft: #1f3530;
  --good: #6fd39c; --good-soft: #173326; --bad: #f08b77; --bad-soft: #3a1f1a; --warn: #e6bf5c; --warn-soft: #352c14;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 "IBM Plex Sans Arabic", system-ui, sans-serif;
  min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--brand); }
.en { font-family: var(--en); direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.top {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.top-in { max-width: 760px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--ink); }
.logo img { width: 30px; height: 30px; }
.top .spacer { flex: 1; }
main { max-width: 760px; margin: 0 auto; padding: 18px 16px 24px; }
h1 { font-size: 1.45rem; margin: 4px 0 4px; }
h2 { font-size: 1.1rem; margin: 22px 0 10px; }
.lead { color: var(--muted); margin: 0 0 18px; }

.tabs {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs-in { max-width: 760px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 9px; text-decoration: none;
  color: var(--muted); font-size: .75rem; font-weight: 500;
}
.tabs a svg { width: 22px; height: 22px; }
.tabs a.on { color: var(--brand); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line);
  background: var(--surface); padding: 10px 16px; border-radius: 12px; cursor: pointer; font-weight: 600;
  text-decoration: none; color: var(--ink); min-height: 44px; transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.good { background: var(--good); color: #fff; border-color: var(--good); }
.btn.bad { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; color: var(--ink);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.icon-btn.rec { background: var(--bad); color: #fff; border-color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--bad) 25%, transparent); } }
.icon-btn.sm { width: 34px; height: 34px; }
.icon-btn.sm svg { width: 16px; height: 16px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: .92rem; }
label.field > span i { font-style: normal; color: var(--muted); font-weight: 400; }
input[type=text], input[type=password], input[type=search], textarea, select {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  outline: none; min-height: 46px;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 70px; }
.with-btn { display: flex; gap: 8px; align-items: center; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; font-size: .9rem; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- home ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

/* ---------- mode picker ---------- */
.modes { display: grid; gap: 10px; }
.mode {
  display: flex; gap: 14px; align-items: flex-start; text-align: start; width: 100%; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
}
.mode:hover { border-color: var(--brand); }
.mode .ic { width: 42px; height: 42px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; flex: none; }
.mode .ic svg { width: 22px; height: 22px; }
.mode b { display: block; font-size: 1.02rem; }
.mode p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.mode .count { margin-inline-start: auto; align-self: center; font-weight: 700; color: var(--brand); white-space: nowrap; font-size: .9rem; }
.options { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin: 14px 0 6px; }
.options > div { display: flex; align-items: center; gap: 8px; }

/* ---------- flashcard ---------- */
.session-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.session-top .bar { flex: 1; margin: 0; }
.session-top .n { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.flip { perspective: 1400px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.flip-in { position: relative; min-height: 330px; transition: transform .45s cubic-bezier(.2,.7,.2,1); transform-style: preserve-3d; }
.flip.flipped .flip-in { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow);
  padding: 22px 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px;
}
.face.back { transform: rotateY(180deg); overflow-y: auto; justify-content: flex-start; padding-top: 26px; }
.face .tag { position: absolute; top: 12px; inset-inline-start: 14px; font-size: .75rem; color: var(--muted); background: var(--surface-2); padding: 2px 9px; border-radius: 99px; }
.face .dots { position: absolute; top: 14px; inset-inline-end: 14px; display: flex; gap: 4px; direction: ltr; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--good); }
.term { font-family: var(--en); font-size: clamp(2rem, 9vw, 3rem); font-weight: 700; line-height: 1.15; direction: ltr; word-break: break-word; }
.term-ar { font-size: clamp(1.6rem, 7vw, 2.2rem); font-weight: 700; line-height: 1.3; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.tools { display: flex; gap: 8px; justify-content: center; }
.ans-ar { font-size: 1.45rem; font-weight: 700; }
.ans-en { font-family: var(--en); font-size: 1.9rem; font-weight: 700; direction: ltr; }
.sentence { background: var(--surface-2); border-radius: 14px; padding: 10px 12px; width: 100%; text-align: start; }
.sentence .en { display: block; font-size: 1.08rem; line-height: 1.5; }
.sentence .ar { display: block; color: var(--muted); font-size: .92rem; margin-top: 4px; }
.sentence .tools { justify-content: flex-start; margin-top: 8px; }
.forms { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; direction: ltr; }
.forms > div { background: var(--surface-2); border-radius: 12px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.forms small { color: var(--muted); font-size: .7rem; font-family: "IBM Plex Sans Arabic", sans-serif; direction: rtl; }
.forms b { font-family: var(--en); font-size: 1.2rem; word-break: break-word; }
.answer { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.answer .btn { min-height: 56px; font-size: 1.05rem; }
.flip-cta { margin-top: 14px; }
.keys { text-align: center; margin-top: 10px; }

.pron { width: 100%; border-radius: 12px; padding: 8px 12px; font-size: .9rem; text-align: start; }
.pron.good { background: var(--good-soft); color: var(--good); }
.pron.mid { background: var(--warn-soft); color: var(--warn); }
.pron.bad { background: var(--bad-soft); color: var(--bad); }
.pron.wait { background: var(--surface-2); color: var(--muted); }
.pron .en { font-weight: 600; }

/* ---------- study list (verbs) ---------- */
.study { display: grid; gap: 12px; }
.study .card { padding: 14px; }
.study .head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.study .head b { font-size: 1.05rem; }
.study .head .num { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; flex: none; }

/* ---------- summary ---------- */
.summary { text-align: center; padding: 26px 18px; }
.summary .big { font-size: 3rem; font-weight: 700; line-height: 1; color: var(--brand); font-variant-numeric: tabular-nums; }
.summary .pills { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 99px; font-size: .85rem; font-weight: 600; background: var(--surface-2); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.missed { text-align: start; margin-top: 16px; }
.missed li { padding: 6px 0; border-bottom: 1px solid var(--line); }

/* ---------- library ---------- */
.lib-tools { display: grid; gap: 10px; margin-bottom: 8px; }
.month { margin: 20px 0 8px; display: flex; align-items: baseline; gap: 8px; }
.month h3 { margin: 0; font-size: 1rem; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.it { border-bottom: 1px solid var(--line); }
.it:last-child { border-bottom: 0; }
.it-row { display: flex; align-items: center; gap: 10px; padding: 11px 14px; cursor: pointer; }
.it-row .w { flex: 1; min-width: 0; }
.it-row .w .en { font-weight: 700; font-size: 1.05rem; }
.it-row .w .tr { color: var(--muted); font-size: .9rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.it-row .badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.it-more { padding: 0 14px 14px; display: grid; gap: 10px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; }
.it-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }

/* ---------- misc ---------- */
.login { max-width: 380px; margin: 14vh auto 0; padding: 0 16px; text-align: center; }
.login img { width: 64px; height: 64px; }
.err { color: var(--bad); font-size: .9rem; min-height: 1.4em; }
#toast {
  position: fixed; bottom: calc(86px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600; opacity: 0;
  transition: .25s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.divider { height: 1px; background: var(--line); margin: 22px 0; }
.note { background: var(--brand-soft); color: var(--ink); border-radius: 12px; padding: 10px 13px; font-size: .9rem; }

@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .flip-in { min-height: 360px; }
}
@media (prefers-reduced-motion: reduce) {
  .flip-in { transition: none; }
}
