/* Simulation session page — page-level layout only.
   Task-type styles live in Shadow DOM (session-chat, session-multichoice, etc.) */

/* Force compositing layer so Clarity can snapshot the DOM during screen sharing */
body,
#main-content {
  transform: translateZ(0);
  will-change: transform;
  backface-visibility: hidden;
}

/* Theme layer — colors, backgrounds, shadows only */
@layer theme {
  .simulation-session-page {
    .session-loading {
      color: var(--text-secondary);
    }

    .loading-spinner {
      border-color: oklch(from var(--accent-primary) l c h / 0.2);
      border-block-start-color: var(--accent-primary);
    }

    .session-header {
      border-block-end-color: oklch(from var(--glass-tint) l c h / 0.1);
    }

    .task-progress {
      background: oklch(from var(--accent-primary) l c h / 0.1);
      color: var(--accent-primary);
    }

    .task-description {
      color: var(--text-secondary);
    }

    /* Phase badge (Task / Debrief) */
    .phase-badge {
      background: oklch(from var(--accent-primary) l c h / 0.1);
      color: var(--accent-primary);

      &.debrief {
        background: oklch(55% 0.18 45 / 0.12);
        color: oklch(55% 0.18 45);
      }
    }

    /* Canvas pane border */
    .canvas-pane {
      border-inline-start-color: oklch(from var(--glass-tint) l c h / 0.1);
    }

    /* Completion state */
    .session-complete {
      .complete-icon {
        color: oklch(55% 0.18 145);
      }

      p {
        color: var(--text-secondary);
      }
    }

    /* Error state */
    .session-error {
      color: var(--text-secondary);

      h2 {
        color: var(--text-primary);
      }
    }
  }
}

