/* Mancala — Kirbo's Games branding: dark navy, cyan accent #25CBE5, Manrope + Fira Code. */

:root {
  --navy-900: #070c16;
  --navy-800: #0b1220;
  --navy-700: #101a2c;
  --navy-600: #16233a;
  --navy-500: #1e2d48;
  --line: #24354f;
  --cyan: #25cbe5;
  --cyan-dim: #1497ad;
  --cyan-glow: rgba(37, 203, 229, 0.35);
  --gold: #f0b45a;
  --rose: #ff6b8a;
  --green: #49d99a;
  --text: #e8eefb;
  --muted: #93a3bf;
  --wood: #6b4a2f;
  --wood-2: #533823;
  --pit: #2a1d13;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100%;
  font-family: Manrope, "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(37, 203, 229, 0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(240, 180, 90, 0.07), transparent 55%),
    var(--navy-800);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

kbd {
  font-family: "Fira Code", ui-monospace, monospace;
  background: var(--navy-600); border: 1px solid var(--line);
  border-radius: 4px; padding: 0 0.3em; font-size: 0.9em;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 50;
  background: var(--cyan); color: var(--navy-900);
  padding: 0.6rem 1rem; border-radius: 0 0 var(--radius-sm) 0; font-weight: 700;
}
.skip-link:focus { left: 0; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem clamp(0.75rem, 3vw, 1.5rem);
  border-bottom: 1px solid var(--line);
  background: rgba(11, 18, 32, 0.85);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 0.65rem; text-decoration: none; color: inherit; }
.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(145deg, var(--cyan), var(--cyan-dim));
  color: var(--navy-900); font-weight: 800; font-size: 0.85rem;
  box-shadow: 0 0 0 1px rgba(37, 203, 229, 0.5), 0 6px 18px var(--cyan-glow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 1.05rem; }
.brand-text small { color: var(--muted); font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; }
.topnav { display: flex; gap: 0.5rem; align-items: center; }

/* ---------------------------------------------------------------- buttons */
.btn {
  font: inherit; font-size: 0.88rem; font-weight: 600;
  padding: 0.55rem 0.95rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--navy-600); color: var(--text);
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 0.4rem;
  transition: transform 120ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--navy-500); border-color: #33507a; }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(145deg, var(--cyan), var(--cyan-dim));
  color: var(--navy-900); border-color: transparent; font-weight: 700;
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 8px 22px var(--cyan-glow); }
.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--navy-600); }
.btn[aria-pressed="false"] { color: var(--muted); }
.btn:focus-visible, .pit:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--cyan); outline-offset: 2px;
}

/* ---------------------------------------------------------------- layout */
main { padding: clamp(0.75rem, 2.5vw, 1.5rem); max-width: 1100px; margin: 0 auto; }
.panel { animation: rise 320ms ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

h1 { font-size: clamp(1.7rem, 4.5vw, 2.4rem); margin: 0.4rem 0 0.5rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
.lede { color: var(--muted); max-width: 68ch; margin: 0 0 1.25rem; line-height: 1.55; }

/* ---------------------------------------------------------------- lobby */
.lobby-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.card {
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem; display: flex; flex-direction: column; gap: 0.5rem;
  box-shadow: var(--shadow);
}
.card label { font-size: 0.78rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.card input, .card select {
  font: inherit; padding: 0.6rem 0.7rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--navy-900); color: var(--text);
}
#join-code { text-transform: uppercase; letter-spacing: 0.18em; font-family: "Fira Code", monospace; }
.card button { margin-top: 0.4rem; }
.cardnote { font-size: 0.8rem; color: var(--muted); margin: 0; line-height: 1.5; }

.status { margin: 1rem 0 0; min-height: 1.3em; color: var(--cyan); font-weight: 600; font-size: 0.9rem; }
.status.error { color: var(--rose); }
.hintline { color: var(--muted); font-size: 0.85rem; margin: 0.8rem 0 0; min-height: 1.2em; }

/* ---------------------------------------------------------------- scores */
.game { display: flex; flex-direction: column; gap: 0.9rem; }
.scorebar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: stretch; justify-content: space-between; }
.seats { display: flex; flex-wrap: wrap; gap: 0.5rem; flex: 1 1 auto; }
.seat {
  flex: 1 1 150px; min-width: 130px;
  background: var(--navy-700); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem; display: flex; flex-direction: column; gap: 0.15rem;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.seat .seat-name { font-weight: 700; font-size: 0.92rem; display: flex; align-items: center; gap: 0.4rem; }
.seat .seat-sub { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.seat .seat-score { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.seat.active { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan), 0 8px 24px var(--cyan-glow); }
.seat.active .seat-score { color: var(--cyan); }
.seat.you .seat-name::after {
  content: "you"; font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--navy-500); color: var(--cyan); border-radius: 999px; padding: 0.1rem 0.4rem;
}
.turncard {
  background: linear-gradient(145deg, var(--navy-600), var(--navy-700));
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.5rem 0.9rem; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem; min-width: 140px; text-align: center;
  transition: color 200ms ease, border-color 200ms ease;
}
.turncard.mine { color: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan-glow); }
.turncard.waiting { color: var(--muted); }

/* ---------------------------------------------------------------- board */
.boardwrap { display: flex; justify-content: center; }

/* The board is a wooden tray: two rows of six pits with a store at each end. */
.board {
  --pit: clamp(44px, min(10vw, 8.4vh), 86px);
  display: grid;
  grid-template-columns: auto repeat(6, var(--pit)) auto;
  grid-template-rows: auto auto;
  gap: clamp(4px, 1vw, 10px);
  padding: clamp(8px, 2vw, 16px);
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.10) 0 6px, transparent 6px 14px),
    linear-gradient(160deg, var(--wood), var(--wood-2));
  border: 1px solid #3b2716;
  border-radius: 22px;
  box-shadow: var(--shadow), inset 0 2px 0 rgba(255, 255, 255, 0.08), inset 0 -4px 12px rgba(0, 0, 0, 0.5);
  touch-action: manipulation;
}

