/* Dominoes, ivory tiles on a green felt table, warm paper around it. Fixed palette. */
:root {
  color-scheme: light;
  --bg: #f1eee7;
  --card: #fffdf8;
  --ink: #1f2024;
  --muted: #74767d;
  --line: #e1dbcf;
  --felt: #2f6e5c;
  --felt-2: #285f4f;
  --felt-3: #1d4a3d;
  --ivory: #fbf8ef;
  --ivory-2: #e9e2d2;
  --pip: #25262b;
  --gold: #ffc94d;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #ffc94d;
  --tut-accent-ink: #1f2024;
  --tut-bubble: #fffdf8;
  --tut-ink: #1f2024;
  --tut-muted: #74767d;
  --tut-dim: rgba(10, 28, 22, .55);
  --p0: #2f6e5c;
  --p1: #c0583c;
  --p2: #3f6fb0;
  --p3: #8a5fb0;
}

* { 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; }

/* ---------- bar ---------- */
.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(31, 32, 36, .1), 0 0 0 1px var(--line);
  transition: transform .12s, background .15s, color .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 {
  outline: 3px solid var(--gold); outline-offset: 2px;
}

/* ---------- game ---------- */
.game {
  flex: 1; min-height: 0;
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  gap: 10px; padding-bottom: 10px;
}
.turn {
  justify-self: center; display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 16px; border-radius: 999px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line); font-weight: 650; font-size: 16px; 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: '...'; } }
