/* Mobile course figures: shared motion tokens, the stage, the controls, the glass phone, the app it shows.
   Built only on the course tokens (courses/mobile/mobile.css): restyling the course restyles the figures.
   One motion language with the home page (css/home.css) and the films:
   - arrive with --fx-ease-out, move between two states with --fx-ease-io, leave with --fx-ease-in;
   - 160 ms to answer a press, 320 ms to appear, 600 ms to change state, 950 ms to enter, 1.2 s to draw a wire;
   - siblings arrive 80 ms apart (at most six steps), a callback on a timeline takes one beat (280 ms). */

/* ---------- Tokens ---------- */
:root {
  --fx-ease-out: cubic-bezier(.2, .7, .2, 1);
  --fx-ease-io: cubic-bezier(.65, 0, .35, 1);
  --fx-ease-in: cubic-bezier(.55, 0, .85, .35);
  --fx-ease-pop: cubic-bezier(.3, 1.45, .55, 1);
  --fx-t-micro: 160ms; --fx-t-short: 320ms; --fx-t-med: 600ms; --fx-t-long: 950ms; --fx-t-draw: 1200ms;
  --fx-step: 80ms; --fx-beat: 280ms;

  --fx-aur-1: rgba(255, 61, 139, .075); --fx-aur-2: rgba(122, 92, 255, .09); --fx-aur-3: rgba(47, 125, 255, .075);
  --fx-dot: rgba(22, 22, 31, .07);
  --fx-glass-a: #ffffff; --fx-glass-b: #e6e5ef; --fx-rim: rgba(22, 22, 31, .16); --fx-rim-hi: rgba(255, 255, 255, .95);
  --fx-phone-shadow: 0 34px 60px -34px rgba(46, 34, 130, .5), 0 12px 22px -14px rgba(22, 22, 31, .28);
  --fx-scr: #0f111b;
  --fx-bounds: #e5484d; --fx-corner: #3f7fff;
  --fx-plate: color-mix(in srgb, var(--surface) 86%, transparent);
  --fx-kill: #d1242f;
}
:root[data-theme="dark"] {
  --fx-aur-1: rgba(255, 61, 139, .13); --fx-aur-2: rgba(122, 92, 255, .17); --fx-aur-3: rgba(47, 125, 255, .13);
  --fx-dot: rgba(255, 255, 255, .055);
  --fx-glass-a: rgba(255, 255, 255, .17); --fx-glass-b: rgba(255, 255, 255, .045); --fx-rim: rgba(255, 255, 255, .2); --fx-rim-hi: rgba(255, 255, 255, .32);
  --fx-phone-shadow: 0 34px 70px -30px rgba(0, 0, 0, .8), 0 0 60px -18px rgba(122, 92, 255, .45);
  --fx-scr: #0b0c14; --fx-bounds: #ff6b6b; --fx-corner: #6ea0ff; --fx-kill: #ff6b6b;
  --fx-plate: color-mix(in srgb, var(--surface-2) 80%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --fx-aur-1: rgba(255, 61, 139, .13); --fx-aur-2: rgba(122, 92, 255, .17); --fx-aur-3: rgba(47, 125, 255, .13);
    --fx-dot: rgba(255, 255, 255, .055);
    --fx-glass-a: rgba(255, 255, 255, .17); --fx-glass-b: rgba(255, 255, 255, .045); --fx-rim: rgba(255, 255, 255, .2); --fx-rim-hi: rgba(255, 255, 255, .32);
    --fx-phone-shadow: 0 34px 70px -30px rgba(0, 0, 0, .8), 0 0 60px -18px rgba(122, 92, 255, .45);
    --fx-scr: #0b0c14; --fx-bounds: #ff6b6b; --fx-corner: #6ea0ff; --fx-kill: #ff6b6b;
    --fx-plate: color-mix(in srgb, var(--surface-2) 80%, transparent);
  }
}

