/* Waypoint, one fixed light palette, set explicitly so the page looks the same whatever the OS does.
   Mobile first from 360px; a wider screen puts the rival's trails and yours side by side. */
:root {
  --bg: #f2efe8;
  --surface: #fbf9f4;
  --panel: #f6f2e9;
  --ink: #2b3328;
  --muted: #6d7566;
  --line: #ddd7c8;
  --accent: #8a5a2b;
  --accent-ink: #fffaf2;
  --good: #3f6a2c;
  --bad: #a4402f;
  --t0: #9a6b3f;   /* Ridge  */
  --t1: #2f6f9f;   /* River  */
  --t2: #4a7c3f;   /* Marsh  */
  --t3: #b8860f;   /* Dune   */
  --t4: #2f7d72;   /* Pine   */
  /* the shared kits (tutorial.js, chat.js, tables.js) take their colours from these */
  --tut-accent: #8a5a2b;
  --tut-accent-deep: #6d4620;
  --tut-accent-ink: #fffaf2;
  --tut-bubble: #fbf9f4;
  --tut-ink: #2b3328;
  --tut-muted: #6d7566;
  --tut-ring: rgba(138, 90, 43, .5);
  --tut-dim: rgba(24, 28, 20, .45);
  --chat-accent: var(--accent);
  --chat-accent-ink: var(--accent-ink);
  --chat-ink: var(--ink);
  --chat-muted: var(--muted);
  --chat-panel: var(--surface);
  --chat-mine: #efe4d2;
  --tb-accent: var(--accent);
  --tb-accent-ink: var(--accent-ink);
  --tb-ink: var(--ink);
  --tb-muted: var(--muted);
  --tb-panel: var(--surface);
  --tb-line: var(--line);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; touch-action: manipulation; min-height: 100vh; overflow-x: hidden; }
button { font: inherit; color: inherit; }

.app { position: relative; max-width: 760px; margin: 0 auto; padding: 0 10px 14px;
  padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }

/* ---------- top bar ---------- */
.topbar { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 4px; padding: 4px 0 6px; }
.back { display: flex; align-items: center; justify-content: center; min-width: 40px; min-height: 40px; text-decoration: none; color: var(--muted); font-size: 20px; }
.brand { margin: 0; text-align: center; font-size: 19px; font-weight: 800; letter-spacing: .01em; color: var(--accent); }
.iconbtn { min-width: 40px; min-height: 40px; border: 0; background: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; border-radius: 10px; }
.iconbtn:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu { position: absolute; right: 8px; top: 46px; z-index: 40; min-width: 210px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 30px rgba(30, 34, 26, .18); padding: 6px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 11px 12px; min-height: 44px; border-radius: 10px; cursor: pointer; }
.menu button:hover { background: var(--panel); }

/* ---------- status ---------- */
.status { position: relative; min-height: 34px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 2px 4px 6px; font-size: 14px; color: var(--muted); text-align: center; }
.status.mine { color: var(--ink); font-weight: 600; }
.status .net-note { position: absolute; left: 50%; top: calc(100% - 6px); transform: translateX(-50%); z-index: 6; width: max-content; max-width: calc(100% - 20px);
  background: var(--ink); color: var(--surface); font-size: 12px; padding: 4px 9px; border-radius: 8px; }