/* ---------- players ---------- */
.players { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }
.pl {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 3px 12px 3px 8px;
  border-radius: 999px; background: var(--card); box-shadow: 0 0 0 1px var(--line);
  font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; transition: box-shadow .2s;
}
.pl .nm { color: var(--ink); }
.pl .sc { color: var(--muted); font-weight: 700; }
.pl .sc small { font-size: 11px; font-weight: 600; }
.pl .ct { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); font-weight: 600; padding-left: 7px; border-left: 1px solid var(--line); }
.pl .back-tile { display: inline-block; width: 7px; height: 13px; border-radius: 2px; background: var(--felt-3); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }
.pl.on { box-shadow: 0 0 0 2px var(--ink); }
.pl.flash { animation: plflash .9s ease-out; }
@keyframes plflash { 0% { background: #fff1c9; } 100% { background: var(--card); } }
.dot { display: inline-block; flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--p0); }
.dot.p1 { background: var(--p1); } .dot.p2 { background: var(--p2); } .dot.p3 { background: var(--p3); }

/* ---------- table ---------- */
.table-wrap {
  min-height: 0; min-width: 0; position: relative;
  border-radius: 18px;
  background: radial-gradient(ellipse at 50% 40%, var(--felt), var(--felt-2) 75%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), inset 0 2px 12px rgba(0, 0, 0, .18);
  display: flex; align-items: center; justify-content: center; padding: 8px;
}
.line { width: 100%; height: 100%; display: block; }
.line .tile { transform-box: fill-box; transform-origin: center; }
.line .tile.place { animation: place .3s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes place { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.line .hot-ring { fill: none; stroke: var(--gold); stroke-width: .9; animation: hot 1.6s ease-out both; }
@keyframes hot { 0%, 50% { opacity: 1; } 100% { opacity: 0; } }
.line .ghost { cursor: pointer; }
.line .ghost .gbox { fill: rgba(255, 201, 77, .28); stroke: var(--gold); stroke-width: .45; stroke-dasharray: 1.2 .8; animation: pulse 1.1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .55; } to { opacity: 1; } }

/* ---------- actions and hand ---------- */
.actions { display: flex; justify-content: center; gap: 10px; min-height: 44px; }
.btn.act { min-width: 140px; }
.btn.end-btn { background: #fff4d6; box-shadow: 0 0 0 2px var(--gold); }
.hand { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-height: 84px; padding-top: 12px; }
.tbtn {
  --w: 42px;
  width: var(--w); height: calc(var(--w) * 2); padding: 0; border: 0; border-radius: 7px; background: transparent;
  cursor: default; transition: transform .18s, opacity .18s, filter .18s;
}
.hand.many .tbtn { --w: 36px; }
.tbtn svg { display: block; width: 100%; height: 100%; overflow: visible; }
.tbtn.can { cursor: pointer; transform: translateY(-8px); }
.tbtn.can svg .face { stroke: var(--felt); stroke-width: .9; }
.tbtn.dim { opacity: .55; }
.tbtn.sel { transform: translateY(-14px); }
.tbtn.sel svg .face { stroke: #d99a00; stroke-width: 1.2; }
.tbtn.new { animation: drawn .4s ease-out; }
@keyframes drawn { from { transform: translateY(18px); opacity: 0; } }
.tbtn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.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; }

/* ---------- hand-over card ---------- */
.ranks { list-style: none; margin: 0 0 18px; padding: 0; text-align: left; }
.ranks li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.ranks li:last-child { border-bottom: 0; }
.ranks .nm { flex: 1; font-weight: 600; }
.ranks .gain { color: var(--p0); font-weight: 700; font-size: 14px; }
.ranks .tot { font-weight: 800; min-width: 3ch; text-align: right; }
.ranks .left { color: var(--muted); font-size: 13px; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(31, 32, 36, .36);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  animation: fade .2s ease-out;
}
.overlay.soft { background: rgba(241, 238, 231, .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(31, 32, 36, .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;
}
.menu-sheet .row:first-of-type { border-top: 1px solid var(--line); }
.caps { font-size: 13px; color: var(--muted); margin: 10px 4px 0; font-variant-numeric: tabular-nums; }
.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(31, 32, 36, .16); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.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; gap: 8px; margin-bottom: 10px; }
.over-mark .stone-icon { width: 52px; height: 52px; box-shadow: 0 4px 10px rgba(0, 0, 0, .18); }
.over-title { font-size: 28px; font-weight: 800; }
.over-title.small { font-size: 22px; }
.over-sub { color: var(--muted); margin: 4px 0 20px; font-variant-numeric: tabular-nums; }
.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; }

/* ---------- small and landscape screens ---------- */
@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 (min-aspect-ratio: 1/1) and (max-height: 520px) {
  .bar { min-height: 50px; }
  .game { gap: 6px; padding-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* ---------- small and landscape screens ---------- */
@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; }
  .tbtn { --w: 38px; }
  .hand.many .tbtn { --w: 33px; }
}
@media (max-height: 700px) {
  .tbtn { --w: 34px; }
  .hand.many .tbtn { --w: 30px; }
  .hand { min-height: 68px; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 520px) {
  .bar { min-height: 50px; }
  .game { gap: 6px; padding-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* The tutorial kit's first-visit chip sits over the turn pill instead of on top of your tiles
   (it goes away once you make your first move). */
body > .tut-chip { top: calc(env(safe-area-inset-top, 0px) + 58px); bottom: auto; }

/* ---------- online (a table with friends: tables.js) ---------- */
/* a short notice (connection lost, the table was updated, someone left) floats just under the turn pill,
   over the players' chips, so the board never moves */
.turn { position: relative; }
.turn .net-note { position: absolute; left: 50%; top: calc(100% + 4px); transform: translateX(-50%); z-index: 6; width: max-content; max-width: min(88vw, 360px);
  padding: 4px 12px; border-radius: 12px; background: var(--ink); color: var(--card); font-size: 12.5px; font-weight: 700; line-height: 1.3; text-align: center;
  white-space: normal; box-shadow: 0 4px 14px rgba(31, 32, 36, .3); pointer-events: none; animation: fade .25s ease-out; }
.turn .net-note[hidden] { display: none; }
/* people's names can be long: a chip keeps to one line */
body.is-online .pl .nm { max-width: 11ch; white-space: normal; overflow-wrap: anywhere; line-height: 1.15; }
/* a friend whose page stopped checking in */
.pl.away .nm, .pl.away .dot { opacity: .5; }
.pl .aw { font-size: 12px; font-weight: 600; font-style: italic; color: var(--muted); }
body.is-online #btn-new { display: none; }
/* one divider above the online rows (How to play keeps its own) */
.menu-sheet #menu-online, .menu-sheet #menu-leave { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet #menu-help { margin-top: 0; border-top: 0; }
.over-card #over-leave { margin-top: 8px; }