/* Stores span both rows: player 1's on the left, player 0's on the right. */
.store {
  grid-row: 1 / span 2;
  width: calc(var(--pit) * 0.78);
  border-radius: 999px;
  background: radial-gradient(circle at 50% 40%, #3a2818, var(--pit) 70%);
  border: 1px solid #241708;
  box-shadow: inset 0 6px 16px rgba(0, 0, 0, 0.65), inset 0 -2px 6px rgba(255, 255, 255, 0.05);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 0.4rem 0.2rem; position: relative; overflow: hidden;
}
.store.left { grid-column: 1; }
.store.right { grid-column: 8; }

.pit {
  position: relative;
  width: var(--pit); height: var(--pit);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #3a2818, var(--pit) 72%);
  border: 1px solid #241708;
  box-shadow: inset 0 5px 14px rgba(0, 0, 0, 0.65), inset 0 -2px 5px rgba(255, 255, 255, 0.05);
  cursor: default;
  display: grid; place-items: center;
  padding: 0; font-family: inherit;
  transition: box-shadow 180ms ease, transform 180ms ease, border-color 180ms ease;
}
.pit.playable { cursor: pointer; border-color: rgba(37, 203, 229, 0.55); }
.pit.playable:hover {
  transform: translateY(-2px);
  box-shadow: inset 0 5px 14px rgba(0,0,0,0.6), 0 0 0 3px var(--cyan-glow), 0 10px 22px rgba(0,0,0,0.45);
}
.pit.mine { border-color: rgba(37, 203, 229, 0.35); }
.pit.theirs { opacity: 0.9; }
.pit.target { box-shadow: inset 0 5px 14px rgba(0,0,0,0.6), 0 0 0 3px var(--cyan); }
.pit.dimmed { opacity: 0.45; }
.pit.landed { animation: pitPulse 520ms ease; }
@keyframes pitPulse {
  0% { box-shadow: inset 0 5px 14px rgba(0,0,0,0.6), 0 0 0 0 rgba(37,203,229,0.8); }
  50% { box-shadow: inset 0 5px 14px rgba(0,0,0,0.6), 0 0 0 8px rgba(37,203,229,0.25); }
  100% { box-shadow: inset 0 5px 14px rgba(0,0,0,0.6), 0 0 0 0 rgba(37,203,229,0); }
}
.pit.captured { animation: pitCapture 620ms ease; }
@keyframes pitCapture {
  0% { box-shadow: inset 0 5px 14px rgba(0,0,0,0.6), 0 0 0 0 rgba(240,180,90,0.9); }
  50% { box-shadow: inset 0 5px 14px rgba(0,0,0,0.6), 0 0 0 10px rgba(240,180,90,0.3); }
  100% { box-shadow: inset 0 5px 14px rgba(0,0,0,0.6), 0 0 0 0 rgba(240,180,90,0); }
}

/* The number of stones in a pit, shown as a badge for clarity. */
.pitcount {
  position: absolute; top: calc(var(--pit) * -0.06); right: calc(var(--pit) * -0.06);
  min-width: calc(var(--pit) * 0.44); height: calc(var(--pit) * 0.44);
  border-radius: 999px; display: grid; place-items: center;
  background: var(--navy-900); color: var(--cyan);
  border: 1px solid var(--line);
  font-family: "Fira Code", monospace; font-weight: 700;
  font-size: calc(var(--pit) * 0.22);
  z-index: 3;
}
.storecount {
  font-family: "Fira Code", monospace; font-weight: 800;
  font-size: calc(var(--pit) * 0.34); color: var(--cyan);
  text-shadow: 0 2px 8px rgba(0,0,0,0.8); z-index: 3; position: relative;
}
.storelabel {
  font-size: calc(var(--pit) * 0.17); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); z-index: 3; position: relative; margin-bottom: 0.2rem;
}

