/* Harbor Lights, calm seaside palette, fixed (the same in light and dark OS modes). */
:root {
  --bg: #eef0ea;
  --surface: #fbfaf5;
  --surface2: #e2e6df;
  --line: rgba(35, 55, 74, .12);
  --ink: #23374a;
  --muted: #6f7e8a;
  --accent: #e0674a;          /* you (coral) */
  --gold: #d9a23a;
  --good: #2f8a55;
  --bad: #c0433a;
  --blue: #3f7fc0;
  --green: #3f9160;
  --red: #cf4f3f;
  --purple: #8558bd;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #e8a93a;
  --tut-accent-ink: #23374a;
  --tut-bubble: #fffdf7;
  --tut-ink: #23374a;
  --tut-muted: #6f7e8a;
  --tut-dim: rgba(28, 44, 60, .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: 24px; height: 24px; display: inline-block; vertical-align: middle; flex: none; }
.coin-i { width: 15px; height: 15px; vertical-align: -2px; }

.app { position: relative; max-width: 1080px; margin: 0 auto; padding: 0 12px 20px; 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: .04em; color: #2b4a66; }
.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(35, 55, 74, .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; }
.btn:hover:not(:disabled) { background: #d6dcd3; }
.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: #cc5539; }
.btn.quiet { background: transparent; }
.btn.small { min-height: 40px; padding: 4px 14px; font-size: 14px; }

/* ---------- player 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: 7px; }
.pchip .co { font-size: 17px; font-weight: 800; display: inline-flex; align-items: center; gap: 3px; }
.lmpips { display: inline-flex; gap: 3px; }
.lmpips i { width: 8px; height: 8px; border-radius: 2px; background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); opacity: .55; }
.lmpips i.on { background: var(--gold); box-shadow: none; opacity: 1; }
.chips.n4 .nm, .chips.n3 .nm { display: none; }
.chips.n4 .pchip { gap: 5px; padding: 5px 6px; }
.chips.n4 .line { flex-direction: column; align-items: flex-start; gap: 2px; }
.float { position: absolute; right: 6px; top: -8px; z-index: 3; padding: 1px 7px; border-radius: 10px; font-size: 13px; font-weight: 800; color: #fff; background: var(--good); pointer-events: none; animation: floatup 2.2s ease-out forwards; }
.float.neg { background: var(--bad); }
@keyframes floatup { 0% { opacity: 0; transform: translateY(4px); } 12% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-6px); } }
.bubble { position: absolute; inset: 0; z-index: 2; border-radius: inherit; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 3px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--pc); animation: bubble 2.6s ease-out forwards; pointer-events: none; font-size: 13px; font-weight: 700; color: var(--pc); }
.bubble .ico { width: 22px; height: 22px; }
.chips.n3 .bubble .verb, .chips.n4 .bubble .verb { display: none; }
@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.mine { color: var(--ink); font-weight: 600; }
.status .msg { flex: 1; min-width: 0; }
.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: grid; grid-template-columns: 1fr; gap: 12px; }
.col-a, .col-b { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* dice tray */
.tray { display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 8px 10px; border-radius: 16px; background: #d9e7ec; }
.dice { display: flex; align-items: center; gap: 8px; flex: none; min-width: 44px; }
.die { width: 42px; height: 42px; border-radius: 9px; background: #fffdf8; box-shadow: 0 2px 0 rgba(35, 55, 74, .18), inset 0 0 0 2px var(--dc, transparent); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 6px; }
.die i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink); place-self: center; visibility: hidden; }
.die i.on { visibility: visible; }
.die.ghost { opacity: .35; box-shadow: none; }
.die.roll { animation: tumble .45s ease-out; }
@keyframes tumble { 0% { transform: rotate(-40deg) scale(.7); opacity: .3; } 70% { transform: rotate(8deg) scale(1.05); } 100% { transform: none; } }
.tray-btns { flex: 1; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; min-width: 0; }
.tray-btns .btn { flex: 0 1 auto; white-space: nowrap; }
.tray-note { flex: 1; text-align: right; font-size: 13px; color: var(--muted); }
.tray-sum { font: 800 22px/1 Georgia, serif; color: #2b4a66; min-width: 26px; text-align: center; }

/* market */
.market { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.card { position: relative; border: 0; padding: 0; background: var(--surface); border-radius: 11px; cursor: pointer; display: flex; flex-direction: column; min-width: 0; overflow: hidden; box-shadow: 0 1px 2px rgba(35, 55, 74, .12); transition: transform .15s, box-shadow .2s, opacity .2s; text-align: center; }
.card .band { background: var(--kc); color: #fff; font-weight: 800; font-size: 14px; line-height: 20px; height: 20px; letter-spacing: .02em; }
.card.blue { --kc: var(--blue); } .card.green { --kc: var(--green); } .card.red { --kc: var(--red); } .card.purple { --kc: var(--purple); }
.card .pic { display: grid; place-items: center; padding-top: 4px; }
.card .pic .ico { width: 28px; height: 28px; }
.card .cname { font-size: 10.5px; font-weight: 650; line-height: 1.15; padding: 2px 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
.card .cfoot { display: flex; justify-content: space-between; align-items: center; padding: 2px 5px 4px; font-size: 12px; }
.card .cost { font-weight: 800; display: inline-flex; align-items: center; gap: 2px; }
.card .left { color: var(--muted); font-size: 11px; }
.card.dim { opacity: .5; }
.card.dim .cost { color: var(--bad); }
.card.out { opacity: .38; }
.card.ai-pick { box-shadow: 0 0 0 3px var(--pc), 0 0 14px 2px var(--pc) !important; transform: translateY(-3px); }
.card:hover { transform: translateY(-1px); }

/* your harbor */
.town { background: var(--surface); border-radius: 16px; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.town.turn { box-shadow: inset 0 0 0 2px rgba(224, 103, 74, .35); }
.landmarks { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.lm { border: 0; border-radius: 12px; padding: 5px 2px 4px; cursor: pointer; background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 0; min-height: 60px; transition: box-shadow .2s, background .2s; }
.lm .lpic { width: 26px; height: 26px; opacity: .45; filter: grayscale(.6); }
.lm .lname { font-size: 11px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; color: var(--muted); }
.lm .lcost { font-size: 12px; font-weight: 800; display: inline-flex; align-items: center; gap: 2px; color: var(--muted); }
.lm.built { background: #f7e7bf; box-shadow: none; }
.lm.built .lpic { opacity: 1; filter: none; }
.lm.built .lname { color: var(--ink); }
.lm.can { box-shadow: inset 0 0 0 2.5px var(--accent); }
.lm.can .lcost { color: var(--accent); }
.lm.ai-pick { box-shadow: 0 0 0 3px var(--pc), 0 0 14px 2px var(--pc); }
.buildings { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.bld { position: relative; border: 0; padding: 0 0 3px; background: var(--bg); border-radius: 9px; overflow: hidden; display: flex; flex-direction: column; align-items: center; cursor: pointer; min-height: 48px; transition: box-shadow .2s, transform .2s; }
.bld .band { width: 100%; height: 14px; line-height: 14px; font-size: 11px; font-weight: 800; color: #fff; background: var(--kc); text-align: center; }
.bld.blue { --kc: var(--blue); } .bld.green { --kc: var(--green); } .bld.red { --kc: var(--red); } .bld.purple { --kc: var(--purple); }
.bld .ico { width: 22px; height: 22px; margin-top: 3px; }
.bld .n { position: absolute; right: 4px; bottom: 3px; font-size: 12px; font-weight: 800; }
.bld.lit { box-shadow: 0 0 0 2.5px var(--gold), 0 0 12px 1px rgba(217, 162, 58, .7); transform: translateY(-2px); }
.bld.lit.lose { box-shadow: 0 0 0 2.5px var(--bad); }

/* ---------- 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(35, 55, 74, .35); }
.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(35, 55, 74, .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: #2b4a66; }
.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; }
.bigcard { display: flex; gap: 14px; align-items: center; }
.bigcard .card { width: 84px; flex: none; cursor: default; }
.bigcard .card .pic .ico { width: 34px; height: 34px; }
.bc-info p { margin: 3px 0; }
.why { color: var(--muted); font-size: 13px; text-align: center; }
.tag { display: inline-block; padding: 0 7px; border-radius: 6px; color: #fff; font-size: 12px; font-weight: 700; line-height: 18px; }
.tag.blue { background: var(--blue); } .tag.green { background: var(--green); } .tag.red { background: var(--red); } .tag.purple { background: var(--purple); }
.owners { width: 100%; border-collapse: collapse; font-size: 14px; }
.owners td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.owners td:last-child { text-align: right; font-weight: 700; }
.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: 240px; 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); }
.mini-town .landmarks { margin-bottom: 8px; }
.mini-town .lm { cursor: default; }
.mini-town .bld { cursor: default; }

/* ---------- modals ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(35, 55, 74, .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(35, 55, 74, .3); }
.over-modal { max-width: 460px; }
.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: #2b4a66; }
.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: #2b4a66; 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; }
.table-wrap { overflow-x: auto; }
.cardlist { width: 100%; border-collapse: collapse; font-size: 13px; }
.cardlist td { padding: 5px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.cardlist td.r { font-weight: 800; white-space: nowrap; }
.cardlist td.c { white-space: nowrap; font-weight: 700; }
.cardlist .ico { width: 20px; height: 20px; }
.result-banner { font: 800 26px/1.2 Georgia, serif; margin: 0 0 12px; }
.result-banner.win { color: var(--accent); }
.results { width: 100%; border-collapse: collapse; font-size: 14px; }
.results th, .results td { padding: 7px 4px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.results th:first-child, .results td:first-child { text-align: left; }
.results th { color: var(--muted); font-size: 12px; font-weight: 600; }
.results tr.me td { font-weight: 700; color: var(--accent); }
.results tr.win td:first-child::after { content: ' \2605'; color: var(--gold); }

/* ---------- wider screens ---------- */
@media (min-width: 560px) {
  .card .pic .ico { width: 34px; height: 34px; }
  .card .cname { font-size: 12px; }
}
@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 { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 24px; align-items: start; }
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 20px; }
}
@media (max-width: 420px) {
  .card .cname { font-size: 10px; letter-spacing: -.025em; padding: 2px 1px 0; }
}
@media (max-width: 360px) {
  .card .pic .ico { width: 24px; height: 24px; }
  .card .cname { font-size: 9.5px; }
  .die { width: 38px; height: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 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 town 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%; }