/* Components layer — layout, sizing, spacing only */
@layer components {
  /* Full-bleed session: body flex column so page fills space after nav */
  body:has(.simulation-session-page) {
    display: flex;
    flex-direction: column;
    block-size: 100dvb;
    overflow: hidden;
  }

  /* Canvas fullscreen: hide nav, lock scroll */
  body.canvas-fullscreen {
    overflow: hidden;

    > nav {
      display: none;
    }
  }

  body:has(.simulation-session-page) > #main-content {
    flex: 1;
    min-block-size: 0;
    display: flex;
    flex-direction: column;
  }

  .simulation-session-page {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-block-size: 0;
    padding-block: 0;
    padding-inline: 0;
    overflow: hidden;

    /* Theme toggle pinned top-right (the full-screen session has no nav). The
       z-index sits below the welcome/consent/fullscreen overlays (45–200) so
       modals cover it, but above the session content. Button visuals + the
       sun/moon swap come from base.css; this only positions it. */
    .session-theme-toggle {
      position: absolute;
      inset-block-start: var(--space-sm);
      inset-inline-end: var(--space-md);
      z-index: 30;
    }

    /* Respect the hidden attribute even when display is set explicitly */
    [hidden] {
      display: none !important;
    }

    /* ── Loading state ── */
    .session-loading {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: var(--space-md);
      flex: 1;
      font-size: var(--fs-large);
    }

    .loading-spinner {
      inline-size: 40px;
      block-size: 40px;
      border: 3px solid;
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }

    /* ── Session container ── */
    .session-container {
      display: flex;
      flex-direction: column;
      flex: 1;
      min-block-size: 0;
      max-inline-size: min(1200px, 100% - 2rem);
      inline-size: 100%;
      margin-inline: auto;
      padding-inline: var(--space-md);
    }

    /* ── Voice pane ── */
    .voice-pane {
      display: flex;
      flex-direction: column;
      flex: 1;
      min-block-size: 0;
      padding-block: 1rem;
    }

    /* ── Canvas pane ── */
    .canvas-pane {
      display: flex;
      flex-direction: column;
      min-block-size: 0;
      overflow: auto;
      border-inline-start: 1px solid;
      padding-inline-start: var(--space-md);
    }

    /* ── Split layout (voice left + canvas right) ── */
    .session-container.split-layout {
      max-inline-size: min(1600px, 100% - 2rem);
      display: grid;
      grid-template-columns: minmax(380px, 2fr) minmax(0, 3fr);
      grid-template-rows: auto 1fr auto;
      gap: 0 var(--space-md);
    }

    @media (width >= 1500px) {
      .session-container.split-layout {
        grid-template-columns: minmax(420px, 2.2fr) minmax(0, 3.4fr);
      }
    }

    .session-container.split-layout .session-header {
      grid-column: 1 / -1;
    }

    .session-container.split-layout .voice-pane {
      grid-column: 1;
      grid-row: 2;
    }

    .session-container.split-layout .canvas-pane {
      grid-column: 2;
      grid-row: 2;
    }

    .session-container.split-layout .next-task-bar {
      grid-column: 1 / -1;
    }

    /* ── Debrief mode: canvas fades ── */
    .session-container.debrief-mode .canvas-pane {
      opacity: 0.3;
      pointer-events: none;
      transition: opacity 0.4s ease;
    }

    /* ── AI speaking: the always-visible brief gently recedes (never hidden) —
       a soft nudge to listen. It stays legible, scrollable, and selectable, so
       no pointer-events lockout and a gentler dim than the debrief canvas. ── */
    .session-container.ai-speaking .task-details {
      opacity: 0.4;
    }

    /* ── Phase badge ── */
    .phase-badge {
      white-space: nowrap;
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-semibold);
      padding: 4px 12px;
      border-radius: 100px;
      flex-shrink: 0;
      text-transform: uppercase;
      letter-spacing: 0.05em;
    }

    /* ── Task header ── */
    .session-header {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: var(--space-md);
      padding-block: var(--space-md);
      /* Reserve the top-right gutter so the brief never runs under the absolute
         theme toggle (44px button + its inset) on narrow widths. */
      padding-inline: 0 calc(44px + var(--space-md) + var(--space-xs));
      border-block-end: 1px solid;
      flex-shrink: 0;
    }

    /* Visually hidden but still announced by screen readers so candidates
       using assistive tech know which task they're on. */
    .task-title {
      position: absolute;
      inline-size: 1px;
      block-size: 1px;
      margin: -1px;
      padding: 0;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
      border: 0;
    }

    .task-details {
      margin-block-start: var(--space-xs);
      transition: opacity 0.4s ease;
    }

    .task-description {
      font-size: var(--fs-small);
      margin: var(--space-xs) 0 0;
      line-height: 1.5;

      /* The brief is always visible (header row is `auto` in the session
         grid), so cap its height and scroll internally — a long brief must
         not crush the voice/canvas panes below. */
      max-block-size: 8lh;
      overflow-y: auto;

      /* Markdown-rendered content */
      p {
        margin: 0 0 0.3em;
      }
      p:last-child {
        margin-bottom: 0;
      }
      ul {
        margin: 0.3em 0;
        padding-left: 1.4em;
      }
      li {
        margin-bottom: 0.15em;
      }
      strong {
        color: var(--accent-primary, oklch(0.65 0.15 250));
        font-weight: 600;
      }
    }

    .task-progress {
      white-space: nowrap;
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-medium);
      padding: 4px 12px;
      border-radius: 100px;
      flex-shrink: 0;
    }

    .session-header-right {
      display: flex;
      align-items: center;
      gap: var(--space-sm);
    }

    /* ── Custom element host sizing ── */
    session-chat,
    session-multichoice,
    session-excel,
    session-ppt,
    session-code,
    session-diagram,
    voice-screen {
      flex: 1;
      min-block-size: 0;
    }

    /* In canvas pane, components fill the pane */
    .canvas-pane session-excel,
    .canvas-pane session-ppt,
    .canvas-pane session-code,
    .canvas-pane session-multichoice,
    .canvas-pane session-diagram {
      flex: 1;
      min-block-size: 0;
    }

    /* ── Next task bar ── */
    .next-task-bar {
      display: flex;
      justify-content: center;
      padding: var(--space-md) 0;
      flex-shrink: 0;
    }

    /* ── Completion state ── */
    .session-complete {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: var(--space-md);
      flex: 1;
      text-align: center;
      padding: var(--space-2xl);

      h1 {
        font-family: var(--font-heading);
        font-size: var(--fs-xxl);
        font-weight: var(--fw-bold);
      }

      p {
        max-inline-size: 480px;
        line-height: 1.7;
      }

      .complete-actions {
        display: flex;
        gap: var(--space-md);
        flex-wrap: wrap;
        justify-content: center;
      }
    }

    /* ── Error state ── */
    .session-error {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: var(--space-md);
      flex: 1;
      text-align: center;
      padding: var(--space-2xl);
    }
  }

  /* ── Responsive ── */
  @media (width < 900px) {
    .simulation-session-page {
      .session-container.split-layout {
        grid-template-columns: 1fr;
      }

      .session-container.split-layout .canvas-pane {
        grid-column: 1;
        grid-row: 3;
        max-block-size: 50dvb;
        border-inline-start: none;
        padding-inline-start: 0;
        border-block-start: 1px solid oklch(from var(--glass-tint) l c h / 0.1);
        padding-block-start: var(--space-md);
      }

      .session-container.split-layout .next-task-bar {
        grid-row: 4;
      }
    }
  }

  @media (width < 640px) {
    /* Allow the page to scroll on mobile instead of being viewport-locked */
    body:has(.simulation-session-page) {
      block-size: auto;
      overflow: auto;
    }

    .simulation-session-page {
      overflow: auto;

      .session-header {
        flex-direction: column;
        gap: var(--space-sm);
        padding: var(--space-sm) 0;
      }

      .task-description {
        font-size: var(--fs-xsmall);
      }

      .session-header-right {
        align-self: flex-start;
      }

      /* Drop the grid on mobile — use a simple stacked flex column */
      .session-container.split-layout {
        display: flex;
        flex-direction: column;
        gap: var(--space-md);
      }

      .voice-pane {
        flex: none;
      }

      .canvas-pane {
        flex: none;
        max-block-size: none;
        border-inline-start: none;
        padding-inline-start: 0;
        border-block-start: 1px solid oklch(from var(--glass-tint) l c h / 0.1);
        padding-block-start: var(--space-md);
      }
    }
  }

  /* ── Short viewport — reclaim chrome so the session fits without scroll ── */
  @media (height < 640px) {
    /* The footer isn't needed mid-interview — hide it to free vertical space */
    body:has(.simulation-session-page) > .page-footer {
      display: none;
    }

    .simulation-session-page {
      .session-header {
        padding-block: var(--space-sm);
      }
    }
  }

  /* ── Very short viewport — last-resort scroll so the controls stay
     reachable even when shrinking the layout isn't enough ── */
  @media (height < 520px) {
    body:has(.simulation-session-page) {
      block-size: auto;
      overflow: auto;
    }

    .simulation-session-page {
      min-block-size: 30rem;
    }
  }
}

