/* ===== Design tokens ===== */
:root {
  --bg: #faf6ee;
  --bg-elevated: #ffffff;
  --ink: #2b241b;
  --ink-soft: #5c5347;
  --line: #e4d9c4;
  --accent: #8a4b2e;
  --accent-soft: #f1e3d1;
  --accent-faint: color-mix(in srgb, var(--accent-soft) 45%, var(--bg-elevated) 55%);
  --accent-strong: #6d3a22;
  --shen: #a0522d;
  --regel: #6b7f3f;
  --bor: #3f6f7f;
  --esh: #b23b2e;
  --sun: #d99a2b;
  --sky: #4a8fbd;
  --shadow: 0 4px 16px rgba(43, 36, 27, 0.08);
  --radius: 14px;
  --font-head: "Rubik", "Heebo", "Arial Hebrew", sans-serif;
  --font-body: "Heebo", "Arial Hebrew", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.75;
  direction: rtl;
  transition: background .2s ease, color .2s ease;
}

img, svg { max-width: 100%; }

a { color: var(--accent-strong); }

h1, h2, h3 { font-family: var(--font-head); color: var(--ink); margin: 0 0 .4em; }

/* Interface chrome (buttons, nav, badges, menu items) shares the headings'
   rounded font, distinct from the body text used for the lesson content
   itself. */
.dropdown-item, .auth-link, .score-badge, .lesson-nav-btn {
  font-family: var(--font-head);
}

/* ===== Layout ===== */
.wrap { max-width: 880px; margin: 0 auto; padding: 0 20px; }

/* ===== Site header ===== */
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 14px;
  gap: 12px;
}
/* Thin reading-progress bar along the header's bottom edge - present in
   every page's markup for one consistent header, but only ever filled in
   by reading-progress.js on an actual lesson page (everywhere else it
   just stays at 0% width, invisible). */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-head);
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--ink);
}
.brand .mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 1.1rem;
}

/* ===== Dropdown menus (brand menu, lesson picker) ===== */
.dropdown { position: relative; }
.dropdown-trigger {
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 20;
}
/* The site's menu: always the same width, scrolling when it's taller than the screen
   (the same in site-header.css, for lesson pages and the text page). */
.brand-menu { width: 280px; max-width: calc(100vw - 32px); max-height: calc(100vh - 90px); overflow-y: auto; }
.dropdown-item {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: .95rem;
}
/* Reset native browser chrome when a .dropdown-item is a <button> (e.g. the
   admin panel's lesson picker) instead of an <a>. */
button.dropdown-item {
  width: 100%;
  text-align: start;
  background: none;
  border: none;
  cursor: pointer;
}
.dropdown-item:hover { background: var(--accent-soft); color: var(--accent-strong); }
.dropdown-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}
.dropdown-menu .auth-area { margin-inline-start: 0; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
#auth-area-in { flex-direction: column; align-items: stretch; gap: 10px; }

/* Per-page lesson submenus nested inside the brand menu - kept independent of
   the generic dropdown toggle (see main.js) since that closes every open
   .dropdown-menu before opening one, which would hide this submenu's own
   ancestor along with it. */
.submenu-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-family: inherit;
  font-size: .95rem;
  background: none;
  border: none;
  cursor: pointer;
}
.submenu-arrow { width: 16px; height: 16px; flex: none; transition: transform .2s ease; }
.submenu:has(> .submenu-panel:not([hidden])) > .submenu-trigger .submenu-arrow { transform: rotate(180deg); }
.submenu-panel {
  position: static;
  min-width: 0;
  margin: 4px 0 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: none;
}
.submenu-panel .dropdown-item { font-size: .88rem; }

/* The home page's lessons list: a full-width panel, open by default,
   instead of a small floating popup. */
.lessons-menu {
  position: static;
  width: 100%;
  min-width: 0;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  display: block;
}
/* A CSS @keyframes animation (unlike a transition) plays on its own the
   moment an element starts rendering - so removing [hidden] is enough to
   trigger this, no JS or display-transition trickery needed. Only covers
   the open direction (closing still snaps away instantly via [hidden]'s
   display:none), which is what "opening animation" actually asks for. */
