:root {
  --bg-0: #06160f;
  --bg-1: #0c2a1d;
  --bg-2: #103a28;
  --felt-0: #1f7d5c;
  --felt-1: #15614687;
  --felt-edge: #0c3122;
  --wood: #5a3a22;
  --wood-light: #7a5235;
  --tile-0: #fdfaf2;
  --tile-1: #ece4d3;
  --tile-line: #b9ad95;
  --dot: #20242b;
  --dot-six: #b4452f;
  --gold: #f2cf52;
  --gold-2: #d8a72f;
  --team-a: #6cb7ef;
  --team-a-d: #2d6fa8;
  --team-b: #ef8a6c;
  --team-b-d: #b8543a;
  --text: #f6f3ec;
  --muted: rgba(246, 243, 236, 0.6);
  --line: rgba(255, 255, 255, 0.1);
  --radius: 18px;
  --tile-w: clamp(38px, 10.8vw, 48px);
  --tile-h: calc(var(--tile-w) * 1.92);
  --tile-half: calc(var(--tile-h) / 2);
  --board-tile-w: clamp(24px, 5.5vw, 30px);
  --board-tile-h: calc(var(--board-tile-w) * 1.92);
  --board-tile-half: calc(var(--board-tile-h) / 2);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg-0);
  touch-action: manipulation;
}

body {
  padding-top: var(--safe-t);
}

.hidden {
  display: none !important;
}

.screen {
  height: 100dvh;
  overflow: hidden;
}

