/* ===========================
   GAME BOARD
   =========================== */
.game-page {
  height: 100vh;
  /* Explicit height so flex children can stretch */
  overflow-y: auto;
  /* Allow scrolling if viewport is very short */
  padding-top: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
}

.game-header {
  text-align: center;
  padding: 1.5rem 2rem;
}

.game-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.game-status {
  font-size: 0.875rem;
  color: var(--fg-muted);
}

/* Board container */
.board-container {
  width: 100%;
  max-width: 860px;
  padding: 0 0.5rem 0.5rem;
  display: flex;
  justify-content: center;
  flex: 1;
  min-height: 0;
  min-height: 320px;
  overflow: hidden;
  /* Constrain board height: fill available space but cap it */
  position: relative;
}

/* The board itself */
.backgammon-board {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 860px;
  flex: 1;
  min-height: 0;
  border-radius: 12px;
  overflow: hidden;
  /* Fill all remaining viewport height */
  height: 100%;
  max-height: 100%;
  box-shadow: 0 0 0 3px rgba(212, 168, 67, 0.25), 0 8px 60px rgba(0,0,0,0.7), 0 0 120px rgba(212, 168, 67, 0.06);
}

/* Board row: single row of columns. Board itself is 2 rows (CSS grid for height control) */
.board-row {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  gap: 0;
}

/* Points row: fills space, contains 6 points */
.points-row {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  /* Grid: each point is a column with checker column filling height */
  display: grid;
  grid-template-columns: repeat(6, 1fr);
}

/* Each point (triangle) — filled by grid column */
.point {
  position: relative;
  cursor: pointer;
  transition: filter 0.15s;
  /* Fill the grid cell */
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.points-row-top .point {
  flex-direction: column-reverse; /* checkers stack at bottom */
}

.points-row-bottom .point {
  flex-direction: column; /* checkers stack at top */
}

.point.selectable { cursor: pointer; }
.point.selectable:hover { filter: brightness(1.2); }

.point-light { background: var(--board-light); }
.point-dark { background: var(--board-dark); }

/* Point labels — OUTSIDE the checker area, at the far end of each point */
.points-row-top .point::before {
  /* Top row: checker stack at bottom, number at top edge */
  content: attr(data-point);
  position: absolute;
  top: 3px;
  bottom: auto;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  color: rgba(212, 168, 67, 0.7);
  font-weight: 600;
  pointer-events: none;
  z-index: 2;
}

.points-row-bottom .point::before {
  /* Bottom row: checker stack at top, number at bottom edge */
  content: attr(data-point);
  position: absolute;
  bottom: 3px;
  top: auto;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  color: rgba(212, 168, 67, 0.7);
  font-weight: 600;
  pointer-events: none;
  z-index: 2;
}

/* Checker column inside point */
.checker-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 1;
  /* Evenly distribute checkers in the column */
  justify-content: space-evenly;
  padding: 2px 1px;
  min-height: 0;
}

.points-row-top .checker-col {
  justify-content: flex-end; /* stack from bottom */
}

.points-row-bottom .checker-col {
  justify-content: flex-start; /* stack from top */
}

/* Individual checker */
.checker {
  width: 22px;
  /* Height: natural based on stacking, controlled by column's space-evenly */
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.2);
  transition: transform 0.15s, box-shadow 0.15s;
  cursor: pointer;
  position: relative;
}

.checker:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.2);
}

.checker.w {
  background: linear-gradient(160deg, #f9f4ee 0%, #c8bfae 60%, #e8dfd0 100%);
  border: 1px solid rgba(255,255,255,0.4);
}

.checker.b {
  background: linear-gradient(160deg, #2d2822 0%, #1a1510 60%, #28221c 100%);
  border: 1px solid rgba(255,255,255,0.08);
}

/* Checker count badge */
.checker-count {
  position: absolute;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(0,0,0,0.6);
  border-radius: 8px;
  padding: 1px 5px;
  line-height: 1.4;
}

.points-row-top .checker-count {
  top: 2px;
}

.points-row-bottom .checker-count {
  bottom: 2px;
}

/* Center bar */
.board-bar {
  width: 28px;
  flex-shrink: 0;
  background: var(--board-bg);
  border-left: 2px solid rgba(212, 168, 67, 0.2);
  border-right: 2px solid rgba(212, 168, 67, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  gap: 6px;
}

.bar-checkers {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.bar-checkers .checker {
  width: 20px;
  height: 13px;
}

.bar-checker-count {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent);
}

/* Bear off areas */
.bear-off {
  width: 34px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 3px;
  gap: 6px;
  background: var(--surface);
  border: 1px solid rgba(212, 168, 67, 0.1);
  border-radius: 6px;
}

.bear-off-label {
  font-size: 0.55rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-muted);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  /* Add accent border for visibility */
  border: 1px solid rgba(212, 168, 67, 0.15);
  padding: 3px;
  border-radius: 3px;
}

.bear-off-checkers {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.bear-off-checkers .checker {
  width: 20px;
  height: 13px;
}

.bear-off-count {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
}

/* Dice */
.dice-area {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--surface);
  border-top: 1px solid rgba(212, 168, 67, 0.08);
}

.dice-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg-muted);
}

