/* Wildwood, mossy, calm palette, fixed (the same in light and dark OS modes). */
:root {
  --bg: #eef0e4;
  --surface: #fbfbf4;
  --surface2: #e1e5d3;
  --line: rgba(40, 56, 36, .13);
  --ink: #2c3a2a;
  --muted: #6f7b69;
  --accent: #c8602e;          /* you (rust) */
  --gold: #d6a53a;
  --good: #3c8a4e;
  --bad: #b8483a;
  --h0: #4f8a57; --h1: #c9d77c; --h2: #86b9a6; --h3: #6ea8d6; --h4: #aca498;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #e2ad3c;
  --tut-accent-ink: #2c3a2a;
  --tut-bubble: #fffef8;
  --tut-ink: #2c3a2a;
  --tut-muted: #6f7b69;
  --tut-dim: rgba(30, 42, 28, .55);
  color-scheme: light;
}
* { 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; }
.muted { color: var(--muted); font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ico { width: 22px; height: 22px; display: inline-block; vertical-align: middle; flex: none; }

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

/* ---------- top bar + menu ---------- */
.topbar { display: flex; align-items: center; gap: 4px; height: 50px; }
.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(--surface2); }
.brand { flex: 1; text-align: center; font: 700 20px/1 Georgia, "Times New Roman", serif; letter-spacing: .05em; color: #3d5a36; }
.menu { position: absolute; right: 12px; top: 46px; z-index: 45; min-width: 190px; padding: 6px; background: var(--surface); border-radius: 14px; box-shadow: 0 14px 36px rgba(40, 56, 36, .22); 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: var(--surface2); }
@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; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover:not(:disabled) { background: #d4d9c3; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #b35427; }
.btn.quiet { background: transparent; }
.btn.small { min-height: 40px; padding: 4px 14px; font-size: 14px; }
.btn.icon { width: 46px; padding: 0; font-size: 20px; }

/* ---------- chips ---------- */
.chips { display: flex; gap: 6px; margin: 0 0 4px; }
.pchip { position: relative; flex: 1 1 0; min-width: 0; min-height: 48px; 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; }
.pchip.cur { box-shadow: inset 0 -3px 0 var(--pc); }
.pchip .av { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--pc); color: #fff; font-weight: 800; font-size: 14px; }
.pchip .cinfo { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; flex: 1; }
.pchip .nm { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip .line { display: flex; align-items: center; gap: 8px; }
.pchip .sc { font-size: 17px; font-weight: 800; }
.pchip .ac { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 1px; }
.pchip .ac .ico { width: 15px; height: 15px; }
.chips.n3 .nm, .chips.n4 .nm { display: none; }
.chips.n4 .pchip { gap: 5px; padding: 5px 6px; }
.chips.n4 .line, .chips.n3 .line { flex-direction: column; align-items: flex-start; gap: 0; }
.chips.n4 .pchip .av { width: 24px; height: 24px; font-size: 12px; }
.bubble { position: absolute; inset: 0; z-index: 2; border-radius: inherit; display: flex; align-items: center; justify-content: center; gap: 4px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--pc); animation: bubble 2.6s ease-out forwards; pointer-events: none; }
.bubble svg { width: 30px; height: 30px; }
@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 4px; font-size: 15px; color: var(--muted); }
.status.mine { color: var(--ink); font-weight: 600; }
.status .msg { flex: 1; min-width: 0; }
.status .turnno { flex: none; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--surface); border-radius: 8px; padding: 2px 7px; }
.status .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.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: '...'; } }