/* ════════════════════════════════════════════════════
   Welcome overlay + Countdown — new styles
   ════════════════════════════════════════════════════ */

@layer theme {
  .simulation-session-page {
    /* Welcome overlay */
    .welcome-card {
      background: oklch(from var(--glass-tint) l c h / 0.04);
      border-color: oklch(from var(--glass-tint) l c h / 0.08);
      box-shadow:
        var(--shadow-lg),
        inset 0 1px 0 oklch(from var(--glass-tint) l c h / 0.05);
    }

    .welcome-card::before {
      background: linear-gradient(90deg, var(--accent-primary), var(--accent-warm));
    }

    .welcome-icon {
      background: oklch(from var(--accent-primary) l c h / 0.1);
      border-color: oklch(from var(--accent-primary) l c h / 0.2);
      color: var(--accent-primary);
    }

    .welcome-card h2 {
      color: var(--text-primary);
    }

    .welcome-subtitle {
      color: var(--text-secondary);
    }

    .welcome-check-item {
      color: var(--text-secondary);

      strong {
        color: var(--text-primary);
      }
    }

    .welcome-check-icon.speaker {
      background: oklch(from var(--accent-primary) l c h / 0.1);
      color: var(--accent-primary);
    }
    .welcome-check-icon.mic {
      background: oklch(from var(--color-success) l c h / 0.1);
      color: var(--color-success);
    }
    .welcome-check-icon.clock {
      background: oklch(from var(--color-warning) l c h / 0.1);
      color: var(--color-warning);
    }
    .welcome-check-icon.headphones {
      background: oklch(from var(--color-info) l c h / 0.1);
      color: var(--color-info);
    }

    .welcome-text-link {
      color: var(--text-secondary);
    }

    /* Countdown overlay */
    .countdown-number {
      background: linear-gradient(135deg, var(--accent-primary), var(--accent-warm));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }

    .countdown-text {
      color: var(--text-secondary);
    }

    /* Consent overlay */
    .consent-card {
      background: oklch(from var(--glass-tint) l c h / 0.04);
      border-color: oklch(from var(--glass-tint) l c h / 0.08);
      box-shadow:
        var(--shadow-lg),
        inset 0 1px 0 oklch(from var(--glass-tint) l c h / 0.05);
    }

    .consent-card::before {
      background: linear-gradient(90deg, var(--color-warning), var(--accent-primary));
    }

    .consent-icon {
      background: oklch(from var(--color-warning) l c h / 0.1);
      border-color: oklch(from var(--color-warning) l c h / 0.2);
      color: var(--color-warning);
    }

    .consent-card h2 {
      color: var(--text-primary);
    }

    .consent-subtitle {
      color: var(--text-secondary);
    }

    .consent-details {
      color: var(--text-secondary);

      strong {
        color: var(--text-primary);
      }
    }

    .consent-input-label {
      color: var(--text-secondary);

      strong {
        color: var(--text-primary);
      }
    }

    .consent-error {
      color: var(--color-warning);
      font-size: 0.85rem;
      text-align: left;
    }

    .consent-input {
      background: oklch(from var(--glass-tint) l c h / 0.04);
      border-color: oklch(from var(--glass-tint) l c h / 0.15);
      color: var(--text-primary);

      &::placeholder {
        color: oklch(from var(--text-secondary) l c h / 0.5);
      }

      &:focus {
        border-color: var(--accent-primary);
        outline: none;
        box-shadow: 0 0 0 3px oklch(from var(--accent-primary) l c h / 0.15);
      }

      &.consent-input--valid {
        border-color: var(--color-success);
      }
    }

    .consent-cancel-link {
      color: var(--text-secondary);
    }
  }
}