/* ---------- The stage: the films' world, at page scale ---------- */
.fx { container: fx / inline-size; position: relative; margin-block: 26px 16px; color: var(--ink); }
.fx__stage {
  position: relative; isolation: isolate; overflow: hidden;
  padding: clamp(16px, 3.4cqi, 32px);
  border-radius: 22px; border: 1px solid var(--rule); box-shadow: var(--shadow);
  background:
    radial-gradient(70% 90% at 0% 0%, var(--fx-aur-1), transparent 60%),
    radial-gradient(60% 80% at 100% 0%, var(--fx-aur-2), transparent 62%),
    radial-gradient(80% 70% at 60% 110%, var(--fx-aur-3), transparent 60%),
    var(--surface);
}
.fx__stage::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(var(--fx-dot) 1px, transparent 1.3px) 0 0 / 18px 18px;
  -webkit-mask-image: radial-gradient(120% 90% at 50% 40%, #000 30%, transparent 85%);
          mask-image: radial-gradient(120% 90% at 50% 40%, #000 30%, transparent 85%);
}
.fx__kicker { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; font: 700 .72rem/1.3 var(--font-body); letter-spacing: .13em; text-transform: uppercase; color: var(--accent); }
.fx__kicker::before { content: ""; width: 18px; height: 2px; border-radius: 2px; background: var(--wire); }
.fx__title { margin: 0 0 6px; font-family: var(--font-display); font-weight: 600; font-size: clamp(1.25rem, 1.6cqi + 1rem, 1.75rem); line-height: 1.2; text-wrap: balance; }
.fx__hint { margin: 0 0 18px; max-width: 62ch; font-size: .95rem; line-height: 1.5; color: var(--ink-2); }
.fx__note { margin: 14px 0 0; font-size: .86rem; line-height: 1.5; color: var(--ink-3); }

/* ---------- Controls: native inputs, styled ---------- */
.fx-seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.fx-seg > legend { float: left; width: 100%; padding: 0; margin: 0 0 7px; font: 700 .7rem/1.3 var(--font-body); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.fx-seg label { position: relative; display: inline-flex; cursor: pointer; }
.fx-seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.fx-seg label > span {
  display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 8px 15px;
  border-radius: 999px; border: 1px solid var(--control); background: var(--surface);
  font: 600 .9rem/1.2 var(--font-body); color: var(--ink-2); white-space: nowrap;
  transition: background-color var(--fx-t-micro) ease, color var(--fx-t-micro) ease, border-color var(--fx-t-micro) ease, transform var(--fx-t-micro) var(--fx-ease-out);
}
.fx-seg label:hover > span { border-color: var(--ink-3); color: var(--ink); }
.fx-seg input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.fx-seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }
.fx-seg label:active > span { transform: scale(.97); }

.fx-switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font: 600 .92rem/1.25 var(--font-body); color: var(--ink); }
.fx-switch input {
  -webkit-appearance: none; appearance: none; flex: none; position: relative; width: 42px; height: 24px; margin: 0;
  border-radius: 999px; background: var(--rule-strong); cursor: pointer; transition: background-color var(--fx-t-short) ease;
}
.fx-switch input::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform var(--fx-t-short) var(--fx-ease-out);
}
.fx-switch input:checked { background: var(--accent); }
.fx-switch input:checked::before { transform: translateX(18px); }
.fx-switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.fx-switch small { display: block; font-weight: 500; font-size: .8rem; color: var(--ink-3); }

.fx-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 9px 14px;
  border-radius: 12px; border: 1px solid var(--control); background: var(--surface); color: var(--ink);
  font: 600 .9rem/1.2 var(--font-body); cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform var(--fx-t-micro) var(--fx-ease-out), border-color var(--fx-t-micro) ease, background-color var(--fx-t-micro) ease, opacity var(--fx-t-short) ease;
}
.fx-btn:hover { border-color: var(--ink-3); }
.fx-btn:active { transform: scale(.96); }
.fx-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.fx-btn svg { width: 18px; height: 18px; flex: none; }
.fx-btn[aria-disabled="true"] { opacity: .42; cursor: not-allowed; }
.fx-btn[aria-disabled="true"]:active { transform: none; }
.fx-btn--primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.fx-btn--primary:hover { border-color: var(--ink); background: color-mix(in srgb, var(--ink) 86%, var(--accent)); }
.fx-btn--ghost { background: transparent; border-style: dashed; }
.fx-btn.is-refused { animation: fx-refuse .36s var(--fx-ease-out); }
@keyframes fx-refuse { 20% { transform: translateX(-4px); } 50% { transform: translateX(3px); } 80% { transform: translateX(-1px); } }

/* A callback, a state, an event: mono chips on a timeline. */
.fx-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 8px;
  font: 600 .78rem/1.25 var(--font-mono); letter-spacing: -.01em; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--rule-strong); color: var(--ink);
}
.fx-in { animation: fx-in var(--fx-t-short) var(--fx-ease-out) both; }
@keyframes fx-in { from { opacity: 0; transform: translateY(6px) scale(.96); } }

.fx-refuse { min-height: 1.4em; margin: 6px 0 0 !important; font-size: .86rem !important; color: var(--no); }
/* ---------- A timeline of callbacks: what the system called, in order (capsules 02, 03, 08) ---------- */
.fx-log { list-style: none; margin: 18px 0 0; padding: 14px 14px 10px; border-radius: 14px; background: var(--code-bg); border: 1px solid var(--code-rule); min-height: 64px; color: var(--code-ink); }
.fx-log:empty::before { content: attr(data-empty); font: 500 .86rem/1.4 var(--font-body); color: var(--code-dim); }
.fx-log > li { display: grid; grid-template-columns: 7.2em minmax(0, 1fr); gap: 10px; align-items: start; margin: 0 0 8px; padding: 0 0 8px; border-bottom: 1px dashed var(--code-rule); transition: opacity .3s ease; }
.fx-log > li:last-child { border-bottom: 0; margin-bottom: 0; }
.fx-log > li.is-old { opacity: .45; }
.fx-log__act { font: 700 .72rem/1.9 var(--font-body); letter-spacing: .08em; text-transform: uppercase; color: var(--code-dim); }
.fx-log__evs { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 5px 6px; }
.fx-log__evs > li { margin: 0; }
.fx-ev { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 7px; font: 600 .76rem/1.3 var(--font-mono); white-space: nowrap; border: 1px solid transparent; }
/* The callbacks are neutral: mint, amber and purple already mean "draws", "your code" and "browser engine" on the page.
   A glyph says the direction (up to the foreground, down from it, saved); colour is kept for the outcomes below. */