@keyframes accordion-open {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.lessons-menu:not([hidden]) { animation: accordion-open .22s ease; }
@media (prefers-reduced-motion: reduce) {
  .lessons-menu:not([hidden]) { animation: none; }
}

/* ===== Auth (login / register) ===== */
.auth-area {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-inline-start: auto;
}
.auth-link {
  font-size: .9rem;
  color: var(--ink-soft);
  text-decoration: none;
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}
.auth-link:hover { color: var(--accent-strong); }
.auth-link-primary {
  background: var(--accent);
  color: #fff;
  padding: 7px 16px;
  border-radius: 999px;
}
.auth-link-primary:hover { color: #fff; opacity: .9; }
.auth-user-name { font-size: .85rem; color: var(--ink-soft); padding: 0 10px; }
#admin-text-link { border-top: 1px solid var(--line); border-top-left-radius: 0; border-top-right-radius: 0; margin-top: 4px; padding-top: 10px; }
.auth-hello { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.auth-hello .auth-user-name { padding: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-logout { flex: none; font: inherit; font-size: .8rem; color: var(--ink-soft); background: none; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.auth-logout:hover { color: var(--accent-strong); border-color: currentColor; }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .9rem;
  color: var(--ink-soft);
}
.auth-form input {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--ink);
}
.auth-form select {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--ink);
}
.auth-form select:focus { outline: none; border-color: var(--accent); }
/* registration: what signing up gives, and two fields to a row from tablet width */
.auth-perks {
  background: var(--accent-faint);
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--accent);
  border-radius: 12px;
  padding: 14px 18px;
  margin: 4px 0 24px;
}
.auth-perks-title { font-family: var(--font-head); font-weight: 700; color: var(--accent-strong); margin: 0 0 6px; }
.auth-perks ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.auth-perks li { position: relative; padding-inline-start: 18px; color: var(--ink); }
.auth-perks li::before { content: ""; position: absolute; inset-inline-start: 2px; top: .7em; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.auth-row { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 560px) { .auth-row { grid-template-columns: 1fr 1fr; } }
.auth-note {
  background: var(--accent-faint);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin: -8px 0 22px;
  color: var(--ink);
  font-size: .95rem;
}
.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}
.auth-submit {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.auth-submit:hover { opacity: .9; }
.auth-submit:disabled { opacity: .6; cursor: default; }
.auth-error {
  color: #b23b2e;
  font-size: .88rem;
  margin: 0;
}
.auth-ok { color: #1a7d72; font-size: .88rem; margin: 0; font-weight: 600; }
/* the settings page: two forms, one under the other */
.auth-form + .auth-form { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }

/* ===== Hero ===== */
.hero {
  padding: 44px 0 30px;
  border-bottom: 1px solid var(--line);
}

.breadcrumbs {
  font-size: .85rem;
  color: var(--ink-soft);
  margin-bottom: 10px;
}
.breadcrumbs a { color: var(--ink-soft); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }

/* ===== Lesson cards (index) ===== */
.group-title-dropdown { margin: 0 0 10px; }
/* One bordered panel per page-group: the title bar spans its full width,
   and when open, the lessons sit inside that same frame below it -
   containment shows they belong to and open from this group. Works for
   any number of future groups (e.g. a second one for "עמוד ב"), each
   getting its own panel. */
.group-panel {
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elevated);
}
.group-title {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 0;
  padding: 14px 20px;
}
.group-title:hover { background: var(--accent-strong); }
/* "X מתוך Y הושלמו" - filled in by homepage-progress.js once a logged-in
   user's quiz answers are known. The auto margin hugs it (and the arrow
   after it) against the end, leaving the title text at the start,
   regardless of .group-title's own justify-content. */

.group-arrow { width: 18px; height: 18px; flex: none; transition: transform .2s ease; }
/* Closed groups point their arrow sideways instead of down, matching a
   typical accordion chevron. */
.group-title-dropdown:has(> .group-panel > .lessons-menu[hidden]) > .group-panel > .group-title .group-arrow { transform: rotate(-90deg); }
/* in a daf's panel: a part per amud, its title a light bar, its lessons below */
.amud-group + .amud-group { border-top: 1px solid var(--line); }
.amud-title { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px; font-family: var(--font-head); font-weight: 700; font-size: .98rem; color: var(--accent-strong); background: var(--accent-soft); border: none; padding: 10px 20px; cursor: pointer; }
.amud-title:hover { filter: brightness(.97); }
.amud-group:has(.amud-menu[hidden]) .group-arrow { transform: rotate(-90deg); }

.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
  padding: 12px;
}
.lesson-card {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform .15s ease, border-color .15s ease;
}
.lesson-card:hover { transform: translateY(-3px); filter: brightness(1.06); }
.lesson-card h3 { font-size: 1.15rem; }
.lesson-card p { margin: 0; color: var(--ink-soft); font-size: .92rem; }
.lesson-card .meta { font-size: .8rem; color: var(--ink-soft); }
/* Filled in by homepage-progress.js once a logged-in user has answered
   every quiz question in that lesson - same green already used for
   .nezek-done and a correct quiz choice, so "done" reads consistently. */

/* One color (the site's own accent brown) stepping gradually darker from
   the first lesson to the last, instead of a different hue per lesson -
   same card size and layout as before. */
.lesson-card:nth-child(6n+1) { background: #d9b8a3; border-color: #d9b8a3; }
.lesson-card:nth-child(6n+2) { background: #c08f6f; border-color: #c08f6f; }
.lesson-card:nth-child(6n+3) { background: #a5673f; border-color: #a5673f; }
.lesson-card:nth-child(6n+4) { background: var(--accent); border-color: var(--accent); }
.lesson-card:nth-child(6n+5) { background: var(--accent-strong); border-color: var(--accent-strong); }
.lesson-card:nth-child(6n+6) { background: #4f2a18; border-color: #4f2a18; }
.lesson-card:nth-child(6n+1) h3, .lesson-card:nth-child(6n+2) h3 { color: var(--ink); }
.lesson-card:nth-child(6n+3) h3, .lesson-card:nth-child(6n+4) h3,
.lesson-card:nth-child(6n+5) h3, .lesson-card:nth-child(6n+6) h3 { color: #fff; }

/* ===== Lesson page ===== */

.lesson-title {
  font-size: 1.15rem;
  margin: 0;
}

/* Headings sit on a full-width accent banner, like a chapter title in a
   colorful textbook, instead of the old bottom-border underline. The
   negative inline margin always escapes .intro-box's own side padding so
   the banner reaches the box's edges; a heading that opens the box (its
   literal first child) also escapes the top padding and picks up the
   box's own corner radius so the banner sits flush with it. */

/* Accordion sections for each Av Nezikin */

/* Media stacks under the text at every width, matching the text's own
   column instead of squeezing into a narrower side-by-side column. */

/* Media placeholder box: swap for a real <img>/<video> once assets are ready */

/* Text emphasis: content paragraphs sit on a tinted band that extends a
   little past the text on each side (equal negative margin + padding keep
   the text itself at the same position as every other paragraph) without
   reaching all the way to the card's own edge; introduction paragraphs
   stay in a muted ink tone. Neither uses bold weight. */

/* Scoped to .intro-box .p-strong (not just .p-strong) so this beats
   .intro-box p's margin: 0 0 10px on specificity (0,1,1 vs 0,1,0) -
   otherwise that rule silently zeroes this margin-inline back out while
   the padding above still applies, leaving the text pushed in with
   nothing pulling the box back out. */

/* Consecutive content paragraphs merge into one continuous band instead of
   showing a gap of page background between them. */

/* Headings no longer merge into the paragraph band below them - each now
   carries its own solid banner (see .intro-box h2/h3 above), which already
   reads as a clear division on its own. A paragraph right after a heading
   rounds its own top corner same as any other band start.
   Rounded corners on the band itself: only at its true start and end, not
   at every paragraph's edge, so consecutive .p-strong paragraphs still
   read as one continuous block rather than a stack of separate pills. A
   paragraph is "the start" when no .p-strong immediately precedes it; a
   paragraph is "the end" when no .p-strong immediately follows it. Either
   can be true alone (rounding just that side) or both at once (a lone
   paragraph with no neighbors, rounded on all four corners). */

/* ===== Score badge ===== */
/* An <a> to achievements.html (see homepage-progress note above), so it
   needs its own reset back to plain badge styling instead of a link's. */
.score-badge {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--accent-strong);
  background: var(--accent-soft);
  padding: 8px 12px;
  border-radius: 14px;
  min-width: 150px;
  text-decoration: none;
  cursor: pointer;
}
.score-badge:hover { opacity: .9; }
.score-badge-text { font-size: .85rem; }
.score-progress-track {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: var(--bg-elevated);
  overflow: hidden;
}
.score-progress-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--sun), var(--esh));
  transition: width .3s ease;
}
.score-badges { display: flex; gap: 5px; }
.score-badge-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 2px solid var(--line);
  flex: none;
}
.score-badge-dot.achieved { background: var(--esh); border-color: var(--esh); }

/* ===== Achievements page ===== */
.achv-total {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
  text-align: center;
  margin-bottom: 24px;
}
.achv-total-count { font-family: var(--font-head); font-size: 2.6rem; font-weight: 700; color: var(--accent-strong); }
.achv-total-label { color: var(--ink-soft); font-size: .95rem; margin: 2px 0 16px; }
.achv-track { height: 10px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; margin-bottom: 8px; }
.achv-track-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--sun), var(--esh));
  transition: width .3s ease;
}
.achv-next { font-size: .85rem; color: var(--ink-soft); }
.achv-milestones { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 18px; }

