/**
 * Opening package styles — compact left-dock HUD (same DNA as puzzle HUD).
 * Self-contained so opening mode does not depend on chess_vision portrait CSS.
 *
 * JS: Opening.Hud  →  #chess-opening-ladder-hud
 */

/* Base + compact fixed dock (mirrors puzzle.css for #chess-puzzle-ladder-hud) */
.chess-opening-ladder-hud,
.opening-hud {
  font-family: "Courier New", monospace;
  font-size: 0.62rem;
  color: #9ec8e8;
  line-height: 1.25;
  pointer-events: auto !important;
  box-sizing: border-box;
}

.chess-opening-ladder-hud--compact,
#chess-opening-ladder-hud.chess-puzzle-ladder-hud--fixed,
#chess-opening-ladder-hud {
  position: fixed !important;
  z-index: 12500 !important;
  left: 10px;
  top: 56px;
  right: auto !important;
  bottom: auto !important;
  /* Wider dock — Tree + Line (main/var) selects */
  width: 168px !important;
  max-width: 168px !important;
  min-width: 148px !important;
  padding: 0.28rem 0.32rem 0.35rem !important;
  border: 1px solid rgba(100, 170, 230, 0.38) !important;
  border-radius: 8px !important;
  background: rgba(4, 12, 18, 0.95) !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45) !important;
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
  overflow: visible !important;
  pointer-events: auto !important;
  transform: none !important;
  user-select: none;
}

#chess-opening-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-opening-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(100, 170, 230, 0.18);
  color: #8ec4f0;
  font-size: 0.58rem;
  letter-spacing: 0.04em;
}
#chess-opening-ladder-hud.is-dragging .cpl-grab {
  cursor: grabbing;
}
#chess-opening-ladder-hud .cpl-lab {
  font-size: 0.7rem;
  letter-spacing: 0;
  color: #8ec4f0;
  flex: 0 0 auto;
}
#chess-opening-ladder-hud .cpl-elo {
  font-size: 0.85rem;
  color: #8ec4f0;
  font-weight: 700;
  flex: 1 1 auto;
  min-width: 0;
}
#chess-opening-ladder-hud .cpl-delta {
  font-size: 0.58rem;
  flex: 0 0 auto;
}
#chess-opening-ladder-hud .cpl-delta.is-up {
  color: #3dffa0;
}
#chess-opening-ladder-hud .cpl-delta.is-down {
  color: #ff6b6b;
}
#chess-opening-ladder-hud .cpl-sub {
  opacity: 0.8;
  margin: 0 0 0.2rem;
  font-size: 0.52rem;
  line-height: 1.2;
  max-height: 2.4em;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
  color: #9ec8e8;
}

/* Family / tree + mainline/variation pickers */
#chess-opening-ladder-hud .cpl-family,
#chess-opening-ladder-hud .cpl-line {
  display: flex !important;
  flex-direction: column;
  align-items: stretch;
  gap: 0.12rem;
  margin: 0 0 0.22rem;
  font-size: 0.52rem;
  color: #7aa8c8;
}
#chess-opening-ladder-hud .cpl-family-lab {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
}
#chess-opening-ladder-hud #col-family,
#chess-opening-ladder-hud #col-line,
#chess-opening-ladder-hud select {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box;
  background: #0a141c !important;
  color: #c8e0f0 !important;
  border: 1px solid #2a4a60 !important;
  border-radius: 4px !important;
  font-size: 0.58rem !important;
  padding: 0.18rem 0.2rem !important;
  cursor: pointer;
  pointer-events: auto !important;
}
#chess-opening-ladder-hud #col-line {
  border-color: #3a5a78 !important;
}

#chess-opening-ladder-hud .cpl-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.18rem;
}
#chess-opening-ladder-hud button {
  font: inherit;
  font-size: 0.58rem;
  letter-spacing: 0.02em;
  padding: 0.2rem 0.28rem;
  border: 1px solid rgba(100, 170, 230, 0.35);
  border-radius: 4px;
  background: rgba(80, 150, 220, 0.1);
  color: #b8d8f0;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 2.4rem;
  line-height: 1.1;
  pointer-events: auto !important;
}
#chess-opening-ladder-hud button:hover {
  background: rgba(80, 150, 220, 0.22);
  color: #fff;
}
#chess-opening-ladder-hud .cpl-retry {
  border-color: rgba(201, 162, 39, 0.5);
  color: #e8d48b;
}
#chess-opening-ladder-hud .cpl-hint {
  border-color: rgba(80, 180, 255, 0.45);
  color: #a8d8ff;
}
#chess-opening-ladder-hud button[hidden] {
  display: none !important;
}

/* Mobile: compact chip, still above chrome */
body.m-body-chess #chess-opening-ladder-hud,
body.m-body-battle #chess-opening-ladder-hud {
  top: max(48px, calc(env(safe-area-inset-top, 0px) + 40px));
  left: 8px;
  width: min(156px, calc(100vw - 16px)) !important;
  max-width: min(156px, calc(100vw - 16px)) !important;
  z-index: 12500 !important;
}

/* Opening ladder: keep float panels draggable (no chrome steal) */
body.chess-page.is-opening-mode.arena-float-active .arena-float-bar,
body.chess-page.is-opening-ladder.arena-float-active .arena-float-bar,
body.chess-page.is-opening-mode.arena-float-active .arena-float-drag,
body.chess-page.is-opening-ladder.arena-float-active .arena-float-drag {
  pointer-events: auto !important;
  cursor: grab;
}

/* Nav highlight */
body.is-opening-mode .chess-mini-nav a#nav-chess-opening {
  color: #8ec4f0;
}

/* Wrong-move flash (same class as puzzle so animation is shared) */
#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: opening-wrong-flash 0.52s ease !important;
}
@keyframes opening-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;
  }
}

/* Result toasts — reuse puzzle toast look (blue-ish for openings) */
.opening-result-toast.puzzle-result-toast {
  z-index: 13000;
}
.opening-result-toast.is-win .puzzle-result-toast__title {
  color: #3dffa0;
}
.opening-result-toast.is-miss .puzzle-result-toast__title {
  color: #ff6b6b;
}
.opening-result-toast.is-next .puzzle-result-toast__title {
  color: #7fd9ff;
}