.dice-row {
  display: flex;
  gap: 0.75rem;
}

.dice-die {
  width: 44px;
  height: 44px;
  background: #f0ebe3;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.5), inset 0 -2px 4px rgba(0,0,0,0.1);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 6px;
  gap: 2px;
}

.dice-die.rolling {
  animation: diceRoll 0.6s ease-in-out;
}

@keyframes diceRoll {
  0% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(90deg) scale(1.1); }
  50% { transform: rotate(180deg) scale(0.95); }
  75% { transform: rotate(270deg) scale(1.05); }
  100% { transform: rotate(360deg) scale(1); }
}

.dice-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--board-bg);
  align-self: center;
  justify-self: center;
}

.dice-dot.off { background: transparent; }

/* Controls */
.game-controls {
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.5rem 1.25rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #0c0b10;
}

.btn-primary:hover {
  background: #e0b84f;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--fg);
  border: 1px solid rgba(255,255,255,0.08);
}

.btn-secondary:hover {
  border-color: rgba(212, 168, 67, 0.3);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Move feedback */
.move-feedback {
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  min-height: 2rem;
}

.move-feedback.hit {
  color: #e55;
  font-weight: 600;
}

.move-feedback.moved {
  color: #8c8;
}

.move-feedback.waiting {
  color: var(--fg-muted);
}

/* Selected checker highlight */
.point.selected {
  filter: brightness(1.4) drop-shadow(0 0 6px rgba(212, 168, 67, 0.6));
}

/* Valid move destination highlight */
.point.valid-dest {
  box-shadow: inset 0 0 0 3px rgba(212, 168, 67, 0.6);
}

/* Audit panel */
.audit-panel {
  max-width: 860px;
  width: 100%;
  margin: 0 auto 2rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid rgba(212, 168, 67, 0.1);
  border-radius: 8px;
}

.audit-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--fg-muted);
  margin-bottom: 0.75rem;
}

.audit-commit {
  font-size: 0.8rem;
  color: var(--accent);
  font-family: monospace;
  word-break: break-all;
  margin-bottom: 0.5rem;
}

.audit-verified {
  font-size: 0.8rem;
  color: #8c8;
  display: none;
}

.audit-verified.show { display: block; }

/* Game over */
.game-over-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 11, 16, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.game-over-box {
  background: var(--surface);
  border: 1px solid rgba(212, 168, 67, 0.3);
  border-radius: 16px;
  padding: 3rem;
  text-align: center;
  max-width: 400px;
}

.game-over-box h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.game-over-box p {
  color: var(--fg-muted);
  margin-bottom: 2rem;
}

