/* ============================================================
   LGS-Akademie · Design-System
   ============================================================ */

@layer tokens, base, layout, components, views, utilities;

@layer tokens {
  :root {
    --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;

    --radius-xs: 8px;
    --radius-sm: 12px;
    --radius: 18px;
    --radius-lg: 26px;
    --radius-pill: 999px;

    --ease: cubic-bezier(.22, 1, .36, 1);
    --ease-out: cubic-bezier(.16, 1, .3, 1);
    --dur: .32s;

    --c-primary: #6c8cff;
    --c-primary-strong: #4f6dff;
    --c-violet: #a07bff;
    --c-mint: #2ee6a8;
    --c-amber: #ffc45c;
    --c-rose: #ff6b8a;
    --c-cyan: #38d9ff;

    --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;
    --sp-4: 16px; --sp-5: 22px; --sp-6: 30px; --sp-7: 44px;

    --shadow-sm: 0 1px 2px rgba(8, 12, 28, .28);
    --shadow: 0 10px 30px -12px rgba(8, 12, 28, .55);
    --shadow-lg: 0 30px 70px -30px rgba(8, 12, 28, .75);
    --ring: 0 0 0 3px color-mix(in srgb, var(--c-primary) 38%, transparent);

    --topbar-h: 62px;
    --sidebar-w: 264px;
    --tabbar-h: 68px;
    --maxw: 1120px;
  }

  html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #080c18;
    --bg-2: #0d1425;
    --bg-glow-1: rgba(108, 140, 255, .20);
    --bg-glow-2: rgba(160, 123, 255, .16);
    --surface: rgba(20, 28, 48, .82);
    --surface-solid: #141c30;
    --surface-2: rgba(31, 42, 68, .72);
    --surface-3: #1b2440;
    --line: rgba(148, 170, 220, .14);
    --line-strong: rgba(148, 170, 220, .28);
    --text: #eaf0ff;
    --text-soft: #b9c6e4;
    --text-dim: #8695b8;
    --ok: #34e0a1;
    --ok-bg: rgba(52, 224, 161, .12);
    --bad: #ff7d96;
    --bad-bg: rgba(255, 125, 150, .12);
    --warn-bg: rgba(255, 196, 92, .13);
    --code-bg: rgba(10, 16, 32, .7);
    --grid-line: rgba(148, 170, 220, .12);
    --grid-line-strong: rgba(148, 170, 220, .3);
  }

  html[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f7ff;
    --bg-2: #eef3ff;
    --bg-glow-1: rgba(108, 140, 255, .22);
    --bg-glow-2: rgba(160, 123, 255, .16);
    --surface: rgba(255, 255, 255, .9);
    --surface-solid: #ffffff;
    --surface-2: #f2f6ff;
    --surface-3: #e9effc;
    --line: rgba(24, 44, 92, .1);
    --line-strong: rgba(24, 44, 92, .2);
    --text: #0f1b34;
    --text-soft: #3f4f70;
    --text-dim: #6b7b9c;
    --ok: #10a774;
    --ok-bg: rgba(16, 167, 116, .1);
    --bad: #d93b5c;
    --bad-bg: rgba(217, 59, 92, .09);
    --warn-bg: rgba(214, 150, 20, .12);
    --code-bg: rgba(240, 245, 255, .95);
    --grid-line: rgba(24, 44, 92, .1);
    --grid-line-strong: rgba(24, 44, 92, .24);
    --shadow: 0 12px 30px -16px rgba(28, 46, 92, .35);
    --shadow-lg: 0 30px 60px -34px rgba(28, 46, 92, .4);
    --c-primary: #4a68f5;
    --c-primary-strong: #3552e0;
  }
}

@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
  body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    background-image:
      radial-gradient(900px 600px at 8% -8%, var(--bg-glow-1), transparent 60%),
      radial-gradient(800px 520px at 100% 0%, var(--bg-glow-2), transparent 55%),
      linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 60%, var(--bg) 100%);
    background-attachment: fixed;
    line-height: 1.62;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    overflow-x: hidden;
  }
  h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.015em; font-weight: 750; }
  h1 { font-size: clamp(1.72rem, 1.2rem + 2vw, 2.7rem); letter-spacing: -.03em; }
  h2 { font-size: clamp(1.32rem, 1.05rem + 1vw, 1.85rem); }
  h3 { font-size: clamp(1.08rem, 1rem + .4vw, 1.28rem); }
  p { margin: 0 0 .85em; color: var(--text-soft); }
  a { color: var(--c-primary); text-decoration: none; }
  a:hover { text-decoration: underline; }
  strong, b { color: var(--text); font-weight: 700; }
  ul, ol { margin: 0 0 1em; padding-left: 1.25em; color: var(--text-soft); }
  li { margin-bottom: .35em; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }
  svg { display: block; }
  ::selection { background: color-mix(in srgb, var(--c-primary) 40%, transparent); }
  :focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; border-radius: 6px; }
  .skip-link {
    position: fixed; left: 12px; top: -60px; z-index: 999;
    background: var(--surface-solid); padding: 10px 16px; border-radius: var(--radius-sm);
    transition: top .2s var(--ease);
  }
  .skip-link:focus { top: 12px; }
}

