/*
 * Aiko student tour overlay.
 *
 * Layer note: joins @layer legacy like account-onboarding.css so it sits in
 * the cascade declared by aios-layers.css instead of outranking every layer.
 * The dim comes from the spotlight's outward box-shadow, which punches a hole
 * around the highlighted element; the scrim only blocks clicks, and takes the
 * dim itself on the two steps that have no anchor.
 */
@layer legacy {
  #aios-student-tour-root {
    --aios-tour-veil: color-mix(in srgb, var(--aios-bg) 72%, transparent);
    --aios-tour-ring: color-mix(in srgb, var(--aios-accent) 55%, transparent);
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-top) + 7);
    pointer-events: none;
  }

  #aios-student-tour-root[hidden] {
    display: none !important;
  }

  body.aios-tour-open {
    overflow: hidden !important;
  }

  .aios-tour-scrim {
    position: absolute;
    inset: 0;
    background: transparent;
    pointer-events: auto;
  }

  #aios-student-tour-root.is-centered .aios-tour-scrim {
    background: var(--aios-tour-veil);
  }

  .aios-tour-spot {
    position: fixed;
    border-radius: var(--aios-radius-lg, 16px);
    box-shadow:
      0 0 0 2px var(--aios-tour-ring),
      0 0 0 100vmax var(--aios-tour-veil);
    opacity: 0;
    pointer-events: none;
    transition:
      left var(--aios-normal, 220ms) ease,
      top var(--aios-normal, 220ms) ease,
      width var(--aios-normal, 220ms) ease,
      height var(--aios-normal, 220ms) ease,
      opacity var(--aios-fast, 140ms) ease;
  }

  .aios-tour-bubble {
    position: fixed;
    width: min(340px, calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px;
    background: var(--aios-elevated, var(--aios-surface));
    border: 1px solid var(--aios-border);
    border-radius: var(--aios-radius-lg, 16px);
    box-shadow: var(--aios-shadow, 0 18px 44px rgba(0, 0, 0, 0.22));
    color: var(--aios-text);
    pointer-events: auto;
    transition:
      left var(--aios-normal, 220ms) ease,
      top var(--aios-normal, 220ms) ease;
  }

  .aios-tour-bubble:focus-visible {
    outline: 2px solid var(--aios-accent);
    outline-offset: 3px;
  }

  #aios-student-tour-root.is-centered .aios-tour-bubble {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(420px, calc(100vw - 24px));
  }

  .aios-tour-arrow {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--aios-elevated, var(--aios-surface));
    border: 1px solid var(--aios-border);
    transform: rotate(45deg);
  }

  .aios-tour-arrow[hidden] {
    display: none;
  }

  .aios-tour-bubble[data-side="right"] .aios-tour-arrow {
    left: -7px;
    margin-top: -6px;
    border-right: 0;
    border-top: 0;
  }

  .aios-tour-bubble[data-side="left"] .aios-tour-arrow {
    right: -7px;
    margin-top: -6px;
    border-left: 0;
    border-bottom: 0;
  }

  .aios-tour-bubble[data-side="bottom"] .aios-tour-arrow {
    top: -7px;
    margin-left: -6px;
    border-right: 0;
    border-bottom: 0;
  }

  .aios-tour-bubble[data-side="top"] .aios-tour-arrow {
    bottom: -7px;
    margin-left: -6px;
    border-left: 0;
    border-top: 0;
  }

  .aios-tour-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .aios-tour-aiko {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border-radius: var(--aios-radius-pill, 999px);
    background: color-mix(in srgb, var(--aios-accent) 13%, transparent);
    color: var(--aios-accent-strong, var(--aios-accent));
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
  }

  .aios-tour-aiko-mark {
    width: 28px;
    height: 28px;
    flex: none;
    display: block;
    /* Aiko has transparent corners and a headband tail that leaves the box,
       so no frame or drop shadow here: they would draw a square halo. */
  }

  .aios-tour-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    margin: -10px -8px -10px 0;
    padding: 0;
    border: 0;
    border-radius: var(--aios-radius-md, 12px);
    background: transparent;
    color: var(--aios-text-muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
  }

  .aios-tour-close:hover {
    background: var(--aios-surface-hover);
    color: var(--aios-text);
  }

  .aios-tour-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 650;
    line-height: 1.3;
    text-wrap: balance;
  }

  .aios-tour-body {
    margin: 0;
    font-size: 0.93rem;
    line-height: 1.55;
    color: var(--aios-text);
  }

  .aios-tour-hint {
    margin: 0;
    padding: 9px 12px;
    border-radius: var(--aios-radius-md, 12px);
    background: var(--aios-surface-subtle, var(--aios-surface));
    color: var(--aios-text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
  }

  .aios-tour-hint[hidden] {
    display: none;
  }

  .aios-tour-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 4px;
  }

  .aios-tour-progress {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }

  .aios-tour-dots {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .aios-tour-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--aios-border);
    transition: all var(--aios-fast, 140ms) ease;
  }

  .aios-tour-dot.is-done {
    background: color-mix(in srgb, var(--aios-accent) 45%, transparent);
  }

  .aios-tour-dot.is-current {
    width: 16px;
    border-radius: var(--aios-radius-pill, 999px);
    background: var(--aios-accent);
  }

  .aios-tour-count {
    font-size: 0.74rem;
    color: var(--aios-text-muted);
    font-variant-numeric: tabular-nums;
  }

  .aios-tour-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
  }

  .aios-tour-btn {
    min-height: 44px;
    padding: 0 16px;
    border-radius: var(--aios-radius-md, 12px);
    border: 1px solid transparent;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--aios-fast, 140ms) ease;
  }

  .aios-tour-ghost {
    background: transparent;
    border-color: var(--aios-border);
    color: var(--aios-text-muted);
  }

  .aios-tour-ghost:hover {
    background: var(--aios-surface-hover);
    color: var(--aios-text);
  }

  .aios-tour-primary {
    background: var(--aios-accent);
    color: #fff;
  }

  .aios-tour-primary:hover {
    background: var(--aios-accent-strong, var(--aios-accent));
  }

  .aios-tour-btn:focus-visible,
  .aios-tour-close:focus-visible,
  .aios-tour-replay:focus-visible {
    outline: 2px solid var(--aios-accent);
    outline-offset: 2px;
  }

  /* Docked on phones: an anchored bubble would sit over the composer or the
     tab bar, which must stay reachable. */
  #aios-student-tour-root.is-docked .aios-tour-bubble {
    left: 12px;
    right: 12px;
    width: auto;
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px) + var(--aios-composer-height, 0px));
    max-height: 60dvh;
  }

  #aios-student-tour-root.is-docked.is-docked-top .aios-tour-bubble {
    bottom: auto;
    top: calc(12px + env(safe-area-inset-top, 0px));
  }

  @media (prefers-reduced-motion: reduce) {
    .aios-tour-spot,
    .aios-tour-bubble,
    .aios-tour-dot,
    .aios-tour-btn {
      transition: none;
    }
  }
}
