/* Shared components — the web counterparts of UI/Components.swift. */

/* ---------- page frame ---------- */

.wrap {
  max-width: var(--reading-width);
  margin: 0 auto;
  padding: 0 var(--space-4) var(--space-6);
}

.site-header {
  max-width: var(--reading-width);
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.site-header .mark {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 65%, #000));
  display: grid;
  place-items: center;
}

.site-header h1 {
  font-size: 1.15rem;
  margin: 0;
  line-height: 1.3;
}

.site-header .sub {
  margin: 2px 0 0;
  font-size: 0.92rem;
  color: var(--text-dim);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: var(--reading-width);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar .back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 700;
}

.topbar .crumb {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-inline-start: auto;
}

/* ---------- home: chapters and tiles ---------- */

.unit-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  margin: var(--space-5) 0 var(--space-2);
}

.chapter-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-dim);
  margin: var(--space-5) 0 var(--space-3);
}

.tile-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

@media (min-width: 460px) { .tile-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .tile-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .tile-grid { grid-template-columns: repeat(4, 1fr); } }

/* ---------- home: everything centred ---------- */

/* The header stacks logo, title and subtitle on the page axis; the theme
   toggle leaves the flex flow and pins to the visual left corner. */
.home .site-header {
  position: relative;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: var(--space-2);
  padding-inline: 64px; /* keep the title clear of the pinned toggle */
}

.home .site-header .mark { margin-bottom: var(--space-1); }

.home .theme-toggle {
  position: absolute;
  inset-block-start: var(--space-5);
  inset-inline-end: var(--space-4);
  margin: 0;
}

.home .unit-title,
.home .chapter-title { text-align: center; }

/* Flex instead of grid so a short last row (2 or 3 tiles) is centred too. */
.home .tile-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.home .tile { width: 100%; }
@media (min-width: 460px) { .home .tile { width: calc(50% - var(--space-4) / 2); } }
@media (min-width: 900px) { .home .tile { width: 270px; } }

.home .tile-body { text-align: center; }

/* Desktop gets a wider canvas for the grid than for reading prose. */
@media (min-width: 900px) {
  .home .wrap,
  .home .site-header { max-width: 1180px; }
}

.tile {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-tile);
  overflow: hidden;
  box-shadow: var(--shadow-tile);
  transition: transform 0.18s ease;
}

.tile:hover { transform: translateY(-2px); }
.tile:active { transform: scale(0.985); }

