/* ============================================================
   Components — glass surfaces, buttons, progress, chips, header
   Glass is used to build HIERARCHY, not as wallpaper. Ordinary
   flat surfaces carry most of the reading.
   ============================================================ */

/* ---- Glass surfaces ------------------------------------------------ */
.glass {
  position: relative;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.5);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.5);
  border: 1px solid var(--glass-line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2), inset 0 1px 0 rgba(255,255,255,.85);
}
/* The specular seam along the top edge — what sells "glass". */
.glass::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(175deg, rgba(255,255,255,.55) 0%, rgba(255,255,255,0) 42%);
}
.glass-soft { background: var(--glass-bg-soft); box-shadow: var(--sh-1), inset 0 1px 0 rgba(255,255,255,.7); }
.glass-deep { background: var(--glass-bg-deep); box-shadow: var(--sh-3), inset 0 1px 0 rgba(255,255,255,.9); }
.glass-flat { /* opaque sibling: same shape, no blur cost, for long text */
  background: rgba(255,255,255,.86);
  border: 1px solid var(--glass-edge);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass, .glass-soft, .glass-deep { background: rgba(255,255,255,.90); }
}

.pad   { padding: clamp(var(--s4), 3vw, var(--s6)); }
.pad-s { padding: var(--s4); }
.pad-l { padding: clamp(var(--s5), 4vw, var(--s8)); }

