/**
 * Puzzle package styles (wave-3 comments) — intro cover + ladder HUD.
 * Self-contained so the minigame can ship without chess_vision.css.
 *
 * Sections:
 *   1) Intro cover (#m-puzzle-intro) — full-screen ready / countdown
 *   2) Ladder HUD (#chess-puzzle-ladder-hud) — rating + buttons
 *   3) Wrong-move flash (.is-puzzle-wrong)
 *
 * JS that toggles these:
 *   Puzzle.Intro, Puzzle.Hud, Puzzle.Board.flashWrong
 */

/* Intro cover */
.m-puzzle-intro,
.puzzle-intro {
  position: fixed;
  inset: 0;
  z-index: 12050;
  display: grid;
  place-items: center;
  background: rgba(2, 8, 6, 0.88);
  backdrop-filter: blur(4px);
  pointer-events: all;
}
.m-puzzle-intro[hidden],
.puzzle-intro[hidden] {
  display: none !important;
}
.m-puzzle-intro.is-on,
.puzzle-intro.is-on {
  display: grid;
}
body.is-puzzle-intro #board-wrapper,
body.is-puzzle-intro #main-grid,
body.is-puzzle-intro .flight-deck {
  filter: brightness(0.45);
}
.m-puzzle-intro-card,
.puzzle-intro__card {
  min-width: min(92vw, 360px);
  padding: 1.25rem 1.5rem 1.5rem;
  border: 1px solid rgba(0, 255, 136, 0.35);
  border-radius: 12px;
  background: linear-gradient(160deg, #0a1a12 0%, #041008 100%);
  box-shadow: 0 0 40px rgba(0, 255, 136, 0.12);
  text-align: center;
  font-family: "Courier New", monospace;
  color: #9fdfb0;
}
.m-puzzle-intro-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  color: #c9a227;
  margin-bottom: 0.5rem;
}
.m-puzzle-intro-rating {
  font-size: 0.78rem;
  opacity: 0.85;
  margin-bottom: 0.35rem;
}
.m-puzzle-intro-rating strong {
  color: #00ff88;
}
.m-puzzle-intro-goal {
  font-size: 1rem;
  font-weight: 700;
  color: #e8ffe8;
  margin: 0.5rem 0;
  line-height: 1.35;
}
.m-puzzle-intro-meta {
  font-size: 0.72rem;
  color: #6a9a7a;
  margin-bottom: 0.85rem;
}
.m-puzzle-intro-count {
  font-size: 2.6rem;
  font-weight: 800;
  color: #00ff88;
  text-shadow: 0 0 18px rgba(0, 255, 136, 0.45);
  min-height: 3rem;
  letter-spacing: 0.06em;
}

/* Brief win / miss toast between puzzles */
.puzzle-result-toast {
  position: fixed;
  inset: 0;
  z-index: 13000;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.puzzle-result-toast.is-on {
  opacity: 1;
}
.puzzle-result-toast[hidden] {
  display: none !important;
}
.puzzle-result-toast__card {
  min-width: min(86vw, 320px);
  padding: 1.1rem 1.4rem 1.25rem;
  border-radius: 14px;
  text-align: center;
  font-family: "Courier New", monospace;
  border: 1px solid rgba(0, 255, 136, 0.4);
  background: linear-gradient(165deg, #0c2218 0%, #05140c 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  transform: scale(0.92);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
.puzzle-result-toast.is-on .puzzle-result-toast__card {
  transform: scale(1);
}
.puzzle-result-toast__title {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #00ff88;
  text-shadow: 0 0 18px rgba(0, 255, 136, 0.4);
}
.puzzle-result-toast__sub {
  margin-top: 0.4rem;
  font-size: 0.82rem;
  color: #9fdfb0;
  letter-spacing: 0.04em;
}
.puzzle-result-toast.is-win .puzzle-result-toast__title {
  color: #3dffa0;
}
.puzzle-result-toast.is-win .puzzle-result-toast__card {
  border-color: rgba(60, 255, 140, 0.55);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.55),
    0 0 32px rgba(0, 255, 120, 0.2);
}
.puzzle-result-toast.is-miss .puzzle-result-toast__title {
  color: #ff6b6b;
  text-shadow: 0 0 16px rgba(255, 60, 60, 0.35);
}
.puzzle-result-toast.is-miss .puzzle-result-toast__card {
  border-color: rgba(255, 90, 90, 0.5);
  background: linear-gradient(165deg, #22100e 0%, #140808 100%);
}
.puzzle-result-toast.is-next .puzzle-result-toast__title {
  color: #7fd9ff;
  text-shadow: none;
}

/* Wrong try flash — strong enough to see over immersion/float shadows */
#board-wrapper.is-puzzle-wrong,
#main-grid.is-puzzle-wrong,
#chess-flight-deck.is-puzzle-wrong,
.arena-float-panel[data-float-id='board'].is-puzzle-wrong {
  animation: puzzle-wrong-flash 0.52s ease !important;
}
@keyframes puzzle-wrong-flash {
  0% {
    filter: brightness(1);
    box-shadow: 0 0 0 0 rgba(255, 40, 40, 0);
    outline: 2px solid transparent;
  }
  25% {
    filter: brightness(1.15) saturate(1.4);
    box-shadow:
      0 0 0 4px rgba(255, 50, 50, 0.95),
      0 0 28px rgba(255, 0, 0, 0.55);
    outline: 3px solid rgba(255, 70, 70, 0.9);
  }
  55% {
    filter: brightness(0.92);
    box-shadow: 0 0 0 2px rgba(255, 80, 80, 0.5);
  }
  100% {
    filter: brightness(1);
    box-shadow: none;
    outline: 2px solid transparent;
  }
}

/* Ladder HUD — compact left dock (not over MOVES on the right) */
.chess-puzzle-ladder-hud,
.puzzle-hud {
  font-family: "Courier New", monospace;
  font-size: 0.62rem;
  color: #9fdfb0;
  line-height: 1.25;
  pointer-events: auto !important;
  box-sizing: border-box;
}

/*
 * Default: under champion portrait (avatar + XP + Hint/Skip together).
 * Fixed floating only when --fixed or free-dragged.
 */
#chess-hero-portrait .chess-puzzle-ladder-hud,
#chess-hero-portrait #chess-puzzle-ladder-hud,
.chess-puzzle-ladder-hud--portrait {
  position: relative !important;
  left: auto !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  z-index: 6 !important;
  width: 100% !important;
  max-width: 118px !important;
  min-width: 0 !important;
  margin: 0.35rem 0 0 !important;
  padding: 0.28rem 0.32rem 0.35rem !important;
  border: 1px solid rgba(0, 255, 136, 0.32) !important;
  border-radius: 8px !important;
  background: rgba(4, 14, 10, 0.94) !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45) !important;
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
  overflow: hidden !important;
  pointer-events: auto !important;
  transform: none !important;
  user-select: none;
}

/* Free-float (user dragged off portrait) */
.chess-puzzle-ladder-hud--fixed,
body > #chess-puzzle-ladder-hud.chess-puzzle-ladder-hud--fixed {
  position: fixed !important;
  z-index: 12500 !important;
  left: 10px;
  top: 56px;
  right: auto !important;
  bottom: auto !important;
  width: 132px !important;
  max-width: 132px !important;
  min-width: 120px !important;
  padding: 0.28rem 0.32rem 0.35rem !important;
  border: 1px solid rgba(0, 255, 136, 0.32) !important;
  border-radius: 8px !important;
  background: rgba(4, 14, 10, 0.94) !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45) !important;
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
  overflow: hidden !important;
  pointer-events: auto !important;
  transform: none !important;
  user-select: none;
}