.tile-art {
  position: relative;
  height: 118px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.tile-art .blob {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}

.tile-art .blob-a { width: 150px; height: 150px; inset-block-start: 58px; inset-inline-start: -46px; }
.tile-art .blob-b { width: 90px; height: 90px; inset-block-start: -42px; inset-inline-end: -18px; background: rgba(255, 255, 255, 0.10); }

.tile-art svg { position: relative; width: 56px; height: 56px; color: #fff; filter: drop-shadow(0 3px 6px rgba(0,0,0,0.22)); }

.tile-num {
  position: absolute;
  inset-block-start: 10px;
  inset-inline-end: 10px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.tile-body { padding: var(--space-3); }
.tile-body h3 { margin: 0 0 6px; font-size: 0.98rem; line-height: 1.4; }
.tile-body p { margin: 0; font-size: 0.85rem; color: var(--text-dim); line-height: 1.55; }

/* ---------- part chooser ---------- */

.lesson-head {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
  padding: var(--space-5) 0 var(--space-2);
}

.lesson-head .badge {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: 18px;
  display: grid;
  place-items: center;
}

.lesson-head .badge svg { width: 30px; height: 30px; color: #fff; }
.lesson-head h2 { margin: 0; font-size: 1.4rem; line-height: 1.35; }
.lesson-head p { margin: 4px 0 0; color: var(--text-dim); font-size: 0.95rem; }
.lesson-head .eyebrow { font-size: 0.8rem; font-weight: 700; margin: 0 0 2px; }

.chooser-hint { color: var(--text-dim); font-size: 0.95rem; margin: var(--space-4) 0 var(--space-3); }

.part-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--surface);
  border-radius: var(--radius-tile);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-card);
  transition: transform 0.18s ease;
}

.part-card:hover { transform: translateY(-2px); }
.part-card .icon { width: 58px; height: 58px; flex: none; border-radius: 16px; display: grid; place-items: center; }
.part-card .icon svg { width: 26px; height: 26px; color: #fff; }
.part-card .label { font-size: 0.8rem; font-weight: 700; }
.part-card h3 { margin: 2px 0 4px; font-size: 1.05rem; }
.part-card p { margin: 0; font-size: 0.86rem; color: var(--text-dim); line-height: 1.5; }
.part-card .chev { margin-inline-start: auto; color: var(--text-faint); flex: none; }

/* ---------- blocks ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 18px;
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-card);
}

.section-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 1.18rem;
  font-weight: 700;
  margin: var(--space-5) 0 var(--space-3);
}

.section-title svg { width: 20px; height: 20px; color: var(--text-dim); flex: none; }

.info-card h3 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-2);
  font-size: 1.02rem;
}

.info-card h3 svg { width: 20px; height: 20px; flex: none; }
.info-card p { margin: 0; color: var(--text-dim); font-size: 0.96rem; line-height: 1.7; }

/* terms */
.term {
  width: 100%;
  text-align: start;
  background: var(--accent-soft);
  border: 0;
  border-radius: 11px;
  padding: 10px 12px;
  margin-bottom: var(--space-2);
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: block;
}

.term-head { display: flex; align-items: center; gap: var(--space-2); font-weight: 700; font-size: 0.95rem; }
.term-head .chev { margin-inline-start: auto; color: var(--text-dim); transition: transform 0.2s ease; }
.term[aria-expanded="true"] .term-head .chev { transform: rotate(180deg); }
.term-body { margin: 8px 0 0; font-size: 0.9rem; color: var(--text-dim); line-height: 1.65; }

/* formulas */
.formula { margin-bottom: var(--space-4); }
.formula:last-child { margin-bottom: 0; }
.formula .expr {
  display: inline-block;
  background: var(--accent-soft);
  border-radius: var(--radius-inner);
  padding: 8px 14px;
  font-size: 1.15rem;
  font-style: italic;
  font-weight: 600;
}
.formula .meaning { margin: 6px 0 0; font-size: 0.92rem; color: var(--text-dim); }

/* comparison table */
.cmp { width: 100%; border-collapse: separate; border-spacing: 1px; background: var(--border); border-radius: var(--radius-inner); overflow: hidden; }
.cmp th, .cmp td { padding: 9px 6px; font-size: 0.8rem; text-align: center; line-height: 1.5; }
.cmp th { font-weight: 700; }
.cmp .aspect { width: 84px; background: var(--surface-sunken); font-weight: 700; }

/* quiz */
.quiz h3 { display: flex; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-3); font-size: 1.05rem; }
.quiz h3 svg { width: 20px; height: 20px; color: var(--accent); }
.quiz .counter { margin-inline-start: auto; font-size: 0.82rem; color: var(--text-dim); }
.quiz .prompt { font-weight: 600; margin: 0 0 var(--space-3); line-height: 1.7; }

.choice {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  text-align: start;
  font: inherit;
  color: inherit;
  background: var(--accent-soft);
  border: 1.5px solid transparent;
  border-radius: var(--radius-inner);
  padding: 12px;
  margin-bottom: var(--space-2);
  cursor: pointer;
}

.choice:disabled { cursor: default; }
.choice .mark { margin-inline-start: auto; flex: none; }
.choice.correct { background: var(--green-soft); border-color: var(--green); }
.choice.wrong { background: var(--red-soft); border-color: var(--red); }
.choice.dim { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }

.explanation { font-size: 0.9rem; color: var(--text-dim); line-height: 1.7; margin: var(--space-2) 0 var(--space-3); }

.quiz-result { text-align: center; padding: var(--space-4) 0; }
.quiz-result .score { font-size: 1.25rem; font-weight: 700; margin: var(--space-2) 0 var(--space-3); }

/* ---------- tools ---------- */

.tool h3 { display: flex; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-2); font-size: 1.05rem; }
.tool h3 svg { width: 20px; height: 20px; color: var(--accent); flex: none; }
.tool .hint { margin: 0 0 var(--space-4); font-size: 0.93rem; color: var(--text-dim); line-height: 1.65; }

.tool canvas { display: block; width: 100%; }

.slider-row { margin-bottom: var(--space-4); }
.slider-label { display: flex; align-items: baseline; gap: var(--space-2); margin-bottom: 6px; font-size: 0.95rem; font-weight: 500; }
.slider-value { margin-inline-start: auto; font-weight: 700; }

input[type="range"] {
  width: 100%;
  direction: ltr;
  accent-color: var(--accent);
  height: 28px;
}

.results { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }

.result {
  flex: 1 1 140px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--accent-soft);
  border-radius: var(--radius-inner);
  padding: 8px 14px;
  font-size: 0.92rem;
}

.result .result-value { margin-inline-start: auto; font-weight: 700; white-space: nowrap; }

.btn-row { display: flex; gap: var(--space-3); margin-bottom: var(--space-4); }

.btn {
  flex: 1;
  font: inherit;
  font-weight: 600;
  padding: 11px 16px;
  border-radius: var(--radius-inner);
  border: 1.5px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

.note { font-size: 0.88rem; color: var(--text-dim); line-height: 1.65; margin: 0; }

.feedback {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  border-radius: var(--radius-inner);
  padding: 10px;
  margin-bottom: var(--space-3);
  font-size: 0.9rem;
  line-height: 1.6;
}

.feedback svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.feedback.ok { background: var(--green-soft); }
.feedback.ok svg { color: var(--green); }
.feedback.bad { background: var(--red-soft); }
.feedback.bad svg { color: var(--red); }


/* ---------- theme toggle ---------- */

/* Sits at the visual left of the header: in RTL the inline end is the left side. */
.theme-toggle {
  margin-inline-start: auto;
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
}

.theme-toggle:hover { color: var(--text); }
.theme-toggle svg { width: 20px; height: 20px; }

/* `_{…}` subscripts (A_{x}, v_{0x}) — keep line height steady */
sub { font-size: .72em; line-height: 0; vertical-align: -.28em; }

/* Latin maths inside Arabic prose: one left-to-right island that only breaks between steps */
.math { unicode-bidi: isolate; direction: ltr; }
.math-step { white-space: nowrap; }
