/* Mancala — game skin over the shared tabletop layer. */

:root {
  --felt: #17342e;
  --felt-2: #0c211d;
  --wood: #9a6431;
  --wood-hi: #c2884a;
  --wood-lo: #5f3a17;
  --hollow: #3c2412;
  --gold: #e8b45c;
  --panel: rgba(8, 26, 22, 0.92);
  --panel-line: rgba(232, 180, 92, 0.24);
  --text: #f1f0e8;
  --dim: rgba(241, 240, 232, 0.6);
  --take: #ef6b5a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--felt-2);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#table {
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 35%, #1f463d 0%, var(--felt) 45%, var(--felt-2) 100%);
  touch-action: none;
}

.tt-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 220px rgba(0, 0, 0, 0.55);
}

/* ---------- the board ---------- */

.board-layer { position: absolute; transition: transform 0.45s ease; }
.board-layer.flipped { transform: rotate(180deg); }

.frame {
  position: absolute;
  border-radius: 90px;
  background:
    repeating-linear-gradient(97deg, rgba(0, 0, 0, 0.05) 0 3px, rgba(255, 255, 255, 0.035) 3px 7px),
    linear-gradient(168deg, var(--wood-hi) 0%, var(--wood) 42%, var(--wood-lo) 100%);
  box-shadow:
    0 26px 50px rgba(0, 0, 0, 0.5),
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    inset 0 -3px 8px rgba(0, 0, 0, 0.4);
}

.cell {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(75% 70% at 50% 28%, #1c1008 0%, var(--hollow) 70%, #4a2c15 100%);
  box-shadow:
    inset 0 7px 14px rgba(0, 0, 0, 0.65),
    inset 0 -2px 0 rgba(255, 255, 255, 0.12),
    0 1px 0 rgba(255, 255, 255, 0.16);
  transition: box-shadow 0.15s ease, transform 0.12s ease;
}

.cell.store { border-radius: 58px; }

.cell.pit.playable {
  cursor: pointer;
  box-shadow:
    inset 0 7px 14px rgba(0, 0, 0, 0.6),
    0 0 0 3px rgba(232, 180, 92, 0.75),
    0 0 18px rgba(232, 180, 92, 0.35);
}

.cell.pit.playable:hover { transform: scale(1.04); }

.cell.on-path {
  box-shadow:
    inset 0 7px 14px rgba(0, 0, 0, 0.6),
    0 0 0 2px rgba(255, 255, 255, 0.5);
}

.cell.landing {
  box-shadow:
    inset 0 7px 14px rgba(0, 0, 0, 0.6),
    0 0 0 4px var(--gold),
    0 0 26px rgba(232, 180, 92, 0.55);
}

.cell.selected { transform: scale(1.06); }

.cell.receiving { animation: bump 0.22s ease; }
.cell.lifting { animation: lift 0.3s ease; }
.cell.taken { animation: taken 0.45s ease; }
.cell.gaining { animation: gaining 0.5s ease; }

@keyframes bump {
  0% { transform: scale(1); }
  45% { transform: scale(1.11); }
  100% { transform: scale(1); }
}

@keyframes lift {
  0% { transform: scale(1); }
  50% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

@keyframes taken {
  0%, 100% { box-shadow: inset 0 7px 14px rgba(0, 0, 0, 0.6); }
  40% { box-shadow: inset 0 7px 14px rgba(0, 0, 0, 0.6), 0 0 0 5px var(--take), 0 0 26px rgba(239, 107, 90, 0.6); }
}

@keyframes gaining {
  0%, 100% { box-shadow: inset 0 7px 14px rgba(0, 0, 0, 0.6); }
  45% { box-shadow: inset 0 7px 14px rgba(0, 0, 0, 0.6), 0 0 0 6px var(--gold), 0 0 34px rgba(232, 180, 92, 0.6); }
}

/* ---------- seeds ---------- */

.seeds {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.seed {
  position: absolute;
  width: 21px;
  height: 21px;
  border-radius: 50% 50% 48% 52% / 52% 48% 50% 50%;
  background:
    radial-gradient(60% 55% at 36% 30%, #fff6dd 0%, #e7c48a 45%, #a97433 100%);
  filter: hue-rotate(var(--tint, 0deg)) saturate(0.85);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.55), inset 0 -1px 2px rgba(0, 0, 0, 0.25);
}

.cell.store .seed { width: 19px; height: 19px; }

/* ---------- pit labels ---------- */

.count {
  position: absolute;
  bottom: -27px;
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

.cell.store .count {
  bottom: auto;
  top: -32px;
  font-size: 24px;
  color: var(--gold);
}

.cell.on-turn .count { color: var(--text); }
.cell.empty .count { opacity: 0.4; }

.gain {
  position: absolute;
  top: -12px;
  right: -6px;
  font-size: 13px;
  font-weight: 700;
  color: #14221c;
  background: var(--gold);
  border-radius: 999px;
  padding: 0 7px;
  line-height: 19px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.gain:empty { display: none; }

/* The board turns over for the far player; its numbers must not. */
.board-layer.flipped .count,
.board-layer.flipped .gain { transform: rotate(180deg); }
.board-layer.flipped .count { bottom: auto; top: -27px; }
.board-layer.flipped .cell.store .count { top: auto; bottom: -32px; }

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 5;
}

#hud > * { pointer-events: auto; }

.hud-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.scores { display: flex; gap: 6px; }

.score-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-left: 3px solid var(--seat);
  font-size: 13px;
  opacity: 0.72;
}

.score-chip.on-turn { opacity: 1; border-color: var(--gold); border-left-color: var(--seat); }
.score-value { color: var(--seat); font-size: 17px; font-variant-numeric: tabular-nums; }
.score-games { color: var(--gold); font-size: 10px; letter-spacing: 2px; }

.hud-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  color: var(--dim);
  margin-left: auto;
}

/* ---------- status bar ---------- */

#tray {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 12px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(8, 26, 22, 0) 0%, rgba(8, 26, 22, 0.85) 45%);
  z-index: 5;
}

.tray-bar { display: flex; align-items: center; gap: 12px; }
.tray-label { display: flex; flex-direction: column; line-height: 1.25; }
.tray-sub { font-size: 12.5px; color: var(--dim); }
.tray-actions { margin-left: auto; display: flex; gap: 6px; }

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--gold); color: #23201a; border-color: var(--gold); font-weight: 600; }
.btn.ghost { background: rgba(8, 26, 22, 0.6); }

