/* ===== CHESS LESSON PLAYER COMPONENT STYLES ===== */

/* Component root — mirrors the old #chess-lesson-content div */
chess-lesson-player.chess-lesson-content {
  display: flex;
  flex-direction: column;
  block-size: 100%;
}

/* The fragment Inja renders is wrapped in a single .lesson-player-root
   div. Without this rule it stays a plain `display: block` content-sized
   element inside the flex-column <chess-lesson-player>, so it doesn't
   inherit the parent's full height — the chess-panels-container then
   collapses to its board-panel's content size, and the info panel gets
   whatever scrap is left (~45px on iPad portrait). Make it the actual
   flex-column carrier so the lesson header + panels container split the
   full available height. */
.lesson-player-root {
  display: flex;
  flex-direction: column;
}

/* The lesson's title: one line tall (30px, which the board's size leaves it
   below), so a new lesson cannot change the board's height, centred over the
   board. */
.lesson-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  flex: 0 0 30px;
  height: 30px;
  min-height: 30px;
  max-height: 30px;
  padding: 0 6px;
  overflow: hidden;
  background: transparent;
  box-shadow: none;
  color: var(--hp-muted);
}

.lesson-title-display {
  margin: 0;
  flex: 1;
  color: var(--hp-text);
  min-width: 0;
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 30px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== CHESS LAYOUT ===== */
.chess-panels-container {
  width: 100%;
  /* Take remaining space inside the flex-column .lesson-player-root,
     after the lesson-header-bar. */
  flex: 1;
  overflow: hidden;
}

.chess-board-panel {
  flex: 1 1 70%;
  min-width: 0;
  padding: 0;
}

/* ===== CHESSBOARD ===== */
/* A square as wide as its panel; dashboard.css sizes it to the panel's
   height as well. */
.chessboard-container {
  width: 100%;
  aspect-ratio: 1 / 1;
  margin-inline: 0;
  position: relative;
  touch-action: manipulation;
}

/* The board takes every tap itself (chessboard-interaction.js listens on
   the whole of it): no browser flash over it on a touch screen. */
#chessboard {
  transform-origin: center center;
  transition: transform 0.2s ease;
  width: 100%;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 10;
  aspect-ratio: 1 / 1;
  -webkit-tap-highlight-color: transparent;
}

/* Server-rendered chessboard layout (replaces chessboard.js's grid).
   The parent #chessboard already has aspect-ratio: 1/1, so stretching to
   100% in both directions keeps us perfectly square. */
.chessboard-server {
  width: 100%;
  height: 100%;
  position: relative;
}

.board-b72b1 {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  position: relative;
  user-select: none;
  /* Small round corners: the corner squares, and whatever is drawn over
     them (marks, the promotion chooser), are cut to the board's outline. */
  border-radius: 6px;
  overflow: hidden;
  /* One hand over the whole board, pieces and empty squares alike: the
     system's pointing hand, a little larger (img/cursors/hand.svg). */
  cursor: url("/img/cursors/hand.svg") 8 1, pointer;
}

.square-55d63 {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  --legal-dest: 102, 126, 234;
}

/* The piece images carry their own margin, so at the square's full size a
   piece fills it as on Lichess. */
.square-55d63 img[data-piece] {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: auto;
  /* Touch drags are handled via Pointer Events; without `touch-action:
     none` the browser would treat a touch on a piece as a scroll/pan
     candidate and steal the gesture once the finger moves. */
  touch-action: none;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}

/* A piece in hand (chessboard-interaction.js): the board's hand wherever the
   pointer goes until the drop. */
html.board-dragging,
html.board-dragging * {
  cursor: url("/img/cursors/hand.svg") 8 1, pointer !important;
}

/* Check: a thin ring around the king, above the piece and out of the
   click path. Sized in percentages so it follows the square. */
.square-55d63 .king-in-check {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  border: 4px solid rgba(204, 24, 24, 0.78);
  border-radius: 50%;
  pointer-events: none;
}

/* Drag visuals: the original piece fades to a ghost in place, the
   floating clone (.dragging-clone, parented to <body>) carries the full
   opacity image under the pointer. */
.square-55d63.dragging-from img[data-piece] {
  opacity: 0.3;
}

.dragging-clone {
  position: fixed;
  pointer-events: none;
  z-index: 999999;
  opacity: 1;
  object-fit: contain;
  will-change: left, top;
  /* Slight lift cue so the dragged piece feels picked up. */
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
  transform: scale(1.05);
  transform-origin: center center;
}

/* View Transitions: each piece carries `view-transition-name: pid-XX`
   (stamped inline by chessboard.html) so the browser pairs old/new
   positions automatically. We want pure positional motion — no fades,
   no cross-dissolves — so we override both the OLD and NEW pseudo-
   elements to skip the default opacity animation. The group's position
   tween is what gives us the glide. */