/* Selected move highlight */
.move-sequence {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  padding: 0.75rem;
  background: var(--surface-2);
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.move-badge {
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(212, 168, 67, 0.1);
  color: var(--accent);
  border: 1px solid rgba(212, 168, 67, 0.2);
}

/* ===========================
   POINT DIRECTION
   =========================== */

/* Top row points: triangles point UP (column-reverse so checkers stack from bottom) */
.points-row-top .point {
  flex-direction: column-reverse;
}

/* Bottom row points: triangles point DOWN (column so checkers stack from top) */
.points-row-bottom .point {
  flex-direction: column;
}

/* ===========================
   MOBILE LAYOUT (320px - 500px)
   =========================== */
@media (max-width: 500px) {
  .game-page {
    padding-top: 58px;
    height: 100dvh;
    overflow-y: auto;
    box-sizing: border-box;
  }

  .game-header {
    padding: 0.4rem 0.75rem 0.2rem;
    flex-shrink: 0;
  }

  .game-title { font-size: 1.05rem; }
  .game-status { font-size: 0.7rem; }

  /* Board container: explicit height fill of remaining viewport */
  .board-container {
    padding: 0 0.2rem 0.4rem;
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow: hidden;
    /* Enforce a minimum board height so it's readable on short viewports */
    min-height: 300px;
  }

  /* Board: flex column with 2 equal rows */
  .backgammon-board {
    width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    border-radius: 8px;
    overflow: hidden;
  }

  /* Board row: single horizontal row of columns */
  .board-row {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
  }

  /* Points row: 6-column CSS grid fills available space evenly */
  .points-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  }

  /* Each point: fills grid cell, holds checker column */
  .point {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 44px;
    touch-action: manipulation;
    display: flex;
    flex-direction: column;
  }

  .points-row-top .point { flex-direction: column-reverse; }
  .points-row-bottom .point { flex-direction: column; }

  /* Point number: outside checker zone */
  .point::before {
    font-size: 0.5rem;
    z-index: 3;
    pointer-events: none;
  }

  .points-row-top .point::before {
    top: 2px;
    bottom: auto;
    transform: translateX(-50%);
  }

  .points-row-bottom .point::before {
    bottom: 2px;
    top: auto;
    transform: translateX(-50%);
  }

  /* Checker column: evenly distributed in the point */
  .checker-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
    padding: 2px 1px;
    min-height: 0;
    justify-content: space-evenly;
  }

  .points-row-top .checker-col { justify-content: flex-end; }
  .points-row-bottom .checker-col { justify-content: flex-start; }

  /* Checkers: natural stacking height */
  .checker {
    width: 18px;
    height: 12px;
    min-height: 10px;
    flex-shrink: 0;
    border-radius: 50%;
    touch-action: manipulation;
  }

  /* Checker count badge */
  .checker-count {
    font-size: 0.5rem;
    padding: 0 2px;
    z-index: 2;
  }

  .points-row-top .checker-count {
    bottom: 1px;
    top: auto;
  }

  .points-row-bottom .checker-count {
    top: 1px;
    bottom: auto;
  }

  /* Center bar: full height of row */
  .board-bar {
    width: 22px;
    flex-shrink: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 6px 0;
    background: var(--board-bg);
    border-left: 2px solid rgba(212, 168, 67, 0.15);
    border-right: 2px solid rgba(212, 168, 67, 0.15);
  }

  .bar-checkers {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
  }

  .bar-checkers .checker {
    width: 16px;
    height: 11px;
    min-height: 8px;
  }

  .bar-checker-count { font-size: 0.5rem; }

  /* Bear off areas: full height */
  .bear-off {
    width: 26px;
    flex-shrink: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 6px 3px;
    background: var(--surface);
    border: 1px solid rgba(212, 168, 67, 0.08);
    border-radius: 4px;
  }

  .bear-off-label {
    font-size: 0.35rem;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    padding: 2px 1px;
    border-radius: 2px;
    flex-shrink: 0;
    border: 1px solid rgba(212, 168, 67, 0.1);
  }

  .bear-off-checkers {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex: 1;
    justify-content: space-evenly;
  }

  .bear-off-checkers .checker {
    width: 14px;
    height: 11px;
    min-height: 7px;
  }

  .bear-off-count { font-size: 0.5rem; }

  /* Dice area */
  .dice-area {
    padding: 0.4rem;
    flex-shrink: 0;
  }

  .dice-die {
    width: 32px;
    height: 32px;
    padding: 4px;
  }

  .dice-dot { width: 5px; height: 5px; }
  .dice-label { font-size: 0.6rem; }

  /* Controls */
  .game-controls {
    padding: 0.3rem 0.75rem;
    gap: 0.4rem;
    flex-shrink: 0;
  }

  .btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.7rem;
  }

  /* Audit panel */
  .audit-panel {
    margin: 0 0.2rem 0.4rem;
    padding: 0.4rem;
    flex-shrink: 0;
  }

  .audit-title { font-size: 0.6rem; }
  .audit-commit { font-size: 0.65rem; }

  /* Move feedback */
  .move-feedback {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    min-height: 1.3rem;
    flex-shrink: 0;
  }

  .move-sequence { padding: 0.4rem; flex-shrink: 0; }
  .move-badge { font-size: 0.65rem; padding: 0.2rem 0.4rem; }
}

/* ===========================
   EXTRA SMALL (≤360px)
   =========================== */
@media (max-width: 360px) {
  .checker { width: 14px; height: 10px; }
  .board-bar { width: 20px; }
  .bar-checkers .checker { width: 12px; height: 9px; }
  .bear-off { width: 22px; }
  .bear-off-checkers .checker { width: 12px; height: 9px; }
  .dice-die { width: 28px; height: 28px; }
  .point::before { font-size: 0.42rem; }
}