/* The game screen: board mat, track cells and legend, pieces, HUD, roll queue,
   nudge/turn indicators, guided tour callouts, local new-game setup. */

/* Small board legend -- a toggled popover rather than a permanent strip,
   so it doesn't eat into the board's own limited space; opens explaining
   exactly the symbols this pass added (piece shapes, safe-cell color,
   zone tints, the king). */
.board-legend-btn {
  position: absolute; top: 10px; right: 10px; z-index: 50;
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  background: var(--surface-solid); border: 1.5px solid var(--gold-accent); color: var(--gold-accent);
  font-family: 'Cinzel', serif; font-weight: 800; font-size: .92rem;
  box-shadow: 0 3px 8px var(--shadow);
}
/* Mirror of the legend button, top-left: opens the match-stats drawer. */
.stats-drawer-btn {
  position: absolute; top: 10px; left: 10px; z-index: 50;
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; padding: 0;
  background: var(--surface-solid); border: 1.5px solid var(--gold-accent);
  font-size: .85rem; line-height: 1; box-shadow: 0 3px 8px var(--shadow);
}
.board-legend-panel {
  position: absolute; top: 46px; right: 10px; z-index: 51; width: 190px;
  background: var(--surface-solid); border: 1.5px solid var(--gold-accent); border-radius: 12px;
  padding: 10px 12px; box-shadow: 0 8px 22px var(--shadow-strong);
  display: none; flex-direction: column; gap: 7px;
}
.board-legend-panel.open { display: flex; }
.board-legend-title { font-family: 'Cinzel', serif; font-weight: 800; color: var(--gold-accent); font-size: .74rem; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 2px; }
.board-legend-row { display: flex; align-items: center; gap: 8px; font-size: .72rem; color: var(--text-primary); }
.legend-swatch { flex-shrink: 0; cursor: default; }
.legend-cell { width: 20px; height: 20px; border-radius: 3px; position: relative; display: inline-block; }
.legend-cell.safe { background: var(--safe-cell-bg); border: 2px solid var(--safe-cell-border); }
.legend-cell.safe::before { content: "\2715"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--safe-cell-border); }
.legend-zone { width: 20px; height: 20px; border-radius: 50%; display: inline-block; }

.team-label-top, .team-label-bottom {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 8px 0; z-index: 3; position: relative;
}