/* Stones are rendered as a small packed cluster inside the pit. */
.stones { position: absolute; inset: 12%; display: flex; flex-wrap: wrap; align-content: center;
  justify-content: center; gap: 2px; }
.stone {
  width: calc(var(--pit) * 0.19); height: calc(var(--pit) * 0.19);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fdf6e6, #cbb994 60%, #9c8a67);
  box-shadow: 0 1px 2px rgba(0,0,0,0.55);
  flex: 0 0 auto;
}
.stone.alt { background: radial-gradient(circle at 35% 30%, #d9f4fb, #7fc7d8 60%, #4a93a6); }
.stone.alt2 { background: radial-gradient(circle at 35% 30%, #ffe6cf, #e0a878 60%, #b07a4c); }
.stone.drop { animation: stoneDrop 300ms cubic-bezier(0.22, 1.4, 0.4, 1) both; }
@keyframes stoneDrop {
  0% { transform: translateY(-70%) scale(0.5); opacity: 0; }
  60% { transform: translateY(6%) scale(1.12); opacity: 1; }
  100% { transform: none; }
}
.stone.taken { animation: stoneTaken 280ms ease-in both; }
@keyframes stoneTaken {
  to { transform: scale(0.2); opacity: 0; }
}

/* Player labels above/below the rows. */
.rowlabel {
  grid-column: 2 / span 6; text-align: center;
  font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: rgba(255,255,255,0.62); padding-bottom: 2px;
}

/* ---------------------------------------------------------------- floaters */
.floater {
  position: fixed; z-index: 60; pointer-events: none;
  font-weight: 800; font-size: 1.5rem; color: var(--gold);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  animation: floatUp 1100ms cubic-bezier(0.22, 1, 0.4, 1) both;
  font-variant-numeric: tabular-nums;
}
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.7); }
  25% { opacity: 1; transform: translate(-50%, -18px) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -70px) scale(1); }
}

/* ---------------------------------------------------------------- invite & result */
.invite {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  margin: 1rem auto 0; max-width: 1100px; padding: 0.6rem 1rem;
  background: var(--navy-700); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 0.82rem;
}
.invite span { color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; font-size: 0.7rem; }
.invite input {
  flex: 1 1 240px; font: inherit; font-size: 0.8rem;
  padding: 0.4rem 0.55rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--navy-900); color: var(--cyan);
  font-family: "Fira Code", monospace;
}

.result {
  margin-top: 1.5rem; background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow);
}
.result table { width: 100%; border-collapse: collapse; margin: 0.8rem 0 1.2rem; }
.result th, .result td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); }
.result th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.result td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.result tr.winner td { color: var(--gold); }
.result .tag { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--cyan); }

/* ---------------------------------------------------------------- dialog */
dialog.rules {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  color: var(--text); max-width: 620px; padding: 1.4rem; box-shadow: var(--shadow);
}
dialog.rules::backdrop { background: rgba(4, 8, 16, 0.7); backdrop-filter: blur(3px); }
dialog.rules h2 { font-size: 1.2rem; }
dialog.rules h3 { font-size: 0.95rem; margin-top: 1.2rem; }
dialog.rules ol, dialog.rules ul { line-height: 1.6; padding-left: 1.2rem; }
dialog.rules li { margin-bottom: 0.45rem; }
dialog.rules form { margin-top: 1.2rem; text-align: right; }

/* ---------------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .panel { animation: none; }
  .pit.playable:hover { transform: none; }
}

/* ---------------------------------------------------------------- small screens */
@media (max-width: 700px) {
  .topbar { padding: 0.6rem 0.7rem; }
  .brand-text small { display: none; }
  .topnav .btn { padding: 0.45rem 0.6rem; font-size: 0.8rem; }
  .board {
    --pit: clamp(38px, 11.4vw, 62px);
    gap: 3px; padding: 7px;
    grid-template-columns: auto repeat(6, var(--pit)) auto;
    border-radius: 16px;
  }
  .pitcount { font-size: calc(var(--pit) * 0.26); }
  .seat { flex: 1 1 46%; }
  .turncard { min-width: 0; font-size: 0.82rem; }
  .stage-buttons .btn { flex: 1 1 auto; justify-content: center; }
}

@media (max-width: 430px) {
  .board { --pit: clamp(34px, 10.6vw, 50px); }
  .rowlabel { font-size: 0.64rem; letter-spacing: 0.06em; }
}