/* ---- Buttons ------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s2);
  min-height: 46px; padding: 0 var(--s5);
  font-family: var(--font-display); font-size: var(--t-md); font-weight: 800;
  color: var(--ink-800); text-decoration: none;
  background: rgba(255,255,255,.72);
  border: 1px solid var(--glass-edge);
  border-radius: var(--r-pill);
  box-shadow: var(--sh-1);
  cursor: pointer;
  transition: transform var(--d-fast) var(--e-spring),
              box-shadow var(--d-fast) var(--e-out),
              background var(--d-fast) var(--e-out);
}
.btn:hover  { transform: translateY(-1px); box-shadow: var(--sh-2); }
.btn:active { transform: translateY(1px) scale(.985); }
.btn[disabled], .btn[aria-disabled="true"] {
  opacity: .48; cursor: not-allowed; transform: none; box-shadow: var(--sh-1);
}

.btn-primary {
  color: #fff; border-color: transparent;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  box-shadow: var(--sh-2), var(--sh-glow), inset 0 1px 0 rgba(255,255,255,.34);
}
.btn-primary:hover { box-shadow: var(--sh-3), var(--sh-glow), inset 0 1px 0 rgba(255,255,255,.34); }

.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--ink-700); }
.btn-ghost:hover { background: rgba(255,255,255,.6); box-shadow: var(--sh-1); }

.btn-lg { min-height: 58px; padding: 0 var(--s6); font-size: var(--t-lg); }
.btn-sm { min-height: 38px; padding: 0 var(--s4); font-size: var(--t-sm); }
.btn-block { display: flex; width: 100%; }
.btn-icon { min-height: 42px; width: 42px; padding: 0; border-radius: 50%; }

/* ---- Chips & badges ------------------------------------------------ */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--r-pill);
  font-family: var(--font-display); font-weight: 800; font-size: var(--t-xs);
  background: var(--accent-wash); color: var(--accent-ink);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
  white-space: nowrap;
}
.chip-plain { background: rgba(255,255,255,.7); color: var(--ink-700); border-color: var(--glass-edge); }
.chip-ok   { background: var(--ok-soft);   color: #0a6a48; border-color: var(--ok-line); }
.chip-warn { background: var(--warn-soft); color: #7a4a03; border-color: var(--warn-line); }
.chip-bad  { background: var(--bad-soft);  color: #8f1730; border-color: var(--bad-line); }

/* ---- Progress bar (honest: always paired with "n of m" text) ------- */
.bar {
  height: 8px; border-radius: var(--r-pill);
  background: rgba(23,20,60,.09);
  overflow: hidden;
}
.bar > span {
  display: block; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width var(--d-slow) var(--e-out);
  box-shadow: 0 0 12px var(--accent-wash);
}
.bar-thin { height: 5px; }

/* ---- Mastery ring -------------------------------------------------- */
.ring { display: block; }
.ring circle { fill: none; stroke-linecap: round; }
.ring .ring-track { stroke: rgba(23,20,60,.10); }
.ring .ring-fill {
  stroke: url(#ringGrad);
  transition: stroke-dashoffset var(--d-slow) var(--e-out);
  transform: rotate(-90deg); transform-origin: 50% 50%;
}
.ring-wrap { position: relative; display: inline-grid; place-items: center; }
.ring-wrap > .ring-label {
  position: absolute; text-align: center; line-height: 1.05;
  font-family: var(--font-display); font-weight: 800; color: var(--ink-900);
}

/* ---- Illustration frame ------------------------------------------- */
/* The frame is only created when real artwork exists for the slug — see
   src/ui/illustration.js. Nothing here should ever be visible on its own. */
.illus {
  position: relative; display: block; width: 100%;
  border-radius: var(--r-md);
  overflow: hidden;
  background: rgba(255,255,255,.5);
  border: 1px solid var(--glass-line);
}
.illus img { display: block; width: 100%; height: 100%; object-fit: contain; }
.illus[data-orient="landscape"] { aspect-ratio: 16 / 9; }
.illus[data-orient="portrait"]  { aspect-ratio: 3 / 4; max-width: 320px; }
.illus[data-orient="square"]    { aspect-ratio: 1 / 1; }
.illus[data-orient="wide"]      { aspect-ratio: 21 / 9; }
.illus[data-orient="spot"]      { aspect-ratio: 1 / 1; max-width: 132px; }

/* A quiet tint while the real file is in flight. It carries no text: a
   learner must never be shown a developer filename or an art brief. */
.illus-ph {
  position: absolute; inset: 0; z-index: 0;
  background:
    radial-gradient(120% 90% at 20% 0%, color-mix(in srgb, var(--accent) 12%, transparent) 0%, transparent 60%),
    radial-gradient(110% 80% at 90% 100%, color-mix(in srgb, var(--accent-2) 14%, transparent) 0%, transparent 62%),
    rgba(255,255,255,.45);
  transition: opacity var(--d-mid, .28s) ease;
}
.illus.is-loaded .illus-ph { opacity: 0; }

/* Real art always sits above the loading tint. */
.illus .illus-primary { position: relative; z-index: 1; }

/* A block whose slug has no artwork renders nothing at all. */
.illus-omitted { display: none !important; }

.illus-cap { font-size: var(--t-sm); color: var(--ink-600); margin-top: var(--s2); }

/* ---- App header (floating, compact) -------------------------------- */
.appbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 clamp(var(--s3), 3vw, var(--s5));
  background: rgba(255,255,255,.66);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  backdrop-filter: blur(18px) saturate(1.6);
  border-bottom: 1px solid var(--glass-line);
}
.appbar .brand {
  display: flex; align-items: center; gap: var(--s2);
  font-family: var(--font-display); font-weight: 800; font-size: var(--t-md);
  color: var(--ink-900); text-decoration: none; letter-spacing: -.02em;
  flex: none;
}

/* On a narrow phone the bar has room for the mark, the flame and one link.
   The wordmark and the flame's caption are the first things to go. */
@media (max-width: 460px) {
  .appbar { gap: var(--s2); padding-inline: var(--s3); }
  .appbar .brand span:not(.brand-mark) { display: none; }
  .flame { padding: 6px 8px; }
  .flame > span:not(.fl-glyph) { display: none; }
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 10px; flex: none;
  background: linear-gradient(140deg, var(--c-electric), var(--c-violet) 45%, var(--c-pink));
  box-shadow: 0 3px 10px rgba(80,60,220,.30), inset 0 1px 0 rgba(255,255,255,.6);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px 6px;
  border-radius: 3px;
  background: linear-gradient(180deg, transparent 0 32%, #fff 32% 46%, transparent 46% 60%, #fff 60% 74%, transparent 74%);
  opacity: .92;
}

/* ---- Lesson header: never eats vertical space ---------------------- */
.lessonbar {
  position: sticky; top: 0; z-index: 60;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: var(--s3);
  padding: var(--s2) clamp(var(--s3), 3vw, var(--s5)) var(--s3);
  background: rgba(255,255,255,.72);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  backdrop-filter: blur(18px) saturate(1.6);
  border-bottom: 1px solid var(--glass-line);
}
.lessonbar .lb-title {
  font-family: var(--font-display); font-weight: 800; font-size: var(--t-sm);
  color: var(--ink-800); line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lessonbar .lb-sub { font-size: var(--t-xs); color: var(--ink-600); }
.lessonbar .bar { margin-top: 5px; }
.lessonbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: .5;
}
.lessonbar { position: sticky; }

/* ---- Toast (used sparingly — no modal interruptions mid-lesson) ---- */
.toast-host {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 200; display: grid; gap: var(--s2); pointer-events: none;
  width: min(94vw, 440px);
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  background: rgba(255,255,255,.90);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--glass-line);
  box-shadow: var(--sh-3);
  font-weight: 700; font-size: var(--t-sm);
  animation: toast-in var(--d-med) var(--e-spring);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }
.toast.is-out { animation: toast-out var(--d-med) var(--e-out) forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(.97); } }
.toast .t-emoji { font-size: 1.3rem; flex: none; }

/* ---- Segmented control -------------------------------------------- */
/* Shrink-to-fit, but never wider than its column: on a phone the five
   toolkit filters are wider than the screen, so they scroll inside the pill
   instead of pushing the whole page sideways. */
.seg {
  display: flex; padding: 4px; gap: 2px;
  width: max-content; max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
  background: rgba(23,20,60,.06); border-radius: var(--r-pill);
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: none; white-space: nowrap;
  border: 0; background: transparent; cursor: pointer;
  font-family: var(--font-display); font-weight: 800; font-size: var(--t-sm);
  color: var(--ink-600); padding: 8px 16px; border-radius: var(--r-pill);
  min-height: 38px;
  transition: background var(--d-fast) var(--e-out), color var(--d-fast) var(--e-out);
}
.seg button[aria-selected="true"] {
  background: var(--white); color: var(--ink-900); box-shadow: var(--sh-1);
}

/* ---- Divider ---- */
.rule { height: 1px; background: var(--glass-edge); border: 0; margin: var(--s5) 0; }

/* ---- Inline SVG icons ---- */
.ico { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ico svg { display: block; }
.btn .ico, .audiobtn .ico { margin-right: -2px; }
.ms .ico-lock { color: var(--ink-400); vertical-align: -2px; margin-left: 4px; }