@layer components {
  .simulation-session-page {
    /* ── Welcome overlay ── */
    .session-welcome-overlay {
      position: absolute;
      inset: 0;
      z-index: 50;
      display: flex;
      align-items: center;
      justify-content: center;
      background: oklch(from var(--surface-sunken) l c h / 0.8);
      backdrop-filter: blur(24px);
    }

    .welcome-card {
      border: 1px solid;
      border-radius: var(--radius-2xl);
      padding: 40px 44px;
      max-inline-size: 520px;
      inline-size: 92%;
      backdrop-filter: blur(20px);
      position: relative;
      overflow: hidden;
    }

    .welcome-card::before {
      content: '';
      position: absolute;
      inset-block-start: 0;
      inset-inline: 0;
      block-size: 2px;
      opacity: 0.6;
    }

    .welcome-icon {
      inline-size: 52px;
      block-size: 52px;
      border-radius: var(--radius-lg);
      border: 1px solid;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-block-end: 20px;
    }

    .welcome-card h2 {
      font-family: var(--font-heading);
      font-size: 1.4rem;
      font-weight: var(--fw-bold);
      margin-block-end: 8px;
      letter-spacing: -0.02em;
    }

    .welcome-subtitle {
      font-size: var(--fs-small);
      line-height: 1.6;
      margin-block-end: 24px;
    }

    .welcome-checklist {
      display: flex;
      flex-direction: column;
      gap: 14px;
      margin-block-end: 28px;
    }

    .welcome-check-item {
      display: flex;
      align-items: flex-start;
      gap: 12px;
      font-size: var(--fs-xsmall);
      line-height: 1.55;

      strong {
        font-weight: var(--fw-semibold);
      }
    }

    .welcome-check-icon {
      inline-size: 30px;
      block-size: 30px;
      border-radius: var(--radius-sm);
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      margin-block-start: 1px;
    }

    .welcome-start-btn {
      inline-size: 100%;
    }

    .welcome-text-link {
      display: block;
      inline-size: 100%;
      text-align: center;
      margin-block-start: 14px;
      font-size: var(--fs-tiny);
      background: none;
      border: none;
      font-family: var(--font-primary);
      cursor: pointer;
      opacity: 0.7;
      transition: opacity var(--time-fast) ease;

      &:hover {
        opacity: 1;
      }
    }

    /* ── Consent overlay ── */
    .session-consent-overlay {
      position: absolute;
      inset: 0;
      z-index: 50;
      display: flex;
      align-items: center;
      justify-content: center;
      background: oklch(from var(--surface-sunken) l c h / 0.8);
      backdrop-filter: blur(24px);
    }

    .consent-card {
      border: 1px solid;
      border-radius: var(--radius-2xl);
      padding: 40px 44px;
      max-inline-size: 520px;
      inline-size: 92%;
      backdrop-filter: blur(20px);
      position: relative;
      overflow: hidden;
    }

    .consent-card::before {
      content: '';
      position: absolute;
      inset-block-start: 0;
      inset-inline: 0;
      block-size: 2px;
      opacity: 0.6;
    }

    .consent-icon {
      inline-size: 52px;
      block-size: 52px;
      border-radius: var(--radius-lg);
      border: 1px solid;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-block-end: 20px;
    }

    .consent-card h2 {
      font-family: var(--font-heading);
      font-size: 1.4rem;
      font-weight: var(--fw-bold);
      margin-block-end: 8px;
      letter-spacing: -0.02em;
    }

    .consent-subtitle {
      font-size: var(--fs-small);
      line-height: 1.6;
      margin-block-end: 20px;
    }

    .consent-details {
      list-style: none;
      padding: 0;
      margin: 0 0 24px;
      display: flex;
      flex-direction: column;
      gap: 12px;
      font-size: var(--fs-xsmall);
      line-height: 1.55;

      strong {
        font-weight: var(--fw-semibold);
      }
    }

    .consent-input-label {
      display: block;
      font-size: var(--fs-xsmall);
      line-height: 1.5;
      margin-block-end: 8px;

      strong {
        font-weight: var(--fw-semibold);
      }
    }

    .consent-input {
      inline-size: 100%;
      padding: 10px 14px;
      border: 1px solid;
      border-radius: var(--radius-md);
      font-family: var(--font-primary);
      font-size: var(--fs-small);
      margin-block-end: 16px;
      transition:
        border-color var(--time-fast) ease,
        box-shadow var(--time-fast) ease;
    }

    .consent-proceed-btn {
      inline-size: 100%;
    }

    .consent-cancel-link {
      display: block;
      inline-size: 100%;
      text-align: center;
      margin-block-start: 14px;
      font-size: var(--fs-tiny);
      background: none;
      border: none;
      font-family: var(--font-primary);
      cursor: pointer;
      opacity: 0.7;
      transition: opacity var(--time-fast) ease;

      &:hover {
        opacity: 1;
      }
    }

    /* ── Countdown overlay ── */
    .session-countdown-overlay {
      position: absolute;
      inset: 0;
      z-index: 45;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background: oklch(from var(--surface-sunken) l c h / 0.88);
      backdrop-filter: blur(16px);
      gap: 14px;
    }

    .countdown-number {
      font-family: var(--font-heading);
      font-size: 80px;
      font-weight: var(--fw-bold);
      animation: count-pop 1s ease-in-out infinite;
    }

    .countdown-text {
      font-size: var(--fs-small);
      font-weight: var(--fw-medium);
    }
  }

  /* ── Responsive — welcome / consent overlays ── */
  @media (width < 640px) {
    .simulation-session-page {
      .welcome-card,
      .consent-card {
        padding: 28px 24px;
        border-radius: var(--radius-xl);
      }

      .welcome-card h2,
      .consent-card h2 {
        font-size: 1.2rem;
      }
    }
  }
}