::view-transition-group(*) {
  animation-duration: 480ms;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* A step through the moves already played (a move of the card, ← →, the
   way back to the live board) glides twice as fast as a move played: the
   page marks its glide with board-stepping (lesson-renderer-wasm.js for a
   lesson's card, multiplayer-game.js for a game and its replay). */
html.board-stepping::view-transition-group(*) {
  animation-duration: 240ms;
}

/* Hide the old snapshot instantly, show the new one instantly. For a
   paired piece, the new snapshot rides the group's interpolated
   position from old → new square, which reads as a clean glide.
   Unpaired (captured) pieces just vanish; unpaired (newly-appeared)
   pieces just pop in. Both are usually instant in chess anyway. */
::view-transition-old(*) {
  animation: none;
  opacity: 0;
}
::view-transition-new(*) {
  animation: none;
  opacity: 1;
}

/* Square colors */
.white-1e1d7 {
  background-color: #f0d9b5 !important;
}

.black-3c85d {
  background-color: #b58863 !important;
}

/* Coordinate notation labels.
   Absolutely positioned so the flexbox-centered piece image is unaffected by
   their presence (and they sit in a fixed corner regardless of whether the
   square is occupied). Contrast colors mirror chessboard.js's convention:
   labels on a light square use the dark square color, and vice-versa. */
.notation-322f9 {
  position: absolute;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

.notation-322f9.numeric-fc462 {
  top: 2px;
  left: 3px;
}

.notation-322f9.alpha-1ac5d {
  bottom: 2px;
  right: 3px;
}

.white-1e1d7 .notation-322f9 {
  color: #b58863;
}

.black-3c85d .notation-322f9 {
  color: #f0d9b5;
}

/* Squares of the move that produced the current position. Painted with
   the square, under the piece. Light and dark squares get different
   yellow-green overlays so the board's light/dark difference remains.
   The annotation SVG follows the squares and stays the top layer. */
.square-55d63.last-move::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.square-55d63.last-move.white-1e1d7::before {
  background-color: rgba(210, 222, 72, 0.62);
}

.square-55d63.last-move.black-3c85d::before {
  background-color: rgba(108, 156, 36, 0.68);
}

/* A kept premove's two squares: a very slight tint of its arrow's red
   (#e07a7a, PREMOVE_ARROW in chessboard-interaction.js). */
.square-55d63.premove-square {
  box-shadow: inset 0 0 0 999px rgba(224, 122, 122, 0.16);
}

/* Selected square highlight for click-to-move */
.square-55d63.selected-square {
  box-shadow: inset 0 0 0 4px rgba(255, 215, 0, 0.8) !important;
  position: relative;
}

.square-55d63.selected-square::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 215, 0, 0.3);
  pointer-events: none;
}

/* Hint: pulsing ring around the piece the player should move. Distinct from
   .selected-square (static golden inset) so it reads as a system suggestion
   rather than the user's own click selection. */
.square-55d63.hint-piece {
  position: relative;
  border-radius: 4px;
  animation: hint-pulse 1.1s ease-in-out infinite;
}

@keyframes hint-pulse {
  0% {
    box-shadow:
      inset 0 0 0 4px rgba(255, 193, 7, 0.95),
      0 0 0 0 rgba(255, 193, 7, 0.55);
  }
  70% {
    box-shadow:
      inset 0 0 0 4px rgba(255, 193, 7, 0.95),
      0 0 10px 6px rgba(255, 193, 7, 0);
  }
  100% {
    box-shadow:
      inset 0 0 0 4px rgba(255, 193, 7, 0.95),
      0 0 0 0 rgba(255, 193, 7, 0);
  }
}

/* Legal move hints */
.square-55d63.legal-move {
  position: relative;
}

.square-55d63.legal-move::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 25%;
  height: 25%;
  background-color: rgba(var(--legal-dest), 0.6);
  border-radius: 50%;
  pointer-events: none;
  transition: all 0.2s ease;
}

.square-55d63.legal-move:hover::after,
.square-55d63.legal-move.drag-over::after {
  width: 35%;
  height: 35%;
  background-color: rgba(var(--legal-dest), 0.8);
}

/* Legal capture hints */
.square-55d63.legal-capture {
  position: relative;
}

.square-55d63.legal-capture::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 4px solid rgba(var(--legal-dest), 0.7);
  border-radius: 50%;
  pointer-events: none;
  box-sizing: border-box;
  transition: all 0.2s ease;
}

.square-55d63.legal-capture:hover::after,
.square-55d63.legal-capture.drag-over::after {
  border-width: 6px;
  border-color: rgba(var(--legal-dest), 0.9);
}

/* Strong "land here" cue while dragging — applied to whichever legal
   target the pointer is currently over. The growing dot/ring above is
   subtle enough to miss, especially on small mobile boards; the inset
   border makes the destination square unambiguous. */