@layer layout {
  .topbar {
    position: sticky; top: 0; z-index: 40;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: var(--sp-3);
    padding: 0 var(--sp-4);
    background: color-mix(in srgb, var(--bg) 78%, transparent);
    backdrop-filter: blur(18px) saturate(140%);
    border-bottom: 1px solid var(--line);
  }
  .brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
  .brand:hover { text-decoration: none; }
  .brand-mark {
    width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center;
    color: #fff; background: linear-gradient(140deg, var(--c-primary), var(--c-violet));
    box-shadow: 0 8px 22px -8px var(--c-primary-strong);
  }
  .brand-mark svg { width: 22px; height: 22px; }
  .brand-text { font-weight: 800; letter-spacing: -.02em; font-size: 1.05rem; }
  .brand-text span { color: var(--text-dim); font-weight: 600; }
  .topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

  .pill {
    display: inline-flex; align-items: center; gap: 6px;
    height: 36px; padding: 0 12px;
    border-radius: var(--radius-pill);
    background: var(--surface-2); border: 1px solid var(--line);
    font-weight: 700; font-size: .86rem; color: var(--text);
    white-space: nowrap;
  }
  .pill-label { color: var(--text-dim); font-weight: 600; font-size: .78rem; }
  .pill.xp { background: linear-gradient(120deg, color-mix(in srgb, var(--c-amber) 18%, transparent), color-mix(in srgb, var(--c-violet) 16%, transparent)); border-color: color-mix(in srgb, var(--c-amber) 30%, transparent); }
  .lvl { font-size: .72rem; padding: 2px 7px; border-radius: 999px; background: color-mix(in srgb, var(--c-violet) 26%, transparent); }
  .icon-btn {
    width: 40px; height: 40px; display: grid; place-items: center;
    border-radius: 12px; border: 1px solid var(--line);
    background: var(--surface-2); color: var(--text);
    transition: transform .2s var(--ease), background .2s;
  }
  .icon-btn:hover { background: var(--surface-3); transform: translateY(-1px); }
  .icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

  html[data-theme="dark"] .ico-sun { display: none; }
  html[data-theme="light"] .ico-moon { display: none; }

  .shell { display: flex; align-items: flex-start; gap: 0; }
  .sidebar {
    position: sticky; top: var(--topbar-h);
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    height: calc(100vh - var(--topbar-h));
    overflow-y: auto; overscroll-behavior: contain;
    padding: var(--sp-5) var(--sp-3) var(--sp-5) var(--sp-4);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column; gap: var(--sp-5);
  }
  .side-group { display: flex; flex-direction: column; gap: 3px; }
  .side-title {
    margin: 0 0 6px 12px; font-size: .72rem; letter-spacing: .12em; text-transform: uppercase;
    color: var(--text-dim); font-weight: 700;
  }
  .side-link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 12px;
    color: var(--text-soft); font-weight: 600; font-size: .94rem;
    transition: background .18s, color .18s, transform .18s var(--ease);
  }
  .side-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; transform: translateX(2px); }
  .side-link.active { background: color-mix(in srgb, var(--c-primary) 18%, transparent); color: var(--text); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c-primary) 28%, transparent); }
  .si { width: 22px; text-align: center; font-size: 1rem; }
  .side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
  .mini-goal {
    padding: 14px; border-radius: var(--radius); background: var(--surface-2);
    border: 1px solid var(--line);
  }
  .mini-goal p { margin: 0 0 8px; font-size: .8rem; font-weight: 700; color: var(--text); }
  .mini-goal small { color: var(--text-dim); font-size: .76rem; }
  .side-note { font-size: .76rem; color: var(--text-dim); margin: 0; padding: 0 4px; }

  .view {
    flex: 1 1 auto; min-width: 0;
    padding: var(--sp-6) clamp(16px, 4vw, 40px) calc(var(--tabbar-h) + 40px);
    max-width: calc(var(--maxw) + 80px);
    margin: 0 auto;
    outline: none;
  }

  .tabbar { display: none; }

  .page-loading { display: grid; place-items: center; gap: 14px; padding: 18vh 0; color: var(--text-dim); }
  .spinner {
    width: 34px; height: 34px; border-radius: 50%;
    border: 3px solid var(--line-strong); border-top-color: var(--c-primary);
    animation: spin .8s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  @media (max-width: 1023px) {
    .sidebar {
      position: fixed; top: var(--topbar-h); left: 0; z-index: 45;
      width: min(300px, 84vw); flex-basis: auto;
      background: var(--surface-solid);
      box-shadow: var(--shadow-lg);
      transform: translateX(-104%);
      transition: transform .34s var(--ease);
    }
    .sidebar.open { transform: translateX(0); }
    .view { padding-bottom: calc(var(--tabbar-h) + 30px); }
    .tabbar {
      position: fixed; left: 0; right: 0; bottom: 0; z-index: 42;
      height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
      padding-bottom: env(safe-area-inset-bottom, 0px);
      display: grid; grid-template-columns: repeat(5, 1fr);
      background: color-mix(in srgb, var(--bg) 88%, transparent);
      backdrop-filter: blur(20px);
      border-top: 1px solid var(--line);
    }
    .tabbar a {
      display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
      color: var(--text-dim); font-size: .7rem; font-weight: 700; text-decoration: none;
      padding: 6px 2px;
    }
    .tabbar a span { font-size: 1.16rem; line-height: 1; }
    .tabbar a.active { color: var(--c-primary); }
    .tabbar a.tab-primary span {
      display: grid; place-items: center; width: 42px; height: 42px; margin-top: -14px;
      border-radius: 14px; color: #fff;
      background: linear-gradient(140deg, var(--c-primary), var(--c-violet));
      box-shadow: 0 10px 24px -10px var(--c-primary-strong);
    }
    .tabbar a.tab-primary { color: var(--text-soft); }
    body.menu-open::after {
      content: ""; position: fixed; inset: var(--topbar-h) 0 0; z-index: 44;
      background: rgba(4, 8, 18, .55); backdrop-filter: blur(2px);
    }
  }

  @media (min-width: 1024px) {
    .only-mobile { display: none !important; }
  }
  @media (max-width: 640px) {
    .pill-label, .brand-text span { display: none; }
    .topbar { padding: 0 12px; gap: 8px; }
    .pill { padding: 0 10px; height: 34px; }
    .lvl { display: none; }
  }
}

