/* First-run tutorial overlay (src/tutorial-view.js, docs/TUTORIAL.md).
 *
 * Colours come from the ui-theme roles, so it follows the chosen palette.
 * Positions are viewport pixels set by the view each frame.
 */

/* ---- what the lesson hides ----------------------------------------------
 * One shot is being taught: everything else is out of the way. Settings stays,
 * for sound and accessibility. The match bar gives its place to the banner.
 */
#hud[data-tut] #matchbar,
#hud[data-tut] #turnbanner,
#hud[data-tut] #spinpad,
#hud[data-tut] #spinlabel,
#hud[data-tut] #spintools,
#hud[data-tut] #aimwheel,
#hud[data-tut] #btnLobby,
#hud[data-tut] #btnHelp,
#hud[data-tut] #callrule,
#hud[data-tut] #callhint,
#hud[data-tut] #bihhint,
#hud[data-tut] #result,
#hud[data-tut] #toast {
  display: none !important;
}

/* The power bar is not live until the power step. */
#hud[data-tut]:not([data-tut="power"]) #powerbar {
  opacity: 0.35;
  pointer-events: none;
  filter: grayscale(0.6);
}
#hud[data-tut="power"] #powerbar {
  animation: tutGlow 1.4s ease-in-out infinite;
}

@keyframes tutGlow {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent-primary), 0 0 0 0 color-mix(in srgb, var(--accent-primary) 55%, transparent); }
  50% { box-shadow: 0 0 0 2px var(--accent-primary), 0 0 0 12px color-mix(in srgb, var(--accent-primary) 0%, transparent); }
}

/* ---- the overlay ---------------------------------------------------------- */

.tut {
  position: fixed;
  inset: 0;
  pointer-events: none; /* the table stays playable; the card opts back in */
  z-index: 15; /* above the HUD controls, below the Settings sheet (20) */
  font-family: inherit;
}
.tut [hidden] { display: none !important; }

.tut-scrim {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--background) 62%, transparent);
  backdrop-filter: blur(3px);
  pointer-events: auto; /* a card blocks the table */
  animation: tutFade 0.3s ease both;
}

.tut-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 32px));
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 26px 24px 22px;
  border-radius: 22px;
  background: var(--panel-fill);
  box-shadow: var(--control-shadow), 0 0 0 1px var(--line);
  color: var(--text);
  text-align: center;
  pointer-events: auto;
  animation: tutCardIn 0.4s cubic-bezier(0.2, 1.3, 0.3, 1) both;
}
.tut-card h2 {
  margin: 4px 0 0;
  font-size: 22px;
  letter-spacing: 0.04em;
  color: var(--accent-primary);
}
.tut-card p { margin: 0 0 8px; color: var(--text); line-height: 1.45; }
.tut-card .tut-go { min-width: 180px; }
.tut-card .tut-reward {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent-wash, var(--surface));
  font-weight: 800;
  font-size: 18px;
  color: var(--accent-primary);
  font-variant-numeric: tabular-nums;
}
.tut-reward .tut-coin { width: 26px; height: 26px; }

/* The coach's face badge: a circle cropped from her portrait. */
.tut-coach {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  background: var(--raised);
  box-shadow: 0 0 0 2px var(--accent-primary);
}
.tut-coach.big { width: 76px; height: 76px; margin-top: -4px; }
.tut-coach img { width: 100%; height: 100%; display: block; object-fit: cover; }

/* The coach herself, standing to the left of the card with her feet off the
 * bottom edge (the art is cut at mid-thigh). Only where there is room: on a
 * narrower screen the face badge inside the card stands in for her. */
.tut-figure {
  position: absolute;
  right: calc(100% - 36px);
  bottom: -2px;
  height: min(440px, 62vh);
  width: auto;
  aspect-ratio: 2 / 3;
  pointer-events: none;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45));
}
@media (min-width: 1000px) and (min-height: 560px) {
  .tut-card { padding-left: 40px; }
  .tut-card .tut-coach.big { display: none; }
}
@media (max-width: 999px), (max-height: 559px) {
  .tut-figure { display: none; }
}

.tut-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px 8px 8px;
  border-radius: 16px;
  background: var(--panel-fill);
  box-shadow: var(--control-shadow), 0 0 0 1px var(--accent-line);
  color: var(--text);
  animation: tutFade 0.3s ease both;
}
.tut-banner p { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.35; }

/* A ring on the ball to pot. */
.tut-target {
  position: absolute;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  border: 3px solid var(--accent-primary);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent-primary) 60%, transparent);
  animation: tutPulse 1.2s ease-in-out infinite;
}

/* The hand, with its fingertip on the point it is placed at. */
.tut-hand {
  position: absolute;
  width: 40px;
  height: 40px;
  margin: -2px 0 0 -14px;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5));
}
.tut-hand svg { width: 100%; height: 100%; display: block; }
.tut-hand[data-gesture="aim"] { animation: tutSweep 2s ease-in-out infinite; }
.tut-hand[data-gesture="power"] { animation: tutPull 1.6s ease-in-out infinite; }

.tut-callout {
  position: absolute;
  transform: translateY(-50%);
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--accent-primary);
  color: var(--on-accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow: var(--control-shadow);
}
.tut-callout[data-side="left"] { transform: translate(-100%, -50%); }

@keyframes tutFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes tutCardIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 18px)) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes tutPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.18); opacity: 0.7; }
}
@keyframes tutSweep {
  0% { transform: translate(-36px, 0); opacity: 0; }
  15% { opacity: 1; }
  70% { transform: translate(36px, -10px); opacity: 1; }
  100% { transform: translate(36px, -10px); opacity: 0; }
}
@keyframes tutPull {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: 1; }
  70% { transform: translateY(var(--travel, 150px)); opacity: 1; }
  100% { transform: translateY(var(--travel, 150px)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tut-hand, .tut-target, #hud[data-tut="power"] #powerbar { animation: none; }
}