/* ---------- menu ---------- */

#menu {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(5, 17, 14, 0.84);
  backdrop-filter: blur(3px);
  z-index: 20;
  padding: 20px;
  overflow: auto;
}

#menu.open { display: grid; }

.menu-card {
  width: min(470px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}

.menu-card h1 {
  margin: 0 0 4px;
  font-size: 26px;
  letter-spacing: 0.06em;
  color: var(--gold);
}

.menu-card .sub { margin: 0 0 16px; color: var(--dim); font-size: 14px; }
.menu-card .summary { margin-top: 14px; }

.menu-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 11px 14px;
  margin-bottom: 8px;
  cursor: pointer;
}

.menu-item:hover { border-color: var(--gold); background: rgba(232, 180, 92, 0.1); }
.menu-item.primary { background: var(--gold); color: #23201a; border-color: var(--gold); }
.menu-item.primary .mi-sub { color: rgba(35, 32, 26, 0.75); }
.mi-label { font-weight: 600; }
.mi-sub { font-size: 12.5px; color: var(--dim); }

.form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }

.seg-row { display: flex; flex-direction: column; gap: 5px; }
.seg-row.hidden { display: none; }
.seg-label { font-size: 12.5px; color: var(--dim); }
.seg { display: flex; gap: 5px; flex-wrap: wrap; }

.seg-btn {
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
}

.seg-btn.on { background: var(--gold); color: #23201a; border-color: var(--gold); font-weight: 600; }

.howto {
  margin: 0 0 12px;
  padding-left: 20px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.howto li { margin-bottom: 7px; }
.howto-head { font-size: 15px; color: var(--gold); margin: 14px 0 6px; }

/* ---------- modals, toast ---------- */

.lede { font-size: 18px; margin: 0 0 8px; }
.dim { color: var(--dim); }

.score-table { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 5px 10px;
  border-left: 3px solid var(--seat);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  font-size: 13.5px;
}

.score-row strong { font-size: 17px; color: var(--seat); font-variant-numeric: tabular-nums; }
.score-totals { margin-top: 8px; font-size: 13px; }

.stat-grid { display: flex; gap: 10px; margin-top: 14px; }

.stat-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-top: 3px solid var(--seat);
  font-size: 12.5px;
}

.stat-name { font-weight: 600; font-size: 13.5px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translate(-50%, 12px);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 30;
  max-width: min(92vw, 420px);
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- phones ---------- */

@media (max-width: 760px), (max-height: 520px) {
  .hud-meta { width: 100%; margin-left: 0; }
  .menu-card { padding: 18px; }
  .menu-card h1 { font-size: 22px; }
  .stat-grid { flex-direction: column; }
  .toast { bottom: 84px; }
}