@layer components {
  /* Buttons */
  .btn {
    --btn-bg: var(--surface-2);
    --btn-fg: var(--text);
    display: inline-flex; align-items: center; justify-content: center; gap: 9px;
    min-height: 46px; padding: 0 20px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--line-strong);
    background: var(--btn-bg); color: var(--btn-fg);
    font-weight: 750; font-size: .96rem; letter-spacing: -.01em;
    text-decoration: none; white-space: nowrap;
    transition: transform .18s var(--ease), box-shadow .2s, background .2s, border-color .2s, filter .2s;
    user-select: none;
  }
  .btn:hover { transform: translateY(-2px); box-shadow: var(--shadow); text-decoration: none; }
  .btn:active { transform: translateY(0) scale(.985); }
  .btn-primary {
    background: linear-gradient(135deg, var(--c-primary), var(--c-violet));
    border-color: transparent; color: #fff;
    box-shadow: 0 14px 30px -14px var(--c-primary-strong);
  }
  .btn-primary:hover { filter: brightness(1.06); }
  .btn-mint { background: linear-gradient(135deg, #1fc48a, #14a3c7); border-color: transparent; color: #04231a; }
  .btn-gold { background: linear-gradient(135deg, var(--c-amber), #ff9f5c); border-color: transparent; color: #33220a; }
  .btn-ghost { background: transparent; }
  .btn-lg { min-height: 56px; padding: 0 28px; font-size: 1.04rem; border-radius: var(--radius-pill); }
  .btn-sm { min-height: 38px; padding: 0 14px; font-size: .85rem; }
  .btn-block { width: 100%; }
  .btn[disabled] { opacity: .5; pointer-events: none; }

  /* Cards */
  .card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: clamp(18px, 3vw, 26px);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(14px);
  }
  .card + .card { margin-top: 16px; }
  .card-flat { background: var(--surface-2); box-shadow: none; }
  .card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
  .card-head h3 { margin: 0; }
  .card-icon {
    flex: 0 0 auto; width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center;
    font-size: 1.2rem; background: color-mix(in srgb, var(--c-primary) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--c-primary) 24%, transparent);
  }

  /* Progress */
  .progress {
    position: relative; height: 10px; border-radius: 999px; overflow: hidden;
    background: color-mix(in srgb, var(--text-dim) 20%, transparent);
  }
  .progress.thin { height: 6px; }
  .progress.lg { height: 14px; }
  .progress-bar {
    height: 100%; width: 0; border-radius: 999px;
    background: linear-gradient(90deg, var(--c-primary), var(--c-violet), var(--c-cyan));
    transition: width .9s var(--ease-out);
    background-size: 200% 100%;
    animation: shimmer 5s linear infinite;
  }
  .progress-bar.mint { background: linear-gradient(90deg, var(--c-mint), #35c7ff); }
  .progress-bar.gold { background: linear-gradient(90deg, var(--c-amber), var(--c-rose)); }
  @keyframes shimmer { to { background-position: 200% 0; } }

  .chips { display: flex; flex-wrap: wrap; gap: 8px; }
  .chip {
    padding: 8px 15px; border-radius: var(--radius-pill);
    background: var(--surface-2); border: 1px solid var(--line-strong);
    color: var(--text-soft); font-weight: 650; font-size: .87rem;
    transition: all .18s var(--ease);
  }
  .chip:hover { color: var(--text); border-color: var(--c-primary); transform: translateY(-1px); }
  .chip.active {
    background: linear-gradient(135deg, var(--c-primary), var(--c-violet));
    border-color: transparent; color: #fff;
    box-shadow: 0 10px 22px -12px var(--c-primary-strong);
  }
  .chip small { opacity: .7; font-weight: 700; margin-left: 4px; }

  .badge-soft {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: .75rem; font-weight: 750; letter-spacing: .02em;
    padding: 4px 10px; border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--line);
    color: var(--text-soft);
  }
  .badge-soft.ok { color: var(--ok); background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
  .badge-soft.bad { color: var(--bad); background: var(--bad-bg); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }

  /* Equations & math blocks */
  .eq {
    font-family: var(--mono);
    font-size: clamp(1rem, .95rem + .4vw, 1.22rem);
    letter-spacing: .01em;
    color: var(--text);
    background: var(--code-bg);
    border: 1px solid var(--line);
    border-left: 3px solid var(--c-primary);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin: 0 0 8px;
    overflow-x: auto;
    white-space: nowrap;
  }
  .eq.center { text-align: center; border-left-width: 1px; }
  .eq .hl { color: var(--c-amber); font-weight: 700; }
  .eq .ok { color: var(--ok); }
  .eq-stack { display: grid; gap: 6px; margin: 12px 0 16px; }
  .eq-pair { position: relative; padding-left: 34px; }
  .eq-pair::before {
    content: attr(data-label); position: absolute; left: 0; top: 11px;
    font-family: var(--mono); font-size: .78rem; color: var(--text-dim);
  }
  .kbd, code.inline {
    font-family: var(--mono); font-size: .88em; padding: 1px 6px; border-radius: 6px;
    background: var(--code-bg); border: 1px solid var(--line); color: var(--text);
  }
  .muted { color: var(--text-dim); }
  .math { font-family: var(--mono); color: var(--text); }

  /* Callouts */
  .callout {
    display: flex; gap: 12px; align-items: flex-start;
    border-radius: var(--radius); padding: 14px 16px; margin: 14px 0;
    background: var(--surface-2); border: 1px solid var(--line);
    border-left: 3px solid var(--c-primary);
  }
  .callout .ci { font-size: 1.1rem; line-height: 1.4; }
  .callout p:last-child { margin-bottom: 0; }
  .callout.warn { border-left-color: var(--c-amber); background: var(--warn-bg); }
  .callout.ok { border-left-color: var(--ok); background: var(--ok-bg); }
  .callout.tip { border-left-color: var(--c-mint); }
  .callout.info { border-left-color: var(--c-cyan); }

  /* Steps */
  .steps { display: grid; gap: 10px; margin: 14px 0; counter-reset: step; }
  .step {
    position: relative; padding: 12px 14px 12px 48px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    animation: stepIn .4s var(--ease) both;
  }
  .step::before {
    counter-increment: step; content: counter(step);
    position: absolute; left: 12px; top: 12px;
    width: 26px; height: 26px; border-radius: 9px;
    display: grid; place-items: center;
    font-size: .8rem; font-weight: 800; color: #fff;
    background: linear-gradient(135deg, var(--c-primary), var(--c-violet));
  }
  .step b { display: block; font-size: .92rem; margin-bottom: 2px; }
  .step p { margin: 0; font-size: .9rem; }
  .step .eq { margin: 8px 0 0; background: transparent; border: none; padding: 0; font-size: .96rem; white-space: pre-wrap; }
  .task-solution .eq, .task-hint .eq, .msg .eq, .callout .eq, .lesson-section .eq:not(.eq-pair) { white-space: pre-wrap; }
  .lesson-section .eq-pair { white-space: nowrap; }
  details > summary { cursor: pointer; color: var(--text); font-weight: 650; padding: 7px 0; list-style-position: inside; }
  details > summary:hover { color: var(--c-primary); }
  details[open] > summary { margin-bottom: 6px; }
  .flashcard:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 4px; }
  .gen-row summary { font-size: .85rem; }
  @keyframes stepIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

  /* Toast */
  .toast-stack {
    position: fixed; z-index: 90; left: 50%; bottom: calc(var(--tabbar-h) + 22px);
    transform: translateX(-50%);
    display: flex; flex-direction: column; gap: 8px; align-items: center;
    pointer-events: none; width: min(92vw, 420px);
  }
  .toast {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 18px; border-radius: var(--radius-pill);
    background: var(--surface-solid); border: 1px solid var(--line-strong);
    box-shadow: var(--shadow-lg); font-weight: 650; font-size: .9rem;
    animation: toastIn .34s var(--ease) both;
    max-width: 100%;
  }
  .toast.ok { border-color: color-mix(in srgb, var(--ok) 45%, transparent); color: var(--text); }
  .toast.bad { border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
  .toast.out { animation: toastOut .3s var(--ease) forwards; }
  @keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }
  @keyframes toastOut { to { opacity: 0; transform: translateY(10px) scale(.97); } }

  .confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 95; overflow: hidden; }
  .confetti-piece {
    position: absolute; width: 9px; height: 14px; border-radius: 2px;
    animation: confettiFall var(--dur, 1.5s) cubic-bezier(.2, .6, .4, 1) forwards;
  }
  @keyframes confettiFall {
    from { transform: translate3d(0, -10vh, 0) rotate(0deg); opacity: 1; }
    to { transform: translate3d(var(--dx, 0), 96vh, 0) rotate(720deg); opacity: .2; }
  }

  /* Tutor */
  .tutor-fab-wrap { position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + 18px); z-index: 60; }
  .tutor-fab {
    display: inline-flex; align-items: center; gap: 9px;
    height: 52px; padding: 0 18px 0 14px;
    border-radius: var(--radius-pill); border: 1px solid color-mix(in srgb, var(--c-violet) 40%, transparent);
    background: linear-gradient(135deg, color-mix(in srgb, var(--c-violet) 92%, #000), var(--c-primary));
    color: #fff; font-weight: 750; font-size: .92rem;
    box-shadow: 0 16px 34px -14px color-mix(in srgb, var(--c-violet) 70%, transparent);
    transition: transform .2s var(--ease), filter .2s;
  }
  .tutor-fab:hover { transform: translateY(-2px) scale(1.02); filter: brightness(1.06); }
  .tutor-fab span[aria-hidden] { font-size: 1.1rem; }
  @media (min-width: 1024px) {
    .tutor-fab-wrap { bottom: 24px; right: 26px; }
  }
  @media (max-width: 520px) { .tutor-fab-label { display: none; } .tutor-fab { width: 52px; padding: 0; justify-content: center; } }

  .tutor-panel {
    position: fixed; z-index: 80; right: 16px; bottom: calc(var(--tabbar-h) + 16px);
    width: min(400px, calc(100vw - 32px));
    max-height: min(640px, calc(100vh - 140px));
    display: flex; flex-direction: column;
    background: var(--surface-solid); border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    transform: translateY(18px) scale(.97); opacity: 0; visibility: hidden;
    transition: all .3s var(--ease);
    overflow: hidden;
  }
  .tutor-panel.open { transform: none; opacity: 1; visibility: visible; }
  .tutor-head {
    display: flex; align-items: center; gap: 10px; padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(120deg, color-mix(in srgb, var(--c-violet) 16%, transparent), transparent);
  }
  .tutor-id { display: flex; align-items: center; gap: 10px; }
  .tutor-id small { display: block; color: var(--text-dim); font-size: .74rem; }
  .tutor-avatar {
    width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--c-violet), var(--c-primary)); font-size: 1.05rem;
  }
  .tutor-head .icon-btn { margin-left: auto; width: 34px; height: 34px; }
  .tutor-chips { display: flex; gap: 6px; padding: 10px 12px 0; flex-wrap: wrap; }
  .tutor-chips .chip { font-size: .76rem; padding: 5px 10px; }
  .tutor-log {
    flex: 1 1 auto; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px;
    scroll-behavior: smooth;
  }
  .msg { max-width: 88%; padding: 10px 13px; border-radius: 16px; font-size: .9rem; line-height: 1.55; }
  .msg p:last-child { margin-bottom: 0; }
  .msg.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
  .msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--c-primary), var(--c-violet)); color: #fff; border-bottom-right-radius: 6px; }
  .msg.user p { color: #fff; }
  .msg .eq { white-space: normal; font-size: .88rem; margin: 8px 0; }
  .tutor-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
  .tutor-form input {
    flex: 1; min-width: 0; height: 42px; padding: 0 14px;
    border-radius: var(--radius-pill); border: 1px solid var(--line-strong);
    background: var(--surface-2); color: var(--text);
  }
  .tutor-form input::placeholder { color: var(--text-dim); }
  .tutor-form .btn { min-height: 42px; padding: 0 16px; font-size: .88rem; }
  .tutor-foot { margin: 0; padding: 0 14px 10px; font-size: .7rem; color: var(--text-dim); }

  @media (min-width: 1024px) { .tutor-panel { bottom: 24px; right: 26px; } }

  /* Inputs */
  .answer-input {
    width: 100%; height: 58px; padding: 0 16px;
    font-family: var(--mono); font-size: 1.12rem; font-weight: 600;
    text-align: center; color: var(--text);
    background: var(--surface-2);
    border: 2px solid var(--line-strong); border-radius: var(--radius-sm);
    transition: border-color .2s, box-shadow .2s, background .2s;
  }
  .answer-input::placeholder { color: var(--text-dim); font-family: var(--font); font-weight: 500; font-size: .92rem; }
  .answer-input:focus { outline: none; border-color: var(--c-primary); box-shadow: var(--ring); }
  .answer-input.ok { border-color: var(--ok); background: var(--ok-bg); }
  .answer-input.bad { border-color: var(--bad); background: var(--bad-bg); animation: shake .4s; }
  @keyframes shake {
    0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
  }

  .field { display: flex; flex-direction: column; gap: 6px; }
  .field label { font-size: .8rem; font-weight: 700; color: var(--text-dim); letter-spacing: .02em; }
  .field-row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; margin: 16px 0; }

  .switch { display: inline-flex; align-items: center; gap: 8px; font-size: .86rem; color: var(--text-soft); font-weight: 600; }
  .switch input { width: 18px; height: 18px; accent-color: var(--c-primary); }

  /* Reveal animation */
  .reveal { opacity: 0; transform: translateY(14px); animation: reveal .55s var(--ease-out) forwards; }
  @keyframes reveal { to { opacity: 1; transform: none; } }
  .stagger > * { animation-delay: calc(var(--i, 0) * 55ms); }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
    .reveal { opacity: 1; transform: none; }
  }
}

