/* Saltworks: a calm, fixed coastal palette (the same in light and dark OS modes).
   One accent (brine teal) marks "your action": your turn, your bid, the Bid button. */
:root {
  color-scheme: light;
  --bg: #f0ece2;
  --card: #fdfbf5;
  --ink: #232b2e;
  --muted: #6e7a74;
  --soft: rgba(35, 43, 46, .07);
  --line: rgba(35, 43, 46, .14);
  --tray: #e3ded0;
  --accent: #0f6d78;
  --accent-soft: rgba(15, 109, 120, .14);
  --gold: #b07f1c;
  --bad: #b4452f;
  --radius: 14px;
  /* lot flats */
  --marsh: #5f8f52;
  --rock: #a2714a;
  --sea: #2f74a8;
  --sun: #cf9a24;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #0f6d78;
  --tut-accent-ink: #ffffff;
  --tut-bubble: #fdfbf5;
  --tut-ink: #232b2e;
  --tut-muted: #6e7a74;
  --tut-dim: rgba(23, 32, 34, .55);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/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; }

/* ------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 4px;
  max-width: 1040px; margin: 0 auto; height: 50px;
  padding: 0 max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
}
.back, .icon-btn {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--ink);
  text-decoration: none; font-size: 22px; line-height: 1; cursor: pointer;
}
.back:hover, .icon-btn:hover { background: var(--soft); }
.brand {
  flex: 1; margin: 0; text-align: center; font-size: 18px; font-weight: 750;
  letter-spacing: .08em; font-variant: small-caps;
}
.back:focus-visible, .icon-btn:focus-visible, .btn:focus-visible, .pchip:focus-visible,
.seg button:focus-visible, .menu button:focus-visible, .lot:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* ------------------------------------------------------------- buttons */
.btn {
  min-height: 46px; padding: 0 16px; border-radius: 12px; border: 0;
  background: var(--soft); cursor: pointer; font-weight: 650; line-height: 1.1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.warn { background: var(--bad); color: #fff; }
.btn[disabled] { opacity: .4; cursor: not-allowed; transform: none; }
.btn.step { min-width: 48px; padding: 0; font-size: 22px; font-weight: 700; background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line); }

/* ------------------------------------------------------------- layout */
.app {
  max-width: 1040px; margin: 0 auto;
  padding: 0 max(14px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.board-area { display: grid; gap: 10px; min-width: 0; }
@media (min-width: 900px) { .board-area { gap: 14px; padding-top: 6px; } }

/* ------------------------------------------------------------- player chips */
.players { display: flex; gap: 6px; min-width: 0; }
.pchip {
  position: relative; display: flex; align-items: center; gap: 7px;
  flex: 1 1 0; min-width: 0; min-height: 48px; padding: 0 10px 0 6px;
  border: 0; border-radius: 14px; background: var(--card); cursor: pointer;
  box-shadow: inset 0 0 0 1.5px var(--line);
  transition: box-shadow .2s, opacity .2s;
}
.pchip.turn { box-shadow: inset 0 0 0 2.5px var(--pc, var(--accent)); }
.pchip.out { opacity: .45; }
.pchip.won-lot { box-shadow: inset 0 0 0 2.5px var(--gold); }
.av {
  display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--pc, #888); color: #fff; font-size: 13px; font-weight: 800;
}
.pchip .who { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; line-height: 1.15; }
.pchip .nm { font-size: 12px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pchip .pts { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pchip .purse {
  /* Always a clear gap from the points, or the two numbers read as one. */
  margin-left: auto; padding-left: 8px; display: inline-flex; align-items: center; gap: 3px;
  font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--gold);
}
.pchip .purse svg { width: 15px; height: 15px; display: block; }
.pchip .delta {
  position: absolute; right: 6px; top: -7px; font-size: 12px; font-weight: 800; color: var(--bad);
  animation: rise 1.2s ease-out 1 both; pointer-events: none;
}
@keyframes rise { 0% { opacity: 0; transform: translateY(6px); } 20% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-9px); } }
@media (max-width: 439px) {
  .players[data-n="3"] .nm, .players[data-n="4"] .nm { display: none; }
  .players[data-n="4"] .pchip { padding: 0 6px 0 4px; gap: 5px; }
  .players[data-n="4"] .av { width: 24px; height: 24px; font-size: 12px; }
  .players[data-n="4"] .pts, .players[data-n="4"] .purse { font-size: 15px; }
  .players[data-n="4"] .purse svg { width: 13px; height: 13px; }
  /* With the names hidden, the points and the purse are two bare numerals side by
     side ("0 10" reads as "010"), so put the coin in front of the amount. */
  .players[data-n="3"] .purse, .players[data-n="4"] .purse {
    flex-direction: row-reverse; padding-left: 10px; gap: 3px;
  }
}

/* ------------------------------------------------------------- coast strip */
.coast-head { display: flex; align-items: baseline; gap: 8px; padding: 0 2px; }
.round { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .09em; }
.lots { display: grid; gap: 8px; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
.lot {
  position: relative; display: grid; gap: 2px; justify-items: center; align-content: center;
  min-width: 0; min-height: 76px; padding: 7px 4px 6px; border: 0; border-radius: 12px;
  background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line);
  font: inherit; cursor: default; transition: box-shadow .2s, opacity .25s, transform .15s;
}
.lot .pan { width: 34px; height: 26px; display: block; }
.lot .val { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.lot .flat { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--fc, var(--muted)); }
.lot.now { box-shadow: 0 0 0 3px var(--accent), 0 4px 14px rgba(35, 43, 46, .16); transform: translateY(-2px); background: #fff; }
.lot.done { opacity: .5; }
.lot.unsold { opacity: .45; }
.lot .sold {
  position: absolute; right: -4px; top: -6px; display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 5px; border-radius: 999px; background: var(--pc, #888); color: #fff;
  font-size: 10.5px; font-weight: 800; box-shadow: 0 0 0 2px var(--bg);
}
.lot .tide { position: absolute; right: -4px; top: -6px; padding: 1px 6px; border-radius: 999px; background: var(--muted); color: #fff; font-size: 10px; font-weight: 700; box-shadow: 0 0 0 2px var(--bg); }

/* ------------------------------------------------------------- the block */
.block {
  display: grid; gap: 10px; justify-items: center;
  padding: 14px 12px 15px; border-radius: 18px; background: var(--tray);
}
.block .pan-big { width: 118px; height: 88px; display: block; filter: drop-shadow(0 2px 4px rgba(35, 43, 46, .18)); }
.block .title { display: flex; align-items: baseline; gap: 8px; font-weight: 750; }
.block .title .val { font-size: 26px; font-weight: 850; font-variant-numeric: tabular-nums; line-height: 1; }
.block .title .flat { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--fc, var(--muted)); font-weight: 800; }
.block .worth { font-size: 13px; color: var(--muted); text-align: center; }
.block .worth b { color: var(--accent); }
.bidline {
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
  min-height: 34px; padding: 5px 14px; border-radius: 999px; background: var(--card);
  box-shadow: inset 0 0 0 1.5px var(--line); font-size: 14px; text-align: center;
}
.bidline .amount { font-size: 19px; font-weight: 850; font-variant-numeric: tabular-nums; color: var(--gold); display: inline-flex; align-items: center; gap: 3px; }
.bidline .amount svg { width: 16px; height: 16px; }
.bidline .by { color: var(--muted); }
.bidline.none { color: var(--muted); }
.racers { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }
.racer {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px 2px 3px; border-radius: 999px;
  background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line); font-size: 12px; font-weight: 650;
}
.racer .av { width: 19px; height: 19px; font-size: 10px; }
.racer.gone { opacity: .4; text-decoration: line-through; }
.racer.top { box-shadow: inset 0 0 0 2px var(--gold); }
.block.settling { animation: settle .5s ease-out; }
@keyframes settle { 0% { transform: scale(.97); } 60% { transform: scale(1.01); } 100% { transform: none; } }

/* ------------------------------------------------------------- status */
.status-row { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.status { display: flex; align-items: center; gap: 9px; min-height: 24px; font-size: 16px; font-weight: 650; padding: 0 2px; min-width: 0; }
.status .msg { min-width: 0; }
.status .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--pc, var(--muted)); }
.status.mine .dot { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.status.err .msg { color: var(--bad); }
.status.thinking .msg { color: var(--muted); }
.status-row .net { color: var(--muted); justify-content: flex-start; padding: 0 3px; }
.happened { margin: 0; padding: 0 2px; min-height: 19px; font-size: 13.5px; color: var(--muted); }
.happened b { color: var(--ink); font-weight: 700; }

/* ------------------------------------------------------------- action bar */
.actionbar {
  /* Above the tutorial kit's first-visit chip (z 12): on a short phone the two
     land in the same corner, and the controls must stay tappable. */
  position: sticky; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 14;
  width: fit-content; max-width: 100%; margin: 2px auto 0; min-height: 58px;
  display: flex; gap: 6px; align-items: center; padding: 6px;
  background: var(--card); border-radius: 18px; white-space: nowrap;
  box-shadow: 0 4px 18px rgba(35, 43, 46, .16);
  animation: barin .18s ease-out;
}
.actionbar:empty { visibility: hidden; animation: none; }
@keyframes barin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.actionbar .bid-amt {
  display: inline-flex; align-items: center; gap: 4px; min-width: 56px; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.actionbar .bid-amt svg { width: 16px; height: 16px; }
/* Keep the four controls on one row, and inside the screen, on a small phone. */
@media (max-width: 420px) {
  .actionbar { gap: 5px; padding: 5px; }
  .actionbar .btn { padding: 0 12px; }
  .actionbar .btn.step { min-width: 44px; }
  .actionbar .bid-amt { min-width: 44px; }
}

/* ------------------------------------------------------------- overlays */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(23, 32, 34, .42); padding: 14px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 420px; max-height: calc(100vh - 28px); max-height: calc(100dvh - 28px); overflow-y: auto;
  background: var(--card); border-radius: 20px; padding: 18px;
  box-shadow: 0 12px 40px rgba(20, 28, 30, .28);
  animation: pop .18s ease-out;
}
.modal.wide { max-width: 600px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { margin: 0 0 12px; font-size: 20px; text-align: center; }
.modal-head { display: flex; align-items: center; gap: 8px; margin: -6px -6px 8px 0; }
.modal-head h2 { flex: 1; margin: 0; text-align: left; }
.modal .lede { margin: -4px 0 14px; text-align: center; color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal-actions .btn { flex: 1 1 auto; }

/* menu */
.menu-overlay { background: rgba(23, 32, 34, .12); place-items: start end; padding: 50px 10px 0; }
.menu {
  min-width: 212px; background: var(--card); border-radius: 16px; padding: 6px;
  box-shadow: 0 10px 30px rgba(20, 28, 30, .22); animation: pop .15s ease-out; display: grid;
}
.menu button {
  min-height: 48px; padding: 0 14px; border: 0; background: transparent; text-align: left;
  border-radius: 10px; cursor: pointer; font-size: 15px; font-weight: 550;
}
.menu button:hover { background: var(--soft); }
@media (min-width: 1060px) { .menu-overlay { padding-right: calc((100vw - 1040px) / 2 + 8px); } }

/* setup */
.field { margin: 14px 0; }
.field-label { font-weight: 650; margin-bottom: 6px; font-size: 14px; }
.field-hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--soft); }
.seg button { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; font-weight: 650; }
.seg button[aria-checked="true"] { background: var(--accent); color: #fff; }

/* info */
.info-round { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; }
.info-scores { display: grid; gap: 14px; }
.info-player { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.info-player:last-child { border-bottom: 0; padding-bottom: 0; }
.info-head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.info-head .info-sub { font-weight: 400; font-size: 12.5px; color: var(--muted); }
.info-head .total { margin-left: auto; font-size: 18px; }
.sub-title { margin: 20px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.holding { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; border-radius: 999px;
  background: var(--soft); font-size: 13px; white-space: nowrap;
}
.pill svg.pan { width: 22px; height: 17px; display: block; flex: none; }
.pill.bonus { background: var(--accent-soft); }
.pill.muted { color: var(--muted); padding-left: 10px; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: 13px; max-height: 38vh; overflow-y: auto; }
.log li { display: flex; gap: 7px; align-items: flex-start; }
.log li .av { width: 18px; height: 18px; font-size: 10px; margin-top: 1px; }
.log li.round-line { color: var(--muted); font-style: italic; }

/* help */
.help-body h3 { margin: 16px 0 4px; font-size: 15px; }
.help-body h3:first-child { margin-top: 0; }
.help-body p, .help-body li { font-size: 14px; }
.help-body ul, .help-body ol { padding-left: 20px; margin: 4px 0; }
.color-key { list-style: none; padding: 0 !important; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.color-key li { display: flex; align-items: center; gap: 8px; }
.color-key svg.pan { width: 30px; height: 23px; flex: none; }

/* game over */
.go-table { display: grid; gap: 4px; }
.go-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; }
.go-row.win { background: var(--accent-soft); }
.go-row .place { width: 28px; color: var(--muted); font-size: 13px; font-weight: 700; }
.go-name { display: flex; flex-direction: column; font-weight: 700; min-width: 0; }
.go-name small { font-weight: 400; color: var(--muted); font-size: 12px; }
.go-row .total { margin-left: auto; font-size: 22px; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Online play (online.js). */
body.is-online #btn-new { display: none; }
.menu #menu-online { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; margin-top: 4px; }
#over-leave { display: flex; width: 100%; margin-top: 8px; }