.board-team-name {
  font-family: 'Cinzel', serif;
  font-size: calc(0.85rem * var(--board-scale, 1));
  font-weight: 800; letter-spacing: 1px; color: var(--gold-accent);
  text-shadow: 1px 1px 0 var(--shadow-strong);
  max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.board-team-name.mine { cursor: pointer; }
.board-team-name.mine::after { content: " ✏️"; font-size: 0.72em; }

.board-player-badges { display: flex; gap: calc(8px * var(--board-scale, 1)); }
.board-player-badges .player-badge { width: calc(50px * var(--board-scale, 1)); height: calc(50px * var(--board-scale, 1)); }
.board-player-badges .player-badge .badge-num { width: calc(18px * var(--board-scale, 1)); height: calc(18px * var(--board-scale, 1)); font-size: calc(10px * var(--board-scale, 1)); }
.board-player-badges .player-badge .badge-lock { font-size: calc(13px * var(--board-scale, 1)); top: calc(-6px * var(--board-scale, 1)); right: calc(-6px * var(--board-scale, 1)); }

.board-stage-wrap { margin: 0 auto; overflow: hidden; }

.board-svg-container { position: relative; width: 1000px; height: 380px; transition: transform 0.1s ease; }

svg.board-decor { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.oval-yard-ring { fill: none; stroke: var(--mat-border); stroke-width: 2; stroke-dasharray: 6 5; opacity: .55; }

.track-cell {
  position: absolute; width: 52px; height: 52px;
  background: var(--cell-bg); border: 1.5px solid var(--cell-border);
  border-radius: 4px; display: flex; align-items: center; justify-content: center;
  z-index: 3; transition: transform 0.15s ease, background-color 0.2s;
}
/* Safe cells get their own color family (warm amber), not just a slightly
   different shade of the track's cream -- plus a thicker, solid border so
   "this is a different kind of square" reads before you even notice the
   symbol. The X is a shape, not a color, so it stays meaningful for
   colorblind players regardless of the red/green pieces sitting on it. */
.track-cell.safe { background: var(--safe-cell-bg); border: 2.5px solid var(--safe-cell-border); }
.track-cell.safe::before {
  content: "\2715"; font-size: 26px; font-weight: 700; color: var(--safe-cell-border);
  position: absolute; pointer-events: none; opacity: 0.55;
}

.oval-zone {
  position: absolute; border-radius: 50%; display: flex; flex-wrap: wrap;
  align-items: center; justify-content: center; align-content: center; gap: 4px; padding: 10px 10px 22px; z-index: 2;
}
/* Each zone gets a real fill + a matching solid ring, not just the dashed
   decorative oval-yard-ring alone -- reserve/home used to have no
   background at all, so they read as empty mat rather than a zone. The
   text label (::after) is `position:absolute` so it never competes with
   flex-laid-out tokens for space, and fades as the zone fills up. */
#red-reserve-zone { top: 75px; left: 133.5px; width: 155px; height: 210px; background: var(--reserve-red-bg); box-shadow: inset 0 0 0 2px var(--reserve-red-border); }
#green-reserve-zone { top: 75px; right: 171.5px; width: 155px; height: 210px; background: var(--reserve-green-bg); box-shadow: inset 0 0 0 2px var(--reserve-green-border); }
#center-home-zone { top: 75px; left: 401px; width: 160px; height: 210px; background: var(--home-bg); box-shadow: inset 0 0 0 2px var(--home-border); }
.oval-zone::after {
  position: absolute; bottom: 10px; left: 0; right: 0; text-align: center;
  font-family: 'Cinzel', serif; font-size: .62rem; font-weight: 800; letter-spacing: .6px;
  text-transform: uppercase; pointer-events: none; z-index: 1;
}
#red-reserve-zone::after { content: "Reserve"; color: var(--reserve-red-border); }
#green-reserve-zone::after { content: "Reserve"; color: var(--reserve-green-border); }
#center-home-zone::after { content: "Home"; color: var(--home-border); }

.token {
  width: 44px; height: 44px; border-radius: 50%; position: relative; cursor: pointer;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.3), 0 4px 8px rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 16px; transition: transform 0.2s ease; z-index: 10;
}
/* Both teams use the same round piece. Team isn't color-only: red pieces
   carry white numerals on a dark fill, green dark numerals on a light fill,
   so the two stay distinguishable in grayscale / red-green color blindness. */
.token.t-red { background: radial-gradient(circle at 35% 35%, var(--red-highlight), var(--red-dark)); border: 2.5px solid #fff; color: #fff; }
.token.t-green { background: radial-gradient(circle at 35% 35%, var(--green-light), var(--green-border)); border: 2.5px solid #eef7f0; color: #16241a; }
.token.king {
  width: 50px; height: 50px; font-size: 20px;
  border: 3px solid #ffd700 !important;
  box-shadow: 0 4px 10px rgba(0,0,0,0.65), 0 0 0 3px rgba(255,215,0,.5), 0 0 14px 2px rgba(255,215,0,.55) !important;
}
.token.king::after { content: "\265B"; font-size: 24px; color: #000; text-shadow: 0 0 3px rgba(255,255,255,.65); }
.token.selectable { animation: tokenGlow 0.8s infinite alternate; cursor: pointer; z-index: 20; }
.token.attackable { animation: tokenAttackGlow 0.8s infinite alternate; cursor: pointer; z-index: 20; }

@keyframes tokenGlow { 0% { transform: scale(1.05); filter: drop-shadow(0 0 3px var(--success)); } 100% { transform: scale(1.22); filter: drop-shadow(0 0 10px var(--success)); } }
@keyframes tokenAttackGlow { 0% { transform: scale(1.05); filter: drop-shadow(0 0 3px var(--danger)); } 100% { transform: scale(1.22); filter: drop-shadow(0 0 10px var(--danger)); } }

.hud-panel {
  background: var(--surface-solid);
  border: 1px solid var(--border-gold);
  border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 8px 20px var(--shadow-strong);
  color: var(--text-primary);
}

.dice-row { display: flex; align-items: center; gap: 10px; }
.cowries-box { display: flex; justify-content: center; gap: 5px; flex: 1 1 auto; }

.cowrie {
  width: 22px; height: 31px; background: #f1e4c3;
  border: 2px solid #855b32; border-radius: 50% 50% 45% 45% / 60% 60% 40% 40%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 4px rgba(0,0,0,0.3);
}
.cowrie.flat::after { content: ""; width: 4px; height: 18px; background: #3e2410; border-radius: 5px; }
.cowrie.back { background: #b08d66; border-color: #5c3817; }

.roll-btn, .pass-btn { flex: 0 0 auto; padding: 10px 16px; border-radius: 8px; font-size: 0.85rem; font-weight: 900; cursor: pointer; }
.roll-btn {
  background: linear-gradient(180deg, #d4af37, #997819); border: none; color: #120a06;
  font-family: 'Cinzel', serif; box-shadow: 0 4px 10px rgba(212, 175, 55, 0.35);
}
.roll-btn:disabled { background: #473527; color: #887462; cursor: not-allowed; box-shadow: none; }
.pass-btn { display: block; background: #4b1b1b; border: 1px solid var(--danger); color: var(--status-error); }
.pass-btn:hover { background: var(--danger); color: #fff; }
.nudge-btn { background: #4b3410; border: 1px solid var(--gold-accent); color: #fbd97a; }
.nudge-btn:hover { background: var(--gold-accent); color: #120a06; }
.nudge-btn:disabled { background: #3a2f1d; border-color: #6b5a35; color: #8a7a56; cursor: not-allowed; }
/* Its own row below .dice-row rather than a 4th item crammed into that
   row -- dice-row is a no-wrap flex already sized to fit THROW/Pass/Nudge
   plus the shell icons, so one more inline button there overflowed the
   panel on both desktop and mobile widths. */
.last-throw-btn {
  display: block; width: 100%; margin-top: 8px; padding: 8px 12px;
  border-radius: 8px; font-size: 0.78rem; font-weight: 800; cursor: pointer;
  background: #4b3410; border: 1px solid var(--gold-accent); color: #fbd97a;
}
.last-throw-btn:hover { background: var(--gold-accent); color: #120a06; }
@keyframes nudgeShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); } 40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(3px); }
}
.nudged { animation: nudgeShake .5s ease; }

.moves-queue-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.queue-label { font-size: 0.7rem; color: var(--gold-accent); font-weight: 800; text-transform: uppercase; white-space: nowrap; }
.moves-queue { display: flex; gap: 6px; flex-wrap: wrap; min-height: 26px; align-items: center; }

.move-pill {
  background: var(--surface-1); border: 1.5px solid var(--gold-accent); color: var(--text-primary);
  padding: 3px 9px; border-radius: 14px; font-weight: 800; font-size: 0.8rem; cursor: pointer;
}
.move-pill.active { background: var(--success); border-color: #fff; color: #000; transform: scale(1.1); }

.status-text {
  font-size: 0.76rem; background: var(--surface-deep); padding: 6px 8px; border-radius: 6px;
  border: 1px solid var(--border-gold); margin-top: 6px; color: var(--text-primary);
  line-height: 1.3; min-height: 44px; overflow-wrap: break-word;
}

.team-stats-card { width: 100%; max-width: 1060px; font-size: 0.78rem; color: var(--text-muted); }
.team-stats-row { display: flex; flex-direction: column; gap: 8px; }
.team-stats-row > div { line-height: 1.45; }

/* Match stats live in a drawer so the board keeps the space: a sheet that
   slides up above the bottom nav, opened from the mat's 📊 button. Only the
   wide desktop layout (responsive.css) shows it inline in the side column. */
.game-drawer {
  position: fixed; z-index: 180; left: 50%;
  bottom: calc(var(--navbar-h) + env(safe-area-inset-bottom) + 10px);
  width: min(440px, calc(100% - 20px)); max-height: 60%; overflow-y: auto;
  transform: translate(-50%, 24px); opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform .22s ease, opacity .22s ease, visibility 0s linear .22s;
}
.game-drawer.open {
  transform: translate(-50%, 0); opacity: 1; visibility: visible; pointer-events: auto;
  transition: transform .22s ease, opacity .22s ease;
}
.game-drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.game-drawer-title { font-family: 'Cinzel', serif; font-weight: 800; color: var(--gold-accent); font-size: .78rem; text-transform: uppercase; letter-spacing: .5px; }
.game-drawer-close {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; cursor: pointer;
  border: 1px solid var(--border-gold); background: var(--surface-deep); color: var(--text-muted); font-size: .8rem;
}

.modal-overlay {
  position: fixed; inset: 0; background: var(--scrim);
  display: flex; align-items: center; justify-content: center;
  z-index: 210; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.join-modal-card { max-width: 400px; text-align: center; }
.join-modal-card h2 { margin-bottom: 4px; }
.join-modal-card p { color: var(--text-muted); font-size: .82rem; margin-bottom: 16px; }
.modal-card {
  background: var(--surface-solid); border: 2px solid var(--gold-accent); border-radius: 12px;
  padding: 20px; max-width: 540px; width: 90%; max-height: 85vh; overflow-y: auto;
  color: var(--text-primary);
}
.modal-card h2 { font-family: 'Cinzel', serif; color: var(--gold-accent); margin-bottom: 10px; }
.modal-card p, .modal-card li { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 6px; }
.modal-card ul { margin-left: 18px; margin-bottom: 8px; }
.newgame-card { padding: 16px 18px; }
.newgame-card h2 { font-size: 1.15rem; margin-bottom: 4px; }
.newgame-card > p { font-size: 0.78rem; margin-bottom: 10px; }

/* Cowrie throw cinematic — a 3D physics overlay shown while a roll's real
   result (already decided by the server / local rules, unchanged) is
   hidden underneath. See cowrieCinematic in app/cowrie-cinematic.js. */
.cowrie-cinematic-overlay {
  position: fixed; inset: 0; z-index: 470;
  background: radial-gradient(120% 100% at 50% 20%, #2a1a10 0%, #140b06 70%, #0a0503 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease;
}
.cowrie-cinematic-overlay.open { opacity: 1; pointer-events: auto; }
.cowrie-cinematic-overlay canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.cowrie-cinematic-caption {
  position: absolute; top: 14%; left: 50%; transform: translateX(-50%);
  font-family: 'Cinzel', serif; color: var(--gold-accent); font-size: 0.95rem;
  letter-spacing: 0.06em; text-shadow: 0 2px 6px rgba(0,0,0,0.6); pointer-events: none;
}
.cowrie-cinematic-skip {
  position: absolute; bottom: 6%; right: 6%; padding: 8px 16px; border-radius: 20px;
  background: rgba(20,12,7,0.72); border: 1px solid var(--border-gold-soft); color: var(--text-primary);
  font-size: 0.78rem; font-weight: 700; cursor: pointer;
}

/* Guided tour — spotlight cutout + speech-bubble callout over the live game UI */
.tour-overlay {
  position: fixed; inset: 0; z-index: 400; display: none;
}
.tour-overlay.open { display: block; }
.tour-spotlight {
  position: fixed; border-radius: 14px; box-shadow: 0 0 0 9999px rgba(8,4,2,.78);
  transition: left .28s ease, top .28s ease, width .28s ease, height .28s ease, opacity .2s ease;
  pointer-events: none; opacity: 0;
}
.tour-spotlight.visible { opacity: 1; }
.tour-bubble {
  position: fixed; width: min(300px, calc(100vw - 24px)); background: var(--surface-solid);
  border: 2px solid var(--gold-accent); border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 14px 34px rgba(0,0,0,.55); color: var(--text-primary);
  transition: left .28s ease, top .28s ease;
}
.tour-bubble::before {
  content: ''; position: absolute; width: 14px; height: 14px; background: var(--surface-solid);
  border: 2px solid var(--gold-accent); transform: rotate(45deg);
  left: var(--arrow-left, 50%); margin-left: -7px;
  display: none;
}
.tour-bubble.arrow-top::before { display: block; top: -8px; border-right: none; border-bottom: none; }
.tour-bubble.arrow-bottom::before { display: block; bottom: -8px; border-left: none; border-top: none; }
.tour-bubble-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.tour-step-count { font-size: .66rem; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; color: var(--gold-accent); }
.tour-skip { background: none; border: none; color: var(--text-muted); font-size: .72rem; cursor: pointer; padding: 2px; }
.tour-bubble h3 { font-size: 1.02rem; margin-bottom: 6px; }
.tour-bubble p { font-size: .82rem; color: var(--text-muted); line-height: 1.45; }
.tour-bubble-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.tour-dots { display: flex; gap: 5px; }
.tour-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--border-gold-soft); }
.tour-dots span.active { background: var(--gold-accent); }
.tour-nav { display: flex; gap: 8px; }
.tour-nav .play-btn { min-width: 0; padding: 8px 14px; font-size: .74rem; }

#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 200; display: block; }

.player-badge {
  position: relative; width: 62px; height: 62px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; color: #fff;
  background: #f4ecd6; border: 3px solid rgba(255,255,255,0.35);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.player-badge.team-red { border-color: var(--red-dark); }
.player-badge.team-green { border-color: var(--green-border); }
.player-badge svg { width: 68%; height: 68%; color: #6b5544; }
.player-badge .badge-num {
  position: absolute; bottom: -3px; right: -3px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--dark-wood); color: #fff;
  font-size: 12px; font-weight: 900; display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,255,255,0.4);
}
.player-badge .badge-lock {
  position: absolute; top: -8px; right: -8px; font-size: 15px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.6));
}
.player-badge.active-turn {
  z-index: 5; border-color: #fff;
  animation: activeBadgePulse 1.1s ease-in-out infinite;
}
@keyframes activeBadgePulse {
  0%, 100% { transform: scale(1.2); box-shadow: 0 0 10px 3px var(--gold-accent), 0 0 0 4px rgba(255,255,255,0.55), inset 0 0 0 2px rgba(0,0,0,0.2); }
  50% { transform: scale(1.38); box-shadow: 0 0 22px 9px var(--gold-accent), 0 0 0 4px rgba(255,255,255,0.95), inset 0 0 0 2px rgba(0,0,0,0.2); }
}
.player-badge:not(.active-turn) { opacity: 0.55; filter: saturate(0.6); }

.newgame-card { max-width: 640px; }
.team-setup-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 10px; }
.team-setup-grid > .team-setup-block { min-width: 0; }
@media (max-width: 320px) { .team-setup-grid { grid-template-columns: 1fr; } }
.team-setup-block { margin-bottom: 10px; }
.team-setup-heading { font-family: 'Cinzel', serif; font-weight: 900; letter-spacing: 1px; margin-bottom: 6px; font-size: 0.9rem; }
.team-setup-heading.red { color: var(--red-highlight); }
.team-setup-heading.green { color: var(--green-team); }
.team-name-input { display: block; width: 100%; margin-bottom: 6px; padding: 5px 8px; font-size: 0.8rem; }
.count-stepper { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.count-stepper button { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--gold-accent); background: #3b2214; color: #fef08a; font-weight: 900; cursor: pointer; font-size: 0.85rem; }
.count-stepper button:hover { background: var(--gold-accent); color: #000; }
.count-stepper span { font-weight: 800; min-width: 40px; text-align: center; font-size: 0.85rem; }
.name-input-row { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; }
.name-input-row span { font-size: 0.72rem; color: #94a3b8; width: 20px; flex-shrink: 0; }
.name-input { flex: 1; background: #120a06; border: 1px solid rgba(212, 175, 55, 0.4); border-radius: 6px; color: #fff; padding: 5px 8px; font-size: 0.78rem; min-width: 0; }
.name-input:focus { outline: none; border-color: var(--gold-accent); }
.gender-toggle { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--gold-accent); background: #f4ecd6; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 0; overflow: hidden; }
.gender-toggle:hover { border-color: #fff; box-shadow: 0 0 6px 1px var(--gold-accent); }
.gender-toggle svg { width: 72%; height: 72%; color: #6b5544; }

@media (max-width: 640px) {
  .game-layout { gap: 10px; }
  .top-controls-row { flex-direction: column; gap: 8px; }
  .top-controls-row .hud-panel { padding: 8px 10px; }
}

.unlock-note { font-size: 0.7rem; color: var(--status-error); margin-bottom: 6px; }
.queue-empty { color: var(--text-dim); font-size: 0.8rem; }
.legend-swatch.legend-token { width: 22px; height: 22px; font-size: 0; }
.legend-zone.zone-reserve { background: var(--reserve-red-bg); box-shadow: inset 0 0 0 2px var(--reserve-red-border); }
.legend-zone.zone-home { background: var(--home-bg); box-shadow: inset 0 0 0 2px var(--home-border); }
.team-setup-heading.accent { color: var(--gold-accent); }
/* Two classes so it outranks the generic `.modal-card p` rule above. */
.modal-card .turnorder-desc { font-size: 0.72rem; color: var(--text-subtle); }
