/* ------------------------------------------------------------------
   App shell and UI components (web), v2 "studio". Tokens only: every
   colour, radius, duration, shadow and wallpaper is a variable from
   app/assets/tailwind/application.css. Same layer order as the Tailwind
   build, so utilities still win over these component rules.

   Tailwind emits a theme variable only when a utility in a template uses
   it. The radii, durations and type sizes used here are all used by
   utilities somewhere in the app's templates, so they exist at runtime
   (checked after every change: every var() here is in builds/tailwind.css).
   Shared with the landing: tailwind/base.css. Video surfaces (stages,
   library, theater, share page): videos.css, loaded only on those pages.
   ------------------------------------------------------------------ */
@layer theme, base, components, utilities;

@layer components {
  /* ================================================================ shell */
  /* The bar's glass is on a pseudo-element: backdrop-filter on the bar
     itself would trap the phone nav (position: fixed) inside it. The same
     goes for view-transition-name (it makes the bar a backdrop root and the
     phone pill's blur would see nothing), so it is set on wide screens only. */
  .app-bar {
    position: sticky;
    top: 0;
    z-index: 40;
    border-bottom: 1px solid var(--line);
    @media (min-width: 40rem) { view-transition-name: app-bar; }
    &::before {
      content: "";
      position: absolute;
      inset: 0;
      z-index: -1;
      background: var(--glass);
      -webkit-backdrop-filter: blur(20px) saturate(1.6);
      backdrop-filter: blur(20px) saturate(1.6);
    }
  }
  .app-bar-inner {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.75rem;
    height: 3.5rem;
    max-width: 82rem;
    margin-inline: auto;
    padding-inline: 1rem;
    @media (min-width: 40rem) { grid-template-columns: 1fr auto 1fr; padding-inline: 1.5rem; }
  }
  .app-bar-end { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; }

  /* The three places. One nav element: a segmented switch in the bar on
     wide screens, a floating glass pill in thumb reach on phones. */
  .app-nav {
    position: fixed;
    z-index: 40;
    left: 50%;
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    display: flex;
    gap: 2px;
    padding: 4px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    box-shadow: var(--overlay-shadow);
    transform: translateX(-50%);
    view-transition-name: app-nav;
    @media (min-width: 40rem) {
      position: static;
      transform: none;
      padding: 3px;
      background: var(--raised);
      border-color: var(--line);
      box-shadow: none;
      -webkit-backdrop-filter: none;
      backdrop-filter: none;
    }
  }
  .app-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4375rem;
    height: 2.5rem;
    padding-inline: 0.875rem;
    border-radius: 999px;
    font-size: var(--text-sm);
    font-weight: 560;
    color: var(--muted);
    white-space: nowrap;
    transition: color var(--duration-fast) var(--ease-out), background-color var(--duration-fast) var(--ease-out);
    &:hover { color: var(--ink); }
    &[aria-current="page"] { color: var(--ink); background: var(--overlay); box-shadow: inset 0 0 0 1px var(--line-strong); }
    &:focus-visible { outline-offset: 1px; }
    @media (min-width: 40rem) { height: 1.875rem; padding-inline: 0.875rem; font-weight: 540; svg { display: none; } }
  }
  .app-main { padding-bottom: 6rem; @media (min-width: 40rem) { padding-bottom: 0; } }

  .cmdk-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    height: 2.25rem;
    min-width: 2.25rem;
    justify-content: center;
    padding-inline: 0.625rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--raised);
    color: var(--muted);
    font-size: var(--text-sm);
    transition: border-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
    &:hover { border-color: var(--line-strong); color: var(--ink); }
    @media (min-width: 64rem) { width: 15rem; justify-content: flex-start; padding-inline: 0.875rem 0.375rem; }
  }
  .cmdk-trigger-label {
    flex: 1;
    text-align: left;
    @media (max-width: 63.99rem) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  }
  .cmdk-trigger .kbd-group { display: none; @media (min-width: 64rem) { display: inline-flex; } }

  .page {
    width: 100%;
    max-width: 82rem;
    margin-inline: auto;
    padding: 1.75rem 1rem 4rem;
    @media (min-width: 40rem) { padding: 2.5rem 1.5rem 5rem; }
  }
  .page-narrow { max-width: 60rem; }
  .page-title {
    font-size: var(--text-2xl);
    line-height: var(--text-2xl--line-height);
    font-weight: 660;
    letter-spacing: -0.025em;
    color: var(--ink);
    text-wrap: balance;
  }

  /* ========================================================= components */
  .kbd-group { display: inline-flex; align-items: center; gap: 0.25rem; }
  .btn-icon { width: 2.25rem; padding-inline: 0; }
  .btn-sm.btn-icon { width: 1.875rem; }
  .btn-lg.btn-icon { width: 2.75rem; }
  .btn-lg { border-radius: var(--radius-md); }
  .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
  .btn-quiet { color: var(--ink); }
  .btn-primary { box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--accent-ink) 18%, transparent); }
  .btn:active:not(:disabled):not([aria-disabled="true"]) { transform: scale(0.98); }
  .btn-pill { border-radius: 999px; }
  .btn-danger-quiet { background: transparent; color: var(--danger); &:hover:not(:disabled) { background: var(--danger-surface); } }

  .avatar {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--overlay);
    box-shadow: inset 0 0 0 1px var(--line-strong);
    color: var(--ink);
    font-weight: 640;
    letter-spacing: 0.01em;
    line-height: 1;
  }
  .avatar-button { border-radius: 999px; padding: 2px; transition: background-color var(--duration-fast) var(--ease-out); &:hover { background: var(--raised); } }

  .input { transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out); }
  .input:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent); }
  .input-lg { height: 2.75rem; padding-inline: 0.875rem; font-size: var(--text-md); border-radius: var(--radius-md); }
  .input:read-only:not([type="radio"]) {
    background: var(--raised);
    color: var(--muted);
    &:hover { border-color: var(--line-strong); }
  }
  /* A field with a leading icon and a trailing key hint (search). */
  .input-affix { position: relative; display: flex; align-items: center; }
  .input-affix > svg { position: absolute; left: 0.75rem; color: var(--faint); pointer-events: none; }
  .input-affix .input { padding-left: 2.25rem; padding-right: 2.25rem; }
  .input-affix > .kbd { position: absolute; right: 0.5rem; pointer-events: none; @media (pointer: coarse) { display: none; } }
  /* Password with a show/hide toggle inside the field. */
  .input-reveal { position: relative; }
  .input-reveal .input { padding-right: 2.75rem; }
  .input-reveal-toggle { position: absolute; right: 0.25rem; top: 50%; transform: translateY(-50%); color: var(--muted); &:hover { color: var(--ink); } }

  .chip-glass {
    background: var(--glass);
    color: var(--ink);
    border-color: var(--line-strong);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
  .live-dot {
    width: 0.4375rem;
    height: 0.4375rem;
    border-radius: 999px;
    background: var(--accent);
    flex-shrink: 0;
    animation: w-pulse 1.4s var(--ease-in-out) infinite;
  }
  .chip-live .live-dot { background: var(--accent-ink); }

  .empty-state {
    padding: 2rem 1.75rem;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-md);
    background: var(--surface);
  }

  .divider-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: var(--text-sm);
    color: var(--muted);
    &::before, &::after { content: ""; height: 1px; flex: 1; background: var(--line); }
  }

  .link {
    color: var(--ink);
    text-decoration: underline;
    text-decoration-color: var(--line-strong);
    text-underline-offset: 3px;
    border-radius: 2px;
    &:hover { text-decoration-color: currentColor; }
  }
  .link-quiet {
    color: var(--muted);
    border-radius: var(--radius-xs);
    &:hover { color: var(--ink); }
  }

  /* Dialog: native <dialog>; the panel is the visible box so a click on
     the dialog element itself is a click on the backdrop. */
  .dialog {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink);
    width: calc(100% - 2rem);
    max-width: 28rem;
    margin: auto;
    overflow: visible;
    &::backdrop { background: color-mix(in srgb, var(--canvas) 55%, transparent); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
    &[open] { animation: w-rise var(--duration-base) var(--ease-out); }
    &[open]::backdrop { animation: w-fade var(--duration-base) var(--ease-out); }
  }
  .dialog-panel {
    padding: 1.375rem;
    background: var(--overlay);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--overlay-shadow);
  }

  /* Menu: a popover in the top layer, placed under its button by the menu
     controller. */
  .menu {
    position: fixed;
    inset: auto;
    margin: 0;
    min-width: 15rem;
    max-width: calc(100vw - 1.5rem);
    padding: 0.3125rem;
    color: var(--ink);
    background: var(--glass);
    -webkit-backdrop-filter: blur(24px) saturate(1.6);
    backdrop-filter: blur(24px) saturate(1.6);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--overlay-shadow);
    &:popover-open { animation: w-drop var(--duration-fast) var(--ease-out); }
  }
  .menu-header {
    margin: -0.3125rem -0.3125rem 0.3125rem;
    padding: 0.75rem 0.875rem;
    border-bottom: 1px solid var(--line);
  }
  .menu-item {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 0.625rem;
    min-height: 2.125rem;
    padding-inline: 0.625rem;
    border-radius: var(--radius-sm);
    font-size: var(--text-base);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
    &:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
    &:focus-visible { background: color-mix(in srgb, var(--ink) 7%, transparent); outline-offset: -2px; }
    svg { color: var(--muted); }
  }
  .menu-item-danger, .menu-item-danger svg { color: var(--danger); }
  .menu-separator { height: 1px; margin: 0.3125rem -0.3125rem; background: var(--line); }

  /* ============================================================== toasts */
  .toast-region {
    position: fixed;
    z-index: 70;
    inset-inline: 0.75rem;
    bottom: calc(max(0.75rem, env(safe-area-inset-bottom)) + 3.75rem);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    @media (min-width: 40rem) { bottom: 1.5rem; }
  }
  .toast-region-plain { bottom: max(0.75rem, env(safe-area-inset-bottom)); @media (min-width: 40rem) { bottom: 1.5rem; } }
  .toast {
    position: relative;
    overflow: hidden;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    max-width: 30rem;
    min-height: 3rem;
    padding: 0.375rem 0.375rem 0.375rem 0.875rem;
    color: var(--ink);
    background: var(--glass);
    -webkit-backdrop-filter: blur(24px) saturate(1.6);
    backdrop-filter: blur(24px) saturate(1.6);
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    box-shadow: var(--overlay-shadow);
    animation: w-rise var(--duration-base) var(--ease-out);
    &[data-leaving] { animation: w-sink var(--duration-fast) var(--ease-out) forwards; }
  }
  .toast-message { min-width: 0; flex: 1; font-size: var(--text-base); line-height: 1.3; overflow-wrap: anywhere; }
  .toast-icon { color: var(--muted); }
  .toast-success .toast-icon { color: var(--success); }
  .toast-danger .toast-icon { color: var(--danger); }
  .toast-action {
    height: 2.125rem;
    padding-inline: 0.875rem;
    border-radius: 999px;
    background: var(--ink);
    color: var(--canvas);
    font-size: var(--text-sm);
    font-weight: 620;
    white-space: nowrap;
    &:hover { background: color-mix(in srgb, var(--ink) 86%, var(--canvas)); }
  }
  .toast-close { border-radius: 999px; }
  /* How long the Undo stays: a hairline that runs out. Its duration is set
     by the toast controller; hover or focus pauses it with the timer. */
  .toast-timer {
    position: absolute;
    left: 1.5rem;
    right: 1.5rem;
    bottom: 0;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
    transform-origin: left;
    animation: w-drain linear forwards;
    .toast[data-paused] & { animation-play-state: paused; }
  }

  /* ===================================================== command palette */
  .palette {
    margin: 13vh auto auto;
    max-width: 40rem;
  }
  .palette-panel {
    overflow: hidden;
    background: var(--glass);
    -webkit-backdrop-filter: blur(32px) saturate(1.7);
    backdrop-filter: blur(32px) saturate(1.7);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--overlay-shadow);
  }
  .palette-search {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-inline: 1.125rem 0.75rem;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
  }
  .palette-input {
    flex: 1;
    min-width: 0;
    height: 3.5rem;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-size: var(--text-lg);
    letter-spacing: -0.01em;
    &::placeholder { color: var(--faint); }
    &:focus-visible { outline: none; }
    &::-webkit-search-cancel-button { display: none; }
  }
  .palette-list {
    max-height: min(26rem, 55vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.375rem;
    scroll-padding-block: 0.375rem;
  }
  .palette-group-label {
    padding: 0.625rem 0.75rem 0.375rem;
    font-size: var(--text-xs);
    font-weight: 560;
    color: var(--muted);
  }
  .palette-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.75rem;
    padding: 0.375rem 0.75rem 0.375rem 0.5rem;
    border-radius: var(--radius-md);
    color: var(--ink);
    font-size: var(--text-base);
    cursor: pointer;
    &[aria-selected="true"] { background: color-mix(in srgb, var(--ink) 8%, transparent); }
  }
  .palette-glyph {
    display: grid;
    place-items: center;
    width: 1.875rem;
    height: 1.875rem;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    background: var(--raised);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--muted);
    .palette-option[aria-selected="true"] & { color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
  }
  .palette-hint { font-size: var(--text-sm); color: var(--muted); white-space: nowrap; }
  .palette-enter { display: none; .palette-option[aria-selected="true"] & { display: inline-flex; } }
  .palette-empty { padding: 0.75rem; font-size: var(--text-base); color: var(--muted); }
  .palette-footer {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0.75rem 0.5rem 1rem;
    border-top: 1px solid var(--line);
    font-size: var(--text-xs);
    color: var(--muted);
  }

  /* ========================================================== auth pages */
  /* Two halves on wide screens: the task on the left, a live product scene
     on a stage on the right. Phones get the task only. */
  .auth-shell {
    display: grid;
    min-height: 100dvh;
    @media (min-width: 64rem) { grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); }
  }
  .auth-side { display: flex; flex-direction: column; min-width: 0; }
  .auth-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: 4rem;
    padding-inline: 1rem;
    @media (min-width: 40rem) { padding-inline: 2rem; }
  }
  .auth-main {
    flex: 1;
    display: grid;
    align-content: start;
    justify-items: center;
    padding: 2.5rem 1rem 4rem;
    @media (min-width: 40rem) { align-content: center; padding-bottom: 6rem; }
  }
  .auth-foot { padding: 1.25rem 1rem; font-size: var(--text-sm); color: var(--muted); text-align: center; @media (min-width: 40rem) { padding-inline: 2rem; text-align: left; } }
  .auth-column { width: 100%; max-width: 24rem; }
  .auth-column-wide { max-width: 28rem; }
  .auth-title {
    font-size: var(--text-2xl);
    line-height: var(--text-2xl--line-height);
    font-weight: 660;
    letter-spacing: -0.028em;
    color: var(--ink);
    text-wrap: balance;
    overflow-wrap: break-word;
  }
  .auth-lede { margin-top: 0.5rem; font-size: var(--text-md); line-height: var(--text-md--line-height); color: var(--muted); text-wrap: pretty; }
  .auth-lede strong { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
  /* An address moves to the next line whole instead of breaking at a hyphen;
     only one longer than the line wraps inside. */
  .auth-email { display: inline-block; max-width: 100%; overflow-wrap: anywhere; }
  .auth-badge {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    margin-bottom: 1.5rem;
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line-strong), var(--overlay-shadow);
    color: var(--ink);
  }
  .auth-badge-success { color: var(--success); }
  .auth-badge-danger { color: var(--danger); }
  .auth-note {
    display: flex;
    gap: 0.625rem;
    padding: 0.75rem 0.875rem;
    border-radius: var(--radius-md);
    background: var(--raised);
    font-size: var(--text-sm);
    line-height: var(--text-sm--line-height);
    color: var(--muted);
    svg { margin-top: 2px; }
  }
  .auth-alert { display: flex; gap: 0.5rem; margin-top: 1rem; font-size: var(--text-sm); color: var(--danger); svg { margin-top: 2px; } &[data-stale] { visibility: hidden; } }
  .soon-tag {
    margin-left: 0.25rem;
    padding: 0.125rem 0.4375rem;
    border-radius: 999px;
    background: var(--raised);
    box-shadow: inset 0 0 0 1px var(--line);
    font-size: var(--text-2xs);
    font-weight: 560;
    color: var(--muted);
  }
  .auth-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 2rem; }

  /* The scene beside sign-in: describe, approve the script, get the video.
     A product frame on a stage wallpaper; one loop, transform and opacity
     only, paused for reduced motion (a still frame stays). */
  .auth-stage {
    display: none;
    @media (min-width: 64rem) {
      position: sticky;
      top: 0;
      height: 100dvh;
      display: grid;
      padding: 0.75rem 0.75rem 0.75rem 0;
    }
  }
  .auth-stage-inner {
    position: relative;
    isolation: isolate;
    display: grid;
    place-items: center;
    align-content: center;
    overflow: hidden;
    padding: 2rem;
    border-radius: var(--radius-xl);
    background: var(--wallpaper-dusk);
  }
  .scene {
    width: 34rem;
    flex-shrink: 0;
    @media (max-width: 80rem) { scale: 0.78; }
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--frame-shadow), inset 0 0 0 1px var(--line);
    color-scheme: inherit;
  }
  .scene-chrome { display: flex; align-items: center; gap: 0.375rem; height: 2.25rem; padding-inline: 0.875rem; border-bottom: 1px solid var(--line); background: var(--raised); }
  .scene-dot { width: 0.5rem; height: 0.5rem; border-radius: 999px; background: var(--line-strong); }
  .scene-url { margin-left: 0.75rem; height: 1.25rem; flex: 1; max-width: 13rem; border-radius: 999px; background: var(--line); }
  .scene-ext { margin-left: auto; display: grid; place-items: center; width: 1.375rem; height: 1.375rem; border-radius: var(--radius-xs); color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
  .scene-body { position: relative; display: grid; grid-template-columns: 6.5rem 1fr; height: 13.5rem; }
  .scene-side { display: grid; align-content: start; gap: 0.5rem; padding: 1rem 0.75rem; border-right: 1px solid var(--line); }
  .scene-bar { height: 0.5rem; border-radius: 999px; background: var(--line-strong); }
  .scene-bar-soft { background: var(--line); }
  .scene-content { display: grid; align-content: start; gap: 0.75rem; padding: 1rem 1.125rem; }
  .scene-row { display: flex; align-items: center; gap: 0.625rem; height: 1.75rem; padding-inline: 0.5rem; border-radius: var(--radius-sm); box-shadow: inset 0 0 0 1px var(--line); }
  .scene-row .scene-bar { flex: 1; }
  .scene-avatar { width: 0.875rem; height: 0.875rem; border-radius: 999px; background: var(--line-strong); }
  .scene-button { justify-self: end; width: 5.5rem; height: 1.625rem; border-radius: var(--radius-sm); background: var(--ink); opacity: 0.85; }
  .scene-ring { position: absolute; border-radius: var(--radius-sm); box-shadow: 0 0 0 2px var(--accent); opacity: 0; animation: scene-ring 9s var(--ease-out) infinite; }
  .scene-ring-1 { right: 1.125rem; top: 1rem; width: 5.5rem; height: 1.625rem; }
  .scene-cursor { position: absolute; left: 0; top: 0; width: 1.125rem; height: 1.125rem; color: var(--ink); filter: drop-shadow(0 1px 1px var(--canvas)); animation: scene-cursor 9s var(--ease-in-out) infinite; }
  .scene-strip { position: relative; display: grid; grid-template-columns: 3fr 2fr 4fr 2.5fr; gap: 0.25rem; padding: 0.75rem 0.875rem 0.875rem; border-top: 1px solid var(--line); background: var(--raised); }
  .scene-beat { height: 1.5rem; border-radius: var(--radius-xs); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-strong); }
  .scene-playhead { position: absolute; top: 0.5rem; bottom: 0.625rem; left: 0.875rem; width: 2px; border-radius: 2px; background: var(--accent); animation: scene-playhead 9s linear infinite; }
  /* Captions roll up through a one-line window: transform only, always at
     full contrast (no fades). */
  .scene-captions { position: relative; height: 1.5rem; margin-top: 0.625rem; padding-left: 0.75rem; grid-column: 1 / -1; overflow: hidden; }
  .scene-caption { position: absolute; inset: 0 0 0 0.75rem; font-size: var(--text-sm); line-height: 1.5rem; color: var(--muted); white-space: nowrap; transform: translateY(110%); animation: scene-caption 9s linear infinite; }
  .scene-caption:nth-child(2) { animation-delay: 3s; }
  .scene-caption:nth-child(3) { animation-delay: 6s; }

  /* One-time code: six cells drawn over one real input, so paste, autofill
     and screen readers all work on a single field. Without JavaScript the
     plain input shows instead. */
  .otp { position: relative; }
  .otp-cells { display: none; }
  .otp[data-enhanced] {
    .otp-cells { display: grid; grid-template-columns: repeat(3, 1fr) 0.75rem repeat(3, 1fr); gap: 0.5rem; pointer-events: none; }
    .otp-input {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      opacity: 0;
      font-size: var(--text-md);
      cursor: text;
    }
  }
  .otp-input-plain { height: 3.5rem; padding-inline: 1rem; font-size: var(--text-2xl); font-weight: 600; letter-spacing: 0.4em; font-variant-numeric: tabular-nums; }
  .otp-cell {
    display: grid;
    place-items: center;
    height: 3.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    font-size: var(--text-2xl);
    font-weight: 620;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
    &[data-filled] { animation: w-pop var(--duration-fast) var(--ease-out); }
  }
  .otp-gap { align-self: center; justify-self: center; width: 0.5rem; height: 2px; border-radius: 2px; background: var(--line-strong); }
  .otp:focus-within .otp-cell[data-active] {
    border-color: var(--focus);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent);
  }
  .otp:focus-within .otp-cell[data-active]:not([data-filled])::after {
    content: "";
    width: 2px;
    height: 1.5rem;
    border-radius: 1px;
    background: var(--ink);
    animation: w-blink 1s steps(1) infinite;
  }
  .otp[data-invalid] .otp-cell { border-color: var(--danger); }
  .otp[data-busy] .otp-cell { color: var(--muted); }
  .otp[data-invalid][data-shake] .otp-cells { animation: w-shake 320ms var(--ease-out); }

  /* Welcome: how the name will look on a share page, as it is typed. */
  .byline-preview {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
  }
  .byline-thumb {
    width: 5rem;
    aspect-ratio: 16 / 10;
    flex-shrink: 0;
    padding: 0.3125rem;
    border-radius: var(--radius-sm);
    background: var(--wallpaper-tide);
  }
  .byline-thumb-frame {
    height: 100%;
    border-radius: var(--radius-xs);
    background:
      linear-gradient(var(--line-strong), var(--line-strong)) 14% 26% / 46% 9% no-repeat,
      linear-gradient(var(--line), var(--line)) 14% 50% / 70% 7% no-repeat,
      linear-gradient(var(--line), var(--line)) 14% 70% / 56% 7% no-repeat,
      var(--surface);
  }
  .byline-title { font-size: var(--text-sm); font-weight: 600; color: var(--ink); }
  .byline-meta { font-size: var(--text-sm); color: var(--muted); overflow-wrap: anywhere; }
  .byline-name { color: var(--ink); font-weight: 560; }
  .byline-name[data-empty] { color: var(--muted); font-weight: 400; font-style: italic; }

  /* Device approval: the code people compare with their terminal. */
  .code-compare {
    display: flex;
    justify-content: center;
    gap: clamp(0.25rem, 1.2vw, 0.375rem);
    line-height: 1;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
  }
  .code-char {
    display: grid;
    place-items: center;
    width: min(2.25rem, 8.6vw);
    height: 3.25rem;
    border-radius: var(--radius-sm);
    background: var(--raised);
    box-shadow: inset 0 0 0 1px var(--line-strong);
    font-size: var(--text-2xl);
    @media (min-width: 26rem) { width: 2.5rem; height: 3.5rem; border-radius: var(--radius-md); }
  }
  .code-dash { align-self: center; width: 0.625rem; height: 2px; border-radius: 2px; background: var(--muted); }
  .approval-card {
    padding: 1.75rem 1.25rem 1.25rem;
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line), var(--overlay-shadow);
  }
  .approval-hint { margin-top: 0.875rem; text-align: center; font-size: var(--text-sm); color: var(--muted); }
  .approval-facts { display: grid; gap: 0.75rem; margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
  .approval-fact { display: flex; justify-content: space-between; gap: 1rem; font-size: var(--text-sm); dt { color: var(--muted); } dd { min-width: 0; color: var(--ink); font-weight: 540; text-align: right; overflow-wrap: anywhere; } }
  .code-entry { text-transform: uppercase; letter-spacing: 0.18em; font-variant-numeric: tabular-nums; font-weight: 600; font-size: var(--text-xl); height: 3.5rem; text-align: center; &::placeholder { letter-spacing: 0.18em; } }

  /* Extension consent: two parties and the link between them. */
  .connect-pair { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.75rem; }
  .connect-node {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line-strong), var(--overlay-shadow);
    color: var(--ink);
  }
  .connect-wire {
    flex: 1;
    max-width: 4.5rem;
    height: 2px;
    background-image: linear-gradient(to right, var(--line-strong) 50%, transparent 50%);
    background-size: 8px 2px;
    animation: w-wire 0.9s linear infinite;
  }
  .grant-list { display: grid; gap: 0.625rem; margin-top: 1.5rem; padding: 1rem 1.125rem; border-radius: var(--radius-md); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
  .grant-item { display: flex; gap: 0.625rem; font-size: var(--text-base); color: var(--ink); svg { margin-top: 3px; color: var(--success); } }

  /* ============================================================ settings */
  .settings-section {
    display: grid;
    gap: 1rem 2.5rem;
    padding-block: 2rem;
    border-top: 1px solid var(--line);
    scroll-margin-top: 4.5rem;
    @media (min-width: 52rem) { grid-template-columns: 15rem minmax(0, 1fr); }
  }
  .settings-section:first-of-type { border-top: 0; padding-top: 1.5rem; }
  .settings-heading { font-size: var(--text-md); font-weight: 620; color: var(--ink); }
  .settings-help { margin-top: 0.25rem; font-size: var(--text-sm); line-height: var(--text-sm--line-height); color: var(--muted); text-wrap: pretty; }
  .settings-group {
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
  }
  .settings-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
    padding: 0.875rem 1rem;
    & + & { border-top: 1px solid var(--line); }
  }
  .settings-row-main { min-width: 0; flex: 1 1 14rem; }
  .settings-row-title { font-size: var(--text-base); font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
  .settings-row-meta { font-size: var(--text-sm); color: var(--muted); }

  /* Voice picker: one radio card per voice, with its sample. */
  .voice-grid { display: grid; gap: 0.5rem; @media (min-width: 36rem) { grid-template-columns: 1fr 1fr; } }
  .voice-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 4.25rem;
    padding: 0.75rem 0.75rem 0.75rem 0.875rem;
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
    transition: box-shadow var(--duration-fast) var(--ease-out), background-color var(--duration-fast) var(--ease-out);
    &:hover { box-shadow: inset 0 0 0 1px var(--line-strong); }
    &:has(input:checked) { box-shadow: inset 0 0 0 1.5px var(--ink); }
    &:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
    input[type="radio"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
    label { cursor: pointer; }
    label::before { content: ""; position: absolute; inset: 0; border-radius: inherit; }
  }
  .voice-check {
    display: grid;
    place-items: center;
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
    border-radius: 999px;
    box-shadow: inset 0 0 0 1.5px var(--line-strong);
    color: var(--canvas);
    svg { opacity: 0; }
    .voice-card:has(input:checked) & { background: var(--ink); box-shadow: none; svg { opacity: 1; } }
  }
  .voice-name { display: flex; align-items: center; gap: 0.5rem; font-size: var(--text-base); font-weight: 600; color: var(--ink); }
  .voice-description { display: block; font-size: var(--text-sm); color: var(--muted); }
  .voice-play { position: relative; z-index: 1; border-radius: 999px; }
  .voice-play[aria-pressed="true"] { background: var(--ink); color: var(--canvas); &:hover:not(:disabled) { background: var(--ink); } }

  .app-icon {
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    flex-shrink: 0;
    border-radius: var(--radius-md);
    background: var(--raised);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--ink);
  }

  /* ================================================================ plan */
  .usage {
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
    @media (min-width: 40rem) { padding: 2rem; }
  }
  .usage-figure {
    font-size: var(--text-3xl);
    line-height: var(--text-3xl--line-height);
    letter-spacing: var(--text-3xl--letter-spacing);
    font-weight: 660;
    color: var(--ink);
    @media (min-width: 40rem) { font-size: var(--text-4xl); line-height: var(--text-4xl--line-height); letter-spacing: var(--text-4xl--letter-spacing); }
  }
  .usage-of { font-size: var(--text-md); color: var(--muted); }
  /* A native <meter>, so no inline widths are needed; one tick per minute. */
  .usage-meter {
    display: block;
    width: 100%;
    height: 0.75rem;
    appearance: none;
    border: 0;
    background: none;
    &::-webkit-meter-bar {
      height: 0.75rem;
      border: 0;
      border-radius: 999px;
      background:
        repeating-linear-gradient(to right, transparent 0 calc(10% - 1px), var(--line-strong) calc(10% - 1px) 10%),
        var(--raised);
      box-shadow: inset 0 0 0 1px var(--line);
    }
    &::-webkit-meter-optimum-value,
    &::-webkit-meter-suboptimum-value { border-radius: 999px; background: var(--ink); }
    &::-webkit-meter-even-less-good-value { border-radius: 999px; background: var(--danger); }
    &::-moz-meter-bar { border-radius: 999px; background: var(--ink); }
    &:-moz-meter-sub-sub-optimum::-moz-meter-bar { background: var(--danger); }
  }
  .usage-scale { display: flex; justify-content: space-between; margin-top: 0.5rem; font-size: var(--text-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
  .plan-grid { display: grid; gap: 1rem; margin-top: 1rem; @media (min-width: 48rem) { grid-template-columns: 1fr 1fr; } }
  .plan-card {
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
  }
  .plan-card-current { box-shadow: inset 0 0 0 1.5px var(--ink); }
  .plan-card-soon { background: transparent; box-shadow: inset 0 0 0 1px var(--line); border: 1px dashed var(--line-strong); }
  .plan-name { font-size: var(--text-lg); font-weight: 640; color: var(--ink); }
  .plan-list { display: grid; gap: 0.625rem; margin-top: 1.25rem; font-size: var(--text-base); color: var(--ink); li { display: flex; gap: 0.5rem; } svg { margin-top: 3px; } }
  .plan-foot { margin-top: auto; padding-top: 1.5rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
}

@keyframes w-rise { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
@keyframes w-sink { to { opacity: 0; transform: translateY(6px) scale(0.985); } }
@keyframes w-drop { from { opacity: 0; transform: translateY(-4px) scale(0.985); } }
@keyframes w-fade { from { opacity: 0; } }
@keyframes w-pop { 0% { transform: scale(0.94); } 60% { transform: scale(1.03); } }
@keyframes w-blink { 50% { opacity: 0; } }
@keyframes w-pulse { 50% { opacity: 0.35; transform: scale(0.8); } }
@keyframes w-drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes w-wire { to { background-position: 8px 0; } }
@keyframes w-shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

/* The sign-in scene: the cursor travels to the button, the ring marks the
   click, the playhead crosses the strip and the caption follows it. */
@keyframes scene-cursor {
  0% { transform: translate(9rem, 9rem); }
  22%, 30% { transform: translate(27.5rem, 1.6rem); }
  52%, 60% { transform: translate(14rem, 5.1rem); }
  82%, 92% { transform: translate(20rem, 9.2rem); }
  100% { transform: translate(9rem, 9rem); }
}
@keyframes scene-ring { 0%, 21% { opacity: 0; transform: scale(1.15); } 25%, 33% { opacity: 1; transform: scale(1); } 40%, 100% { opacity: 0; } }
@keyframes scene-playhead { from { transform: translateX(0); } to { transform: translateX(31.5rem); } }
@keyframes scene-caption { 0% { transform: translateY(110%); } 3%, 30% { transform: none; } 33.3%, 100% { transform: translateY(-110%); } }

@media (prefers-reduced-motion: reduce) {
  .live-dot, .connect-wire { animation: none; }
  .toast-timer { display: none; }
  .scene-cursor { animation: none; transform: translate(27.5rem, 1.6rem); }
  .scene-ring { animation: none; opacity: 1; }
  .scene-playhead { animation: none; transform: translateX(12rem); }
  .scene-caption { animation: none; }
  .scene-caption:first-child { transform: none; }
}
