/* Ludo, a bright, clean cross board: four clear colours on white, soft shadows. Fixed palette. */
:root {
  color-scheme: light;
  --bg: #f3f0ea;
  --card: #fffdf9;
  --ink: #22252d;
  --muted: #767985;
  --line: #e4dfd5;
  --grid: #d9d4ca;
  --c0: #e5484d;  --c0-d: #b62f34;  --c0-l: #fde3e3;   /* red, bottom-left (you) */
  --c1: #2fa36b;  --c1-d: #1f7a4f;  --c1-l: #dcf3e7;   /* green, top-left */
  --c2: #f2b100;  --c2-d: #b98500;  --c2-l: #fdf1cc;   /* yellow, top-right */
  --c3: #3d6ae0;  --c3-d: #2849a8;  --c3-l: #e0e8fb;   /* blue, bottom-right */
  --gold: #ffcf4a;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #ffcf4a;
  --tut-accent-ink: #22252d;
  --tut-bubble: #fffdf9;
  --tut-ink: #22252d;
  --tut-muted: #767985;
  --tut-dim: rgba(24, 26, 32, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation; overflow-x: hidden; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 900px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(14px, env(safe-area-inset-left));
}
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 60px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; white-space: nowrap; padding: 12px 2px; }
.back:hover, .back:focus-visible { color: var(--ink); }
.bar-actions { display: flex; gap: 8px; }
.btn {
  min-height: 44px; min-width: 44px; padding: 0 18px; border-radius: 22px; border: 0;
  background: var(--card); color: var(--ink); font-weight: 650; cursor: pointer;
  box-shadow: 0 1px 2px rgba(34, 37, 45, .1), 0 0 0 1px var(--line); transition: transform .12s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.icon { padding: 0; width: 44px; font-size: 22px; line-height: 1; letter-spacing: .04em; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--card); box-shadow: none; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.btn:disabled, .row:disabled { opacity: .35; cursor: default; transform: none; }
.btn:focus-visible, .seg button:focus-visible, .row:focus-visible, .link:focus-visible, .die-btn:focus-visible, .piece:focus-visible {
  outline: 3px solid var(--ink); outline-offset: 2px;
}

.game { flex: 1; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; padding-bottom: 12px; }
.turn {
  justify-self: center; display: inline-flex; align-items: center; gap: 10px; padding: 8px 18px; border-radius: 999px;
  background: var(--card); box-shadow: 0 0 0 1px var(--line); font-weight: 650; min-height: 40px;
}
.turn.thinking #turn-text::after { content: ''; display: inline-block; width: 1.1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.dot { display: inline-block; flex: none; width: 16px; height: 16px; border-radius: 50%; }
.dot.s0 { background: var(--c0); } .dot.s1 { background: var(--c1); } .dot.s2 { background: var(--c2); } .dot.s3 { background: var(--c3); }
.hint { justify-self: center; min-height: 22px; font-size: 15px; color: var(--muted); text-align: center; opacity: 0; transform: translateY(3px); transition: opacity .25s, transform .25s; }
.hint.show { opacity: 1; transform: none; }

/* ---------- board ---------- */
.board-wrap { min-height: 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.board {
  position: relative; width: min(100%, 640px); aspect-ratio: 1; flex: none;
  background: #fff; border-radius: 18px; overflow: hidden;
  box-shadow: 0 0 0 1px var(--line), 0 12px 30px rgba(34, 37, 45, .12);
  user-select: none; -webkit-user-select: none;
}
@supports (container-type: size) {
  .board-wrap { container-type: size; }
  .board { width: min(100cqw, 100cqh - 94px, 640px); }
}
.yard, .cell, .centre { position: absolute; }
.yard { padding: 0; }
.yard.y0 { background: var(--c0); } .yard.y1 { background: var(--c1); } .yard.y2 { background: var(--c2); } .yard.y3 { background: var(--c3); }
.yard.idle { filter: saturate(.18) brightness(1.18); }
.yard-in {
  position: absolute; left: 16.67%; top: 16.67%; width: 66.67%; height: 66.67%;
  background: #fff; border-radius: 16%; box-shadow: inset 0 2px 6px rgba(0, 0, 0, .12);
}
.slot { position: absolute; width: 25%; height: 25%; border-radius: 50%; background: rgba(34, 37, 45, .07); }
.slot:nth-child(1) { left: 12.5%; top: 12.5%; } .slot:nth-child(2) { left: 62.5%; top: 12.5%; }
.slot:nth-child(3) { left: 12.5%; top: 62.5%; } .slot:nth-child(4) { left: 62.5%; top: 62.5%; }
.cell { box-shadow: inset 0 0 0 .5px var(--grid); background: #fff; display: grid; place-items: center; }
.cell.start.y0, .cell.homecol.y0 { background: var(--c0); } .cell.start.y1, .cell.homecol.y1 { background: var(--c1); }
.cell.start.y2, .cell.homecol.y2 { background: var(--c2); } .cell.start.y3, .cell.homecol.y3 { background: var(--c3); }
.cell.star svg { width: 62%; height: 62%; fill: #cfc8bb; }
.centre {
  background: conic-gradient(from 315deg, var(--c2) 0 90deg, var(--c3) 90deg 180deg, var(--c0) 180deg 270deg, var(--c1) 270deg 360deg);
}
.board.n2 .centre { background: conic-gradient(from 315deg, var(--c2) 0 90deg, #e9e6e0 90deg 180deg, var(--c0) 180deg 270deg, #e9e6e0 270deg 360deg); }
.board.n3 .centre { background: conic-gradient(from 315deg, var(--c2) 0 90deg, #e9e6e0 90deg 180deg, var(--c0) 180deg 270deg, var(--c1) 270deg 360deg); }

/* ---------- pieces ---------- */
.piece {
  position: absolute; left: 0; top: 0; width: 6.6667%; height: 6.6667%; padding: 0; border: 0; background: transparent;
  cursor: default; z-index: 10;
  transition: transform .16s ease-out;
}
.piece.moving { transition-duration: .06s; }
.piece i {
  position: absolute; left: 8%; top: 8%; width: 84%; height: 84%; border-radius: 50%;
  box-shadow: 0 2px 3px rgba(0, 0, 0, .3), inset 0 -2px 0 rgba(0, 0, 0, .18), inset 0 0 0 2px rgba(255, 255, 255, .9);
}
.piece i::after { content: ''; position: absolute; left: 32%; top: 32%; width: 36%; height: 36%; background: rgba(255, 255, 255, .92); }
.piece.y0 i { background: var(--c0); } .piece.y0 i::after { border-radius: 50%; }
.piece.y1 i { background: var(--c1); } .piece.y1 i::after { border-radius: 2px; }
.piece.y2 i { background: var(--c2); } .piece.y2 i::after { clip-path: polygon(50% 5%, 100% 95%, 0 95%); }
.piece.y3 i { background: var(--c3); } .piece.y3 i::after { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.piece.can { cursor: pointer; z-index: 25; }
.piece.can::before { content: ''; position: absolute; inset: -35%; }          /* a bigger tap target */
.piece.can i { animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse {
  from { transform: scale(1); box-shadow: 0 2px 3px rgba(0, 0, 0, .3), inset 0 0 0 2px rgba(255, 255, 255, .9), 0 0 0 0 rgba(34, 37, 45, .0); }
  to { transform: scale(1.12); box-shadow: 0 2px 3px rgba(0, 0, 0, .3), inset 0 0 0 2px rgba(255, 255, 255, .9), 0 0 0 4px rgba(34, 37, 45, .55); }
}
.piece.last i { box-shadow: 0 2px 3px rgba(0, 0, 0, .3), inset 0 0 0 2px rgba(255, 255, 255, .9), 0 0 0 3px var(--gold); }
.piece.big { position: relative; display: inline-block; width: 60px; height: 60px; }

/* ---------- die ---------- */
.dock { flex: none; display: flex; justify-content: center; }
.die-btn {
  --d: 64px;
  width: var(--d); height: var(--d); border: 0; border-radius: 16px; padding: 10px; cursor: default;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  background: linear-gradient(150deg, #fff, #efe9df);
  box-shadow: 0 3px 0 #d8cfbf, 0 6px 14px rgba(34, 37, 45, .15), 0 0 0 3px var(--ring, transparent);
  transition: box-shadow .2s, transform .15s;
}
.die-btn.y0 { --ring: var(--c0); } .die-btn.y1 { --ring: var(--c1); } .die-btn.y2 { --ring: var(--c2); } .die-btn.y3 { --ring: var(--c3); }
.die-btn .pip { width: 74%; height: 74%; margin: auto; border-radius: 50%; background: var(--ink); }
.pip.q0 { grid-area: 1 / 1; } .pip.q1 { grid-area: 1 / 2; } .pip.q2 { grid-area: 1 / 3; }
.pip.q3 { grid-area: 2 / 1; } .pip.q4 { grid-area: 2 / 2; } .pip.q5 { grid-area: 2 / 3; }
.pip.q6 { grid-area: 3 / 1; } .pip.q7 { grid-area: 3 / 2; } .pip.q8 { grid-area: 3 / 3; }
.die-btn.go { cursor: pointer; animation: nudge 1.4s ease-in-out infinite; }
.die-btn.go.blank::after { content: 'Roll'; grid-area: 1 / 1 / 4 / 4; place-self: center; font-weight: 800; font-size: 17px; }
@keyframes nudge { 0%, 65%, 100% { transform: none; } 75% { transform: translateY(-4px) rotate(-6deg); } 85% { transform: translateY(0) rotate(4deg); } }
.die-btn.rolling { animation: tumble .38s cubic-bezier(.2, .8, .3, 1); }
@keyframes tumble { 0% { transform: rotate(-200deg) scale(.6); } 60% { transform: rotate(16deg) scale(1.08); } 100% { transform: none; } }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(34, 37, 45, .36); display: flex; align-items: flex-end; justify-content: center; padding: 12px; animation: fade .2s ease-out; }
.overlay.soft { background: rgba(243, 240, 234, .55); align-items: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet, .card {
  background: var(--card); color: var(--ink); width: 100%; max-width: 440px;
  max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow: auto; overscroll-behavior: contain;
  border-radius: 24px; padding: 8px 20px 20px; box-shadow: 0 20px 50px rgba(34, 37, 45, .22); animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .overlay { align-items: center; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.row { display: block; width: 100%; text-align: left; min-height: 50px; padding: 0 4px; border: 0; border-bottom: 1px solid var(--line); background: transparent; font-weight: 600; cursor: pointer; }
.group { padding: 12px 0 4px; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--bg); }
.seg button { flex: 1 1 0; min-height: 44px; border: 0; border-radius: 12px; background: transparent; font-weight: 600; cursor: pointer; color: var(--muted); transition: background .15s, color .15s; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(34, 37, 45, .16); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.menu-sheet .row:first-of-type { border-top: 1px solid var(--line); }
.menu-sheet #menu-help { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet .btn.wide { margin-top: 16px; }
.over-card { max-width: 340px; text-align: center; padding: 24px 22px 14px; }
.over-mark { display: flex; justify-content: center; margin-bottom: 8px; }
.over-title { font-size: 28px; font-weight: 800; margin-bottom: 10px; }
.ranks { list-style: none; margin: 0 0 18px; padding: 0; text-align: left; }
.ranks li { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-top: 1px solid var(--line); font-weight: 600; }
.ranks li:first-child { border-top: 0; }
.ranks li span { flex: 1; }
.ranks li b { font-weight: 600; color: var(--muted); font-size: 14px; }
.link { display: block; margin: 8px auto 0; min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.help-sheet { max-width: 560px; }
.help-body { padding-bottom: 6px; }
.help-body h3 { font-size: 16px; margin: 18px 0 4px; }
.help-body p { font-size: 15px; margin: 4px 0; }
.fine { font-size: 13px; color: var(--muted); margin-top: 14px; }
.t0 { color: var(--c0-d); }

@media (max-width: 380px) {
  .app { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .btn { padding: 0 14px; }
  .back { font-size: 13px; }
}
@media (max-height: 700px) {
  .bar { min-height: 52px; }
  .game { gap: 8px; padding-bottom: 8px; }
  .turn { min-height: 36px; padding: 5px 16px; }
  .die-btn { --d: 54px; padding: 8px; }
  .board-wrap { gap: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Online play (online.js): no New game while a friend is playing; a presence line under the turn. */
body.is-online #btn-new { display: none; }
.top { justify-self: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.net { color: var(--muted); }
/* Online as Yellow the board is turned half a turn (render.js places every square turned); the centre follows. */
.board.flip .centre { transform: rotate(180deg); }
/* The online rows take the divider above How to play (one line, not two). */
.menu-sheet #menu-online, .menu-sheet #menu-leave { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet #menu-online ~ #menu-help { margin-top: 0; border-top: 0; }
#over-leave { margin-top: 8px; }