/* ---------- table ---------- */
.table { display: flex; flex-direction: column; gap: 10px; }
.map-wrap { position: relative; background: #e3e8d6; border-radius: 18px; overflow: hidden; }
.map { display: block; width: 100%; height: min(100vw - 24px, 100vh - 330px, 560px); min-height: 250px; touch-action: manipulation; }
.map .tile { cursor: default; }
.tile .edge { fill: none; stroke: rgba(40, 56, 36, .35); stroke-width: .04; }
.tile .split { stroke: rgba(255, 255, 255, .55); stroke-width: .04; }
.map .spot { fill: rgba(255, 255, 255, .35); stroke: #fff; stroke-width: .06; stroke-dasharray: .16 .12; cursor: pointer; }
.map .spot.sel { fill: rgba(255, 255, 255, .6); }
.map .spot.idle { fill: rgba(255, 255, 255, .12); stroke: rgba(255, 255, 255, .45); cursor: default; }
.map .preview { opacity: .9; cursor: pointer; }
.map .preview-edge { fill: none; stroke: var(--accent); stroke-width: .1; }
.map .ring { fill: rgba(255, 255, 255, .18); stroke: var(--accent); stroke-width: .12; animation: ringpulse 1.2s ease-in-out infinite; }
.map .hit { fill: transparent; cursor: pointer; }
.map .new-edge { fill: none; stroke: var(--pc, #fff); stroke-width: .09; }
.tile .slotbg { fill: rgba(255, 255, 255, .72); }
.tile .haven { fill: none; stroke: var(--gold); stroke-width: .07; }
@keyframes ringpulse { 0%, 100% { stroke-opacity: .95; } 50% { stroke-opacity: .35; } }

/* market */
.market { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.pair { border: 0; padding: 6px 2px 6px; border-radius: 14px; background: var(--surface); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; transition: box-shadow .2s, transform .15s, opacity .2s; }
.pair svg.mtile { width: 100%; max-width: 70px; height: 62px; }
.pair .tok { width: 36px; height: 36px; display: block; }
.pair .tok.none { visibility: hidden; }
.pair.sel { box-shadow: 0 0 0 3px var(--accent); transform: translateY(-2px); }
.pair.ai-pick { box-shadow: 0 0 0 3px var(--pc), 0 0 14px 2px var(--pc); transform: translateY(-3px); }
.pair.idle { cursor: default; }
.pair .part { border: 0; background: none; padding: 0; border-radius: 10px; cursor: pointer; display: grid; place-items: center; width: 100%; }
.pair .part.on { box-shadow: 0 0 0 3px var(--accent); }
.pair.wipe-on .tok { opacity: .35; }
.pair.fresh { animation: arrive .45s ease-out; }
@keyframes arrive { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

.actions-row { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; min-height: 48px; }
.actions-row .btn { flex: 0 1 auto; }
.actions-row .grow { flex: 1 1 auto; }
.acorn-btn .ico { width: 20px; height: 20px; }

/* ---------- 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(40, 56, 36, .35); }
.sheet { position: relative; width: 100%; max-width: 560px; max-height: 88vh; 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(40, 56, 36, .2); }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet h3 { font: 700 19px/1.2 Georgia, serif; margin-bottom: 8px; color: #3d5a36; }
.sheet p { margin: 6px 0; }
.sheet .actions { display: flex; gap: 8px; margin-top: 14px; }
.sheet .actions .btn { flex: 1 1 0; white-space: nowrap; }
.sheet .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 12px 0 5px; }
.sheet .map { height: min(80vw, 46vh); background: #e3e8d6; border-radius: 14px; }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 12px; margin-top: 8px; border: 0; border-radius: 14px; background: var(--surface2); cursor: pointer; text-align: left; }
.opt b { display: block; }
.opt small { color: var(--muted); }
.opt:disabled { opacity: .45; cursor: not-allowed; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.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, .log li.mine { 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: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); color: var(--accent); }

/* score table */
.table-wrap { overflow-x: auto; }
.scores { width: 100%; border-collapse: collapse; font-size: 14px; }
.scores th, .scores td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.scores th:first-child, .scores td:first-child { text-align: left; }
.scores thead th { color: var(--muted); font-size: 12px; font-weight: 600; }
.scores td .ico { width: 18px; height: 18px; margin-right: 4px; }
.scores tr.tot td { font-weight: 900; font-size: 15px; border-bottom: 0; }
.scores td.me, .scores th.me { color: var(--accent); }
.scores small { color: var(--muted); font-size: 11px; }
.hb { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin: 0 3px -1px 2px; }
.hb.h0 { background: var(--h0); } .hb.h1 { background: var(--h1); } .hb.h2 { background: var(--h2); } .hb.h3 { background: var(--h3); } .hb.h4 { background: var(--h4); }

/* ---------- modals ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(40, 56, 36, .4); display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 640px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(40, 56, 36, .3); }
.over-modal { max-width: 480px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.modal-head h2 { font: 700 21px/1.2 Georgia, serif; color: #3d5a36; }
.modal-body { padding: 0 18px 14px; overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 16px; }
.modal-foot .btn { flex: 1 1 110px; }
.rules h3 { font-size: 15px; margin: 16px 0 4px; color: #3d5a36; font-family: Georgia, serif; }
.rules p, .rules li { font-size: 14px; }
.rules ol, .rules ul { padding-left: 20px; margin: 4px 0; }
.rules li { margin: 4px 0; }
.animal-rules { list-style: none; padding-left: 0 !important; }
.animal-rules li { display: flex; gap: 10px; align-items: flex-start; }
.animal-rules .ico { width: 30px; height: 30px; }
.result-banner { font: 800 26px/1.2 Georgia, serif; margin: 0 0 8px; }
.result-banner.win { color: var(--accent); }

/* ---------- wider screens ---------- */
@media (min-width: 900px) {
  .chips { justify-content: center; margin: 4px auto 6px; }
  .pchip { flex: 0 1 210px; }
  .status { justify-content: center; font-size: 16px; }
  .status .msg { flex: 0 1 auto; }
  .table { flex-direction: row; align-items: flex-start; gap: 20px; }
  .map-wrap { flex: 1 1 auto; }
  .map { height: min(72vh, 640px); }
  .side { flex: 0 0 340px; display: flex; flex-direction: column; gap: 12px; }
  .market { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pair svg.mtile { max-width: 90px; height: 78px; }
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 20px; }
}
.side { display: flex; flex-direction: column; gap: 8px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- online play (online.js): a presence line under the status, in the same row ---------- */
.status-row { display: flex; flex-direction: column; min-width: 0; }
.status-row .net { color: var(--muted); justify-content: flex-start; padding: 0 2px 4px; margin-top: -2px; }
@media (min-width: 900px) { .status-row .net { justify-content: center; } }
body.is-online #menu-new { display: none; }
/* The online row sits above How to play and carries the menu's one divider (online, Leave is the
   first row, so it has none). */
.menu #menu-online { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; margin-top: 4px; }
/* Leave takes its own row under Rematch / View map; the footer's 8px gap is the space above it. */
#over-leave { flex: 1 1 100%; margin-top: 0; }
