/* ==========================================================================
   INTERACTIVE TUTORIAL SYSTEM OVERLAY & COACHMARK STYLES
   Target File: ./stylesheets/modals/modal_tutorial.css
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Outer Overlay Container (Scoped inside #game-wrapper)
   -------------------------------------------------------------------------- */
#tutorial-overlay,
.tutorial-overlay {
  position: absolute;
  inset: 0;
  z-index: 9500;
  pointer-events: none;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.25s ease;
}

#tutorial-overlay.hidden,
.tutorial-overlay.hidden,
#tutorial-overlay[hidden],
.tutorial-overlay[hidden] {
  display: none !important;
}

/* Dual-HUD Highlight Backdrop Mode (Legacy fallback; disabled when spotlight is active) */
#tutorial-overlay.dual-hud-highlight:not(.spotlight-active),
.tutorial-overlay.dual-hud-highlight:not(.spotlight-active) {
  background-color: rgba(8, 5, 3, 0.85);
}

#tutorial-overlay.dual-hud-highlight:not(.spotlight-active) #tutorial-spotlight,
.tutorial-overlay.dual-hud-highlight:not(.spotlight-active) .tutorial-spotlight {
  display: none;
}

/* --------------------------------------------------------------------------
   2. Spotlight Cutout & Backdrop Dimmer
   -------------------------------------------------------------------------- */
