/* Branch / map lessons — use with reader.css + body.reader.branch-lesson */

body.reader.branch-lesson {
  height: auto;
  min-height: 100dvh;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
}

body.reader.branch-lesson .reader-progress {
  display: none;
}

body.reader.branch-lesson .reader-flow {
  flex: 1 1 auto;
  min-height: 0;
  overflow: visible;
}

body.reader.branch-lesson .reader-article {
  flex: 0 0 auto;
  overflow: visible;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}

body.reader.branch-lesson .reader-article-stack {
  flex: 0 0 auto;
  overflow: visible;
}

.branch-wrap {
  width: 100%;
  max-width: none;
}

.branch-board {
  margin-top: clamp(6px, 1vh, 12px);
  padding: clamp(14px, 2.5vw, 22px) var(--reader-inset);
  background-color: var(--paper-cream);
  background-image:
    linear-gradient(rgba(165, 148, 130, 0.11) 1px, transparent 1px),
    linear-gradient(90deg, rgba(165, 148, 130, 0.11) 1px, transparent 1px);
  background-size: 20px 20px;
  background-position: -1px -1px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.branch-tag {
  margin: 0 0 10px;
  padding: 4px 10px;
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.45);
}

.branch-tag[dir="rtl"] {
  font-family: "Tajawal", system-ui, sans-serif;
  text-transform: none;
  letter-spacing: 0.02em;
}

/* “Lazy student” strip: one copy-paste skeleton + level */
.branch-lazy-bar {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px dashed rgba(15, 118, 110, 0.45);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(240, 253, 250, 0.65));
  box-shadow: 0 2px 10px rgba(44, 40, 37, 0.04);
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.branch-lazy-bar__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  width: 100%;
}

.branch-lazy-bar__level {
  flex-shrink: 0;
  padding: 3px 10px;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
}

.branch-lazy-bar__level--1 {
  background: linear-gradient(90deg, #0f766e, #14b8a6);
}

.branch-lazy-bar__level--2 {
  background: linear-gradient(90deg, #b45309, var(--gold));
  color: #1a2233;
}

.branch-lazy-bar__level--3 {
  background: linear-gradient(90deg, #6b4c7a, #7c3aed);
}

.branch-lazy-bar__skel {
  margin: 0;
  flex: 1 1 12rem;
  font-family: var(--font-ui);
  font-size: clamp(0.78rem, 1.35vw, 0.88rem);
  font-weight: 600;
  line-height: 1.45;
  color: var(--ink);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}

.branch-skel-chunk {
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.branch-skel-slot {
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(224, 122, 95, 0.14);
  border: 1px dashed rgba(180, 35, 24, 0.4);
  font-weight: 700;
  color: #9a3412;
  white-space: nowrap;
}

.branch-skel-op {
  opacity: 0.4;
  font-weight: 800;
  user-select: none;
}

.branch-lazy-bar__ar {
  margin: 8px 0 0;
  padding: 0;
  font-family: "Tajawal", system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.55;
  color: #7c2d12;
  direction: rtl;
  text-align: right;
  unicode-bidi: isolate;
  width: 100%;
  box-sizing: border-box;
}

/* Latin tokens inside Arabic strip (have/has, can, etc.) — keeps order readable */
.branch-lazy-bar__ar [dir="ltr"],
.branch-lazy-bar__lat {
  unicode-bidi: isolate;
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.branch-diagram {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin-bottom: clamp(18px, 3vw, 26px);
}

.branch-tier {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(8px, 2vw, 14px);
  width: 100%;
}

.branch-tier--verbs {
  max-width: 52rem;
}

.branch-tier--split {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: clamp(8px, 2vw, 16px);
  width: 100%;
  max-width: 56rem;
}

@media (max-width: 700px) {
  .branch-tier--split {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .branch-brace-note {
    order: 3;
    max-width: 100%;
  }
}

.branch-connector {
  width: 2px;
  height: clamp(10px, 1.5vh, 16px);
  background: linear-gradient(180deg, var(--pop), rgba(180, 150, 130, 0.45));
  border-radius: 1px;
  margin: 2px 0;
}

.branch-connector--short {
  height: 8px;
}

.branch-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px 12px;
  min-width: 4.5rem;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(44, 40, 37, 0.05);
}

.branch-node--root {
  padding: 10px 20px;
  border-width: 2px;
  border-color: rgba(180, 35, 24, 0.35);
}

.branch-en {
  font-family: var(--font-reading);
  font-size: clamp(0.95rem, 1.8vw, 1.1rem);
  font-weight: 600;
  font-optical-sizing: auto;
  color: var(--ink);
  line-height: 1.2;
}

.branch-node--root .branch-en {
  font-size: clamp(1.15rem, 2.4vw, 1.45rem);
}

.branch-ar {
  margin-top: 4px;
  font-family: "Tajawal", system-ui, sans-serif;
  font-size: clamp(0.78rem, 1.5vw, 0.9rem);
  font-weight: 600;
  line-height: 1.25;
  color: #b42318;
}

.branch-to {
  margin: 6px 0;
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid var(--accent);
  border-radius: 999px;
}

.branch-to .branch-en {
  font-variant: small-caps;
  letter-spacing: 0.04em;
}

.branch-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.branch-col__head .branch-en {
  font-size: 1.05rem;
}

/* One row: several items in separate compact boxes (saves vertical space) */
.branch-box-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: 6px 8px;
  width: 100%;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.branch-box {
  flex: 1 1 auto;
  min-width: 5.25rem;
  max-width: 16rem;
  padding: 6px 10px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(44, 40, 37, 0.05);
}

.branch-box .branch-en {
  font-size: clamp(0.78rem, 1.45vw, 0.92rem);
  line-height: 1.2;
}

.branch-box .branch-ar {
  margin-top: 0;
  font-size: clamp(0.68rem, 1.25vw, 0.8rem);
  line-height: 1.2;
}

.branch-col .branch-box-row {
  max-width: 100%;
}

.branch-list {
  margin: 0;
  padding: 10px 14px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: min(100%, 11rem);
}

.branch-list li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(226, 212, 194, 0.9);
}

.branch-list li:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.branch-brace-note {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  align-self: center;
  text-align: center;
}

.branch-brace-note .branch-node {
  min-width: auto;
  padding: 6px 10px;
}

/* Vocab block */
.branch-vocab {
  margin-top: 8px;
  padding-top: clamp(14px, 2vw, 20px);
  border-top: 2px solid rgba(180, 35, 24, 0.2);
}

.branch-vocab__title {
  margin: 0 0 10px;
  font-family: "Tajawal", system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
}

.branch-vocab__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 10.5rem), 1fr));
  gap: 8px 14px;
}

