/* Apothecary, fixed palette (same in light and dark OS modes). Calm: few borders, one accent. */
:root {
  --bg: #16201c;
  --surface: #1e2a25;
  --surface2: #26352e;
  --line: rgba(255, 255, 255, .08);
  --ink: #efe7d6;
  --muted: #92a298;
  --accent: #e4b454;          /* "your action" */
  --accent-ink: #251b06;
  --parch: #f1e6cc;
  --parch2: #e3d4b0;
  --parch-ink: #2e2416;
  --good: #8ccf74;
  --warn: #efa24c;
  --bad: #e26e5e;
  --k-produce: #6f9c44;
  --k-upgrade: #5580ad;
  --k-trade: #b5733a;
  --gold: #f3c64b;
  --silver: #cfd6dc;
  color-scheme: dark;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #e4b454;
  --tut-accent-ink: #251b06;
  --tut-bubble: #f1e6cc;
  --tut-ink: #2e2416;
  --tut-muted: #6e5d44;
  --tut-dim: rgba(6, 10, 8, .62);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 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; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; }

.app { max-width: 1120px; margin: 0 auto; padding: 0 12px 24px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 4px; height: 52px; position: relative; }
.back, .iconbtn {
  width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px;
  color: var(--muted); text-decoration: none; font-size: 22px; background: none; border: 0; cursor: pointer; padding: 0;
}
.back:hover, .iconbtn:hover, .iconbtn[aria-expanded="true"] { color: var(--ink); background: var(--surface); }
.brand { flex: 1; text-align: center; font: 700 19px/1 Georgia, "Times New Roman", serif; letter-spacing: .05em; color: var(--ink); }
.menu {
  position: absolute; right: 12px; top: 48px; z-index: 45; min-width: 190px; padding: 6px;
  background: var(--surface2); border-radius: 14px; box-shadow: 0 14px 36px rgba(0, 0, 0, .5);
  display: flex; flex-direction: column; animation: pop .14s ease-out;
}
.menu button { min-height: 46px; text-align: left; padding: 0 14px; border: 0; background: none; border-radius: 10px; cursor: pointer; font-weight: 600; }
.menu button:hover, .menu button:focus-visible { background: rgba(255, 255, 255, .06); }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- buttons ---------- */
.btn {
  min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 0;
  background: var(--surface2); color: var(--ink); cursor: pointer; font-weight: 650;
  transition: background .15s, transform .1s, opacity .15s;
}
.btn:hover:not(:disabled) { background: #2f4138; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #f0c46a; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- tokens ---------- */
.tok { width: 22px; height: 22px; display: inline-block; vertical-align: middle; flex: none; }
.tok.sm { width: 14px; height: 14px; }
.tok.md { width: 18px; height: 18px; }
.tok.lg { width: 26px; height: 26px; }
.toks { display: inline-flex; flex-wrap: wrap; gap: 2px; align-items: center; justify-content: center; }
.toks.left { justify-content: flex-start; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 8px 0; }
.legend .li { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.legend .li small { color: var(--muted); }
.ico { width: 14px; height: 14px; vertical-align: -2px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; flex: none; }

/* ---------- player chips ---------- */
.chips { display: flex; gap: 6px; margin: 2px 0 6px; }
.chip {
  position: relative; flex: 1 1 0; min-width: 0; min-height: 46px; display: flex; align-items: center; gap: 7px;
  padding: 5px 8px; border: 0; border-radius: 14px; background: var(--surface); cursor: pointer; text-align: left;
  transition: box-shadow .2s, background .2s;
}
.chip.cur { box-shadow: inset 0 -3px 0 var(--pc); background: var(--surface2); }
.chip .av {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pc); color: #1a1410; font-weight: 800; font-size: 14px;
}
.chip .cinfo { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; flex: 1; }
.chip .nm { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .line { display: flex; align-items: baseline; gap: 8px; }
.chip .sc { font-size: 17px; font-weight: 800; }
.chip .rem { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; }
.chips.n4 .chip .nm, .chips.n5 .chip .nm { display: none; }
.chips.n4 .chip, .chips.n5 .chip { gap: 5px; padding: 5px 6px; }
.chips.n4 .line, .chips.n5 .line { flex-direction: column; gap: 0; }
.chips.n4 .rem, .chips.n5 .rem { font-size: 11px; }
.chips.n4 .rem .ico, .chips.n5 .rem .ico { width: 11px; height: 11px; }
.chips.n5 .chip .av { width: 24px; height: 24px; font-size: 12px; }
/* a computer's move flashes up inside its chip for a moment */
.bubble {
  position: absolute; inset: 0; z-index: 2; border-radius: inherit;
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 3px;
  background: var(--surface2); box-shadow: inset 0 0 0 2px var(--pc);
  animation: bubble 2.6s ease-out forwards; pointer-events: none;
}
.bubble .verb { font-size: 13px; color: var(--pc); font-weight: 700; }
.chips.n4 .bubble .verb, .chips.n5 .bubble .verb { display: none; }
.bubble .act-card { width: 30px; display: flex; }
.bubble .act-card .rc { min-height: 38px; padding: 4px 1px 2px; gap: 0; border-radius: 6px; box-shadow: inset 0 3px 0 var(--kc); }
.bubble .act-card .toks { gap: 0; }
.bubble .act-card .tok.md { width: 10px; height: 10px; }
.bubble .act-card .tok.sm { width: 8px; height: 8px; }
.bubble .act-card .plus { font-size: 10px; }
.bubble .act-card .arrow { font-size: 8px; }
.bubble .act-card .chev { width: 14px; }
.bubble .act-ico { font-size: 22px; line-height: 1; color: var(--pc); }
.bubble .act-pts { font-weight: 900; font-size: 18px; color: var(--pc); }
@keyframes bubble { 0% { opacity: 0; transform: scale(.9); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- status ---------- */
.status { min-height: 34px; display: flex; align-items: center; gap: 8px; padding: 2px 2px 6px; font-size: 15px; color: var(--muted); }
.status.you { color: var(--ink); }
.status.you .msg { font-weight: 600; }
.status .msg { flex: 1; min-width: 0; }
.status .final { background: var(--warn); color: #2a1600; font-weight: 800; font-size: 11px; border-radius: 6px; padding: 2px 6px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.thinking::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }


/* ---------- layout ---------- */
.board { display: grid; grid-template-columns: 1fr; gap: 16px; }
.col-left, .col-right { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.zone { min-width: 0; }
.zlabel { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px 2px; opacity: .8; }

/* ---------- commissions ---------- */
.orders { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; padding-top: 6px; }
.order {
  position: relative; background: var(--parch); color: var(--parch-ink); border: 0; border-radius: 12px;
  padding: 10px 3px 8px; min-height: 96px; display: flex; flex-direction: column; align-items: center; gap: 5px; cursor: pointer;
  transition: transform .15s, box-shadow .2s, opacity .2s; width: 100%; min-width: 0;
}
.order .opts { font: 800 22px/1 Georgia, serif; }
.order .ocost { display: flex; flex-wrap: wrap; justify-content: center; gap: 1px; max-width: 58px; }
.order .coin { position: absolute; top: -7px; right: -4px; }
.order.can { box-shadow: 0 0 0 3px var(--accent), 0 6px 16px rgba(228, 180, 84, .25); }
.order.empty { background: transparent; box-shadow: inset 0 0 0 2px var(--line); cursor: default; }
.coin { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 900; font-size: 11px; color: #3a2a00; box-shadow: 0 1px 3px rgba(0, 0, 0, .4); }
.coin.gold { background: radial-gradient(circle at 35% 35%, #fff2b0, var(--gold) 55%, #b88a18); }
.coin.silver { background: radial-gradient(circle at 35% 35%, #ffffff, var(--silver) 55%, #8d979f); color: #2b3136; }
.coin.sm { width: 16px; height: 16px; font-size: 9px; vertical-align: -3px; }

/* ---------- recipe cards ---------- */
.market { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.mslot { background: none; border: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; cursor: pointer; text-align: center; min-width: 0; border-radius: 12px; }
.mcost { height: 12px; display: flex; justify-content: center; align-items: center; gap: 3px; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--good); }
.mcost i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); opacity: .8; }
.mcubes { min-height: 14px; display: flex; flex-wrap: wrap; gap: 1px; justify-content: center; align-items: center; }
.mslot.cant .rc { opacity: .45; }

.rc {
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px;
  background: var(--parch); color: var(--parch-ink); border-radius: 12px; min-height: 88px; width: 100%;
  padding: 7px 3px 5px; text-align: center; position: relative; overflow: hidden;
  box-shadow: inset 0 4px 0 var(--kc, transparent);
  transition: transform .15s, box-shadow .2s, opacity .2s;
}
.rc.k-produce { --kc: var(--k-produce); }
.rc.k-upgrade { --kc: var(--k-upgrade); }
.rc.k-trade { --kc: var(--k-trade); }
.rc .toks { max-width: 54px; }
.rc .plus { font-weight: 900; font-size: 15px; line-height: 1; color: var(--k-produce); }
.rc .arrow { font-size: 12px; line-height: 1; color: #8a7450; }
.rc .upn { display: flex; color: var(--k-upgrade); }
.chev { width: 26px; height: auto; display: block; }

.handgrid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.hand { display: contents; }
.hand-empty { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cardbtn { background: none; border: 0; padding: 0; cursor: pointer; min-width: 0; display: flex; border-radius: 12px; }
.cardbtn.cant .rc { opacity: .45; }
.cardbtn:hover .rc, .mslot:hover .rc, .order:not(.empty):hover { transform: translateY(-2px); }
.sel .rc, .order.sel { box-shadow: inset 0 4px 0 var(--kc, transparent), 0 0 0 3px var(--accent) !important; }
.order.sel { box-shadow: 0 0 0 3px var(--accent) !important; }
.rest {
  min-height: 88px; border-radius: 12px; border: 2px dashed rgba(255, 255, 255, .16); background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; font-weight: 650; font-size: 13px; padding: 4px 2px;
}
.rest .rest-ico { font-size: 20px; line-height: 1.1; }
.rest small { color: var(--muted); font-size: 11px; font-weight: 500; }
.rest:disabled { opacity: .35; cursor: default; }
.rest:not(:disabled) { border-color: rgba(228, 180, 84, .55); }
.rest.pulse { border-style: solid; border-color: var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(228, 180, 84, .5); } 70% { box-shadow: 0 0 0 10px rgba(228, 180, 84, 0); } 100% { box-shadow: 0 0 0 0 rgba(228, 180, 84, 0); } }

/* computer about to take this / newly revealed */
.ai-pick .rc, .order.ai-pick { box-shadow: 0 0 0 3px var(--pc), 0 0 18px 2px var(--pc) !important; transform: translateY(-3px); }
.new .rc, .order.new { animation: arrive .45s ease-out; }
@keyframes arrive { from { transform: translateX(14px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- me ---------- */
.satchel { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; }
.slot { aspect-ratio: 1; max-height: 38px; border-radius: 50%; background: rgba(255, 255, 255, .045); display: grid; place-items: center; }
.slot .tok { width: 82%; height: 82%; max-width: 30px; max-height: 30px; }
.slot.over { background: rgba(226, 110, 94, .25); }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(5, 10, 8, .55); }
.sheet {
  position: relative; width: 100%; max-width: 520px; max-height: 86vh; overflow-y: auto; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: up .18s ease-out; box-shadow: 0 -10px 40px rgba(0, 0, 0, .4);
}
@media (min-width: 700px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet h3 { font: 700 19px/1.2 Georgia, serif; margin-bottom: 10px; }
.sheet p { margin: 6px 0; }
.sheet .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.sheet .actions { display: flex; gap: 8px; margin-top: 14px; }
.sheet .actions .btn { flex: 1 1 0; }
.sheet .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 12px 0 5px; }
.sheet .step { font-weight: 650; margin-top: 12px; }
.sheet .step .muted { font-weight: 400; margin-left: 6px; }
.preview { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; background: rgba(0, 0, 0, .18); border-radius: 12px; padding: 8px 10px; margin-top: 10px; }
.preview .lbl { margin: 0 !important; }
.preview .warn { flex-basis: 100%; color: var(--warn); font-size: 12.5px; }
.bigcard { display: flex; gap: 14px; align-items: center; }
.bigcard .rc, .bigcard .order { width: 88px; flex: none; cursor: default; }
.bigcard p { margin: 2px 0; }
.kind { font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.kind.k-produce { color: #9cc873; } .kind.k-upgrade { color: #86aee0; } .kind.k-trade { color: #e09a5c; }
.pick { display: flex; flex-wrap: wrap; gap: 5px; }
.pickbtn {
  width: 46px; height: 46px; border-radius: 12px; border: 0; background: var(--surface2); display: grid; place-items: center; cursor: pointer; position: relative; padding: 0;
  transition: background .12s, transform .1s;
}
.pickbtn:disabled { cursor: default; opacity: .4; }
.pickbtn.up { background: #2c4630; box-shadow: inset 0 0 0 2px var(--good); }
.pickbtn.x { background: #3d2825; box-shadow: inset 0 0 0 2px var(--bad); }
.pickbtn.hole { background: transparent; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .15); cursor: default; }
.pickbtn .badge { position: absolute; top: -5px; right: -5px; background: var(--good); color: #10240a; font-size: 10px; font-weight: 900; border-radius: 8px; padding: 0 4px; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper .val { font-size: 20px; font-weight: 800; min-width: 2.4ch; text-align: center; }
.stepper .btn { width: 44px; padding: 0; font-size: 22px; }
.scorebar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.scorebar b { color: var(--ink); font-size: 20px; }
.scorebar span { display: inline-flex; align-items: center; gap: 4px; }
.minis { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 5px; }
.minis .rc { min-height: 60px; }
.facts { padding-left: 18px; margin: 12px 0 0; font-size: 13.5px; color: var(--muted); }
.facts li { margin: 4px 0; }
.facts b { color: var(--ink); }
.log { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; font-size: 13px; }
.log li { padding: 5px 2px; border-bottom: 1px solid var(--line); color: var(--muted); }
.log li:first-child { color: var(--ink); }

.setup-sheet .field { margin: 12px 0; }
.setup-sheet .label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1 1 0; min-width: 0; min-height: 46px; border-radius: 12px; border: 0; background: var(--surface2); cursor: pointer; font-weight: 650; }
.seg button.on { background: #33463d; box-shadow: inset 0 0 0 2px var(--accent); color: #ffe7b0; }

/* ---------- modals ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(5, 10, 8, .7); display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 620px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0, 0, 0, .5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; }
.modal-head h2 { font: 700 21px/1.2 Georgia, serif; }
.modal-head .btn.ghost { background: var(--surface2); }
.modal-body { padding: 0 18px 14px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 16px 16px; }
.modal-foot .btn { flex: 1 1 120px; }
.rules h3 { font-size: 15px; color: var(--accent); margin: 16px 0 4px; }
.rules p, .rules li { color: var(--ink); }
.rules ol, .rules ul { padding-left: 20px; margin: 6px 0; }
.rules li { margin: 4px 0; }

.result-banner { font: 800 26px/1.2 Georgia, serif; margin: 0 0 12px; }
.result-banner.win { color: var(--good); }
.result-banner.lose { color: var(--ink); }
.results-wrap { overflow-x: auto; }
.results { width: 100%; border-collapse: collapse; font-size: 14px; }
.results th, .results td { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.results th:first-child, .results td:first-child { text-align: left; }
.results th { color: var(--muted); font-weight: 600; font-size: 12px; }
.results tr.me td { color: var(--accent); font-weight: 700; }
.results tr.win td:first-child::after { content: ' \2605'; color: var(--gold); }
.results .tot { font-weight: 800; }

/* ---------- desktop: shop on the left, your bench on the right ---------- */
@media (min-width: 900px) {
  .app { padding-top: 6px; }
  .chips { justify-content: center; margin: 4px auto 10px; }
  .chip { flex: 0 1 200px; }
  .status { justify-content: center; font-size: 16px; padding-bottom: 12px; }
  .status .msg { flex: 0 1 auto; }
  .board { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 32px; align-items: start; }
  .order { min-height: 108px; }
  .order .opts { font-size: 28px; }
  .rc { min-height: 96px; }
  .rc .toks { max-width: 72px; }
  .tok.md { width: 20px; height: 20px; }
  .col-right { background: var(--surface); border-radius: 18px; padding: 16px; }
  .handgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
  .rest { min-height: 96px; }
}
@media (max-width: 360px) {
  .order .opts { font-size: 19px; }
  .chip { padding: 5px 6px; gap: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .bubble { opacity: 1; }
}

/* Online play (online.js): a presence line under the status, the online rows in the menu. */
.turn-row { display: flex; flex-direction: column; }
.turn-row .net { justify-content: flex-start; margin: -4px 0 6px; padding: 0 2px; color: var(--muted); }
/* The menu has no divider above How to play, so the online rows are plain menu items. */
/* Result card online: Rematch, Leave and View board stacked. The footer's 8px flex gap is the space
   above #over-leave (a margin on top of it would double it). */
#over-rematch, #over-leave { flex-basis: 100%; }
