/* ===== Domino Gaple ===== */

.domino-app {
  grid-template-rows: auto 1fr auto auto auto !important;
}

/* ---------- Tiles (pure CSS pips) ---------- */
.domino {
  --u: 30px;
  display: flex;
  flex: 0 0 auto;
  background: linear-gradient(160deg, #fffdf6 0%, #efe6cf 100%);
  border: 1px solid #b9a77a;
  border-radius: calc(var(--u) * 0.16);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45), inset 0 -1px 0 rgba(0, 0, 0, 0.12);
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.domino.h { width: calc(var(--u) * 2); height: var(--u); flex-direction: row; }
.domino.v { width: var(--u); height: calc(var(--u) * 2); flex-direction: column; }
.domino .half {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: calc(var(--u) * 0.12);
}
.domino.h .half + .half { border-left: 1px solid rgba(60, 40, 10, 0.45); }
.domino.v .half + .half { border-top: 1px solid rgba(60, 40, 10, 0.45); }
.domino .pip {
  width: 74%;
  height: 74%;
  place-self: center;
  border-radius: 50%;
}
.domino .pip.on {
  background: radial-gradient(circle at 35% 35%, #4a4a4a 0%, #111 70%);
}

/* face-down tile for opponents */
.domino-back {
  width: 11px;
  height: 22px;
  border-radius: 2px;
  background: linear-gradient(135deg, #6b1a1a 0%, #3a0c0c 100%);
  border: 1px solid #a8842a;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.domino.mini { --u: 11px; border-radius: 2px; }
.domino.mini .half { padding: 1px; }

/* ---------- Table + seats ---------- */
.domino-table {
  width: min(92vw, 1000px, max(560px, calc((100vh - 330px) * 1.78)));
}
.domino-seat { width: 190px; }
.domino-seat .opp-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  min-height: 24px;
}
.domino-seat .player { min-width: 120px; padding: 6px 10px; }
.domino-seat .player .name { font-size: 13px; }
.domino-seat .player .chips { font-size: 12px; }
.domino-seat .player .status { font-size: 11px; }
.domino-seat .player .status.passed { color: #f87171; }
.domino-seat .player.winner {
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.6);
}

/* ----- turn signal: opponent seat -----
   The seat to move (its face-down tiles + player card) gets a pulsing cream-gold
   ring and a soft fill behind it. Both live on pseudo-elements and only their
   opacity animates, so it stays on the compositor (smooth on iPhone Safari).
   While anyone is to move, the other opponent seats dim a little — a calm-down,
   not the greyed-out look of a folded/away seat. */
.domino-seat { isolation: isolate; border-radius: 14px; transition: filter 0.2s; }
.domino-seat::before,
.domino-seat::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 14px;
  pointer-events: none;
  opacity: 0;
}
.domino-seat::before {
  z-index: -1;
  background: radial-gradient(ellipse at 50% 55%, rgba(255, 236, 170, 0.5) 0%, rgba(255, 214, 92, 0.18) 60%, rgba(255, 214, 92, 0) 100%);
}
.domino-seat::after {
  z-index: 2;
  box-shadow:
    0 0 0 1.5px rgba(60, 35, 0, 0.75),
    inset 0 0 0 3px #fff3c4,
    inset 0 0 12px 3px rgba(255, 214, 92, 0.75);
}
/* Desktop: seats are absolutely placed; shrink them to the card so the ring hugs it. */
@media (min-width: 901px) {
  .domino-seat { width: max-content; min-width: 130px; max-width: 190px; }
  .domino-table .seat-left  { left: 22px; }
  .domino-table .seat-right { right: 22px; }
}
.domino-seat.turn::before { animation: domino-turn-fill 1.2s ease-in-out infinite; }
.domino-seat.turn::after  { animation: domino-turn-ring 1.2s ease-in-out infinite; }
.domino-table.has-turn .domino-seat:not(.turn) { filter: brightness(0.78) saturate(0.8); }
.domino-seat.turn .player.active {
  border-color: #fff3c4;
  background: rgba(40, 28, 6, 0.75);
}
@keyframes domino-turn-fill {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}
@keyframes domino-turn-ring {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* "thinking ···" pill on the card of the seat to move (replaces the last action). */
.domino-seat .player .status.turn-status { text-transform: none; letter-spacing: 0; }
.turn-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  line-height: 15px;
  color: #1f150c;
  background: #fff3c4;
  box-shadow: 0 0 0 1px rgba(70, 40, 0, 0.6);
  white-space: nowrap;
}
.turn-dots { display: inline-flex; gap: 2px; }
.turn-dots i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  animation: domino-dot 1.2s ease-in-out infinite;
}
.turn-dots i:nth-child(2) { animation-delay: 0.2s; }
.turn-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes domino-dot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.domino-board {
  width: 62%;
  max-height: 66%;
  gap: 8px;
}
.board-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  text-align: center;
}