.square-55d63.drag-over {
  box-shadow: inset 0 0 0 4px rgba(var(--legal-dest), 0.85) !important;
}

/* Promotion chooser: the four pieces a pawn may become, stacked over the
   promotion square and the three squares toward the middle of the board.
   A child of the board (squares clip their content), one square wide and
   four tall; chessboard-interaction.js sets left/top in board percentages. */
.promotion-chooser {
  position: absolute;
  width: 12.5%;
  height: 50%;
  display: flex;
  flex-direction: column;
  /* Above the pieces (11) and the annotations SVG (10). */
  z-index: 20;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.promotion-choice {
  flex: 1 1 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.promotion-choice:hover,
.promotion-choice:focus-visible {
  background: rgba(102, 126, 234, 0.3);
  outline: none;
}

.promotion-choice img {
  width: 90%;
  height: 90%;
  object-fit: contain;
  pointer-events: none;
}

.king-piece-icon {
  width: auto;
  vertical-align: middle;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
  position: relative;
  z-index: 1;
}

/* Mutări efectuate: every move, a puzzle's game before it included (dimmed),
   in a card that scrolls rather than grows. */
.moves-history-container {
  order: 4;
  flex: 0 1 auto;
  min-height: 4.5rem;
  max-height: 9.5rem;
  margin: 0;
  overflow-y: auto;
  border: 1px solid var(--hp-border);
  border-radius: var(--hp-radius-card);
  background: var(--hp-surface);
}

.moves-header {
  /* The container is the scroller — keep the header readable while the
     move list scrolls underneath (same pattern as .comment-header). */
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--hp-divider);
  background: var(--hp-surface);
  color: var(--hp-text);
  font-size: 0.84rem;
  font-weight: 800;
}

.moves-history-list {
  overflow-wrap: break-word;
  word-break: break-word;
  padding: 8px 12px 10px;
  color: var(--hp-text);
  font-family: var(--hp-font);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.6;
}

.move-pair {
  margin-right: 10px;
}

.white-move,
.black-move {
  display: inline-block;
  margin: 0 2px;
}

.clickable-move {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  transition: background-color 0.2s ease;
}

.clickable-move:hover {
  background-color: #e9ecef;
}

.move-pair.game-history {
  opacity: 0.7;
}

.move-pair.game-history .move-number {
  color: #6c757d;
}

.board-locked {
  pointer-events: none;
  opacity: 0.7;
  position: relative;
}

.board-locked::after {
  content: "📖 Revizuire";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: bold;
  pointer-events: none;
  z-index: 1000;
}

.comment-header {
  padding: 8px 12px;
  /* Pin to the top of the side panel — on small screens (iPhone SE) the
     panel is the only scroll surface, so without sticking the header
     scrolls out of view as the user reads a long comment. The solid
     background covers content scrolling underneath. */
  position: sticky;
  top: 0;
  z-index: 2;
}

.move-comment-container {
  border: 1px solid #dee2e6;
  border-top: none;
  background-color: #fff;
  /* Shrinkable (with a readable floor) so a long comment + long history
     never push the move controls below the fold on short windows. */
  flex: 0 1 auto;
}

.comment-header.has-comment {
  border-bottom: none;
}

.move-comment-text {
  padding: 10px 12px;
  overflow-wrap: break-word;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--hp-text);
}

/* Comment type styles — header (standalone) */
.comment-header.comment-success {
  font-weight: 600;
}

.comment-header.comment-success::before {
  content: "✅ ";
  margin-right: 4px;
}

.comment-header.comment-error {
  background-color: #f8d7da;
  color: #721c24;
  border-color: #dc3545;
  font-weight: 700;
}

.comment-header.comment-error::before {
  content: "⚠️ ";
  margin-right: 4px;
}

.comment-header.comment-neutral::before {
  content: "📖 ";
  margin-right: 4px;
}

/* Comment type styles — text container */
.move-comment-container.comment-success {
  background-color: #f8fff9;
}

.move-comment-container.comment-error {
  border-color: #dc3545;
  border-width: 2px;
  background-color: #fff5f5;
  box-shadow: 0 2px 8px rgba(220, 53, 69, 0.15);
}

.move-comment-container.comment-error .move-comment-text {
  color: #721c24;
  font-weight: 600;
}

.move-comment-container.comment-neutral {
  border-color: #b8daff;
  background-color: #f8fbff;
}

.move-comment-container.comment-neutral .move-comment-text {
  color: #495057;
}

/* ===== MOVE CONTROLS ===== */

#next-computer-move-btn {
  background-color: #28a745;
  border-color: #28a745;
  font-weight: 600;
  padding: 0.75rem 1rem;
  transition: all 0.2s ease;
  animation: pulse-green 2s infinite;
  white-space: normal;
  line-height: 1.2;
}

