/* Backgammon — 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;
  --felt: #1d3a2e;
  --felt-2: #14281f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  /* Checker colours: player 0 is the light side, player 1 the dark side. */
  --w0: #f2ead6;
  --w1: #cbbb95;
  --b0: #3a4a63;
  --b1: #22303f;
  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, .point: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: 1180px; 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; }
h3 { font-size: 0.98rem; margin: 0 0 0.5rem; }
.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.7rem 0 0; min-height: 1.2em; }

/* ------------------------------------------------------------------ scores */
.game { display: flex; flex-direction: column; gap: 0.85rem; }
.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 170px; min-width: 140px;
  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.3rem; 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;
}
.seat .swatch {
  width: 12px; height: 12px; border-radius: 50%; display: inline-block;
  border: 1px solid rgba(0,0,0,0.5);
}
.seat .swatch.p0 { background: radial-gradient(circle at 35% 30%, var(--w0), var(--w1)); }
.seat .swatch.p1 { background: radial-gradient(circle at 35% 30%, var(--b0), var(--b1)); }

.scorebar-side { display: flex; gap: 0.5rem; align-items: stretch; }
.cube {
  background: linear-gradient(145deg, var(--navy-600), var(--navy-700));
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 62px;
}
.cube.doubled { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(240,180,90,0.5); }
.cube-label { font-size: 0.62rem; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.cube-value { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.cube.doubled .cube-value { color: var(--gold); }

.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: 150px; 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 grid is built by the renderer: [off1] [pointsA] [bar] [pointsB] [off0].
   Each point column stacks a top row (pointing down) and a bottom row (pointing up). */
.board {
  --pt: clamp(30px, min(6.4vw, 5.4vh), 58px);
  padding: clamp(8px, 2vw, 16px);
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.02) 0 2px, transparent 2px 4px),
    linear-gradient(160deg, var(--felt), var(--felt-2));
  border: 2px solid #2f2418;
  border-radius: 16px;
  box-shadow: var(--shadow), inset 0 0 80px rgba(0,0,0,0.5);
  touch-action: manipulation;
}

.pointcol { display: flex; flex-direction: column; gap: 8px; }
.pointrow { display: flex; gap: 4px; flex: 1 1 auto; }

.point {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: default;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: var(--pt);
}
.pointrow .point { height: auto; }
.point .tri {
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%; height: var(--pt);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.03));
  border-bottom: 1px solid rgba(0,0,0,0.25);
}
.point.down .tri {
  inset: auto auto 0 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.point.alt .tri { background: linear-gradient(180deg, rgba(37,203,229,0.16), rgba(37,203,229,0.05)); }
.point.down.alt .tri { background: linear-gradient(0deg, rgba(37,203,229,0.16), rgba(37,203,229,0.05)); }

.point .checkers {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  width: calc(var(--pt) * 0.82);
}
.point.down .checkers { flex-direction: column-reverse; }
.point .checkers.top { justify-content: flex-start; }
.point .checkers.bottom { justify-content: flex-end; }

.checker {
  width: calc(var(--pt) * 0.7); height: calc(var(--pt) * 0.7);
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.55);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.5);
  flex: 0 0 auto;
  margin-top: -42%;
  transition: transform 140ms ease, box-shadow 140ms ease;
}
.checker:first-child { margin-top: 0; }
.checker.p0 { background: radial-gradient(circle at 34% 28%, var(--w0), var(--w1) 70%); }
.checker.p1 { background: radial-gradient(circle at 34% 28%, var(--b0), var(--b1) 70%); }

.point.playable { cursor: pointer; }
.point.playable .tri {
  box-shadow: 0 0 0 2px var(--cyan), 0 0 18px var(--cyan-glow);
}
/* A point holding our own checkers that can move: clickable, but visually quieter than a
   legal destination so the two states stay distinguishable. */
.point.selectable { cursor: pointer; }
.point.selectable .tri {
  box-shadow: inset 0 0 0 2px rgba(37, 203, 229, 0.45);
}
.point.selectable:hover .tri {
  box-shadow: 0 0 0 2px var(--cyan), 0 0 14px var(--cyan-glow);
}
.point.selected .checker:last-child {
  transform: translateY(-6px) scale(1.06);
  box-shadow: 0 0 0 3px var(--cyan), 0 8px 18px var(--cyan-glow);
}
.point.hit-target .tri {
  box-shadow: 0 0 0 3px var(--rose), 0 0 22px rgba(255, 107, 138, 0.5);
}
.point.moved .checker:last-child { animation: checkerLand 420ms cubic-bezier(0.22, 1.4, 0.4, 1); }
@keyframes checkerLand {
  0% { transform: translateY(-40%) scale(0.8); opacity: 0.4; }
  60% { transform: translateY(4%) scale(1.08); opacity: 1; }
  100% { transform: none; }
}
.point.hit-anim .checker { animation: checkerHit 520ms ease; }
@keyframes checkerHit {
  0%, 100% { transform: none; }
  30% { transform: translate(4px, -8px) rotate(12deg); }
  60% { transform: translate(-3px, -4px) rotate(-8deg); }
}

