/* ===== Halma (star board) + HUD + side panel ===== */

/* Seat colours. Red/green/yellow/blue are the Ludo token colours; purple and
   white complete the six (shared with the menu card and link preview).
   --tint = --tok mixed 42% into the ivory board (#f2e7cb), precomputed so older
   iOS Safari (no color-mix) gets it; white's point uses a pearl grey instead,
   since a white mix would vanish into the ivory. --rim = marble outline. */
.c-red    { --tok: #d9483f; --tok-dark: #8a1f1a; --tok-light: #ff9a8e; --tint: #e7a490; --rim: #f6eccd; }
.c-purple { --tok: #9156d0; --tok-dark: #4a2380; --tok-light: #d9b8ff; --tint: #c9aacd; --rim: #f6eccd; }
.c-green  { --tok: #2fae6a; --tok-dark: #135a33; --tok-light: #8ff0b8; --tint: #a0cfa2; --rim: #f6eccd; }
.c-yellow { --tok: #e9b72c; --tok-dark: #8a6510; --tok-light: #ffe39a; --tint: #eed388; --rim: #f6eccd; }
.c-blue   { --tok: #3f82d8; --tok-dark: #173f78; --tok-light: #9cc6ff; --tint: #a7bdd0; --rim: #f6eccd; }
.c-white  { --tok: #efe8d6; --tok-dark: #a8987a; --tok-light: #ffffff; --tint: #d9d4c8; --rim: #3d2e1a; }

.halma-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Desktop: board on the left, HUD + side panel stacked on the right.
   Phone: one column — HUD (turn banner + players) above the board. */
.halma-table {
  flex: 1;
  display: grid;
  grid-template-columns: auto minmax(260px, 320px);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "board hud"
    "board side";
  column-gap: clamp(14px, 3vw, 36px);
  row-gap: 12px;
  align-items: start;
  justify-content: center;
  padding: clamp(10px, 2.5vw, 24px);
  min-height: 0;
  overflow-y: auto;
}
.halma-hud { grid-area: hud; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.halma-board-area {
  grid-area: board;
  position: relative;
  /* The star is ~1.15× taller than wide: size it from the viewport height. */
  width: min(calc(100vw - 400px), calc((100vh - 170px) * 0.87), 640px);
  min-width: 300px;
}
.halma-side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
}

/* ----- board ----- */
.halma-board {
  --turn-col: transparent;
  position: relative;
  width: 100%;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.halma-board.can-pick { cursor: pointer; }
.halma-board-inner { position: relative; width: 100%; height: 0; } /* padding-bottom set in JS = aspect */
.halma-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Star: drop shadow, walnut rim, ivory face with a thin gold line. */
.halma-svg .star-shadow {
  fill: rgba(0, 0, 0, 0.45);
  stroke: rgba(0, 0, 0, 0.45);
  stroke-width: 0.7;
  stroke-linejoin: round;
}
.halma-svg .star-rim {
  fill: #2a1c10;
  stroke: #2a1c10;
  stroke-width: 0.46;
  stroke-linejoin: round;
}
.halma-svg .star-face {
  fill: #f2e7cb;
  stroke: #c9a646;
  stroke-width: 0.06;
  stroke-linejoin: round;
}
/* Turn ring around the whole star in the colour of the seat to move. */
.halma-svg .star-glow {
  fill: none;
  stroke: var(--turn-col);
  stroke-width: 0.85;
  stroke-linejoin: round;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.halma-board.has-turn .star-glow { opacity: 0.55; }
.halma-board.has-turn.mine .star-glow { animation: halma-ring 1s ease-in-out infinite; }
@keyframes halma-ring {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* Points */
.halma-svg .pt {
  fill: var(--tint);
  stroke: var(--tok-dark);
  stroke-width: 0.07;
  stroke-linejoin: round;
}
.halma-svg .pt.goal-only {
  fill-opacity: 0.45;
  stroke-dasharray: 0.22 0.16;
  stroke-opacity: 0.8;
}
/* Turn glow on the point of the seat to move (opacity-only animation).
   `.mine` = this device controls the turn right now: faster and stronger. */
.halma-svg .pt-glow {
  fill: var(--tok-light);
  stroke: var(--tok);
  stroke-width: 0.16;
  stroke-linejoin: round;
  opacity: 0;
  pointer-events: none;
}
.halma-svg .pt-glow.turn { animation: halma-pt 1.3s ease-in-out infinite; }
.halma-svg .pt-glow.turn.mine { animation: halma-pt-strong 0.95s ease-in-out infinite; }
@keyframes halma-pt {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.7; }
}
@keyframes halma-pt-strong {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.95; }
}

.halma-svg .lattice {
  fill: none;
  stroke: rgba(120, 88, 36, 0.3);
  stroke-width: 0.045;
}
.halma-svg .well { stroke: rgba(255, 250, 235, 0.55); stroke-width: 0.03; }

/* Destination markers: dot = step, gold ring = jump (dark edge underneath so
   it reads on every tint). */
.halma-svg .mk .o, .halma-svg .mk .i { fill: none; stroke: none; }
.halma-svg .mk.step .i {
  fill: #fff6d8;
  stroke: #6b4a12;
  stroke-width: 0.07;
}
.halma-svg .mk.jump .o { stroke: #4a2e04; stroke-width: 0.2; fill: rgba(74, 46, 4, 0.18); }
.halma-svg .mk.jump .i { stroke: #ffd24d; stroke-width: 0.1; }
.halma-svg .mk.jump { animation: halma-jump-dest 1.1s ease-in-out infinite; }
@keyframes halma-jump-dest {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 1; }
}
.halma-svg .mk.chosen .o { stroke: #4a2e04; stroke-width: 0.2; }
.halma-svg .mk.chosen .i { stroke: #ffffff; stroke-width: 0.11; fill: rgba(255, 255, 255, 0.55); }

/* Last-move trail (gold with a cream halo; dashed ring where the marble started). */
.halma-svg .trail-halo {
  fill: none;
  stroke: #fff6d8;
  stroke-width: 0.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.6;
}
.halma-svg .trail-line {
  fill: none;
  stroke: #d4af37;
  stroke-width: 0.12;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.halma-svg .trail-hop { fill: #d4af37; stroke: #fff6d8; stroke-width: 0.05; }
.halma-svg .trail-from {
  fill: rgba(255, 255, 255, 0.35);
  stroke: var(--tok-dark);
  stroke-width: 0.08;
  stroke-dasharray: 0.15 0.1;
}
.halma-svg .preview-line {
  fill: none;
  stroke: #fffbe8;
  stroke-width: 0.12;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 0.01 0.22;
}

/* ----- marbles ----- */
.halma-pieces { position: absolute; inset: 0; pointer-events: none; }
.halma-piece {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle at 33% 28%, rgba(255, 255, 255, 0.9) 0 7%, transparent 17%),
    radial-gradient(circle at 35% 30%, var(--tok-light) 0 15%, var(--tok) 42%, var(--tok-dark) 100%);
  border: 2px solid var(--rim);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.3);
  transition: transform 0.16s ease, filter 0.2s ease;
  z-index: 2;
}
.halma-piece.c-white { border-width: 1.5px; }
.halma-pieces.selecting .halma-piece:not(.selected) { filter: brightness(0.88) saturate(0.85); }
.halma-piece.selected {
  z-index: 6;
  transform: translate(-50%, -64%) scale(1.2);
  box-shadow: 0 9px 10px rgba(0, 0, 0, 0.42), 0 0 0 1px rgba(0, 0, 0, 0.45);
}
.halma-piece.selected::after {
  content: '';
  position: absolute;
  inset: -30%;
  border-radius: 50%;
  border: 3px solid #fff3c4;
  box-shadow: 0 0 10px rgba(255, 214, 92, 0.95);
  animation: halma-sel 0.9s ease-in-out infinite;
}
@keyframes halma-sel {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}
.halma-piece.hopping {
  z-index: 8;
  transition: none;
  box-shadow: 0 8px 10px rgba(0, 0, 0, 0.38), 0 0 0 1px rgba(0, 0, 0, 0.45);
}
.halma-piece.hopping::after { display: none; }
/* The marble that just moved: a soft white halo so it's easy to spot. */
.halma-piece.just-moved {
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.3), 0 0 0 4px rgba(255, 255, 255, 0.5);
}

/* ----- toast (auto-pass, finishing, errors) ----- */
.halma-toast {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -8px);
  max-width: 88%;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(16, 10, 6, 0.93);
  border: 1px solid rgba(212, 175, 55, 0.7);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
}
.halma-toast.show { opacity: 1; transform: translate(-50%, 0); }
.halma-toast .dot {
  display: inline-block;
  width: 0.75em;
  height: 0.75em;
  margin-right: 0.45em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--tok-light) 0 15%, var(--tok) 45%, var(--tok-dark) 100%);
  box-shadow: 0 0 0 1.5px var(--rim, #f6eccd);
  vertical-align: -0.06em;
}

/* ----- turn banner ----- */
.halma-turn {
  --tok: var(--gold);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid rgba(212, 175, 55, 0.25);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  transition: background 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}
.halma-turn-dot {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--tok-light, #fff3c4) 0 15%, var(--tok) 45%, var(--tok-dark, #8a6510) 100%);
  border: 2px solid var(--rim, #f6eccd);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  opacity: 0.5;
}
.halma-turn-text { min-width: 0; }
.halma-turn.on { border-color: var(--tok); background: rgba(0, 0, 0, 0.38); }
.halma-turn.on .halma-turn-dot { opacity: 1; animation: halma-dot 1.2s ease-in-out infinite; }
@keyframes halma-dot {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}
/* This device's turn: the banner fills with the seat colour. */
.halma-turn.on.mine {
  --ink: #1f150c;
  color: var(--ink);
  background: linear-gradient(180deg, var(--tok-light), var(--tok));
  border-color: #fff3c4;
  font-size: 17px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  animation: halma-banner 1s ease-in-out infinite;
}
.halma-turn.on.mine.c-purple {
  color: #fff;
  background: linear-gradient(180deg, #a77ae4, #7c45c2);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.45);
}
.halma-turn.on.mine.c-white { border-color: #3d2e1a; background: linear-gradient(180deg, #ffffff, #e6dcc6); }
.halma-turn .yt {
  display: inline-block;
  margin-right: 0.35em;
  font-weight: 900;
  letter-spacing: 0.04em;
}
@keyframes halma-banner {
  0%, 100% { box-shadow: 0 0 0 2px var(--tok-dark), 0 0 8px var(--tok); }
  50% { box-shadow: 0 0 0 2px var(--tok-dark), 0 0 22px 4px var(--tok); }
}
.halma-turn.over { border-color: var(--gold); background: rgba(212, 175, 55, 0.14); }

/* ----- players / progress ----- */
.halma-players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.halma-player {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 10px;
  row-gap: 5px;
  padding: 7px 10px 8px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.22);
  border: 2px solid transparent;
  font-size: 14px;
  transition: background 0.25s ease, border-color 0.25s ease, opacity 0.25s ease;
}
.halma-players.has-turn .halma-player:not(.turn) { opacity: 0.72; }
.halma-player.turn {
  border-color: var(--tok);
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.35)), var(--tok-dark);
  box-shadow: 0 0 12px var(--tok);
}
.halma-player.c-white.turn { border-color: #fffbe8; }
.halma-player .swatch {
  grid-row: 1 / span 2;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 33% 28%, rgba(255, 255, 255, 0.9) 0 8%, transparent 18%),
    radial-gradient(circle at 35% 30%, var(--tok-light) 0 15%, var(--tok) 42%, var(--tok-dark) 100%);
  border: 2px solid var(--rim);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.halma-player.turn .swatch { animation: halma-dot 1.2s ease-in-out infinite; }
.halma-player .pname {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.halma-player .you { color: var(--gold); font-weight: 800; }
.halma-player.turn .you { color: #fff3c4; }
.halma-player .tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  margin-left: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--muted);
  vertical-align: 1px;
}
.halma-player .tag.off { background: rgba(239, 68, 68, 0.22); color: #fca5a5; }
.halma-player .pside {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
}
.halma-player .pprog {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  white-space: nowrap;
}
.halma-player .pprog b { color: var(--text); font-size: 14px; }
.halma-player.turn .pprog { color: #f4e6c6; }
.halma-player .pbar {
  grid-column: 2 / span 2;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.halma-player .pbar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--tok);
  transition: width 0.4s ease;
}
.halma-player.turn .pbar i { background: var(--tok-light); }
.halma-player .pplace {
  font-size: 12px;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 999px;
  color: #1f150c;
  background: #e8d6a8;
  white-space: nowrap;
}
.halma-player .pplace[data-place="1"] { background: var(--gold); }
.halma-player .pplace[data-place="2"] { background: #d8dde8; }
.halma-player .pplace[data-place="3"] { background: #d79a63; }
.halma-player.placed { opacity: 0.85; }
.halma-player .pstate {
  font-size: 11px;
  font-weight: 700;
  color: #fff3c4;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ----- side panel ----- */
.halma-hint {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  min-height: 18px;
}
.halma-hint b { color: var(--text); }
.halma-hint .legend {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-right: 12px;
  white-space: nowrap;
}
.halma-hint .lg-dot,
.halma-hint .lg-ring { display: inline-block; border-radius: 50%; }
.halma-hint .lg-dot { width: 8px; height: 8px; background: #fff6d8; box-shadow: 0 0 0 2px #6b4a12; }
.halma-hint .lg-ring { width: 14px; height: 14px; border: 2.5px solid #ffd24d; box-shadow: 0 0 0 1.5px #4a2e04, inset 0 0 0 1.5px #4a2e04; }

.halma-controls { display: flex; gap: 8px; }
.halma-controls button { flex: 1; min-height: 44px; font-size: 15px; }

.halma-setup {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  padding: 10px 12px;
}
.halma-setup label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.halma-setup select {
  background: #1a1410;
  color: var(--text);
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 14px;
  min-height: 36px;
}

.halma-rules {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}
.halma-rules summary {
  cursor: pointer;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 0;
}
.halma-rules ul { margin: 6px 0 4px; padding-left: 18px; }
.halma-rules li { margin: 4px 0; }
.halma-rules b { color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  .halma-svg .pt-glow.turn,
  .halma-svg .pt-glow.turn.mine { animation: none; opacity: 0.65; }
  .halma-board.has-turn.mine .star-glow { animation: none; opacity: 1; }
  .halma-svg .mk.jump,
  .halma-piece.selected::after,
  .halma-turn.on .halma-turn-dot,
  .halma-turn.on.mine,
  .halma-player.turn .swatch { animation: none; }
}

/* ----- tablet / small laptop ----- */
@media (max-width: 1000px) and (min-width: 761px) {
  .halma-table { grid-template-columns: auto minmax(230px, 270px); }
  .halma-board-area { width: min(calc(100vw - 330px), calc((100vh - 170px) * 0.87), 640px); }
}

/* ----- phone: one column, HUD above the board ----- */
@media (max-width: 760px) {
  .halma-table {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas: "hud" "board" "side";
    justify-items: center;
    row-gap: 6px;
    padding: 6px 4px 12px;
    overflow: visible;
  }
  .halma-hud, .halma-side { width: min(100%, 560px); }
  .halma-hud { gap: 6px; }
  .halma-board-area { width: min(100%, 520px); min-width: 0; }
  .halma-side { max-height: none; overflow: visible; padding: 0 4px; }
  .halma-piece { border-width: 1.5px; }
  .halma-piece.c-white { border-width: 1.2px; }
  .halma-piece.selected::after { border-width: 2px; }

  .halma-turn { min-height: 40px; padding: 6px 12px; font-size: 14px; margin: 0 2px; }
  .halma-turn.on.mine { font-size: 15px; }
  /* One line only, so the board never jumps when the hint text changes. */
  .halma-turn-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .halma-players {
    display: grid;
    grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr));
    gap: 5px;
    margin: 0 2px;
  }
  .halma-player {
    grid-template-columns: auto 1fr;
    column-gap: 6px;
    row-gap: 3px;
    padding: 5px 7px 6px;
    font-size: 12.5px;
  }
  .halma-player .swatch { grid-row: 1; width: 15px; height: 15px; border-width: 1.5px; }
  .halma-player .pname { grid-column: 2; }
  .halma-player .pside { grid-column: 1 / span 2; grid-row: 2; justify-self: start; }
  .halma-player .pprog, .halma-player .pplace { font-size: 12px; }
  .halma-player .pprog b { font-size: 12.5px; }
  .halma-player .pbar { grid-column: 1 / span 2; grid-row: 3; height: 4px; }
  /* Tags sit on the progress row (right side) so narrow chips keep the whole name. */
  .halma-player .tag { position: absolute; top: 23px; right: 6px; font-size: 9px; padding: 0 4px; margin: 0; line-height: 14px; }
  .halma-player .pstate { display: none; }
  .halma-toast { font-size: 13px; padding: 7px 14px; }
}
@media (max-width: 400px) {
  .halma-turn { font-size: 13px; }
  .halma-turn.on.mine { font-size: 14px; }
  .halma-player { font-size: 12px; }
}