/* ===== Quiz ===== */
.quiz {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 16px 18px;
  margin: 18px 0;
}

@keyframes choice-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes confetti-fall {
  0% { opacity: 1; transform: translateY(0) rotate(0deg); }
  100% { opacity: 0; transform: translateY(150px) rotate(560deg); }
}

footer.site-footer {
  border-top: 1px solid var(--line);
  padding: 26px 0 50px;
  color: var(--ink-soft);
  font-size: .85rem;
  text-align: center;
}

.lesson-nav-btn {
  display: inline-block;
  font-family: inherit;
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  padding: 12px 28px;
  background: var(--accent);
  color: #fff;
  transition: opacity .15s ease, transform .15s ease;
  /* Asymmetric corners: round on the outer edge, square on the edge
     facing the other button, so the prev/next pair reads as one
     connected unit instead of two separate pills. This one (next, not
     --secondary) sits on the inline-end side of the pair. */
  border-radius: 0;
  border-start-end-radius: 999px;
  border-end-end-radius: 999px;
}
/* The site is RTL-only, so "next" (this button, not --secondary) always
   sits visually on the left and "prev" on the right - each nudges a
   little further the way it already points, on hover. */
.lesson-nav-btn:hover { opacity: .9; transform: translateX(-4px); }
/* A lone button (first/last lesson) has no partner to connect to, so it
   gets its full pill shape back. */