/* ════════════════════════════════════════════════════
   First-time tour — overlay + spotlight ring + mock canvas

   Layered under `components.tour` / `theme.tour` so the feature carries
   its provenance in the layer name itself. Sub-layers cascade exactly
   like their parent (the order declared in base.css), so `components.tour`
   sits with the rest of `components` and `theme.tour` with the rest of
   `theme` — the dot suffix is only a label that makes it obvious which
   rules belong to this feature when scanning the file.
   ════════════════════════════════════════════════════ */

@layer components.tour {
  .session-tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    pointer-events: none;

    /* Full-screen dim used when there is NO spotlight (intro / closing / mock-only
       steps). When a spotlight is active the ring itself paints the dim via a
       huge box-shadow so the highlighted element stays bright. Color rules
       live in the matching `@layer theme` block below. */
    .tut-backdrop {
      position: absolute;
      inset: 0;
      backdrop-filter: blur(2px);
      pointer-events: auto;
      transition: opacity var(--time-fast) ease;
    }

    &.has-spotlight .tut-backdrop {
      /* Ring's box-shadow handles the dim — hide the flat backdrop so we
         don't double-dim the spotlighted control. */
      opacity: 0;
      pointer-events: none;
    }

    /* Highlight ring around the spotlighted element. The first box-shadow
       extends 9999px outward to dim everything beyond the ring while leaving
       the area inside the border untouched. Color rules live in the matching
       `@layer theme` block below. */
    .tut-ring {
      position: fixed;
      border-radius: var(--radius-md);
      pointer-events: auto;
      transition:
        top 0.22s ease,
        left 0.22s ease,
        width 0.22s ease,
        height 0.22s ease;
      animation: tut-ring-pulse 1.6s ease-in-out infinite;
    }

    .tut-card {
      position: fixed;
      inline-size: min(360px, calc(100vw - 32px));
      max-block-size: calc(100vh - 32px);
      overflow-y: auto;
      padding: 20px 22px;
      border-radius: var(--radius-xl);
      backdrop-filter: blur(16px);
      pointer-events: auto;
      font-size: var(--fs-small);

      &.tut-card--center {
        top: 50%;
        left: 50%;
        translate: -50% -50%;
      }
    }

    .tut-close {
      position: absolute;
      inset-block-start: 10px;
      inset-inline-end: 10px;
      inline-size: 28px;
      block-size: 28px;
      border-radius: 50%;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition:
        color var(--time-fast) ease,
        border-color var(--time-fast) ease;
    }

    .tut-progress {
      font-size: var(--fs-tiny);
      font-weight: var(--fw-semibold);
      text-transform: uppercase;
      letter-spacing: 0.08em;
      margin-block-end: 6px;
    }

    .tut-title {
      font-family: var(--font-heading);
      font-size: 1.05rem;
      font-weight: var(--fw-semibold);
      margin: 0 24px 10px 0;
      line-height: 1.3;
    }

    .tut-body {
      line-height: 1.55;

      p {
        margin: 0 0 10px;
      }
      p:last-child {
        margin-block-end: 0;
      }
      strong {
        font-weight: var(--fw-semibold);
      }
      em {
        font-style: normal;
        font-weight: var(--fw-semibold);
      }
      kbd {
        display: inline-block;
        padding: 1px 6px;
        margin: 0 1px;
        font-family: var(--font-mono, ui-monospace, monospace);
        font-size: var(--fs-tiny);
        line-height: 1.4;
        border-radius: 4px;
      }
    }

    .tut-tip {
      font-size: var(--fs-tiny);
      opacity: 0.75;
    }

    .tut-disclosure {
      margin-block-start: 12px;
      padding: 10px 12px;
      border-radius: var(--radius-md);
      font-size: var(--fs-xsmall);
      line-height: 1.5;
    }

    /* ── Mock canvas illustration ── */
    .tut-mock {
      margin-block: 14px 4px;
    }

    .tut-mock-canvas {
      border-radius: var(--radius-md);
      overflow: hidden;
    }

    .tut-mock-canvas-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: var(--space-sm);
      padding: 6px 8px 6px 10px;
    }

    .tut-mock-canvas-title {
      font-size: var(--fs-tiny);
      font-weight: var(--fw-semibold);
      text-transform: uppercase;
      letter-spacing: 0.06em;
    }

    .tut-mock-canvas-expand {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 4px 10px;
      border-radius: var(--radius-sm);
      font-family: var(--font-primary);
      font-size: var(--fs-tiny);
      font-weight: var(--fw-semibold);
      cursor: default;
    }

    .tut-pulse {
      animation: tut-mock-pulse 1.6s ease-in-out infinite;
    }

    .tut-mock-canvas-grid {
      display: flex;
      flex-direction: column;
      font-family: var(--font-mono, ui-monospace, monospace);
      font-size: var(--fs-tiny);
    }

    .tut-mock-row {
      display: grid;
      grid-template-columns: 30px repeat(4, 1fr);
      gap: 0;

      span {
        padding: 5px 8px;
      }

      &.tut-mock-row--head {
        font-weight: var(--fw-semibold);
      }
    }

    /* ── Mock next-task button ── */
    .tut-mock-nextbar {
      display: flex;
      justify-content: center;
      padding: 4px 0;
    }

    .tut-mock-next {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      padding: 9px 18px;
      border-radius: 100px;
      border: none;
      font-family: var(--font-primary);
      font-size: var(--fs-small);
      font-weight: var(--fw-semibold);
      cursor: default;
    }

    /* ── Action row ── */
    .tut-actions {
      display: flex;
      align-items: center;
      gap: 10px;
      margin-block-start: 18px;
    }

    .tut-actions-grow {
      flex: 1;
    }

    .tut-skip,
    .tut-back {
      padding: 7px 14px;
      border-radius: 100px;
      font-family: var(--font-primary);
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-medium);
      cursor: pointer;
      transition:
        color var(--time-fast) ease,
        border-color var(--time-fast) ease;
    }

    .tut-next {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 8px 18px;
      font-size: var(--fs-xsmall);
    }
  }

  @media (width < 640px) {
    .session-tutorial-overlay .tut-card {
      inline-size: calc(100vw - 24px);
      padding: 16px 18px;
    }
    .session-tutorial-overlay .tut-title {
      font-size: 1rem;
    }
  }
}

