:root {
  --bg: #fff8ef;
  --ink: #26283f;
  --muted: #6b6f85;
  --card: #ffffff;
  --line: #ece4d8;
  --defs: #0ea5e9;
  --defs-soft: #e0f4fd;
  --thms: #7c3aed;
  --thms-soft: #efe7fe;
  --solve: #f97316;
  --solve-soft: #ffeedf;
  --accent: #e63946;
  --term: #2563eb;
  --radius: 20px;
  --shadow: 0 2px 0 rgba(38, 40, 63, .06), 0 8px 24px rgba(38, 40, 63, .07);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Rubik', 'Assistant', 'Segoe UI', Arial, sans-serif;
  font-size: 18px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}
body[data-screen="defs"] { --c: var(--defs); --soft: var(--defs-soft); }
body[data-screen="thms"] { --c: var(--thms); --soft: var(--thms-soft); }
body[data-screen="solve"] { --c: var(--solve); --soft: var(--solve-soft); }
body[data-screen="home"] { --c: #4f46e5; --soft: #eef; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--c);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
body[data-screen="home"] .topbar { display: none; }
.top-title { flex: 1; margin: 0; font-size: 22px; font-weight: 800; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0;
  background: rgba(255,255,255,.2); color: inherit;
  font-size: 22px; font-family: inherit; cursor: pointer;
  display: inline-grid; place-items: center; text-decoration: none;
}
.icon-btn[hidden] { display: none; }
.icon-btn.small { width: 38px; height: 38px; font-size: 18px; background: #f2eee7; color: var(--ink); }

main { max-width: 760px; margin: 0 auto; padding: 16px 14px calc(40px + env(safe-area-inset-bottom)); }

/* ---------- home ---------- */
.home { min-height: calc(100vh - 60px); display: flex; flex-direction: column; justify-content: center; }
.hero { text-align: center; margin: 10px 0 26px; }
.hero-shape svg { width: 96px; height: 86px; }
.hero-shape polygon { fill: #ffd166; stroke: var(--ink); stroke-width: 4; stroke-linejoin: round; }
.hero-shape circle { fill: #4f46e5; opacity: .85; }
.hero h1 { font-size: 34px; margin: 8px 0 2px; font-weight: 800; }
.hero p { margin: 0; color: var(--muted); }

.main-buttons { display: grid; gap: 16px; }
.big-btn {
  display: flex; align-items: center; gap: 16px;
  padding: 22px 20px; border-radius: 24px;
  text-decoration: none; color: #fff;
  box-shadow: 0 6px 0 rgba(0,0,0,.14), 0 12px 24px rgba(0,0,0,.08);
  transition: transform .12s ease, box-shadow .12s ease;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.14); }
.big-btn .ic { font-size: 40px; width: 64px; height: 64px; display: grid; place-items: center; background: rgba(255,255,255,.22); border-radius: 18px; flex: none; }
.big-btn b { display: block; font-size: 26px; font-weight: 800; line-height: 1.2; }
.big-btn small { display: block; font-size: 16px; opacity: .92; }
.big-btn.defs { background: var(--defs); }
.big-btn.thms { background: var(--thms); }
.big-btn.solve { background: var(--solve); }

.install {
  margin: 22px auto 0; padding: 10px 20px; border-radius: 999px;
  border: 2px solid #4f46e5; background: #fff; color: #4f46e5;
  font: inherit; font-weight: 700; cursor: pointer;
}
.install[hidden] { display: none; }

/* ---------- groups ---------- */
.intro { color: var(--muted); margin: 4px 4px 14px; font-size: 16px; }
.group {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden;
  border: 2px solid transparent;
}
.group[open] { border-color: var(--soft); }
.group summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; font-size: 21px; font-weight: 700;
  user-select: none;
}
.group summary::-webkit-details-marker { display: none; }
.group summary::after {
  content: '‹'; margin-inline-start: auto; font-size: 28px; line-height: 1;
  color: var(--c); transition: transform .2s; transform: rotate(0deg);
}
.group[open] summary::after { transform: rotate(-90deg); }
.group[open] summary { background: var(--soft); }
.g-ic { width: 42px; height: 42px; flex: none; display: grid; place-items: center; font-size: 22px; background: var(--soft); border-radius: 12px; }
.group[open] .g-ic { background: #fff; }
.count { font-size: 14px; font-weight: 700; color: var(--c); background: var(--soft); border-radius: 999px; padding: 0 10px; }
.group[open] .count { background: #fff; }

.cards { padding: 8px 14px 16px; }
.card { padding: 14px 4px 16px; border-bottom: 2px dashed var(--line); }
.card:last-child { border-bottom: 0; }
.card h3 { margin: 0 0 4px; font-size: 20px; color: var(--c); }
.card p { margin: 0; }
.card ul, #sheet-body ul { margin: 8px 0 0; padding-inline-start: 22px; }
.card li, #sheet-body li { margin: 4px 0; }
.card li::marker, #sheet-body li::marker { color: var(--c); }

/* ---------- terms ---------- */
.term {
  font: inherit; color: var(--term); background: none; border: 0; padding: 0 1px; margin: 0;
  text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px;
  text-decoration-color: rgba(37, 99, 235, .45);
  cursor: pointer; border-radius: 4px;
}
.term:hover, .term:focus-visible { background: #e8efff; outline: none; }
.term.demo { cursor: default; }
.thm-link { font: inherit; color: var(--thms); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
strong { font-weight: 700; }
.m { font-family: 'Rubik', Arial, sans-serif; font-weight: 600; white-space: nowrap; }

/* ---------- solve ---------- */
.try { margin: 4px 4px 0; font-weight: 700; color: var(--c); }
.tips { list-style: hebrew; padding-inline-start: 30px; margin: 6px 0 0; }
.tips > li { padding: 10px 2px 12px; border-bottom: 2px dashed var(--line); }
.tips > li:last-child { border-bottom: 0; }
.tips > li::marker { font-weight: 800; color: var(--c); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  font: inherit; font-size: 15px; font-weight: 500;
  padding: 4px 12px; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--thms-soft); background: #faf7ff; color: var(--thms);
}
.chip:active { background: var(--thms-soft); }

/* ---------- figures ---------- */
.fig-wrap {
  margin: 12px auto 0; max-width: 300px;
  background: #fffdf8; border: 2px solid var(--line); border-radius: 16px; padding: 6px;
}
.fig { display: block; width: 100%; height: auto; direction: ltr; }
.fig .ln { stroke: var(--ink); stroke-width: 2.6; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.fig .ln.hl { stroke: var(--accent); stroke-width: 3.4; }
.fig .ln.dash { stroke-dasharray: 6 5; stroke-width: 2.2; }
.fig .ln.tick { stroke: var(--accent); stroke-width: 2.4; }
.fig .rt { stroke: var(--ink); stroke-width: 2; fill: none; }
.fig .sec { stroke-width: 1.4; }
.fig .sec.c1 { fill: #ffd166; stroke: #e0a800; }
.fig .sec.c2 { fill: #9fd8ff; stroke: #3aa0e0; }
.fig .sec.c3 { fill: #bdf0b4; stroke: #4fb043; }
.fig .sec.c4 { fill: #c7b8ff; stroke: #7c62e0; }
.fig .dot { fill: var(--ink); }
.fig text { font-family: 'Rubik', Arial, sans-serif; text-anchor: middle; dominant-baseline: middle; fill: var(--ink); }
.fig .lb { font-size: 15px; font-weight: 700; }
.fig .al { font-size: 14px; font-weight: 700; fill: #b5179e; }
.fig .hb { font-size: 13px; font-weight: 500; fill: #5b50d6; }

/* ---------- bottom sheet ---------- */
#sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px;
  max-height: 85vh; border-radius: 26px 26px 0 0; background: var(--card); color: var(--ink);
  box-shadow: 0 -10px 40px rgba(0,0,0,.2);
}
#sheet::backdrop { background: rgba(30, 28, 50, .45); }
#sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-inner { display: flex; flex-direction: column; max-height: 85vh; }
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 10px; border-bottom: 2px solid var(--line);
}
#sheet[data-kind="term"] .sheet-head { border-top: 6px solid var(--defs); border-radius: 26px 26px 0 0; }
#sheet[data-kind="thm"] .sheet-head { border-top: 6px solid var(--thms); border-radius: 26px 26px 0 0; }
#sheet-title { flex: 1; margin: 0; font-size: 22px; }
#sheet-body { padding: 12px 20px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; }
#sheet-body p { margin: 6px 0 0; }
.kind { font-size: 14px; font-weight: 700; color: var(--muted); }
#sheet[data-kind="term"] .kind { color: var(--defs); }
#sheet[data-kind="thm"] .kind { color: var(--thms); }
#sheet[data-kind="thm"] li::marker { color: var(--thms); }

@media (min-width: 700px) {
  #sheet { margin: auto; border-radius: 26px; }
  .main-buttons { grid-template-columns: repeat(3, 1fr); }
  .big-btn { flex-direction: column; text-align: center; padding: 28px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