.pointlabel {
  position: absolute; z-index: 3;
  font-size: 0.58rem; font-family: "Fira Code", monospace;
  color: rgba(255,255,255,0.4); pointer-events: none;
}
.point.up .pointlabel { bottom: 2px; }
.point.down .pointlabel { top: 2px; }

/* Bar and off trays occupy their own grid cells. */
.bar {
  grid-column: 1 / -1;
  display: flex; justify-content: center; align-items: center; gap: 0.5rem;
  background: linear-gradient(180deg, rgba(0,0,0,0.35), rgba(0,0,0,0.5));
  border-top: 1px solid rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  padding: 4px; min-height: calc(var(--pt) * 0.5);
}
.bar .checker { margin-top: 0; margin-left: -42%; }
.bar .checker:first-child { margin-left: 0; }
.bar .barlabel { font-size: 0.6rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

.tray-cell {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 6px; border: 1px dashed var(--line);
  background: rgba(0,0,0,0.25); min-height: var(--pt); padding: 3px;
}
.tray-cell .traycount {
  font-family: "Fira Code", monospace; font-weight: 800;
  font-size: calc(var(--pt) * 0.42); color: var(--cyan);
}
.tray-cell .traylabel { font-size: 0.56rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }

/* ------------------------------------------------------------------- dice */
.tray { display: grid; gap: 0.8rem; grid-template-columns: 1fr auto; align-items: center; }
@media (max-width: 700px) { .tray { grid-template-columns: 1fr; } }

.dicebox {
  display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap;
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 0.9rem;
}
.dice-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.dice { display: flex; gap: 0.4rem; min-height: calc(var(--pt) * 0.7); }
.die {
  width: calc(var(--pt) * 0.66); height: calc(var(--pt) * 0.66);
  border-radius: 8px;
  background: linear-gradient(160deg, #f4efe1, #cdc4ad);
  border: 1px solid #9d9683;
  display: grid; place-items: center;
  box-shadow: 0 3px 6px rgba(0,0,0,0.5), inset 0 -2px 0 rgba(0,0,0,0.15);
  position: relative;
}
.die .pip { width: 14%; height: 14%; border-radius: 50%; background: #232b38; position: absolute; }
.die .pip { box-shadow: inset 0 1px 1px rgba(255,255,255,0.3); }
.die.spent { opacity: 0.32; filter: grayscale(0.7); }
.die.rolled { animation: dieRoll 460ms cubic-bezier(0.22, 1.4, 0.4, 1); }
@keyframes dieRoll {
  0% { transform: rotate(-160deg) scale(0.6); opacity: 0; }
  60% { transform: rotate(12deg) scale(1.1); opacity: 1; }
  100% { transform: none; }
}

.actionbar { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.actionbar .btn { flex: 0 1 auto; }

/* ----------------------------------------------------------------- prompt */
.prompt {
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid var(--gold); border-radius: var(--radius);
  padding: 1rem 1.2rem; box-shadow: var(--shadow), 0 0 0 1px rgba(240,180,90,0.25);
  animation: rise 300ms ease both;
}
.prompt p { margin: 0 0 0.8rem; color: var(--muted); line-height: 1.5; }
.prompt strong { color: var(--gold); }

/* ----------------------------------------------------------------- floaters */
.floater {
  position: fixed; z-index: 60; pointer-events: none;
  font-weight: 800; font-size: 1.4rem; 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: 1180px; 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: 660px; 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; }
  .point.playable:hover .tri { box-shadow: 0 0 0 2px var(--cyan); }
}

/* --------------------------------------------------------- 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 {
    --pt: clamp(22px, 8.4vw, 40px);
    gap: 3px; padding: 7px; border-radius: 12px;
    grid-template-columns: var(--pt) var(--pt) 6px var(--pt) var(--pt);
  }
  .pointlabel { font-size: 0.5rem; }
  .seat { flex: 1 1 46%; }
  .turncard { min-width: 0; font-size: 0.8rem; }
  .cube { padding: 0.3rem 0.5rem; min-width: 0; }
}

@media (max-width: 430px) {
  .board { --pt: clamp(20px, 7.8vw, 34px); }
  .pointlabel { display: none; }
}