#next-computer-move-btn:hover {
  background-color: #218838;
  border-color: #1e7e34;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

#next-computer-move-btn.btn-lg {
  font-size: 1.1rem;
  padding: 1rem 1.5rem;
  animation: none;
}

#next-computer-move-btn.btn-secondary {
  animation: none;
}

#back-move-btn {
  background-color: #6c757d;
  border-color: #6c757d;
  font-weight: 600;
  padding: 0.75rem 1rem;
  transition: all 0.2s ease;
}

#back-move-btn:hover {
  background-color: #5a6268;
  border-color: #545b62;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

@keyframes pulse-green {
  0% {
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(40, 167, 69, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
  }
}

@keyframes checkboxPop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes gentlePulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.15);
    opacity: 0.9;
  }
}

/* ===== ANIMATIONS ===== */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ===== RESPONSIVE ===== */

/* Column layout is a PORTRAIT answer: board on top, info below. In
   landscape (phones held sideways, short desktop windows) stacking gives
   a tiny board over an off-screen panel, so those stay on the row layout
   and get the compact-landscape block further down instead. */
@media (max-width: 991px) and (orientation: portrait) {
  .chess-panels-container {
    flex-direction: column;
    gap: 0;
  }

  .chess-board-panel {
    /* 0 1 auto (not 1 1): the panel hugs the board instead of growing to
       its max-height — on narrow phones the board is width-bound well
       below 58vh, and a growing panel would strand that difference as
       dead space while the info panel below overflows. */
    flex: 0 1 auto;
    border-right: none;
    /* Shrink below content if the column gets tight. */
    min-height: 0;
  }

  .chessboard-container {
    width: 100%;
  }

  .move-comment-container {
    /* flex: 0 1 auto (not 1 1 0) so the box hugs a short comment instead of
       stretching to fill the panel — that stretch left a large empty gap
       between a one-line comment and the buttons below. flex-shrink: 1 +
       min-height: 0 still lets a long comment shrink the box to the available
       space and scroll internally (so the panel itself never scrolls and the
       Back/Continue buttons stay visible). */
    flex: 0 1 auto;
  }

  .move-controls {
    position: sticky;
    top: 0;
    z-index: 10;
    margin-top: 0;
  }
}

@media (max-width: 767px) and (orientation: portrait) {
  .move-controls {
    margin-top: 0;
  }

  #next-computer-move-btn,
  #back-move-btn {
    padding: 8px;
    font-size: 0.9rem;
  }
}

@media (max-width: 575px) and (orientation: portrait) {
  #next-computer-move-btn,
  #back-move-btn {
    padding: 6px;
    font-size: 0.85rem;
  }

}

/* Touch devices, any size/orientation: comfortable tap targets and no
   double-tap zoom on the board. (Was a width:480px block — landscape
   phones and small tablets need it just as much.) */
@media (pointer: coarse) {
  .chessboard-container,
  .square-55d63 {
    touch-action: manipulation;
  }

}

/* ===== COMPACT MOVE STRIP (small screens) =====
   On phones/tablets the vertical history box used to be display:none —
   students lost the game record entirely. Instead, collapse it into a
   single-row strip docked right under the board (order: -1 puts it first
   in the info panel): horizontally scrollable, auto-scrolled to the
   latest move by chess-lesson-player.js. Applies to the portrait column
   layout and to short landscape viewports. */
@media (max-width: 991px) and (orientation: portrait), (max-height: 520px) {
  .moves-history-container {
    display: flex;
    align-items: stretch;
    overflow-x: hidden;
  }

  /* No room for a label on a one-line strip — the move list is
     self-explanatory. (Clipping the header down to its 📋 glyph was
     tried first, but the truncated text read as an overlap bug.) */
  .moves-header {
    display: none;
  }

  .moves-history-list {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
  }

  .move-pair {
    flex: 0 0 auto;
    margin-bottom: 0;
  }
}

/* ===== COMPACT LANDSCAPE (short viewports) =====
   Landscape phones keep the desktop row layout (board left, info right);
   this block just slims the chrome so the board gets the height. The
   app header shrinks via --header-block-size in common.css. */
@media (max-height: 520px) {
  /* Long comments scroll inside their box instead of pushing the action
     buttons below the fold (mirrors the portrait column behavior). */
  .move-comment-container {
    flex: 0 1 auto;
  }

  /* Keep Back/Continue reachable even if the panel does end up
     scrolling: pin them to the bottom edge of the scroll surface. */
  .move-controls {
    position: sticky;
    bottom: 0;
    z-index: 10;
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  .lesson-header-bar {
    display: none !important;
  }

  #chessboard {
    max-width: 100%;
    page-break-inside: avoid;
  }
}