/* All color / surface / border-color / background / box-shadow / text-color
   rules for the tutorial overlay live here so the components block above
   carries only structural concerns. The backdrop dim is always-dark by
   convention (a modal backdrop derived from a surface token would flip to
   a washout under the light theme); the per-theme tokens below tune the
   alpha because the light page needs more punch to actually recede. The
   `.tut-ring` box-shadow is driven by an animation, so the dim color is
   exposed as a CSS variable that both the static rule and the @keyframes
   consume — without that, a theme override on the static rule alone would
   be wiped the moment the pulse animation takes over the property. */
@layer theme.tour {
  .session-tutorial-overlay {
    --tut-backdrop-color: oklch(0% 0 0 / 0.45);
    --tut-ring-dim-color: oklch(0% 0 0 / 0.55);

    .tut-backdrop {
      background: var(--tut-backdrop-color);
    }

    .tut-ring {
      border: 2px solid var(--accent-primary);
      box-shadow:
        0 0 0 9999px var(--tut-ring-dim-color),
        0 0 0 4px oklch(from var(--accent-primary) l c h / 0.25),
        0 0 24px 4px oklch(from var(--accent-primary) l c h / 0.45);
    }

    .tut-card {
      background: var(--surface-elevated, var(--bg-primary));
      border: 1px solid oklch(from var(--glass-tint) l c h / 0.15);
      box-shadow: var(--shadow-lg);
      color: var(--text-primary);
    }

    .tut-close {
      border: 1px solid oklch(from var(--glass-tint) l c h / 0.15);
      background: transparent;
      color: var(--text-secondary);

      &:hover {
        color: var(--accent-primary);
        border-color: var(--accent-primary);
      }
    }

    .tut-progress {
      color: var(--accent-primary);
    }

    .tut-title {
      color: var(--text-primary);
    }

    .tut-body {
      color: var(--text-secondary);

      strong {
        color: var(--text-primary);
      }
      em {
        color: var(--accent-primary);
      }
      kbd {
        background: oklch(from var(--glass-tint) l c h / 0.08);
        border: 1px solid oklch(from var(--glass-tint) l c h / 0.18);
        color: var(--text-primary);
      }
    }

    .tut-disclosure {
      background: oklch(from var(--accent-primary) l c h / 0.06);
      border: 1px solid oklch(from var(--accent-primary) l c h / 0.18);
    }

    .tut-mock-canvas {
      border: 1px solid oklch(from var(--glass-tint) l c h / 0.15);
      background: oklch(from var(--glass-tint) l c h / 0.04);
    }

    .tut-mock-canvas-bar {
      border-block-end: 1px solid oklch(from var(--glass-tint) l c h / 0.1);
      background: oklch(from var(--glass-tint) l c h / 0.05);
    }

    .tut-mock-canvas-title {
      color: var(--text-secondary);
    }

    .tut-mock-canvas-expand {
      border: 1px solid var(--accent-primary);
      background: oklch(from var(--accent-primary) l c h / 0.1);
      color: var(--accent-primary);
    }

    .tut-mock-canvas-grid {
      color: var(--text-secondary);
    }

    .tut-mock-row {
      span {
        border-block-end: 1px solid oklch(from var(--glass-tint) l c h / 0.08);
        border-inline-end: 1px solid oklch(from var(--glass-tint) l c h / 0.08);
      }

      span:last-child {
        border-inline-end: 0;
      }

      &.tut-mock-row--head {
        background: oklch(from var(--glass-tint) l c h / 0.06);
        color: var(--text-secondary);
      }
    }

    .tut-mock-next {
      background: linear-gradient(135deg, var(--accent-primary), var(--accent-warm));
      color: oklch(100% 0 0);
      box-shadow: var(--shadow-md);
    }

    .tut-skip,
    .tut-back {
      background: transparent;
      border: 1px solid oklch(from var(--glass-tint) l c h / 0.15);
      color: var(--text-secondary);

      &:hover {
        color: var(--accent-primary);
        border-color: var(--accent-primary);
      }
    }
  }

  html[data-theme='light'] .session-tutorial-overlay {
    --tut-backdrop-color: oklch(0% 0 0 / 0.6);
    --tut-ring-dim-color: oklch(0% 0 0 / 0.7);
  }
}