.fx-ev--up, .fx-ev--down, .fx-ev--save { background: rgba(255, 255, 255, .06); color: var(--code-ink); border-color: var(--code-rule); }
.fx-ev--dead { background: transparent; color: var(--code-ink); border-color: var(--code-dim); border-style: dashed; }
.fx-ev--up::before, .fx-ev--down::before, .fx-ev--save::before { font: 700 .9em/1 var(--font-body); color: var(--code-dim); }
.fx-ev--up::before { content: "↑"; content: "↑" / ""; }
.fx-ev--down::before { content: "↓"; content: "↓" / ""; }
.fx-ev--save::before { content: "⤓"; content: "⤓" / ""; }
.fx-ev--sys { background: transparent; color: var(--code-dim); border-color: var(--code-rule); font-family: var(--font-body); font-weight: 500; font-style: italic; }
.fx-ev--kill { background: rgba(255, 107, 107, .14); color: #ff9b9b; border-color: rgba(255, 107, 107, .45); font-family: var(--font-body); font-weight: 700; }
.fx-ev--ok { background: #5fd3a0; color: #0d1a14; font-family: var(--font-body); font-weight: 700; }
.fx-ev--lost { background: #ff8a80; color: #2a0d0b; font-family: var(--font-body); font-weight: 700; }
.fx-ev small { font: 500 .68rem/1 var(--font-body); color: inherit; opacity: .8; font-style: normal; }
.fx-lesson { min-height: 3em; margin: 12px 0 0 !important; font-size: .98rem !important; line-height: 1.5; color: var(--ink); }
.fx-lesson b { color: var(--ink); }

@container fx (max-width: 719px) { .fx-log > li { grid-template-columns: minmax(0, 1fr); gap: 4px; } .fx-ev { max-width: 100%; white-space: normal; overflow-wrap: anywhere; } }

/* ---------- The glass phone (the films' phone) ---------- */
.fx-phone {
  --w: 200px; position: relative; flex: none; width: var(--w); aspect-ratio: 9 / 18.8;
  border-radius: calc(var(--w) * .15);
  background: linear-gradient(150deg, var(--fx-glass-a), var(--fx-glass-b) 52%, var(--fx-glass-a));
  box-shadow: inset 0 0 0 1px var(--fx-rim-hi), 0 0 0 1px var(--fx-rim), var(--fx-phone-shadow);
  transition: box-shadow var(--fx-t-med) ease, transform var(--fx-t-med) var(--fx-ease-io);
}
.fx-phone__screen {
  position: absolute; inset: calc(var(--w) * .034); overflow: hidden; isolation: isolate;
  border-radius: calc(var(--w) * .118); background: var(--fx-scr);
  font-size: calc(var(--w) * .052); line-height: 1.2; color: #e9e8f4;
}
/* The glass: one soft highlight, above everything the screen shows. */
.fx-phone::after {
  content: ""; position: absolute; inset: calc(var(--w) * .034); border-radius: calc(var(--w) * .118); pointer-events: none; z-index: 3;
  background: linear-gradient(118deg, rgba(255, 255, 255, .13), rgba(255, 255, 255, 0) 34%, rgba(255, 255, 255, 0) 70%, rgba(255, 255, 255, .05));
}
.fx-phone__island { position: absolute; z-index: 4; top: calc(var(--w) * .058); left: 50%; width: 26%; height: calc(var(--w) * .062); transform: translateX(-50%); border-radius: 999px; background: #05060a; }
.fx-phone.is-glow { box-shadow: inset 0 0 0 1px var(--fx-rim-hi), 0 0 0 1.5px var(--screen), 0 0 34px -6px color-mix(in srgb, var(--screen) 70%, transparent), var(--fx-phone-shadow); }

/* Status bar: the system's, in every family. */
.fx-sb { position: absolute; z-index: 2; top: 0; left: 0; right: 0; height: 9%; display: flex; align-items: center; justify-content: space-between; padding: 0 1.25em; font: 600 .62em/1 var(--font-body); color: currentColor; opacity: .9; }
.fx-sb__icons { display: flex; gap: .35em; align-items: center; }
.fx-sb__icons i { display: block; width: .9em; height: .62em; border-radius: .15em; background: currentColor; opacity: .85; }
.fx-sb__icons i:first-child { width: .7em; clip-path: polygon(0 100%, 100% 0, 100% 100%); border-radius: 0; }
.fx-sb__icons i:last-child { width: 1.3em; border-radius: .2em; }

/* ---------- Reduced motion, or motion paused: every state arrives at once ---------- */
.fx--still *, .fx--still *::before, .fx--still *::after { transition-duration: 0s !important; transition-delay: 0s !important; animation: none !important; }

@media (forced-colors: active) {
  .fx-seg input:checked + span { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  .fx-phone { border: 1px solid CanvasText; }
}
