/* ==========================================================================
   Beyond the Rift — first-time tips (client/tutorial.mjs)
   A dimmed layer with a spotlight hole around [data-tutorial] targets and a
   speech-bubble card. Sits above screens (z 950) but below modals (1000),
   toasts (1100) and the boot splash (2000). Uses the tokens from game.css.
   ========================================================================== */

.tutorial-layer {
  --tutorial-dim: rgba(4, 6, 12, 0.7);
  --tutorial-ring: rgba(123, 214, 193, 0.9);
  position: fixed;
  inset: 0;
  z-index: 950;
  pointer-events: none;
  animation: tutorial-fade-in var(--dur) ease both;
}

.tutorial-layer[hidden] {
  display: none;
}

.tutorial-layer.is-soft {
  --tutorial-dim: rgba(4, 6, 12, 0.38);
}

/* ------------------------------------------------ backdrop: centered card */

.tutorial-scrim {
  position: absolute;
  inset: 0;
  display: none;
  background: var(--tutorial-dim);
}

.tutorial-layer.is-center .tutorial-scrim {
  display: block;
}

.tutorial-layer.is-center.is-blocking .tutorial-scrim {
  pointer-events: auto;
}

/* ------------------------------------------------------- spotlight + hole */

/* The hole itself never takes clicks: the highlighted element stays tappable. */
.tutorial-spot {
  position: absolute;
  display: none;
  border-radius: var(--radius);
  box-shadow:
    0 0 0 max(200vw, 200vh) var(--tutorial-dim),
    0 0 0 2px var(--tutorial-ring),
    0 0 26px 6px rgba(123, 214, 193, 0.35);
  pointer-events: none;
}

.tutorial-layer.is-spot .tutorial-spot {
  display: block;
}

.tutorial-spot.is-moving {
  transition:
    left var(--dur) var(--ease-out),
    top var(--dur) var(--ease-out),
    width var(--dur) var(--ease-out),
    height var(--dur) var(--ease-out);
}

.tutorial-spot::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 2px solid var(--tutorial-ring);
  border-radius: inherit;
  opacity: 0;
  animation: tutorial-pulse 1.8s var(--ease-out) infinite;
}

/* Transparent panels around the hole: they swallow stray taps (and nudge the card). */
.tutorial-block {
  position: absolute;
  display: none;
}

.tutorial-layer.is-spot.is-blocking .tutorial-block {
  display: block;
  pointer-events: auto;
}

/* ---------------------------------------------------------------- the card */

.tutorial-card {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(340px, calc(100vw - 24px));
  padding: 14px 16px 12px;
  border: 1px solid rgba(123, 214, 193, 0.45);
  border-radius: var(--radius);
  background: linear-gradient(170deg, #1f2e46, var(--panel) 62%);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.25), 0 0 30px rgba(123, 214, 193, 0.16);
  color: var(--text);
  pointer-events: auto;
  animation: tutorial-card-in 0.32s var(--ease-spring) both;
}

.tutorial-card:focus {
  outline: none;
}

.tutorial-card--center {
  transform: translate(-50%, -50%);
}

.tutorial-card--passive {
  top: auto;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  border-color: var(--border-strong);
}

.tutorial-card.is-nudge {
  animation: tutorial-nudge 0.42s var(--ease-out) both;
}

/* Speech-bubble tail, pointing at the spotlight. */
.tutorial-card::before {
  content: "";
  position: absolute;
  left: var(--tutorial-arrow-x, 50%);
  display: none;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  border: 1px solid rgba(123, 214, 193, 0.45);
  background: #1f2e46;
  transform: rotate(45deg);
}

.tutorial-card[data-placement="below"]::before {
  top: -8px;
  display: block;
  border-right: 0;
  border-bottom: 0;
}

.tutorial-card[data-placement="above"]::before {
  bottom: -8px;
  display: block;
  border-top: 0;
  border-left: 0;
  background: var(--panel);
}

.tutorial-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tutorial-card-glyph {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-pill);
  background: rgba(123, 214, 193, 0.16);
  color: var(--accent);
  font-size: 14px;
}

.tutorial-card-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 800;
  line-height: 1.2;
}

.tutorial-card-text {
  margin: 0;
  color: #cdd6e6;
  font-size: var(--fs-md);
  line-height: 1.45;
}

.tutorial-card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.tutorial-card-count {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tutorial-card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  margin-left: auto;
}

/* Full-size tap targets, even though the kit buttons are the small variant. */
.tutorial-card-actions .btn.btn-sm {
  min-width: 88px;
  min-height: var(--tap);
}

.tutorial-card-actions .btn.tutorial-card-skip {
  min-width: 0;
  color: var(--muted);
}

/* -------------------------------------------------------------- keyframes */

@keyframes tutorial-fade-in {
  from { opacity: 0; }
}

@keyframes tutorial-card-in {
  from { opacity: 0; scale: 0.94; }
}

@keyframes tutorial-nudge {
  0%, 100% { scale: 1; }
  35% { scale: 1.05; }
  70% { scale: 0.98; }
}

@keyframes tutorial-pulse {
  0% { opacity: 0.9; inset: -2px; }
  100% { opacity: 0; inset: -14px; }
}

/* ------------------------------------------------------------ preferences */

@media (prefers-reduced-motion: reduce) {
  .tutorial-layer,
  .tutorial-card,
  .tutorial-card.is-nudge {
    animation: none;
  }

  .tutorial-spot.is-moving {
    transition: none;
  }

  .tutorial-spot::after {
    display: none;
  }
}

@media (forced-colors: active) {
  .tutorial-spot {
    box-shadow: none;
    outline: 3px solid Highlight;
    outline-offset: 0;
  }

  .tutorial-scrim {
    background: Canvas;
    opacity: 0.6;
  }

  .tutorial-card {
    border: 2px solid CanvasText;
  }
}

@media (min-width: 720px) {
  .tutorial-card {
    width: 360px;
  }
}