@media (prefers-reduced-motion: reduce) {
  .lesson-nav-btn:hover{ transform: none; }
}

.done-marks { color: var(--regel); font-weight: 700; }
/* a password typed into a plain text field (so the browser doesn't offer to save it), shown as dots */
.secret { -webkit-text-security: disc; text-security: disc; }

/* In the menu: a daf's list holds its amudim, each amud its lessons; the lessons close together */
.submenu-panel .submenu-panel { margin: 2px 0 4px; padding: 2px 0; border: 0; background: none; padding-inline-start: 10px; }
.submenu-panel .dropdown-item { padding: 5px 10px; line-height: 1.35; }
.submenu-panel .submenu-trigger { padding: 6px 10px; }
.submenu-panel { gap: 0; }

/* Every row of the menu, at every level (page, amud, lesson), starts and ends the same distance
   from the edge, like the page's own margins; the lists don't sit in boxes of their own. The
   levels are told apart by weight, not by indent. */
.brand-menu { padding-inline: 0; }
.brand-menu .submenu-panel, .brand-menu .submenu-panel .submenu-panel { margin: 0; padding: 0; border: 0; border-radius: 0; background: none; }
.brand-menu .dropdown-item, .brand-menu .submenu-trigger, .brand-menu .submenu-panel .dropdown-item, .brand-menu .submenu-panel .submenu-trigger { padding-inline: 16px; border-radius: 0; }
.brand-menu .auth-area { padding-inline: 16px; }
.brand-menu > .submenu > .submenu-trigger, .brand-menu > .tlist > .submenu > .submenu-trigger { font-weight: 700; }
.brand-menu .submenu-panel .submenu-trigger { font-weight: 600; }
/* a line between "עריכה" and "ניהול" */
#admin-page-link { border-top: 1px solid var(--line); border-radius: 0; margin-top: 4px; padding-top: 10px; }