@keyframes tut-mock-pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 0 oklch(from var(--accent-primary) l c h / 0.4),
      0 0 0 0 oklch(from var(--accent-primary) l c h / 0);
  }
  50% {
    box-shadow:
      0 0 0 4px oklch(from var(--accent-primary) l c h / 0.25),
      0 0 16px 3px oklch(from var(--accent-primary) l c h / 0.4);
  }
}

/* Dim is sourced from `--tut-ring-dim-color` (defined in the matching
   theme block) so the per-theme override actually survives the animation
   — without that, the light-theme override on the static `.tut-ring`
   rule gets wiped the moment this animation starts. */
@keyframes tut-ring-pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 9999px var(--tut-ring-dim-color),
      0 0 0 4px oklch(from var(--accent-primary) l c h / 0.2),
      0 0 24px 4px oklch(from var(--accent-primary) l c h / 0.35);
  }
  50% {
    box-shadow:
      0 0 0 9999px var(--tut-ring-dim-color),
      0 0 0 6px oklch(from var(--accent-primary) l c h / 0.4),
      0 0 32px 6px oklch(from var(--accent-primary) l c h / 0.55);
  }
}

/* ── Keyframes ── */

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes count-pop {
  0% {
    transform: scale(1.15);
    opacity: 0.5;
  }
  30% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0.96);
    opacity: 0.7;
  }
}
