:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #e3e1dc;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --warn: #a8650a;
  --ok: #1f8a4c;
  --radius: 14px;
  --tabbar-h: 58px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Hebrew", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --surface: #1f1f22;
    --text: #f2f2f4;
    --muted: #9a9aa1;
    --line: #2e2e33;
    --accent: #5b8ff0;
    --danger: #e5675a;
    --warn: #e0a24a;
    --ok: #4cc27f;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}

.topbar-row { display: flex; align-items: center; justify-content: space-between; max-width: 608px; margin: 0 auto; }
.topbar h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }

.view {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  line-height: 1.45;
}
.card p { margin: 0 0 12px; }
.card pre { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--bg); overflow-x: auto; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
}
.stat-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { margin-top: 2px; font-size: 13px; color: var(--muted); }

button.primary {
  appearance: none;
  border: 0;
  border-radius: var(--radius);
  padding: 15px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
}
button.primary:disabled { opacity: 0.4; }

/* Hebrew text: always mark with lang="he" so direction and font are right. */
[lang="he"] { direction: rtl; unicode-bidi: isolate; }

.tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs[hidden] { display: none; }

.tab {
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10.5px;
  color: var(--muted);
  text-decoration: none;
}
.tab.active { color: var(--accent); }

@media (min-width: 900px) {
  .tabs { max-width: 640px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
}

/* Dictionary */
.search {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px; /* below 16px iOS zooms the page on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}
.search:focus { border-color: var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; }
.chip {
  appearance: none;
  flex: none;
  padding: 7px 14px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  touch-action: manipulation;
}
.chip.active { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }

.meta { margin: 0; font-size: 13px; color: var(--muted); }
.center { text-align: center; }

.dict-section { display: flex; flex-direction: column; gap: 8px; }
.dict-section + .dict-section { margin-top: 12px; }
.section-title { margin: 4px 2px 0; font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.group > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  list-style: none;
  cursor: pointer;
  touch-action: manipulation;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.group > summary::-webkit-details-marker { display: none; }
.group-title { flex: 1; min-width: 0; font-weight: 600; }
.group-count { font-size: 14px; color: var(--muted); }
.group-chevron { display: flex; color: var(--muted); transition: transform 0.15s; }
.group-chevron svg { width: 18px; height: 18px; }
.group[open] .group-chevron { transform: rotate(90deg); }
.group[open] > summary { border-radius: var(--radius) var(--radius) 0 0; border-bottom-color: transparent; }
.group[open] > .entries { border-top-left-radius: 0; border-top-right-radius: 0; }

.entries {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.entry + .entry { border-top: 1px solid var(--line); }
.entry summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  list-style: none;
  cursor: pointer;
}
.entry summary::-webkit-details-marker { display: none; }
.entry-ru { min-width: 0; line-height: 1.3; }
.entry-he { flex: none; max-width: 55%; font-size: 22px; text-align: right; }
.tr { display: block; margin-top: 2px; font-size: 14px; color: var(--muted); }
.entry-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.forms-title { margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.form { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.form > span:first-child { font-size: 14px; color: var(--muted); }
.he-pair { cursor: pointer; display: flex; flex-direction: column; align-items: flex-end; }
.he-pair [lang="he"] { font-size: 19px; }
.label { color: var(--muted); }
.badge { display: inline-block; white-space: nowrap; margin-top: 4px; padding: 1px 8px; font-size: 12px; color: var(--warn); border: 1px solid currentColor; border-radius: 999px; }
.meta.warn { color: var(--warn); }
.nikud { font-size: 22px; }
.meta a { color: var(--accent); }
.note { margin: 0; font-size: 14px; line-height: 1.4; }

/* Today */
.plan { display: flex; flex-direction: column; gap: 6px; }
.plan-row { display: flex; flex-direction: column; gap: 2px; }
.kicker { font-size: 13px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: var(--muted); }

/* Study session */
.study { display: flex; flex-direction: column; gap: 16px; min-height: calc(100dvh - 120px); }
.study-top { display: flex; align-items: center; gap: 12px; }
.progress { flex: 1; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width 0.25s; }
.study-body { display: flex; flex-direction: column; gap: 14px; }
.study-h { margin: 0; font-size: 24px; }
.study-foot {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 0 calc(env(safe-area-inset-bottom) + 8px);
  background: var(--bg);
}
.icon-btn {
  appearance: none;
  border: 0;
  background: none;
  padding: 6px;
  color: var(--muted);
  display: inline-flex;
  touch-action: manipulation;
}
.he-block { display: flex; flex-direction: column; gap: 4px; }
.he-line { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.he-line [lang="he"] { font-size: 24px; }
.he-block.big .he-line [lang="he"] { font-size: 36px; }
.he-block .tr { text-align: right; font-size: 16px; }
.he-block.big .tr { font-size: 19px; }
.tr-toggle { appearance: none; border: 0; background: none; padding: 0; align-self: flex-end; font: inherit; font-size: 14px; color: var(--accent); }
.ru { font-size: 17px; }
.ru.big { font-size: 24px; font-weight: 600; }
.target { font-size: 20px; font-weight: 600; }
.anchor { border-color: var(--accent); }
.intro p { margin: 0 0 8px; }
.intro p:last-child { margin: 0; }
.dialog { display: flex; flex-direction: column; gap: 8px; }
.bubble { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.new-card { display: flex; flex-direction: column; gap: 12px; padding: 24px 18px; }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 14px 16px;
  font: inherit;
  font-size: 18px;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  touch-action: manipulation;
}
.option [lang="he"] { font-size: 22px; text-align: right; }
.option .tr { text-align: right; }
.option.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.option.wrongpick { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }

.answer-line, .tiles { display: flex; flex-wrap: wrap; gap: 8px; min-height: 52px; }
.answer-line { padding: 8px; border-bottom: 2px solid var(--line); }
.answer-line.ok { border-color: var(--ok); }
.answer-line.bad { border-color: var(--danger); }
.tile {
  appearance: none;
  padding: 8px 14px;
  font: inherit;
  font-size: 22px;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  touch-action: manipulation;
}
.tiles .tile:disabled { visibility: hidden; }
.answer-line .tile:disabled { opacity: 1; }

.verdict { font-weight: 700; font-size: 17px; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--danger); }
.reveal { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.self-grade { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
button.secondary {
  appearance: none;
  padding: 13px 6px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  touch-action: manipulation;
}
.done { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 40px; text-align: center; }
.done-mark { display: flex; padding: 14px; border-radius: 50%; color: var(--accent-text); background: var(--ok); }
.done-mark svg { width: 36px; height: 36px; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 90px);
  z-index: 10;
  max-width: 600px;
  margin: 0 auto;
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.35;
  color: var(--bg);
  background: var(--text);
  border-radius: 12px;
}
.form .icon-btn { align-self: center; padding: 0 6px; }

.gtag { display: inline-block; margin-left: 6px; padding: 1px 8px; font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--accent); border: 1px solid currentColor; border-radius: 999px; vertical-align: middle; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented button { appearance: none; padding: 12px; font: inherit; font-weight: 600; color: var(--text); background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; touch-action: manipulation; }
.segmented button.on { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }

.account { display: flex; flex-direction: column; gap: 10px; }
.account p { margin: 0; }
button.secondary.danger { color: var(--danger); }

.account-form { display: flex; flex-direction: column; gap: 10px; }
button.link { appearance: none; border: 0; background: none; padding: 4px 0; font: inherit; color: var(--accent); text-align: left; touch-action: manipulation; }
.save-card { display: flex; flex-direction: column; gap: 10px; border-color: var(--accent); }
.save-card p { margin: 0; }

.debug { display: flex; flex-direction: column; gap: 10px; border-style: dashed; }
.debug p { margin: 0; }
.debug-info { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; font-size: 14px; }
.debug-info dt { color: var(--muted); }
.debug-info dd { margin: 0; font-variant-numeric: tabular-nums; }
.debug-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 15px; }

button.link.danger { color: var(--danger); }

#settings-btn.active { color: var(--accent); }

/* Path */
.level { display: flex; flex-direction: column; gap: 8px; }
.level + .level { margin-top: 10px; }
.level-head { font-size: 18px; font-weight: 700; }
.level-id { color: var(--accent); font-variant-numeric: tabular-nums; }
.level-status { font-size: 13px; color: var(--muted); }
.level.locked .level-head { color: var(--muted); }
.topics { display: flex; flex-direction: column; gap: 8px; }
.topic {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  touch-action: manipulation;
}
.topic.rec { border-color: var(--accent); }
.topic.mastered { border-color: var(--ok); }
.topic:disabled { opacity: 0.55; }
.topic-head { display: flex; align-items: center; gap: 8px; }
.topic-title { flex: 1; font-weight: 600; }
.topic-meta, .topic-after { font-size: 13px; color: var(--muted); }
.tag.rec { padding: 1px 8px; font-size: 12px; font-weight: 600; color: var(--accent-text); background: var(--accent); border-radius: 999px; }
.state-icon { display: flex; color: var(--muted); }
.topic.mastered .state-icon { color: var(--ok); }
.state-icon svg { width: 18px; height: 18px; }
.tp-bars { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.bar { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); }
.bar.stable > div { background: var(--ok); }
.stage-soon { display: flex; justify-content: space-between; padding: 10px 2px; border-top: 1px solid var(--line); }
.topic-detail { display: flex; flex-direction: column; gap: 8px; }
.topic-detail p { margin: 0; }
.lessons { display: flex; flex-direction: column; padding: 4px 14px; }
.lesson-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.lesson-row + .lesson-row { border-top: 1px solid var(--line); }
.lesson-mark { display: flex; width: 18px; color: var(--ok); }
.lesson-mark svg { width: 18px; height: 18px; }
.lesson-title { flex: 1; }
.lesson-row.is-done .lesson-title { color: var(--muted); }
button.small { padding: 8px 14px; font-size: 15px; }