@layer views {
  /* Page headers */
  .page-head { margin-bottom: var(--sp-5); }
  .eyebrow {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: .74rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
    color: var(--c-primary); margin-bottom: 8px;
  }
  .page-head h1 { margin-bottom: 6px; }
  .page-head .lede { font-size: 1.02rem; max-width: 62ch; margin: 0; }
  .back-link { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 650; color: var(--text-dim); margin-bottom: 12px; }
  .back-link:hover { color: var(--text); text-decoration: none; }

  /* Home hero */
  .hero {
    position: relative; overflow: hidden;
    border-radius: var(--radius-lg);
    padding: clamp(22px, 4vw, 38px);
    background:
      radial-gradient(700px 300px at 100% 0%, color-mix(in srgb, var(--c-violet) 30%, transparent), transparent 70%),
      linear-gradient(135deg, color-mix(in srgb, var(--c-primary) 22%, var(--surface-solid)), var(--surface-solid));
    border: 1px solid color-mix(in srgb, var(--c-primary) 32%, transparent);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
  }
  .hero::after {
    content: ""; position: absolute; right: -70px; top: -70px; width: 230px; height: 230px;
    border-radius: 50%; border: 30px solid color-mix(in srgb, var(--c-violet) 22%, transparent);
    pointer-events: none;
  }
  .hero h1 { margin-bottom: 10px; max-width: 20ch; }
  .hero .lede { max-width: 52ch; font-size: 1rem; }
  .hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
  .hero-stats { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
  .hero-stat b { display: block; font-size: 1.24rem; letter-spacing: -.02em; }
  .hero-stat span { font-size: .76rem; color: var(--text-dim); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; }

  .grid { display: grid; gap: 16px; }
  .grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.auto { grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); }
  .grid.tight { gap: 10px; }
  @media (max-width: 860px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }

  .section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 26px 0 12px; }
  .section-title h2 { margin: 0; font-size: 1.16rem; }
  .section-title a { font-size: .84rem; font-weight: 700; }

  /* Daily goal ring */
  .goal-card { display: flex; align-items: center; gap: 18px; }
  .ring { position: relative; width: 96px; height: 96px; flex: 0 0 auto; }
  .ring svg { transform: rotate(-90deg); }
  .ring circle { fill: none; stroke-width: 9; stroke-linecap: round; }
  .ring .track { stroke: color-mix(in srgb, var(--text-dim) 22%, transparent); }
  .ring .fill { stroke: url(#ringGrad); transition: stroke-dashoffset 1s var(--ease-out); }
  .ring-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.1; }
  .ring-center b { font-size: 1.28rem; letter-spacing: -.02em; }
  .ring-center small { display: block; font-size: .64rem; color: var(--text-dim); font-weight: 700; text-transform: uppercase; }

  /* Chapter cards */
  .chapter-card {
    display: flex; flex-direction: column; gap: 10px;
    padding: 18px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--line);
    transition: transform .22s var(--ease), border-color .22s, box-shadow .22s;
    color: var(--text); text-decoration: none;
    position: relative; overflow: hidden;
  }
  .chapter-card::before {
    content: ""; position: absolute; inset: 0 0 auto; height: 3px;
    background: var(--accent, var(--c-primary)); opacity: .9;
  }
  .chapter-card:hover {
    transform: translateY(-3px); border-color: color-mix(in srgb, var(--accent, var(--c-primary)) 50%, transparent);
    box-shadow: var(--shadow); text-decoration: none;
  }
  .chapter-top { display: flex; align-items: center; gap: 10px; }
  .chapter-icon {
    width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
    font-size: 1.1rem; background: color-mix(in srgb, var(--accent, var(--c-primary)) 18%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent, var(--c-primary)) 30%, transparent);
  }
  .chapter-num { font-size: .72rem; font-weight: 800; letter-spacing: .1em; color: var(--text-dim); }
  .chapter-card h3 { margin: 0; font-size: 1.02rem; }
  .chapter-card p { margin: 0; font-size: .86rem; line-height: 1.5; }
  .chapter-meta { margin-top: auto; display: flex; align-items: center; gap: 8px; }
  .chapter-meta .progress { flex: 1; }
  .chapter-meta small { font-size: .72rem; color: var(--text-dim); font-weight: 700; white-space: nowrap; }

  /* Lessons */
  .lesson-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
  @media (max-width: 1080px) { .lesson-layout { grid-template-columns: 1fr; } }
  .lesson-aside { position: sticky; top: calc(var(--topbar-h) + 18px); display: grid; gap: 14px; }
  @media (max-width: 1080px) { .lesson-aside { position: static; } }
  .aside-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
  .aside-card h4 { margin: 0 0 10px; font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-dim); }
  .toc { display: grid; gap: 2px; }
  .toc a {
    display: flex; gap: 8px; align-items: center;
    padding: 7px 10px; border-radius: 9px; font-size: .86rem; font-weight: 600; color: var(--text-soft);
  }
  .toc a:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
  .toc a.done { color: var(--ok); }
  .toc a .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); flex: 0 0 auto; }
  .toc a.done .dot { background: var(--ok); }

  .lesson-section {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-lg); padding: clamp(18px, 3vw, 26px);
    margin-bottom: 16px; scroll-margin-top: calc(var(--topbar-h) + 16px);
  }
  .lesson-section > h2 { font-size: 1.2rem; display: flex; align-items: center; gap: 10px; }
  .lesson-section .sec-body > *:last-child { margin-bottom: 0; }
  .lesson-section .sec-num {
    width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center;
    font-size: .8rem; color: #fff; background: var(--accent, var(--c-primary)); flex: 0 0 auto;
  }
  .sec-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }
  .sec-done { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--ok); font-weight: 700; }

  /* Graph */
  .graph-wrap {
    background: linear-gradient(160deg, var(--surface-2), color-mix(in srgb, var(--surface-2) 60%, transparent));
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 12px; margin: 14px 0;
  }
  .graph-svg { width: 100%; height: auto; display: block; touch-action: none; border-radius: 10px; overflow: visible; }
  .graph-svg .g-grid { stroke: var(--grid-line); stroke-width: 1; }
  .graph-svg .g-axis { stroke: var(--grid-line-strong); stroke-width: 1.6; }
  .graph-svg .g-tick { fill: var(--text-dim); font-size: 9px; font-family: var(--font); }
  .graph-svg .g-line { stroke-width: 3.2; stroke-linecap: round; fill: none; transition: stroke .3s; }
  .graph-svg .g-line.a { stroke: var(--c-primary); }
  .graph-svg .g-line.b { stroke: var(--c-amber); }
  .graph-svg .g-point { fill: var(--c-mint); stroke: var(--bg); stroke-width: 2.4; }
  .graph-svg .g-hit { fill: transparent; stroke: none; cursor: grab; }
  .graph-svg .g-handle { fill: var(--surface-solid); stroke: var(--c-mint); stroke-width: 2.6; cursor: grab; filter: drop-shadow(0 0 6px color-mix(in srgb, var(--c-mint) 60%, transparent)); }
  .graph-svg .g-handle:active { cursor: grabbing; }
  .graph-svg text.g-label { font-family: var(--mono); font-size: 11px; }
  .graph-svg .g-guide { stroke: var(--c-mint); stroke-width: 1; stroke-dasharray: 4 4; opacity: .7; }
  .graph-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: .8rem; font-weight: 650; }
  .graph-legend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
  .range-row { display: grid; grid-template-columns: 96px 1fr 52px; align-items: center; gap: 10px; margin: 8px 0; font-size: .84rem; }
  .range-row input[type="range"] { width: 100%; accent-color: var(--c-primary); }
  .range-row output { font-family: var(--mono); font-size: .88rem; text-align: right; color: var(--text); font-weight: 700; }

  /* Task card */
  .task-card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-lg); padding: clamp(18px, 3vw, 28px);
    box-shadow: var(--shadow-sm);
    animation: reveal .4s var(--ease-out) both;
  }
  .task-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
  .task-top .grow { flex: 1; }
  .task-prompt { font-size: 1.02rem; color: var(--text); margin-bottom: 4px; }
  .task-prompt p { color: var(--text); margin-bottom: .6em; }
  .task-eqs { margin: 14px 0; }
  .task-hint, .task-solution {
    margin-top: 14px; padding: 14px; border-radius: var(--radius);
    background: var(--surface-2); border: 1px solid var(--line);
    animation: reveal .35s var(--ease-out) both;
  }
  .task-hint { border-left: 3px solid var(--c-amber); }
  .task-solution { border-left: 3px solid var(--c-mint); }
  .task-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
  .task-actions .btn { flex: 1 1 140px; }
  .feedback {
    margin-top: 14px; padding: 14px 16px; border-radius: var(--radius);
    display: flex; gap: 12px; align-items: flex-start; animation: reveal .3s var(--ease-out) both;
  }
  .feedback.correct { background: var(--ok-bg); border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent); }
  .feedback.wrong { background: var(--bad-bg); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); }
  .feedback .fi { font-size: 1.3rem; line-height: 1.2; }
  .feedback p:last-child { margin-bottom: 0; }
  .feedback h4 { margin-bottom: 4px; font-size: .98rem; }

  .session-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
  .session-head .progress { flex: 1 1 160px; }
  .session-xp { font-size: .82rem; font-weight: 750; color: var(--c-amber); }

  .result-screen { text-align: center; padding: 12px 4px; }
  .result-emoji { font-size: 3.4rem; line-height: 1; animation: pop .5s var(--ease-out) both; }
  @keyframes pop { from { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.12); } }
  .result-score { font-size: 2.6rem; font-weight: 800; letter-spacing: -.04em; margin: 6px 0 2px; }
  .result-score small { font-size: 1rem; color: var(--text-dim); font-weight: 600; }
  .result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 22px; }
  .result-actions .btn { flex: 0 1 auto; }

  /* Exam */
  .exam-bar {
    position: sticky; top: var(--topbar-h); z-index: 20;
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
    padding: 12px 16px; margin-bottom: 18px;
    background: color-mix(in srgb, var(--surface-solid) 88%, transparent);
    backdrop-filter: blur(16px);
    border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
  }
  .timer { font-family: var(--mono); font-size: 1.12rem; font-weight: 700; letter-spacing: .02em; }
  .timer.low { color: var(--bad); animation: pulse 1s infinite; }
  @keyframes pulse { 50% { opacity: .55; } }
  .exam-q { scroll-margin-top: 150px; }
  .grade-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
  .grade-table th, .grade-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
  .grade-table th { color: var(--text-dim); font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; }

  /* Flashcards */
  .flash-wrap { max-width: 620px; margin: 0 auto; }
  .flashcard {
    position: relative; width: 100%; min-height: 290px;
    perspective: 1400px; cursor: pointer; background: none; border: none; padding: 0;
    display: block; text-align: left;
  }
  .flash-inner {
    position: relative; width: 100%; min-height: 290px;
    transform-style: preserve-3d; transition: transform .62s var(--ease);
  }
  .flashcard.flipped .flash-inner { transform: rotateY(180deg); }
  .flash-face {
    position: absolute; inset: 0; backface-visibility: hidden;
    border-radius: var(--radius-lg); padding: 26px;
    display: flex; flex-direction: column; justify-content: center; gap: 10px;
    border: 1px solid var(--line-strong);
    background:
      radial-gradient(400px 200px at 100% 0%, color-mix(in srgb, var(--c-violet) 26%, transparent), transparent 70%),
      var(--surface-solid);
    box-shadow: var(--shadow);
    overflow: auto;
  }
  .flash-face.back { transform: rotateY(180deg); }
  .flash-face .tag { align-self: flex-start; }
  .flash-face h3 { font-size: clamp(1.2rem, 1rem + 1vw, 1.6rem); margin: 0; }
  .flash-face p { margin: 0; font-size: .96rem; }
  .flash-nav { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

  /* Stats */
  .stat-tile { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
  .stat-tile b { display: block; font-size: 1.6rem; letter-spacing: -.03em; line-height: 1.2; }
  .stat-tile span { font-size: .76rem; color: var(--text-dim); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
  .bar-list { display: grid; gap: 10px; }
  .bar-row { display: grid; grid-template-columns: minmax(96px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: .86rem; }
  .bar-row .name { font-weight: 650; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bar-row .val { font-size: .78rem; color: var(--text-dim); font-weight: 700; font-variant-numeric: tabular-nums; }
  .bar-track { height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--text-dim) 20%, transparent); overflow: hidden; }
  .bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--c-primary), var(--c-violet)); transition: width .8s var(--ease-out); }
  .bar-fill.weak { background: linear-gradient(90deg, var(--c-rose), var(--c-amber)); }
  .bar-fill.strong { background: linear-gradient(90deg, var(--c-mint), var(--c-cyan)); }

  /* Badges */
  .badge-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .badge-tile {
    text-align: center; padding: 18px 12px; border-radius: var(--radius);
    background: var(--surface-2); border: 1px solid var(--line);
    transition: transform .2s var(--ease), border-color .2s;
  }
  .badge-tile:hover { transform: translateY(-2px); }
  .badge-tile .bi { font-size: 2rem; line-height: 1; filter: grayscale(1); opacity: .38; }
  .badge-tile.unlocked { border-color: color-mix(in srgb, var(--c-amber) 45%, transparent); background: linear-gradient(160deg, color-mix(in srgb, var(--c-amber) 14%, transparent), var(--surface-2)); }
  .badge-tile.unlocked .bi { filter: none; opacity: 1; }
  .badge-tile b { display: block; font-size: .86rem; margin-top: 8px; }
  .badge-tile small { display: block; font-size: .74rem; color: var(--text-dim); line-height: 1.4; margin-top: 3px; }
  .badge-tile.locked b { color: var(--text-soft); }

  .level-bar { display: flex; align-items: center; gap: 14px; }
  .level-badge {
    width: 62px; height: 62px; border-radius: 20px; flex: 0 0 auto;
    display: grid; place-items: center; font-weight: 800; font-size: 1.3rem; color: #fff;
    background: linear-gradient(135deg, var(--c-primary), var(--c-violet));
    box-shadow: 0 12px 30px -14px var(--c-primary-strong);
  }

  /* Generator list */
  .gen-row {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 14px; border-radius: var(--radius);
    background: var(--surface-2); border: 1px solid var(--line);
    margin-bottom: 10px;
  }
  .gen-row .num { font-family: var(--mono); font-size: .76rem; color: var(--text-dim); padding-top: 4px; min-width: 34px; }
  .gen-row .body { flex: 1; min-width: 0; }
  .gen-row .body p { margin: 0 0 6px; color: var(--text); font-size: .94rem; }
  .gen-row .sol { margin-top: 8px; }
  .gen-row .tagrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

  /* Misc */
  .videos { display: grid; gap: 8px; }
  .video-link {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 14px; border-radius: var(--radius-sm);
    background: var(--surface-2); border: 1px solid var(--line);
    color: var(--text); font-size: .88rem; font-weight: 600;
    transition: all .18s var(--ease);
  }
  .video-link:hover { border-color: var(--c-rose); transform: translateX(3px); text-decoration: none; }
  .video-link .play {
    width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
    background: color-mix(in srgb, var(--c-rose) 18%, transparent); color: var(--c-rose); font-size: .7rem; flex: 0 0 auto;
  }
  .video-link small { display: block; color: var(--text-dim); font-weight: 600; font-size: .74rem; }
  .video-link .arrow { margin-left: auto; color: var(--text-dim); }

  .quiz-q { font-weight: 700; font-size: 1rem; margin-bottom: 10px; color: var(--text); }
  .qm { display: grid; gap: 8px; }
  .qm button {
    text-align: left; padding: 12px 15px; border-radius: var(--radius-sm);
    background: var(--surface-2); border: 1px solid var(--line-strong);
    font-size: .92rem; font-weight: 600; transition: all .18s var(--ease);
    display: flex; gap: 10px; align-items: center;
  }
  .qm button:hover { border-color: var(--c-primary); transform: translateX(2px); }
  .qm button .letter {
    width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center;
    font-size: .74rem; font-weight: 800; background: var(--surface-3); color: var(--text-dim); flex: 0 0 auto;
  }
  .qm button.right { border-color: var(--ok); background: var(--ok-bg); }
  .qm button.right .letter { background: var(--ok); color: #04231a; }
  .qm button.wrong { border-color: var(--bad); background: var(--bad-bg); }
  .qm button.wrong .letter { background: var(--bad); color: #2b0510; }
  .qm button[disabled] { pointer-events: none; }
  .quiz-note { margin-top: 10px; font-size: .88rem; }

  .empty { text-align: center; padding: 30px 16px; color: var(--text-dim); }
  .empty .ee { font-size: 2.4rem; margin-bottom: 8px; }

  .stat-inline { display: flex; flex-wrap: wrap; gap: 14px; font-size: .82rem; color: var(--text-dim); font-weight: 650; }
  .stat-inline b { color: var(--text); }
}

@layer utilities {
  .mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
  .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-5 { margin-top: 24px; }
  .center { text-align: center; }
  .row { display: flex; align-items: center; gap: 10px; }
  .row.wrap { flex-wrap: wrap; }
  .row.between { justify-content: space-between; }
  .grow { flex: 1 1 auto; }
  .hidden { display: none !important; }
  .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .nowrap { white-space: nowrap; }
  .big { font-size: 1.1rem; }
}

/* ============================================================
   Konten, Bestenliste, Shop, Materialien (Nachtrag)
   ============================================================ */

/* ---------- Hintergrund-Designs ---------- */
html[data-bg="bg-ozean"] { --bg: #04121a; --bg-2: #0a2b38; --bg-glow-1: rgba(56, 217, 255, .20); --bg-glow-2: rgba(46, 230, 168, .14); }
html[data-bg="bg-ozean"][data-theme="light"] { --bg: #eefaff; --bg-2: #e0f5ff; --bg-glow-1: rgba(56, 217, 255, .30); --bg-glow-2: rgba(46, 230, 168, .18); }

html[data-bg="bg-wald"] { --bg: #05130d; --bg-2: #0c2418; --bg-glow-1: rgba(52, 224, 161, .18); --bg-glow-2: rgba(160, 200, 90, .12); }
html[data-bg="bg-wald"][data-theme="light"] { --bg: #f2fbf4; --bg-2: #e5f6e9; --bg-glow-1: rgba(52, 224, 161, .26); --bg-glow-2: rgba(160, 200, 90, .16); }

html[data-bg="bg-sonnenuntergang"] { --bg: #150812; --bg-2: #2a1120; --bg-glow-1: rgba(255, 138, 61, .26); --bg-glow-2: rgba(255, 107, 138, .20); }
html[data-bg="bg-sonnenuntergang"][data-theme="light"] { --bg: #fff6ef; --bg-2: #ffe8d8; --bg-glow-1: rgba(255, 138, 61, .30); --bg-glow-2: rgba(255, 107, 138, .20); }

html[data-bg="bg-weltraum"] { --bg: #06030f; --bg-2: #140a2b; --bg-glow-1: rgba(160, 123, 255, .28); --bg-glow-2: rgba(108, 140, 255, .22); }
html[data-bg="bg-weltraum"][data-theme="light"] { --bg: #f6f2ff; --bg-2: #ebe2ff; --bg-glow-1: rgba(160, 123, 255, .32); --bg-glow-2: rgba(108, 140, 255, .24); }

html[data-bg="bg-papier"] { --bg: #14110c; --bg-2: #241d14; --bg-glow-1: rgba(255, 196, 92, .16); --bg-glow-2: rgba(214, 180, 120, .12); }
html[data-bg="bg-papier"][data-theme="light"] { --bg: #fbf7ee; --bg-2: #f3ecdd; --bg-glow-1: rgba(255, 196, 92, .26); --bg-glow-2: rgba(214, 180, 120, .18); }

html[data-bg="bg-neon"] { --bg: #05060f; --bg-2: #12051f; --bg-glow-1: rgba(255, 61, 214, .24); --bg-glow-2: rgba(56, 217, 255, .22); }
html[data-bg="bg-neon"][data-theme="light"] { --bg: #fdf2ff; --bg-2: #f2e6ff; --bg-glow-1: rgba(255, 61, 214, .26); --bg-glow-2: rgba(56, 217, 255, .24); }

html[data-bg="bg-kirschbluete"] { --bg: #170a11; --bg-2: #2a1220; --bg-glow-1: rgba(255, 155, 186, .22); --bg-glow-2: rgba(255, 107, 138, .16); }
html[data-bg="bg-kirschbluete"][data-theme="light"] { --bg: #fff5f8; --bg-2: #ffe6ee; --bg-glow-1: rgba(255, 155, 186, .34); --bg-glow-2: rgba(255, 107, 138, .20); }

/* ---------- Farbpaletten ---------- */
html[data-palette="palette-mint"] { --c-primary: #2ee6a8; --c-primary-strong: #16c98c; --c-violet: #38d9ff; }
html[data-palette="palette-violett"] { --c-primary: #a07bff; --c-primary-strong: #8560ff; --c-violet: #ff6bd6; }
html[data-palette="palette-gold"] { --c-primary: #ffc45c; --c-primary-strong: #f0a92e; --c-violet: #ff8a3d; }
html[data-palette="palette-rose"] { --c-primary: #ff8aa4; --c-primary-strong: #ff6b8a; --c-violet: #ff9ab0; }

/* ---------- Münzen & Konto ---------- */
.coin-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px; border-radius: var(--radius-pill);
  font-weight: 800; font-size: .9rem;
  background: linear-gradient(120deg, color-mix(in srgb, var(--c-amber) 26%, transparent), color-mix(in srgb, var(--c-amber) 10%, transparent));
  border: 1px solid color-mix(in srgb, var(--c-amber) 36%, transparent);
  color: var(--text);
}
.coin-pill.big { font-size: 1.15rem; padding: 9px 18px; }
.pill.coins { background: linear-gradient(120deg, color-mix(in srgb, var(--c-amber) 24%, transparent), color-mix(in srgb, var(--c-amber) 8%, transparent)); border-color: color-mix(in srgb, var(--c-amber) 34%, transparent); }

.account-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 12px 5px 5px; border-radius: var(--radius-pill);
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); text-decoration: none; max-width: 220px;
  transition: border-color .2s, transform .2s var(--ease);
}
.account-chip:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.account-chip .ac-text { display: flex; flex-direction: column; line-height: 1.15; overflow: hidden; }
.account-chip .ac-text b { font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-chip .ac-text small { font-size: .68rem; color: var(--text-dim); white-space: nowrap; }
#accountTitle { display: none; }
#accountTitle.show { display: inline; }

.avatar {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(140deg, var(--c-primary), var(--c-violet));
  color: #fff; font-weight: 800; font-size: .95rem;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.small { width: 30px; height: 30px; font-size: .82rem; }
.avatar.big { width: 64px; height: 64px; font-size: 1.5rem; }
.title-badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .72rem; font-weight: 800; letter-spacing: .02em;
  background: color-mix(in srgb, var(--c-violet) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--c-violet) 38%, transparent);
}

/* ---------- Profilkarte ---------- */
.profile-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.profile-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px; }
.profile-stats > div {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px; display: flex; flex-direction: column;
}
.profile-stats b { font-size: 1.15rem; }
.profile-stats span { font-size: .74rem; color: var(--text-dim); }
.profile-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-top: 18px; }
.profile-actions form { margin: 0; }

.account-cta { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.account-cta-emoji { font-size: 2.6rem; line-height: 1; }
.check-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 7px; }
.check-list li { position: relative; padding-left: 26px; color: var(--text-soft); }
.check-list li::before { content: "✓"; position: absolute; left: 0; color: var(--ok); font-weight: 800; }

/* ---------- Bestenliste ---------- */
.segmented { display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.segmented a { padding: 7px 14px; border-radius: 999px; font-weight: 700; font-size: .84rem; color: var(--text-soft); text-decoration: none; }
.segmented a.active { background: var(--c-primary); color: #fff; }

.board-head, .board li { display: grid; grid-template-columns: 46px 34px 1fr 76px 64px; align-items: center; gap: 10px; }
.board-head { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); padding: 0 6px 6px; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.board li { padding: 9px 10px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid transparent; }
.board li.me { border-color: color-mix(in srgb, var(--c-primary) 55%, transparent); background: color-mix(in srgb, var(--c-primary) 14%, var(--surface-2)); }
.board .rank { font-weight: 800; text-align: center; font-size: 1rem; }
.board-name { display: flex; flex-direction: column; min-width: 0; }
.board-name b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-name small { color: var(--text-dim); font-size: .72rem; }
.board-xp { text-align: right; display: flex; flex-direction: column; line-height: 1.1; }
.board-xp small { color: var(--text-dim); font-size: .68rem; }
.board-streak { text-align: right; font-size: .82rem; color: var(--text-soft); }

.reward-list { display: grid; gap: 12px; margin-top: 12px; }
.reward-list > div { display: flex; gap: 12px; align-items: flex-start; }
.reward-list span { font-size: 1.25rem; line-height: 1.2; }
.reward-list p { margin: 0; display: flex; flex-direction: column; }
.reward-list small { color: var(--text-dim); }
.reward-list.compact { grid-template-columns: 1fr 1fr; display: grid; gap: 14px; }

/* ---------- Shop ---------- */
.shop-balance { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.shop-item {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.shop-item.is-active { border-color: color-mix(in srgb, var(--c-mint) 55%, transparent); }
.shop-swatch { height: 86px; display: grid; place-items: center; background: var(--surface-2); }
.shop-swatch.palette { display: flex; gap: 10px; }
.shop-swatch.palette i { width: 26px; height: 26px; border-radius: 50%; display: block; }
.shop-swatch.title { font-size: 1.9rem; }
.shop-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.shop-body h3 { margin: 0; font-size: 1rem; }
.shop-body p { margin: 0; color: var(--text-dim); font-size: .84rem; }
.shop-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 10px; }
.shop-price { font-weight: 800; font-size: .86rem; color: var(--c-amber); }
.shop-item .btn { white-space: nowrap; }

/* ---------- Materialien ---------- */
.material-group { margin-bottom: 22px; }
.material-group > h3 { margin: 0 0 10px; font-size: .95rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.material-card {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  padding: 14px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.material-icon { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; font-size: 1.4rem; background: var(--surface-2); }
.material-card h3 { margin: 0 0 3px; font-size: 1rem; }
.material-card p { margin: 0; }
.material-meta { font-size: .76rem; color: var(--text-dim); margin-top: 5px !important; }
.material-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.admin-panel { margin-bottom: 8px; }
.admin-form { display: grid; gap: 12px; margin-top: 14px; }
.field > span { font-size: .8rem; font-weight: 700; color: var(--text-dim); }
.field input, .field select { width: 100%; }
.admin-upload-status { font-size: .84rem; color: var(--text-soft); min-height: 1.2em; }
.badge-soft { font-size: .78rem; font-weight: 700; color: var(--ok); }

@media (max-width: 860px) {
  .profile-stats { grid-template-columns: repeat(2, 1fr); }
  .reward-list.compact { grid-template-columns: 1fr; }
  .board-head, .board li { grid-template-columns: 34px 30px 1fr 62px; }
  .board-streak { display: none; }
}
@media (max-width: 640px) {
  .account-chip .ac-text { display: none; }
  .account-chip { padding: 4px; }
  .pill.coins .pill-label { display: none; }
  .material-actions { width: 100%; }
  .shop-grid { grid-template-columns: 1fr 1fr; }
  .shop-body p { display: none; }
}

/* Kopfleiste auf kleinen Handys kompakt halten */
@media (max-width: 760px) {
  .topbar-right { gap: 6px; }
  .pill { padding: 0 9px; height: 34px; }
  .pill-label { display: none; }
  #streakPill { display: none; }
  .pill.coins { padding: 0 9px; }
}
@media (max-width: 480px) {
  .brand-text span { display: none; }
  .pill.xp .lvl { display: none; }
  .icon-btn { width: 36px; height: 36px; }
  .account-chip .avatar { width: 30px; height: 30px; font-size: .85rem; }
}

/* Hinweiskarten mit Inhalt untereinander */
.callout.stack { flex-direction: column; align-items: flex-start; gap: 10px; }

/* ---------- Anmeldung mit Name und Passwort ---------- */
.auth-card { margin-bottom: 20px; }
.auth-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 6px; }
.auth-head h2 { margin-bottom: 4px; }
.auth-form { display: grid; gap: 14px; max-width: 420px; margin-top: 10px; }
.auth-form .field { display: grid; gap: 6px; margin: 0; }
.auth-form button { justify-self: start; }
.auth-error {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, #ff5a5f 16%, transparent);
  border: 1px solid color-mix(in srgb, #ff5a5f 45%, transparent);
  color: inherit;
  font-size: 0.92rem;
}
.auth-error[hidden] { display: none; }