/* ---------- a side (the rival's trails, then yours) ---------- */
.side { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 7px 8px 9px; }
.side + .side, .middle + .side { margin-top: 8px; }
.side-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-height: 20px; font-size: 13px; }
.side-head .nm { font-weight: 800; }
.side-head .pts { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); }
.side-head .pts.up { color: var(--good); }
.side-head .pts.down { color: var(--bad); }
.cols { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin-top: 5px; }
.col { position: relative; border: 0; background: var(--panel); border-radius: 10px; padding: 4px 2px; min-height: 52px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.col .mark { width: 15px; height: 15px; opacity: .75; color: var(--tc); }
.col .chips { display: flex; flex-direction: column; align-items: center; gap: 1px; width: 100%; }
.col .chip { width: 100%; max-width: 34px; border-radius: 4px; background: var(--tc); color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 15px; height: 15px; font-variant-numeric: tabular-nums; }
.col .chip.pl { background: var(--surface); color: var(--tc); box-shadow: inset 0 0 0 1.5px var(--tc); }
.col .sc { font-size: 11px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.col .sc.up { color: var(--good); }
.col .sc.down { color: var(--bad); }
.col.target { box-shadow: inset 0 0 0 2px var(--accent); background: #f6ecdd; }
.col.fresh { animation: pop .35s ease-out; }
.mine .col { min-height: 74px; }

/* ---------- the middle: heaps and the stack ---------- */
.middle { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; margin-top: 8px; }
.heaps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.heap { position: relative; border: 1px dashed var(--line); background: var(--surface); border-radius: 10px; min-height: 56px; padding: 3px 2px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.heap .mark { width: 14px; height: 14px; color: var(--tc); opacity: .7; }
.heap .top { width: 100%; max-width: 36px; border-radius: 5px; background: var(--tc); color: #fff; font-weight: 800; font-size: 13px; line-height: 22px; height: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.heap .top.pl { background: var(--surface); color: var(--tc); box-shadow: inset 0 0 0 1.5px var(--tc); }
.heap .n { font-size: 10px; color: var(--muted); }
.heap.target { border-style: solid; box-shadow: inset 0 0 0 2px var(--accent); }
.heap.dead { opacity: .55; }
.stack { border: 1px solid var(--line); background: #3c4a3a; color: #f3ead6; border-radius: 12px; min-width: 62px; padding: 6px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.stack .n { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stack .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; opacity: .8; }
.stack.target { box-shadow: 0 0 0 2px var(--accent); }
.stack:disabled { opacity: .5; cursor: default; }

/* ---------- your hand ---------- */
.handbar { margin-top: 9px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 8px; }
.hand { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.card { position: relative; border: 0; padding: 0; border-radius: 9px; background: var(--tc); color: #fff; aspect-ratio: 5 / 7; min-height: 54px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; box-shadow: 0 2px 5px rgba(30, 34, 26, .18); transition: transform .15s, box-shadow .15s; }
.card .v { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.card .mark { width: 13px; height: 13px; opacity: .85; color: #fff; }
.card.pl { background: var(--surface); color: var(--tc); box-shadow: inset 0 0 0 2px var(--tc), 0 2px 5px rgba(30, 34, 26, .18); }
.card.pl .mark { color: var(--tc); }
.card.on { transform: translateY(-6px); box-shadow: 0 0 0 2px var(--accent), 0 6px 14px rgba(30, 34, 26, .25); }
.card:disabled { opacity: .45; cursor: default; }
.controls { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; margin-top: 7px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.controls .hint { color: var(--muted); }

/* ---------- buttons ---------- */
.btn { min-height: 42px; padding: 0 15px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 34px; padding: 0 11px; font-size: 13px; }
.btn.quiet { border-color: transparent; background: none; color: var(--muted); font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- sheets and modals ---------- */
.sheet-wrap, .modal-wrap { position: fixed; inset: 0; z-index: 60; display: flex; }
/* An author `display` beats the browser's [hidden], and these cover the whole screen: without this a
   closed sheet stays over the board and swallows every tap. */
[hidden] { display: none !important; }
.sheet-wrap { align-items: flex-end; justify-content: center; }
.modal-wrap { align-items: center; justify-content: center; padding: 14px; }
.sheet-backdrop, .modal-wrap::before { position: absolute; inset: 0; background: rgba(24, 28, 20, .45); }
.modal-wrap::before { content: ''; }
.sheet { position: relative; width: 100%; max-width: 520px; max-height: 86vh; overflow-y: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 15px 15px calc(15px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px rgba(20, 24, 18, .2); animation: up .18s ease-out; }
.sheet h3 { margin: 0 0 8px; font-size: 17px; }
.sheet .muted, .muted { color: var(--muted); }
.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.field .label { font-weight: 700; font-size: 14px; }
.seg { display: flex; gap: 5px; flex-wrap: wrap; }
.seg button { min-height: 40px; padding: 0 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.modal { position: relative; background: var(--surface); border-radius: 16px; width: 100%; max-width: 620px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(20, 24, 18, .3); }
.over-modal { max-width: 430px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 14px 15px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; padding: 12px 15px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.rules h3 { margin: 16px 0 6px; font-size: 15px; }
.rules ul, .rules ol { margin: 6px 0; padding-left: 20px; }
.rules li { margin: 4px 0; }
.ico { width: 15px; height: 15px; vertical-align: -2px; color: var(--accent); }

/* the round and game scoreboards */
.score-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin: 6px 0 2px; }
.score-table th, .score-table td { padding: 5px 6px; text-align: right; border-bottom: 1px solid var(--line); font-size: 14px; }
.score-table th:first-child, .score-table td:first-child { text-align: left; }
.score-table tr.total td { font-weight: 800; border-bottom: 0; }
.win-line { font-size: 17px; font-weight: 800; margin: 0 0 8px; }
.win-line.you { color: var(--good); }
.win-line.them { color: var(--bad); }
.cardrow { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.cardrow .chip { min-width: 30px; border-radius: 5px; background: var(--tc); color: #fff; font-size: 12px; font-weight: 700; text-align: center; line-height: 20px; padding: 0 5px; }
.cardrow .chip.pl { background: var(--surface); color: var(--tc); box-shadow: inset 0 0 0 1.5px var(--tc); }

@keyframes up { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes pop { from { transform: scale(.92); } to { transform: none; } }

/* online: the local-game buttons step aside (tables.js drives the rest) */
body.is-online .local-only { display: none; }

@media (max-width: 380px) {
  .card { min-height: 48px; }
  .card .v { font-size: 15px; }
  .hand { gap: 3px; }
  .stack { min-width: 54px; }
}
@media (min-width: 720px) {
  .app { padding-bottom: 20px; }
  .col { min-height: 64px; }
  .mine .col { min-height: 96px; }
  .card { min-height: 66px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