.branch-vocab__row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  border: 1px solid var(--line);
}

.branch-vocab__row .branch-en {
  font-weight: 600;
  font-size: 0.88rem;
}

.branch-vocab__row .branch-ar {
  margin-top: 0;
  font-size: 0.82rem;
}

.branch-vocab__sep {
  opacity: 0.45;
  font-weight: 400;
}

/* Exercise */
.branch-exercise {
  margin-top: clamp(16px, 2.5vw, 22px);
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.5);
  border: 2px solid var(--line);
  border-radius: 12px;
}

.branch-exercise__title {
  margin: 0 0 12px;
  font-family: "Tajawal", system-ui, sans-serif;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
}

.branch-exercise__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.branch-exercise__list > li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 14px;
  align-items: start;
  padding: 10px 12px;
  background: rgba(252, 249, 242, 0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.branch-exercise__num {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--pop);
  line-height: 1.4;
}

.branch-exercise__body {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
}

.branch-exercise__i {
  font-family: var(--font-ui);
  font-weight: 800;
  color: var(--ink);
  min-width: 1.25rem;
}

.branch-exercise__ar {
  font-family: "Tajawal", system-ui, sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.5;
  color: #9a3412;
}

.branch-exercise__hint {
  flex-basis: 100%;
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--ink-soft);
  font-family: var(--font-ui);
}

body.branch-focus-mode .reader-eyebrow,
body.branch-focus-mode .reader-eyebrow-ar,
body.branch-focus-mode .reader-lede,
body.branch-focus-mode .reader-logo-ar {
  display: none;
}

body.branch-focus-mode .reader-h1 {
  font-size: clamp(1.2rem, 3vw, 1.45rem);
}

body.branch-focus-mode .reader-h1-ar {
  font-size: clamp(0.95rem, 2.2vw, 1.05rem);
}