/* ───────────── Lobby ───────────── */
.screen-lobby {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background:
    radial-gradient(circle at 50% -10%, #2b9c72 0%, transparent 50%),
    radial-gradient(circle at 50% 120%, #0a3022 0%, transparent 45%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}

.lobby-card {
  width: min(100%, 390px);
  padding: 2rem 1.5rem;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(0, 0, 0, 0.25));
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.logo {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  font-size: 2rem;
  border-radius: 20px;
  color: #1a1200;
  background: linear-gradient(160deg, var(--gold), var(--gold-2));
  box-shadow: 0 8px 24px rgba(242, 207, 82, 0.35);
}

.lobby-card h1 {
  margin: 1rem 0 0;
  text-align: center;
  font-size: 1.75rem;
  letter-spacing: 0.01em;
}

.tagline {
  margin: 0.4rem 0 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}

.field span {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
}

.field input {
  width: 100%;
  padding: 0.9rem 1.05rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-size: 1.05rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(242, 207, 82, 0.18);
}

#input-code {
  letter-spacing: 0.45em;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.error-msg {
  margin: 0.85rem 0 0;
  color: #ff9b8f;
  font-size: 0.9rem;
  text-align: center;
}

.lobby-tip {
  margin: 1.5rem 0 0;
  font-size: 0.76rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.lobby-tip code {
  background: rgba(255, 255, 255, 0.1);
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  color: var(--gold);
}

/* ───────────── Buttons ───────────── */
.btn {
  border: none;
  border-radius: 999px;
  padding: 0.9rem 1.3rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s, background 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-block {
  width: 100%;
  margin-bottom: 0.6rem;
}

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

.btn-primary {
  background: linear-gradient(180deg, var(--gold), var(--gold-2));
  color: #1a1200;
  box-shadow: 0 6px 18px rgba(242, 207, 82, 0.3);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.13);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-gold {
  flex: 1;
  min-width: 0;
  padding: 0.85rem 0.5rem;
  font-size: 0.92rem;
  background: linear-gradient(180deg, rgba(242, 207, 82, 0.22), rgba(216, 167, 47, 0.12));
  color: var(--gold);
  border: 1px solid rgba(242, 207, 82, 0.4);
}

.btn-gold:not(:disabled) {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

/* ───────────── Waiting room ───────────── */
.screen-waiting {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 50% -10%, #2b9c72 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.25rem 0.75rem;
}

.label {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.room-code {
  margin: 0.2rem 0 0;
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  background: linear-gradient(180deg, var(--gold), var(--gold-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.scores-mini {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  text-align: right;
}

.team-a-chip,
.team-b-chip {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
}

.team-a-chip strong {
  color: var(--team-a);
}

.team-b-chip strong {
  color: var(--team-b);
}

.waiting-body {
  flex: 1;
  padding: 1rem 1.25rem;
  overflow: auto;
}

.waiting-body h2 {
  margin: 0.5rem 0 1rem;
  font-size: 1.05rem;
}

.player-list {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.9rem 1.1rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  font-weight: 600;
}

.player-list li.you {
  border-color: rgba(242, 207, 82, 0.5);
  background: rgba(242, 207, 82, 0.08);
}

.player-list li.empty {
  color: var(--muted);
  font-style: italic;
  font-weight: 400;
}

.seat-badge {
  font-size: 0.68rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
}

.seat-badge.a {
  background: rgba(108, 183, 239, 0.2);
  color: var(--team-a);
}

.seat-badge.b {
  background: rgba(239, 138, 108, 0.2);
  color: var(--team-b);
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1rem;
  text-align: center;
}

/* ───────────── Game ───────────── */
.screen-game {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background:
    radial-gradient(ellipse at 50% 18%, #3a2b63 0%, transparent 55%),
    radial-gradient(ellipse at 50% 120%, #1a1330 0%, transparent 50%),
    linear-gradient(180deg, #241a44, #140e28 70%, #0c0820);
}

/* ── Top bar ── */
.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem 0.4rem;
}

.tb-score {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
}

.tb-score strong {
  font-size: 1.05rem;
}

.tb-score.a {
  border-color: rgba(108, 183, 239, 0.4);
}

.tb-score.a strong {
  color: var(--team-a);
}

.tb-score.b {
  border-color: rgba(239, 138, 108, 0.4);
}

.tb-score.b strong {
  color: var(--team-b);
}

.tb-info {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.2;
}

.room-tag {
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--gold);
}

.icon-btn {
  position: absolute;
  right: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}

/* ── Table area (relative anchor for seats + oval felt) ── */
.table-area {
  position: relative;
  flex: 1;
  min-height: 0;
}

/* ── Turn line in the hand dock ── */
.turn-line {
  margin: 0;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 800;
}

.turn-line:not(.waiting) {
  color: var(--gold);
  animation: turnPulse 1.6s ease-in-out infinite;
}

.turn-line.waiting {
  color: var(--muted);
  font-weight: 600;
}

@keyframes turnPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ── Player seats around the oval table ── */
.seat {
  position: absolute;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 96px;
  pointer-events: none;
}

.pos-left  { top: 1%;  left: 7%; }
.pos-mid   { top: -1%; left: 50%; transform: translateX(-50%); }
.pos-right { top: 1%;  right: 7%; }
.pos-you   { bottom: -7%; left: -3%; }

.avatar-wrap {
  position: relative;
  width: 60px;
  height: 60px;
}

.ring {
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: conic-gradient(var(--gold) calc(var(--p, 1) * 360deg), rgba(0, 0, 0, 0.5) 0);
  display: none;
}

.seat.active .ring {
  display: block;
}

.seat.active .avatar {
  box-shadow: 0 0 16px rgba(242, 207, 82, 0.6);
}

.avatar {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.45rem;
  font-weight: 800;
  color: #0a1410;
  border: 3px solid rgba(255, 255, 255, 0.55);
  background: linear-gradient(160deg, #cfd6dd, #8a929c);
  overflow: hidden;
}

.seat.teamA .avatar { background: linear-gradient(160deg, var(--team-a), var(--team-a-d)); }
.seat.teamB .avatar { background: linear-gradient(160deg, var(--team-b), var(--team-b-d)); }

.tiles-badge {
  position: absolute;
  right: -10px;
  bottom: -6px;
  min-width: 22px;
  height: 26px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 6px;
  background: linear-gradient(180deg, #fdfaf2, #e7ddc8);
  color: #1a1200;
  font-size: 0.8rem;
  font-weight: 800;
  border: 1.5px solid rgba(0, 0, 0, 0.25);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

.tiles-badge::before {
  content: "";
  width: 9px;
  height: 13px;
  border-radius: 2px;
  background: repeating-linear-gradient(90deg, #c8392b 0 3px, #fff 3px 5px);
  border: 1px solid rgba(0, 0, 0, 0.4);
}

.sec-badge {
  position: absolute;
  top: -8px;
  left: -8px;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #1c140a;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  border: 2px solid var(--gold);
  z-index: 2;
}

.plate {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  max-width: 110px;
}

.pname {
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.prole {
  font-size: 0.56rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.pscore {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--gold);
}

/* Rectangular wood-framed table */
.board-panel {
  position: absolute;
  top: 66px;
  left: 1%;
  right: 1%;
  bottom: 10%;
  border-radius: 20px;
  padding: 10px;
  background: linear-gradient(160deg, var(--wood-light), var(--wood) 55%, #38240f);
  box-shadow:
    0 16px 34px rgba(0, 0, 0, 0.55),
    inset 0 2px 3px rgba(255, 255, 255, 0.25),
    inset 0 -6px 14px rgba(0, 0, 0, 0.5);
}

.felt-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.022) 0 12px, transparent 12px 24px),
    radial-gradient(ellipse at 50% 45%, var(--felt-0) 0%, #14543c 70%, var(--felt-edge) 100%);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

/* Tiles container fills the whole felt */
.board-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 8px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.board-scroll::-webkit-scrollbar {
  display: none;
}

.board-chain {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  margin: auto;
}

.board-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.95rem;
  font-style: italic;
  white-space: nowrap;
  text-align: center;
}

.board-chain .domino {
  position: absolute;
  animation: dropIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.3) forwards;
  opacity: 1;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

@keyframes dropIn {
  from { transform: scale(0.6) translateY(-12px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

/* End chips — show the open ends of the chain, anchored to felt corners */
.end-chip {
  position: absolute;
  bottom: 10px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem 0.5rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--muted);
  pointer-events: none;
}

.end-chip.left { left: 10px; }
.end-chip.right { right: 10px; }

.end-chip strong {
  display: inline-grid;
  place-items: center;
  min-width: 1.3rem;
  height: 1.3rem;
  border-radius: 6px;
  background: var(--gold);
  color: #1a1200;
  font-size: 0.85rem;
}

/* Drop zones — overlay halves, only visible while dragging a tile */
.drop-zones {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.board-panel.dragging .drop-zones {
  opacity: 1;
}

.drop-zone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.35);
  border: 3px dashed transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.drop-zone.left {
  border-right: 1px dashed rgba(255, 255, 255, 0.18);
}

.drop-zone.valid {
  color: var(--gold);
  border-color: rgba(242, 207, 82, 0.55);
  background: rgba(242, 207, 82, 0.1);
}

.drop-zone.hot {
  color: #fff;
  border-color: var(--gold);
  background: rgba(242, 207, 82, 0.32);
}

.game-msg {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4px;
  z-index: 3;
  margin: 0;
  padding: 0.2rem 0.75rem;
  text-align: center;
  font-size: 0.74rem;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

/* ── Hand dock (your tiles + actions) ── */
.hand-dock {
  position: relative;
  z-index: 5;
  padding: 0.3rem 0 calc(0.5rem + var(--safe-b));
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.5) 40%);
}

.hand-scroll {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.hand-scroll .domino {
  flex-shrink: 0;
}

.action-bar {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.2rem 0.85rem 0.1rem;
}

.action-bar .btn-secondary {
  flex: 0 0 auto;
  padding-inline: 1.1rem;
}

/* ───────────── Domino tile ───────────── */
.domino {
  display: inline-flex;
  flex-direction: column;
  width: var(--domino-w, var(--tile-w));
  height: var(--domino-h, var(--tile-h));
  border-radius: 5px;
  background: linear-gradient(180deg, #f3ead5, #e5d8bb);
  box-shadow:
    0 2px 5px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    inset 0 0 0 1px #b6aa92;
  flex-shrink: 0;
  user-select: none;
  position: relative;
}

.domino::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 35%);
}

.domino.horizontal-board {
  flex-direction: row;
  width: var(--domino-h, var(--tile-h));
  height: var(--domino-w, var(--tile-w));
}

.domino.playable {
  cursor: grab;
  touch-action: none;
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    inset 0 0 0 1px var(--tile-line),
    0 0 0 2px rgba(242, 207, 82, 0.55);
}

.domino.playable:active {
  cursor: grabbing;
}

.domino.selected {
  transform: translateY(-8px);
  box-shadow:
    0 12px 22px rgba(0, 0, 0, 0.45),
    0 0 0 3px var(--gold);
}

.domino.disabled {
  opacity: 0.5;
  filter: grayscale(0.3);
}

.domino.dragging {
  opacity: 0.35;
}

.domino.drag-ghost {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.12) rotate(-3deg);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55), 0 0 0 3px var(--gold);
  transition: none;
}

.half {
  position: relative;
  flex-shrink: 0;
  width: 100%;
  height: var(--domino-half, var(--tile-half));
}

/* Horizontal tile: each half is a square-ish portrait column */
.domino.horizontal-board .half {
  width: var(--domino-half, var(--tile-half));
  height: 100%;
}

.half.top::after,
.half.left::after {
  content: "";
  position: absolute;
}

.half.top::after {
  left: 12%;
  right: 12%;
  bottom: 0;
  height: 1px;
  background: rgba(120, 108, 86, 0.75);
}

.domino.horizontal-board .half.left::after {
  top: 12%;
  bottom: 12%;
  right: 0;
  width: 1px;
  background: rgba(120, 108, 86, 0.75);
}

/*
 * Pips use absolute positioning within each .half.
 * width is set as a % of the half's NARROWER dimension via min().
 * aspect-ratio:1 keeps them perfectly round in any container shape.
 */
.pip {
  position: absolute;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #1a1a1a;
  box-shadow:
    inset 0 1.5px 2px rgba(255, 255, 255, 0.28),
    0 1px 2px rgba(0, 0, 0, 0.7);
  transform: translate(-50%, -50%);
}

/*
 * 9-cell grid positions (rows top→bottom, cols left→right):
 *  1  2  3
 *  4  5  6
 *  7  8  9
 */
.half .pip:nth-child(1) { left: 22%; top: 22%; }
.half .pip:nth-child(2) { left: 50%; top: 22%; }
.half .pip:nth-child(3) { left: 78%; top: 22%; }
.half .pip:nth-child(4) { left: 22%; top: 50%; }
.half .pip:nth-child(5) { left: 50%; top: 50%; }
.half .pip:nth-child(6) { left: 78%; top: 50%; }
.half .pip:nth-child(7) { left: 22%; top: 78%; }
.half .pip:nth-child(8) { left: 50%; top: 78%; }
.half .pip:nth-child(9) { left: 78%; top: 78%; }

/* Board tiles: solid ivory background + larger pips (fixes mobile transparency) */
.board-piece.domino {
  --domino-w: var(--board-tile-w);
  --domino-h: var(--board-tile-h);
  --domino-half: var(--board-tile-half);
  background-color: #f5ecd8;
  background-image: linear-gradient(180deg, #fdfaf2 0%, #e8dcc4 100%);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 0 0 1.5px #b6aa92;
  opacity: 1;
}

.board-piece .pip {
  width: 32%;
  background: #141414;
}

.board-piece .half {
  background: transparent;
}

.pip.hidden {
  visibility: hidden;
}

/* ───────────── Chat ───────────── */
.chat-fab {
  position: fixed;
  right: 0.9rem;
  bottom: calc(5rem + var(--safe-b));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(160deg, var(--gold), var(--gold-2));
  font-size: 1.35rem;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  z-index: 50;
}

.screen-waiting .chat-fab {
  bottom: calc(1.25rem + var(--safe-b));
}

.chat-drawer {
  position: fixed;
  inset: auto 0 0 0;
  max-height: 60dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #12362a, #0b231a);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  z-index: 60;
  padding-bottom: var(--safe-b);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.22s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.chat-drawer[hidden] {
  display: none !important;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.chat-close {
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 140px;
}

.chat-msg {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.4;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  align-self: flex-start;
  max-width: 85%;
}

.chat-msg .chat-name {
  font-weight: 800;
  color: var(--gold);
  margin-right: 0.35rem;
}

.chat-msg.system {
  color: var(--muted);
  font-style: italic;
  background: transparent;
  align-self: center;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  border-top: 1px solid var(--line);
}

.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-size: 0.95rem;
}

.chat-form input:focus {
  outline: none;
  border-color: var(--gold);
}

.chat-form .btn {
  flex-shrink: 0;
  padding: 0.75rem 1.1rem;
}

/* ───────────── Modals ───────────── */
.modal {
  border: none;
  padding: 0;
  max-width: 380px;
  width: calc(100% - 2rem);
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(3px);
}

.modal-box {
  padding: 1.6rem;
  border-radius: 22px;
  background: linear-gradient(180deg, #1a4031, #0e271d);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
}

.modal-box h2 {
  margin: 0 0 0.6rem;
  font-size: 1.6rem;
  color: var(--gold);
}

.modal-box p {
  margin: 0 0 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

.modal-box ul {
  margin: 0 0 1.2rem;
  padding: 0;
  list-style: none;
  color: var(--text);
  line-height: 1.7;
  font-size: 0.92rem;
}

.modal-note {
  margin: 0.6rem 0 0 !important;
  font-size: 0.82rem;
}

/* ───────────── Toast ───────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.5rem + var(--safe-b));
  transform: translateX(-50%);
  max-width: calc(100% - 2rem);
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.94);
  border: 1px solid var(--line);
  color: #fff;
  font-size: 0.85rem;
  z-index: 100;
  text-align: center;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
}

/* Mobile: larger board tiles, stronger domino contrast */
@media (max-width: 599px) {
  :root {
    --board-tile-w: clamp(28px, 7vw, 34px);
    --tile-w: clamp(40px, 11vw, 50px);
  }

  .board-panel {
    top: 58px;
    left: 0.5%;
    right: 0.5%;
    bottom: 8%;
    padding: 8px;
  }

  .board-scroll {
    padding: 6px;
  }

  .board-piece .pip {
    width: 34%;
  }

  .domino::after {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 40%);
  }
}

/* On bigger screens, center everything as a clean phone-like column
   so the table stays large and fully visible. */
@media (min-width: 600px) {
  .screen-game,
  .screen-waiting {
    max-width: 540px;
    margin: 0 auto;
    box-shadow: 0 0 70px rgba(0, 0, 0, 0.55);
  }

  .hand-scroll {
    justify-content: center;
    flex-wrap: wrap;
  }

  .action-bar {
    justify-content: center;
  }

  .chat-drawer {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 540px;
    max-width: 100%;
  }
}