#chess-puzzle-ladder-hud.is-dragging {
  opacity: 0.95 !important;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.55) !important;
  cursor: grabbing;
}

/* Drag handle / rating strip */
#chess-puzzle-ladder-hud .cpl-grab {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.12rem 0.15rem 0.2rem;
  margin: -0.1rem -0.1rem 0.15rem;
  cursor: grab;
  touch-action: none;
  border-bottom: 1px solid rgba(0, 255, 136, 0.15);
  color: #c9a227;
  font-size: 0.58rem;
  letter-spacing: 0.04em;
}
#chess-puzzle-ladder-hud.is-dragging .cpl-grab {
  cursor: grabbing;
}
#chess-puzzle-ladder-hud .cpl-lab {
  font-size: 0.7rem;
  letter-spacing: 0;
  color: #c9a227;
  flex: 0 0 auto;
}
#chess-puzzle-ladder-hud .cpl-elo {
  font-size: 0.85rem;
  color: #00ff88;
  font-weight: 700;
  flex: 1 1 auto;
  min-width: 0;
}
#chess-puzzle-ladder-hud .cpl-delta {
  font-size: 0.58rem;
  flex: 0 0 auto;
}
#chess-puzzle-ladder-hud .cpl-delta.is-up {
  color: #3dffa0;
}
#chess-puzzle-ladder-hud .cpl-delta.is-down {
  color: #ff6b6b;
}
#chess-puzzle-ladder-hud .cpl-sub {
  opacity: 0.75;
  margin: 0 0 0.25rem;
  font-size: 0.52rem;
  line-height: 1.2;
  max-height: 2.4em;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}
#chess-puzzle-ladder-hud .cpl-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.18rem;
}
#chess-puzzle-ladder-hud button {
  font: inherit;
  font-size: 0.58rem;
  letter-spacing: 0.02em;
  padding: 0.2rem 0.28rem;
  border: 1px solid rgba(0, 255, 136, 0.32);
  border-radius: 4px;
  background: rgba(0, 255, 136, 0.08);
  color: #b8f0c8;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 2.4rem;
  line-height: 1.1;
}
#chess-puzzle-ladder-hud button:hover {
  background: rgba(0, 255, 136, 0.18);
  color: #fff;
}
#chess-puzzle-ladder-hud .cpl-ban {
  border-color: rgba(255, 100, 100, 0.45);
  color: #ffb0b0;
  flex: 1 1 100%;
}
#chess-puzzle-ladder-hud .cpl-retry {
  border-color: rgba(201, 162, 39, 0.5);
  color: #e8d48b;
}
#chess-puzzle-ladder-hud .cpl-hint {
  border-color: rgba(80, 180, 255, 0.45);
  color: #a8d8ff;
}

/* Mobile: still compact, a bit lower under safe area */
body.m-body-chess #chess-puzzle-ladder-hud,
body.m-body-battle #chess-puzzle-ladder-hud {
  top: max(48px, calc(env(safe-area-inset-top, 0px) + 40px));
  left: 8px;
  width: 124px !important;
  max-width: 124px !important;
}

body.is-puzzle-intro #chess-puzzle-ladder-hud {
  visibility: hidden !important;
  pointer-events: none !important;
}