/* ---------- Chain (snake layout; rows built in domino_ui.js) ---------- */
.chain {
  --u: 26px;
  --gap: 3px;
  width: 100%;
  min-height: 70px;
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--gap);
  padding: 4px;
  box-sizing: border-box;
}
.chain-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--gap);
}
.chain-row.rev { flex-direction: row-reverse; }
.chain .domino { --u: inherit; }
.chain .domino.last {
  box-shadow: 0 0 0 2px var(--gold), 0 0 12px rgba(212, 175, 55, 0.7);
}
.chain-empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}
.end-slot {
  width: max(calc(var(--u) * 2), 56px);
  height: max(var(--u), 44px);
  padding: 0 4px;
  border: 2px dashed var(--gold);
  border-radius: 6px;
  background: rgba(212, 175, 55, 0.15);
  color: var(--gold);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.05;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  cursor: pointer;
  animation: slot-pulse 1.2s ease-in-out infinite;
}
.chain .domino.end-tile {
  outline: 2px dashed var(--gold);
  outline-offset: 2px;
  cursor: pointer;
}
.end-slot .slot-dir { font-size: 9px; letter-spacing: 0.08em; opacity: 0.85; }
.end-slot .slot-val { font-size: 14px; }
@keyframes slot-pulse {
  0%, 100% { background: rgba(212, 175, 55, 0.12); }
  50%      { background: rgba(212, 175, 55, 0.32); }
}

