/* Yacht, ivory dice on a calm scorecard, one colour per player. Fixed palette. */
:root {
  color-scheme: light;
  --bg: #f2eee6;
  --card: #fffdf9;
  --ink: #23262f;
  --muted: #7a7c86;
  --line: #e6e0d4;
  --line-2: #d9d1c1;
  --p0: #ec6a3f;   /* you: coral */
  --p1: #1d9e94;   /* teal */
  --p2: #7a63d8;   /* violet */
  --p3: #d99a14;   /* amber */
  --p0-soft: #fdebe3;
  --p1-soft: #e2f4f2;
  --p2-soft: #eeeafb;
  --p3-soft: #fbf1dc;
  --gold: #ffc94d;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #ffc94d;
  --tut-accent-ink: #23262f;
  --tut-bubble: #fffdf9;
  --tut-ink: #23262f;
  --tut-muted: #7a7c86;
  --tut-dim: rgba(26, 24, 30, .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: 560px; 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(35, 38, 47, .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:focus-visible, .crow:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
}

/* ---------- game column ---------- */
.game {
  flex: 1; min-height: 0; display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto 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: 12px; height: 12px; border-radius: 50%; }
.turn .dot { width: 16px; height: 16px; }
.p0.dot { background: var(--p0); } .p1.dot { background: var(--p1); } .p2.dot { background: var(--p2); } .p3.dot { background: var(--p3); }
.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; }

/* ---------- scorecard ---------- */
.card-wrap { min-height: 0; display: flex; align-items: flex-start; justify-content: center; }
.card {
  --cw: 3.4rem;
  width: 100%; height: 100%; max-height: 590px;
  display: grid; grid-template-rows: repeat(14, minmax(0, 1fr));
  background: var(--card); border-radius: 18px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(35, 38, 47, .06), 0 0 0 1px var(--line);
}
.card.n3 { --cw: 3.1rem; }
.card.n4 { --cw: 2.85rem; }
.crow {
  display: grid; grid-template-columns: minmax(0, 1fr) repeat(4, var(--cw)); align-items: stretch;
  border: 0; margin: 0; padding: 0 0 0 14px; background: transparent; text-align: left;
  border-top: 1px solid var(--line); min-height: 0; font-size: 15px; cursor: default;
}
.card.n1 .crow { grid-template-columns: minmax(0, 1fr) var(--cw); }
.card.n2 .crow { grid-template-columns: minmax(0, 1fr) repeat(2, var(--cw)); }
.card.n3 .crow { grid-template-columns: minmax(0, 1fr) repeat(3, var(--cw)); }
.crow.head { border-top: 0; font-size: 13px; font-weight: 650; color: var(--muted); }
.crow.split { border-top: 2px solid var(--line-2); }
.crow.total { border-top: 2px solid var(--line-2); font-weight: 800; }
.crow:disabled { opacity: 1; color: inherit; }
.cell { display: flex; align-items: center; justify-content: center; min-width: 0; white-space: nowrap; }
.cell.name { justify-content: flex-start; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.crow.head .cell.name { font-weight: 650; }
.rnd i { font-style: normal; opacity: .7; }
.cell.pl { flex-direction: column; gap: 3px; font-size: 12px; line-height: 1; }
.cell.pl .dot { width: 9px; height: 9px; }
.cell.act { background: rgba(35, 38, 47, .04); }
.cell.pl.act { color: var(--ink); }
.cell.v { font-weight: 700; font-variant-numeric: tabular-nums; }
.cell.v.zero { color: var(--muted); font-weight: 500; }
.crow.open { cursor: pointer; }
.crow.open .cell.name { color: var(--ink); }
.cell.pot { color: var(--p0); font-weight: 650; background: var(--p0-soft); }
.cell.pot.nil { color: #c7b8ae; font-weight: 500; }
@media (hover: hover) { .crow.open:hover { background: #faf5ee; } .crow.open:hover .cell.pot { background: #fbdccf; } }
.crow.open:active { background: #f7efe4; }
.cell.fresh { animation: fresh 1.6s ease-out; }
@keyframes fresh { 0%, 30% { background: var(--gold); } 100% { background: transparent; } }

/* ---------- dice ---------- */
.dice { display: flex; justify-content: center; gap: min(3vw, 14px); padding-top: 8px; }
.die {
  --d: min(16vw, 62px);
  position: relative; width: var(--d); height: var(--d); flex: none; border: 0; border-radius: 22%;
  padding: calc(var(--d) * .13); display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  background: linear-gradient(150deg, #ffffff, #efe8da); cursor: default;
  box-shadow: 0 3px 0 #d6cbb6, 0 6px 12px rgba(35, 38, 47, .14), inset 0 0 0 1px rgba(0, 0, 0, .04);
  transition: transform .18s, box-shadow .18s, opacity .2s;
}
.die.tap { cursor: pointer; }
.die .pip { width: 76%; height: 76%; 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.blank { opacity: .4; box-shadow: 0 2px 0 #d6cbb6, inset 0 0 0 1px rgba(0, 0, 0, .05); }
.die.held { transform: translateY(-8px); }
.die.held::after {
  content: 'HOLD'; position: absolute; left: 0; right: 0; bottom: -22px; text-align: center;
  font-size: 10px; font-weight: 800; letter-spacing: .08em;
}
.die.p0.held { box-shadow: 0 0 0 3px var(--p0), 0 10px 14px rgba(35, 38, 47, .16); }
.die.p1.held { box-shadow: 0 0 0 3px var(--p1), 0 10px 14px rgba(35, 38, 47, .16); }
.die.p2.held { box-shadow: 0 0 0 3px var(--p2), 0 10px 14px rgba(35, 38, 47, .16); }
.die.p3.held { box-shadow: 0 0 0 3px var(--p3), 0 10px 14px rgba(35, 38, 47, .16); }
.die.p0.held::after { color: var(--p0); } .die.p1.held::after { color: var(--p1); }
.die.p2.held::after { color: var(--p2); } .die.p3.held::after { color: var(--p3); }
.die.rolling { animation: tumble .42s cubic-bezier(.2, .8, .3, 1); }
@keyframes tumble {
  0% { transform: rotate(-160deg) scale(.7); }
  60% { transform: rotate(18deg) scale(1.06); }
  100% { transform: rotate(0) scale(1); }
}

.roll { justify-self: center; min-width: 200px; min-height: 52px; font-size: 17px; display: inline-flex; align-items: center; gap: 12px; margin-top: 10px; }
.roll .left { display: inline-flex; gap: 4px; }
.roll .left i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 253, 249, .28); }
.roll .left i.on { background: var(--gold); }
.roll.go { animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 0%, 70%, 100% { transform: none; } 80% { transform: translateY(-3px); } 90% { transform: none; } }
.roll:disabled { opacity: .3; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(35, 38, 47, .36);
  display: flex; align-items: flex-end; justify-content: center; padding: 12px; animation: fade .2s ease-out;
}
.overlay.soft { background: rgba(242, 238, 230, .55); align-items: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet, .card-box {
  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(35, 38, 47, .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(35, 38, 47, .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-title { font-size: 28px; font-weight: 800; }
.over-sub { color: var(--muted); margin: 4px 0 14px; }
.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-variant-numeric: tabular-nums; font-size: 18px; }
.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, .help-body li { font-size: 15px; margin: 4px 0; }
.help-body ul { padding-left: 20px; }
.fine { font-size: 13px; color: var(--muted); margin-top: 14px; }

@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; }
  .crow { font-size: 14px; padding-left: 10px; }
  .card.n4 { --cw: 2.6rem; }
}
@media (max-height: 700px) {
  .bar { min-height: 52px; }
  .game { gap: 8px; padding-bottom: 8px; }
  .turn { min-height: 36px; padding: 5px 16px; }
  .die { --d: min(14vw, 52px); }
  .roll { min-height: 46px; margin-top: 8px; }
}
/* The tutorial kit's first-visit chip sits just above the dice (over the scorecard's last rows,
   which can't be tapped before the first roll) instead of on top of the Roll button. */
body > .tut-chip { bottom: calc(env(safe-area-inset-bottom, 0px) + 198px); }
@media (max-height: 700px) { body > .tut-chip { bottom: calc(env(safe-area-inset-bottom, 0px) + 168px); } }
@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); }
/* 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; }