@keyframes tutorial-spotlight-pulse {
  0%,
  100% {
    border-color: var(--border-gold-light, #f3d078);
    box-shadow:
      0 0 0 9999px rgba(8, 5, 3, 0.80),
      0 0 18px rgba(243, 208, 120, 0.65),
      inset 0 0 8px rgba(243, 208, 120, 0.25);
  }
  50% {
    border-color: #fff5cc;
    box-shadow:
      0 0 0 9999px rgba(8, 5, 3, 0.80),
      0 0 26px rgba(243, 208, 120, 0.9),
      inset 0 0 12px rgba(243, 208, 120, 0.45);
  }
}

@keyframes tutorial-spotlight-secondary-pulse {
  0%,
  100% {
    border-color: var(--border-gold-light, #f3d078);
    box-shadow:
      0 0 18px rgba(243, 208, 120, 0.65),
      inset 0 0 8px rgba(243, 208, 120, 0.25);
  }
  50% {
    border-color: #fff5cc;
    box-shadow:
      0 0 26px rgba(243, 208, 120, 0.9),
      inset 0 0 12px rgba(243, 208, 120, 0.45);
  }
}

@keyframes tutorial-hud-glow-pulse {
  0%,
  100% {
    border-color: var(--border-gold-light, #f3d078);
    box-shadow:
      0 0 18px rgba(243, 208, 120, 0.65),
      inset 0 0 8px rgba(243, 208, 120, 0.2);
  }
  50% {
    border-color: #fff5cc;
    box-shadow:
      0 0 26px rgba(243, 208, 120, 0.9),
      inset 0 0 12px rgba(243, 208, 120, 0.35);
  }
}

#tutorial-spotlight,
.tutorial-spotlight {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 8px;
  pointer-events: none;
  z-index: 9502;
  border: 2px solid var(--border-gold-light, #f3d078);
  box-shadow:
    0 0 0 9999px rgba(8, 5, 3, 0.80),
    0 0 18px rgba(243, 208, 120, 0.65);
  transition:
    top 0.25s ease,
    left 0.25s ease,
    width 0.25s ease,
    height 0.25s ease;
  animation: tutorial-spotlight-pulse 2.2s ease-in-out infinite;
}

#tutorial-spotlight.no-target,
.tutorial-spotlight.no-target {
  top: 50% !important;
  left: 50% !important;
  width: 0 !important;
  height: 0 !important;
  border-color: transparent;
  animation: none;
  box-shadow: 0 0 0 9999px rgba(8, 5, 3, 0.80);
}

/* Secondary Spotlight Box (Optional Dual-Spotlight Cutout Support) */
#tutorial-spotlight-secondary,
.tutorial-spotlight-secondary {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 8px;
  pointer-events: none;
  z-index: 9502;
  border: 2px solid var(--border-gold-light, #f3d078);
  box-shadow:
    0 0 18px rgba(243, 208, 120, 0.65),
    inset 0 0 8px rgba(243, 208, 120, 0.25);
  transition:
    top 0.25s ease,
    left 0.25s ease,
    width 0.25s ease,
    height 0.25s ease;
  animation: tutorial-spotlight-secondary-pulse 2.2s ease-in-out infinite;
}

#tutorial-spotlight-secondary.no-target,
.tutorial-spotlight-secondary.no-target,
#tutorial-spotlight-secondary.hidden,
.tutorial-spotlight-secondary.hidden,
#tutorial-spotlight-secondary[hidden],
.tutorial-spotlight-secondary[hidden] {
  display: none !important;
}

/* Elevated Dual-Player HUD Containers (Steps 6 & 7) */
.tutorial-hud-elevated {
  position: relative !important;
  z-index: 9505 !important;
  border-color: var(--border-gold-light, #f3d078) !important;
  box-shadow:
    0 0 18px rgba(243, 208, 120, 0.65),
    inset 0 0 8px rgba(243, 208, 120, 0.2) !important;
  animation: tutorial-hud-glow-pulse 2.2s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   3. Coachmark Instruction Card
   -------------------------------------------------------------------------- */
#tutorial-card,
.tutorial-card {
  position: absolute;
  left: 50%;
  bottom: 4cqh;
  transform: translateX(-50%);
  width: clamp(280px, 82cqw, 620px);
  max-width: calc(100cqw - 24px);
  pointer-events: auto;
  z-index: 9510;
  box-sizing: border-box;

  background: linear-gradient(180deg, #18110b 0%, #0e0a07 100%);
  border: 1.5px solid var(--border-gold, #c89d38);
  outline: 1px solid #4a3818;
  outline-offset: -3px;
  border-radius: clamp(7px, 1cqw, 12px);
  padding: clamp(12px, 2.4cqw, 24px) clamp(14px, 2.8cqw, 28px);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.9),
    0 0 20px rgba(200, 157, 56, 0.22);

  transition:
    top 0.25s ease,
    bottom 0.25s ease,
    transform 0.25s ease,
    opacity 0.2s ease;
}

#tutorial-card > *,
.tutorial-card > * {
  opacity: 0.8;
}

#tutorial-card.opacity-50,
.tutorial-card.opacity-50 {
  opacity: 0.5;
}

#tutorial-card.pos-top,
.tutorial-card.pos-top {
  top: 4cqh;
  bottom: auto;
  transform: translateX(-50%);
}

#tutorial-card.pos-bottom,
.tutorial-card.pos-bottom {
  top: auto;
  bottom: 4cqh;
  transform: translateX(-50%);
}

#tutorial-card.pos-center,
.tutorial-card.pos-center {
  top: 50%;
  bottom: auto;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: clamp(200px, 58cqh, 640px);
  overflow-y: auto;
}

#tutorial-card.pos-below-enemy-hearts,
.tutorial-card.pos-below-enemy-hearts {
  top: clamp(72px, 12cqh, 175px);
  bottom: auto;
  transform: translateX(-50%);
}

#tutorial-card.pos-above-user-hearts,
.tutorial-card.pos-above-user-hearts {
  top: auto;
  bottom: clamp(72px, 12cqh, 175px);
  transform: translateX(-50%);
}

#tutorial-card.pos-above-back-menu,
.tutorial-card.pos-above-back-menu {
  top: auto;
  bottom: clamp(86px, 14cqh, 195px);
  left: 50%;
  transform: translateX(-50%);
}

/* --------------------------------------------------------------------------
   4. Phase 2 & 3 Heart-Loss Animations & HUD Target Highlights
   -------------------------------------------------------------------------- */
@keyframes tutorial-heart-lose-loop {
  0%,
  25% {
    opacity: 1;
    transform: scale(1) translate(0, 0);
    filter: drop-shadow(0 0 6px var(--hp-red, #e74c3c));
  }
  40% {
    opacity: 1;
    transform: scale(1.28) translateX(-2px);
    filter: brightness(1.55) drop-shadow(0 0 10px var(--hp-red, #e74c3c));
  }
  48% {
    opacity: 1;
    transform: scale(1.28) translateX(2px);
    filter: brightness(1.4) drop-shadow(0 0 10px var(--hp-red, #e74c3c));
  }
  55% {
    opacity: 0.95;
    transform: scale(1.18) translateX(-1px);
    filter: brightness(1.2) drop-shadow(0 0 8px var(--hp-red, #e74c3c));
  }
  70%,
  90% {
    opacity: 0.22;
    transform: scale(0.75) translateY(3px);
    filter: grayscale(1) drop-shadow(0 0 0 transparent);
  }
  100% {
    opacity: 1;
    transform: scale(1) translate(0, 0);
    filter: drop-shadow(0 0 6px var(--hp-red, #e74c3c));
  }
}

@keyframes tutorial-heart-decrement-pulse {
  0% {
    opacity: 1;
    transform: scale(1);
    filter: drop-shadow(0 0 0 transparent);
  }
  30% {
    opacity: 1;
    transform: scale(1.32);
    filter: brightness(1.5) drop-shadow(0 0 10px var(--hp-red, #e74c3c));
  }
  65% {
    opacity: 0.55;
    transform: scale(0.72) translateY(2px);
    filter: drop-shadow(0 0 8px var(--hp-red, #e74c3c));
  }
  100% {
    opacity: 0.35;
    transform: scale(0.92);
    filter: grayscale(0.85) drop-shadow(0 0 2px rgba(231, 76, 60, 0.35));
  }
}

#user-lives,
#enemy-lives,
#user-hearts-indicator,
#enemy-hearts-indicator {
  transition:
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    background-color 0.25s ease;
}

#user-lives .heart-icon,
#enemy-lives .heart-icon,
#user-lives > span,
#enemy-lives > span,
#user-hearts-indicator .heart-icon,
#enemy-hearts-indicator .heart-icon,
#user-hearts-indicator > span,
#enemy-hearts-indicator > span {
  display: inline-block;
  transform-origin: center center;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease,
    filter 0.25s ease,
    color 0.25s ease;
}

/* Step 7 Sequential Heart Reduction (5 down to 1) */
#user-lives.tutorial-heart-reducing,
#enemy-lives.tutorial-heart-reducing,
#user-hearts-indicator.tutorial-heart-reducing,
#enemy-hearts-indicator.tutorial-heart-reducing,
.tutorial-heart-reducing {
  position: relative;
  z-index: 9505;
  border-radius: 6px;
  outline: 1.5px solid var(--hp-red, #e74c3c);
  outline-offset: 2px;
  box-shadow:
    0 0 14px rgba(231, 76, 60, 0.55),
    inset 0 0 8px rgba(231, 76, 60, 0.22);
}

.heart-shrinking,
.tutorial-heart-reducing .heart-icon.empty,
.tutorial-heart-reducing > span.empty,
.tutorial-heart-reducing .heart-icon.heart-shrinking,
.tutorial-heart-reducing > span.heart-shrinking {
  will-change: transform, opacity, filter;
  animation: tutorial-heart-decrement-pulse 0.38s ease-out forwards;
}

/* Phase 3 Continuous Heart-Loss Loop */
#user-lives.tutorial-heart-loss-loop,
#enemy-lives.tutorial-heart-loss-loop,
#user-hearts-indicator.tutorial-heart-loss-loop,
#enemy-hearts-indicator.tutorial-heart-loss-loop,
.tutorial-heart-loss-loop {
  position: relative;
  z-index: 9505;
  border-radius: 6px;
  outline: 1.5px solid var(--hp-red, #e74c3c);
  outline-offset: 2px;
  background-color: rgba(231, 76, 60, 0.14);
  box-shadow:
    0 0 12px rgba(231, 76, 60, 0.55),
    inset 0 0 8px rgba(231, 76, 60, 0.25);
}

.tutorial-heart-loss-loop .heart-icon,
.tutorial-heart-loss-loop > span {
  display: inline-block;
  transform-origin: center center;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease,
    filter 0.25s ease;
}

.tutorial-heart-loss-loop .heart-icon:last-child,
.tutorial-heart-loss-loop > span:last-child,
.tutorial-heart-lost-anim {
  display: inline-block;
  transform-origin: center center;
  will-change: transform, opacity, filter;
  animation: tutorial-heart-lose-loop 1.8s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   5. Card Header, Typography & Action Hint
   -------------------------------------------------------------------------- */
.tutorial-card-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: clamp(8px, 1.4cqw, 16px);
  margin-bottom: clamp(8px, 1.2cqh, 16px);
}

#tutorial-phase-badge,
.tutorial-phase-badge {
  display: inline-flex;
  align-items: center;
  font-family: 'Cinzel', 'MedievalSharp', serif;
  font-weight: 700;
  font-size: clamp(0.55rem, 1.8cqw, 0.85rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-gold-light, #f3d078);
  background: rgba(18, 10, 6, 0.9);
  border: 1px solid var(--border-gold, #c89d38);
  border-radius: 999px;
  padding: clamp(3px, 0.45cqh, 6px) clamp(8px, 1.8cqw, 16px);
  box-shadow: inset 0 0 6px rgba(200, 157, 56, 0.2);
}

#tutorial-step-counter,
.tutorial-step-counter {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.6rem, 2cqw, 0.9rem);
  font-weight: 600;
  color: #9a8871;
  letter-spacing: 0.04em;
}

#tutorial-step-title,
.tutorial-step-title {
  margin: 0 0 clamp(6px, 0.9cqh, 12px) 0;
  font-family: 'Cinzel', 'MedievalSharp', serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-gold, #e2b755);
  font-size: clamp(0.8rem, 2.8cqw, 1.35rem);
  line-height: 1.25;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.85);
}

#tutorial-step-body,
.tutorial-step-body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: #d4c5b0;
  line-height: 1.5;
  font-size: clamp(0.68rem, 2.3cqw, 1.05rem);
}

#tutorial-action-hint,
.tutorial-action-hint {
  margin-top: clamp(8px, 1.2cqh, 16px);
  padding: clamp(6px, 0.9cqh, 12px) clamp(10px, 1.9cqw, 18px);
  background: rgba(200, 157, 56, 0.14);
  border-left: 2px solid var(--border-gold-light, #f3d078);
  border-radius: 0 4px 4px 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: clamp(0.64rem, 2.15cqw, 0.98rem);
  font-weight: 600;
  line-height: 1.4;
  color: #fef08a;
}

#tutorial-action-hint:empty,
.tutorial-action-hint:empty,
#tutorial-action-hint.hidden,
.tutorial-action-hint.hidden,
#tutorial-action-hint[hidden],
.tutorial-action-hint[hidden] {
  display: none;
}

/* --------------------------------------------------------------------------
   6. Footer Action Buttons
   -------------------------------------------------------------------------- */
.tutorial-card-footer {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: clamp(10px, 1.8cqw, 20px);
  margin-top: clamp(12px, 1.6cqh, 22px);
}

#btn-tutorial-primary,
.btn-tutorial-primary,
#btn-tutorial-next {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(28px, 3.6cqh, 44px);
  padding: clamp(6px, 0.8cqh, 12px) clamp(14px, 3cqw, 28px);
  background: linear-gradient(180deg, #c89d38 0%, #8c6a28 100%);
  border: 1px solid var(--border-gold-light, #f3d078);
  border-radius: 4px;
  color: var(--bg-wood-dark, #1a0f0a);
  font-family: 'Cinzel', 'MedievalSharp', serif;
  font-weight: 700;
  font-size: clamp(0.65rem, 2.1cqw, 0.95rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 245, 204, 0.45);
  transition:
    filter 0.15s ease,
    transform 0.12s ease,
    box-shadow 0.15s ease;
}

#btn-tutorial-primary:hover,
.btn-tutorial-primary:hover,
#btn-tutorial-next:hover {
  filter: brightness(1.12);
  box-shadow:
    0 4px 12px rgba(243, 208, 120, 0.35),
    inset 0 1px 0 rgba(255, 245, 204, 0.65);
}

#btn-tutorial-primary:active,
.btn-tutorial-primary:active,
#btn-tutorial-next:active {
  transform: translateY(1px);
  filter: brightness(0.96);
}

#btn-tutorial-primary:focus-visible,
.btn-tutorial-primary:focus-visible,
#btn-tutorial-next:focus-visible {
  outline: 2px solid var(--border-gold-light, #f3d078);
  outline-offset: 2px;
}

#btn-tutorial-primary.hidden,
.btn-tutorial-primary.hidden,
#btn-tutorial-primary[hidden],
.btn-tutorial-primary[hidden],
#btn-tutorial-next.hidden,
#btn-tutorial-next[hidden] {
  display: none;
}

#btn-tutorial-skip,
.btn-tutorial-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(28px, 3.6cqh, 44px);
  padding: clamp(6px, 0.8cqh, 12px) clamp(12px, 2.4cqw, 22px);
  background: var(--bg-wood-dark, #1a0f0a);
  border: 1px solid rgba(200, 157, 56, 0.45);
  border-radius: 4px;
  color: #c0b098;
  font-family: 'Cinzel', 'MedievalSharp', serif;
  font-weight: 600;
  font-size: clamp(0.6rem, 1.95cqw, 0.88rem);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.12s ease;
}

#btn-tutorial-skip:hover,
.btn-tutorial-secondary:hover {
  background: var(--bg-wood-mid, #2c1a12);
  border-color: var(--border-gold, #c89d38);
  color: var(--text-gold-light, #f3d078);
}

#btn-tutorial-skip:active,
.btn-tutorial-secondary:active {
  transform: translateY(1px);
}

#btn-tutorial-skip:focus-visible,
.btn-tutorial-secondary:focus-visible {
  outline: 2px solid var(--border-gold-light, #f3d078);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   7. Container Query Adjustments for Compact Aspect Heights
   -------------------------------------------------------------------------- */
@container game (max-height: 560px) {
  #tutorial-card,
  .tutorial-card {
    padding: 1.8cqw 2.4cqw;
  }

  #tutorial-card.pos-top,
  .tutorial-card.pos-top {
    top: 2.5cqh;
  }

  #tutorial-card.pos-bottom,
  .tutorial-card.pos-bottom {
    bottom: 2.5cqh;
  }

  #tutorial-card.pos-center,
  .tutorial-card.pos-center {
    top: 50%;
    bottom: auto;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: clamp(150px, 46cqh, 260px);
  }

  #tutorial-card.pos-below-enemy-hearts,
  .tutorial-card.pos-below-enemy-hearts {
    top: clamp(56px, 10cqh, 88px);
  }

  #tutorial-card.pos-above-user-hearts,
  .tutorial-card.pos-above-user-hearts {
    bottom: clamp(56px, 10cqh, 88px);
  }

  #tutorial-card.pos-above-back-menu,
  .tutorial-card.pos-above-back-menu {
    bottom: clamp(68px, 12cqh, 100px);
  }

  .tutorial-card-header {
    margin-bottom: 0.7cqh;
  }

  .tutorial-card-footer {
    margin-top: 1cqh;
  }
}