/* ---------- Your hand ---------- */
.domino-hand-bar {
  position: relative;
  isolation: isolate;
  background: linear-gradient(180deg, #0a0604 0%, #1a1410 100%);
  border-top: 2px solid #2a1d12;
  padding: 8px 20px 14px;
  transition: border-color 0.2s;
}
.domino-hand-bar > :not(.hand-turn-tag) { position: relative; z-index: 1; }

/* ----- turn signal: your turn -----
   Stronger than an opponent's turn: the whole hand area pulses (gold fill +
   thick cream ring), faster, with a "YOUR TURN" tag on the top edge. Same
   opacity-only pseudo-element trick as the seats. The chooser (dashed gold end
   tiles/slots on the chain) stays a separate, dashed look. */
.domino-hand-bar::before,
.domino-hand-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}
.domino-hand-bar::before {
  z-index: 0;
  background: radial-gradient(ellipse 75% 95% at 50% 0%, rgba(255, 214, 92, 0.42) 0%, rgba(255, 214, 92, 0.12) 65%, rgba(255, 214, 92, 0) 100%);
}
.domino-hand-bar::after {
  z-index: 0;
  box-shadow:
    inset 0 0 0 4px #fff3c4,
    inset 0 0 22px 8px rgba(255, 214, 92, 0.6);
}
.domino-hand-bar.active { border-top-color: #fff3c4; }
.domino-hand-bar.active::before { animation: domino-turn-fill-strong 0.9s ease-in-out infinite; }
.domino-hand-bar.active::after  { animation: domino-turn-ring 0.9s ease-in-out infinite; }
@keyframes domino-turn-fill-strong {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
.hand-turn-tag {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 2;
  transform: translate(-50%, -55%);
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.3;
  color: #1f150c;
  background: #fff3c4;
  box-shadow: 0 0 0 1.5px rgba(70, 40, 0, 0.7), 0 1px 5px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  pointer-events: none;
  display: none;
}
.domino-hand-bar.active .hand-turn-tag { display: block; }
.domino-hand-bar.active .hand-label { color: #fff3c4; }

/* Nothing fits: the Pass button (already .primary) is the thing to tap. */
#btn-pass.must-pass { position: relative; }
#btn-pass.must-pass::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 7px;
  box-shadow: 0 0 0 3px #fff3c4, 0 0 12px 3px rgba(255, 214, 92, 0.8);
  pointer-events: none;
  animation: domino-turn-ring 0.9s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .domino-seat.turn::before,
  .domino-seat.turn::after,
  .domino-hand-bar.active::before,
  .domino-hand-bar.active::after,
  #btn-pass.must-pass::after,
  .turn-dots i { animation: none; }
  .domino-seat.turn::before { opacity: 0.8; }
  .domino-seat.turn::after,
  .domino-hand-bar.active::after,
  #btn-pass.must-pass::after { opacity: 1; }
  .domino-hand-bar.active::before { opacity: 0.85; }
  .turn-dots i { opacity: 0.8; }
}
.domino-hand-bar .hand-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}
.domino-hand-bar .hand-label { color: var(--text); font-weight: 600; }
.domino-hand-bar .hand-hint { font-style: italic; color: var(--gold); text-align: right; }
.domino-hand-bar .hand-hint.warn { color: #f87171; }

.domino-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: flex-end;
  min-height: 100px;
  padding-top: 10px;
}
.domino-hand .domino {
  --u: 44px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s;
}
.domino-hand .domino:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.domino-hand .domino.playable {
  box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(212, 175, 55, 0.55);
}
.domino-hand .domino.dim { opacity: 0.45; }
.domino-hand .domino.selected {
  transform: translateY(-10px);
  box-shadow: 0 0 0 3px var(--active), 0 10px 18px rgba(0, 0, 0, 0.55);
}
@media (hover: hover) {
  .domino-hand .domino.playable:hover { transform: translateY(-4px); }
  .domino-hand .domino.selected:hover { transform: translateY(-10px); }
}

/* ---------- Actions ---------- */
.end-btn {
  border-color: var(--gold) !important;
  color: var(--gold);
}
.rules-btn {
  padding: 4px 10px;
  font-size: 12px;
  min-height: 30px;
}

/* ---------- Rules overlay ---------- */
.rules-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.rules-overlay.hidden { display: none; }
.rules-card {
  background: linear-gradient(180deg, #221a12 0%, #140e09 100%);
  border: 1px solid rgba(212, 175, 55, 0.5);
  border-radius: 14px;
  padding: 22px 22px 18px;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}
.rules-card h2 { margin: 0 0 12px; color: var(--gold); font-size: 20px; }
.rules-card ul { margin: 0 0 16px; padding-left: 18px; }
.rules-card li { margin: 8px 0; font-size: 14px; line-height: 1.5; color: var(--text); }
.rules-card li b { color: var(--gold); }
.rules-card button { width: 100%; min-height: 46px; font-size: 15px; }

/* ===== Tablet + phone: stack opponents above a full-width board ===== */
@media (max-width: 900px) {
  .table.domino-table {
    width: 100%;
    max-width: 720px;
    aspect-ratio: auto;
    height: auto;
    min-height: 0;
    border-radius: 18px;
    border-width: 6px;
    padding: 8px 6px;
    display: grid;
    grid-template-areas:
      "left   top    right"
      "board  board  board";
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 6px;
  }
  .domino-table .seat {
    position: relative; /* anchor for the turn ring */
    inset: auto;        /* drop the desktop top/left/right offsets */
    transform: none !important;
    width: auto;
    min-width: 0;
    gap: 3px;
  }
  .domino-seat::before,
  .domino-seat::after { inset: -3px; border-radius: 12px; }
  .domino-table .seat-top   { grid-area: top; }
  .domino-table .seat-left  { grid-area: left; }
  .domino-table .seat-right { grid-area: right; }
  .domino-table .board {
    position: static;
    transform: none;
    grid-area: board;
    width: 100%;
    max-height: none;
    margin-top: 4px;
  }
  .domino-seat .player { min-width: 0; width: 100%; padding: 4px 6px; }
  .domino-seat .player .name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .domino-seat .player .chips { font-size: 11px; }
  .domino-seat .player .status { font-size: 10px; }
  .chain { max-height: none; overflow: visible; min-height: 90px; }
  .domino-hand-bar { padding: 6px 10px 10px; }
  .domino-hand .domino { --u: 42px; }
  .domino-hand { gap: 6px; min-height: 96px; }
}

@media (max-width: 640px) {
  .domino-seat .domino-back { width: 8px; height: 16px; }
  .domino-seat .domino.mini { --u: 8px; }
  .domino-seat .opp-tiles { min-height: 18px; }
  .board-label { font-size: 11px; letter-spacing: 1px; }
  .domino-hand-bar .hand-info { font-size: 12px; flex-wrap: wrap; }
  .domino-hand .domino { --u: 40px; }
  .domino-hand { gap: 6px; }
  .rules-card { padding: 18px 16px 14px; }
  .rules-card li { font-size: 13px; }
}

@media (max-width: 400px) {
  .domino-hand .domino { --u: 37px; }
  .domino-hand { gap: 5px; }
}
