/* Night Market: lantern-lit bazaar theme. Fixed palette (ignores OS dark/light). Calm: few borders, one accent. */
:root {
  --night: #15112a;
  --surface: #211b42;
  --surface2: #2c2555;
  --line: rgba(255, 255, 255, .09);
  --ink: #f6eedd;
  --muted: #a99fc6;
  --faint: #6f6696;
  --glow: #ffb347;           /* "your action" */
  --glow-ink: #2a1604;
  --rival: #6fc3e0;
  --seal: #d6434c;
  --good-ink: #1b1530;
  --ok: #8fe3b2;
  --bad: #ff9a8a;

  --pearl-1: #f4f7ff;  --pearl-2: #9fb2e3;
  --amber-1: #ffd98a;  --amber-2: #e59422;
  --jade-1: #a6f0cf;   --jade-2: #2fa877;
  --silk-1: #ffb3d1;   --silk-2: #d3467f;
  --incense-1: #d9c8ff; --incense-2: #8a66d6;
  --lantern-1: #ffb08f; --lantern-2: #e0502b;
  --porter-1: #ecd3a8; --porter-2: #a9804a;

  /* tutorial kit (tutorial.css) */
  --tut-accent: #ffb347;
  --tut-accent-ink: #2a1604;
  --tut-bubble: #f6eedd;
  --tut-ink: #1b1530;
  --tut-muted: #5d5480;
  --tut-dim: rgba(8, 6, 22, .64);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--night); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(ellipse 90% 40% at 50% -10%, rgba(255, 170, 70, .16), transparent 70%), var(--night);
  background-attachment: fixed;
  font: 15px/1.35 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; cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--glow); outline-offset: 2px; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- layout ---------- */
#app {
  position: relative;
  max-width: 560px; margin: 0 auto;
  padding: 0 12px calc(16px + env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 12px;
}
.topbar { display: flex; align-items: center; gap: 4px; height: 52px; }
.back, .iconbtn {
  width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px; flex: none;
  color: var(--muted); text-decoration: none; font-size: 22px; background: none; border: 0; padding: 0;
}
.back:hover, .iconbtn:hover, .iconbtn[aria-expanded="true"] { color: var(--ink); background: var(--surface); }
.title {
  flex: 1; margin: 0; text-align: center; font-size: 19px; letter-spacing: .05em; font-weight: 700;
  color: #ffe2b0; text-shadow: 0 0 14px rgba(255, 170, 70, .45);
}
.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, .55);
  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; font-weight: 600; }
.menu button:hover, .menu button:focus-visible { background: rgba(255, 255, 255, .07); }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- player chips ---------- */
.chips { display: flex; gap: 8px; }
.pchip {
  position: relative; flex: 1 1 0; min-width: 0; min-height: 50px; display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border: 0; border-radius: 14px; background: var(--surface); text-align: left;
  transition: box-shadow .2s;
}
.pchip.you { --pc: var(--glow); }
.pchip.rival { --pc: var(--rival); }
.pchip.cur { box-shadow: inset 0 -3px 0 var(--pc); }
.pchip .av { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--pc); color: var(--good-ink); font-weight: 800; font-size: 14px; }
.pchip .cinfo { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.15; }
.pchip .nm { font-size: 12px; color: var(--muted); }
.pchip .line { display: flex; align-items: center; gap: 10px; }
.coinv { display: inline-flex; align-items: center; gap: 5px; font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.handn { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.coin-ico { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff1c2, #e0a02a 70%); flex: none; }
.back-ico { display: inline-block; width: 9px; height: 13px; border-radius: 2px; background: linear-gradient(160deg, #4a3c94, #2a2160); box-shadow: inset 0 0 0 1px #7a6bc8; }
.seals { display: inline-flex; gap: 4px; flex: none; }
.seal { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--faint); }
.seal.won { box-shadow: 0 0 8px rgba(214, 67, 76, .6); background: radial-gradient(circle at 40% 35%, #f07078, var(--seal) 60%, #7c1820); }
.bubble {
  position: absolute; inset: 0; z-index: 2; border-radius: inherit;
  display: flex; align-items: center; justify-content: center; gap: 4px; padding: 3px 8px;
  background: var(--surface2); box-shadow: inset 0 0 0 2px var(--pc);
  animation: bubble 2.6s ease-out forwards; pointer-events: none; font-size: 13px;
}
.bubble .verb { color: var(--pc); font-weight: 700; margin: 0 3px; }
.bubble b { font-size: 12px; }
.bubble .plus { color: #ffe2a0; font-weight: 800; margin-left: 4px; }
@keyframes bubble { 0% { opacity: 0; transform: scale(.92); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
.mini {
  display: inline-grid; place-items: center; width: 20px; height: 26px; border-radius: 4px; flex: none; vertical-align: middle;
  background: linear-gradient(165deg, var(--c1), var(--c2));
}
.mini .ico { width: 17px; height: 17px; }

/* ---------- status ---------- */
.hint { min-height: 22px; font-size: 15px; color: var(--muted); padding: 0 2px; }
.hint.mine { color: var(--ink); font-weight: 600; }
.hint.bad { color: var(--bad); font-weight: 600; }
.hint.ok { color: var(--ok); }

/* ---------- goods colours ---------- */
[data-good="pearl"]   { --c1: var(--pearl-1);   --c2: var(--pearl-2); }
[data-good="amber"]   { --c1: var(--amber-1);   --c2: var(--amber-2); }
[data-good="jade"]    { --c1: var(--jade-1);    --c2: var(--jade-2); }
[data-good="silk"]    { --c1: var(--silk-1);    --c2: var(--silk-2); }
[data-good="incense"] { --c1: var(--incense-1); --c2: var(--incense-2); }
[data-good="lantern"] { --c1: var(--lantern-1); --c2: var(--lantern-2); }
[data-good="porter"]  { --c1: var(--porter-1);  --c2: var(--porter-2); }

/* ---------- coin piles ---------- */
.piles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.pile {
  display: flex; align-items: center; justify-content: center; gap: 5px; min-height: 48px; min-width: 0;
  padding: 4px 2px; border: 0; border-radius: 12px; background: var(--surface); transition: box-shadow .3s;
}
.pile .pico { width: 24px; height: 32px; flex: none; border-radius: 5px; display: grid; place-items: center; background: linear-gradient(165deg, var(--c1), var(--c2)); }
.pile .pico .ico { width: 22px; height: 22px; display: block; }
.pile .coin { min-width: 20px; font-weight: 800; font-size: 17px; color: var(--ink); font-variant-numeric: tabular-nums; text-align: center; }
.pile.empty { opacity: .35; }
.pile.empty .coin { display: none; }
.pile.flash { animation: pileFlash 1.2s ease-out; }
.pile.ai-pick { box-shadow: 0 0 0 2px var(--rival), 0 0 14px var(--rival); }
@keyframes pileFlash { 0% { box-shadow: 0 0 0 2px var(--glow), 0 0 14px var(--glow); } 100% { box-shadow: none; } }

/* ---------- cards ---------- */
.card {
  position: relative; padding: 0; margin: 0;
  display: grid; place-items: center;
  border-radius: 10px; border: 0;
  background: linear-gradient(165deg, var(--c1) 0%, var(--c2) 100%);
  color: var(--good-ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s;
}
.card .ico { width: 64%; height: auto; max-height: 60%; display: block; }
.card:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.card.sel { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--glow), 0 0 16px 2px rgba(255, 179, 71, .7); }
.card.dim { opacity: .4; }
.card.ai-pick { transform: translateY(-6px); box-shadow: 0 0 0 3px var(--rival), 0 0 18px 3px rgba(111, 195, 224, .8); }
.card.fresh { animation: fresh 1s ease-out; }
@keyframes fresh { 0% { transform: translateY(-14px); opacity: 0; } 100% { transform: none; opacity: 1; } }

.market { display: flex; justify-content: center; gap: 8px; padding: 10px 0 4px; }
.market .card { flex: 1 1 0; max-width: 92px; min-width: 0; aspect-ratio: 5 / 7; }
.market .slot-empty { flex: 1 1 0; max-width: 92px; aspect-ratio: 5 / 7; border-radius: 10px; box-shadow: inset 0 0 0 2px var(--line); }

/* your stall */
.stall { display: flex; align-items: flex-end; gap: 10px; padding: 16px 12px 12px; border-radius: 16px; background: var(--surface); min-height: 108px; }
.herd {
  position: relative; flex: none; width: 56px; height: 78px; padding: 0; border: 0; border-radius: 10px;
  background: linear-gradient(165deg, var(--porter-1), var(--porter-2)); box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
  display: grid; place-items: center; transition: box-shadow .15s, transform .15s;
}
.herd .herd-card { width: 70%; display: grid; place-items: center; }
.herd .herd-card svg { width: 100%; }
.herd-n {
  position: absolute; top: -8px; right: -8px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px;
  background: var(--night); color: var(--ink); font-size: 12px; font-weight: 800; display: grid; place-items: center; box-shadow: 0 0 0 2px var(--surface);
}
.herd-sel { position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 800; color: var(--glow-ink); background: var(--glow); border-radius: 8px; padding: 0 5px; }
.herd-sel:empty { display: none; }
.herd.target { box-shadow: 0 0 0 2px rgba(255, 179, 71, .55), 0 3px 0 rgba(0, 0, 0, .35); }
.herd.sel { transform: translateY(-6px); box-shadow: 0 0 0 3px var(--glow), 0 0 14px rgba(255, 179, 71, .6); }
.herd.none { opacity: .35; }
.herd:disabled { cursor: default; }

.hand { flex: 1; display: flex; align-items: flex-end; gap: 4px; min-height: 70px; min-width: 0; padding-left: 8px; box-shadow: inset 1px 0 0 var(--line); }
.hand .card { flex: 0 1 54px; min-width: 30px; height: 78px; }
.hand .card.grp-more { margin-left: -14px; }
.hand .card.grp-more.sel, .hand .card.sel + .card.grp-more { margin-left: -6px; }
.hand-empty { color: var(--faint); font-size: 13px; align-self: center; }

/* actions: only the moves your selection allows are shown */
.actions { display: flex; gap: 8px; min-height: 52px; }
.act {
  flex: 1 1 0; min-height: 52px; padding: 4px 8px; border-radius: 14px; font-weight: 700; font-size: 15px; line-height: 1.1;
  background: var(--glow); color: var(--glow-ink); border: 0; box-shadow: 0 3px 0 #9a5a12;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform .1s; animation: pop .15s ease-out;
}
.act small { font-size: 11px; font-weight: 600; opacity: .8; }
.act:active { transform: translateY(2px); box-shadow: 0 1px 0 #9a5a12; }
.act-clear { flex: none; width: 52px; min-height: 52px; border-radius: 14px; border: 0; background: var(--surface); color: var(--muted); font-size: 24px; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(8, 6, 20, .72);
  animation: fadeIn .2s ease-out;
}
.overlay.sheety { align-items: flex-end; padding: 0; }
.overlay.sheety .panel { max-width: 520px; border-radius: 20px 20px 0 0; max-height: 86vh; padding-bottom: calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.panel {
  position: relative; width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--surface); border-radius: 18px;
  padding: 18px 18px 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, .6);
}
.panel h2 { margin: 2px 0 10px; font-size: 20px; color: #ffe2b0; }
.panel h3 { margin: 16px 0 6px; font-size: 14px; color: #ffd28a; }
.panel p, .panel li { font-size: 14px; }
.panel ul, .panel ol { padding-left: 20px; margin: 6px 0; }
.panel li { margin: 3px 0; }
.lede { color: var(--muted); margin: 4px 0 12px; }
.panel-lanterns { display: flex; justify-content: center; gap: 18px; }
.panel-lanterns i { width: 16px; height: 22px; border-radius: 45%; background: radial-gradient(circle at 50% 40%, #ffe3a3, #ff7a3d 70%); box-shadow: 0 0 16px 4px rgba(255, 150, 60, .5); }
.panel-lanterns i:nth-child(2) { background: radial-gradient(circle at 50% 40%, #ffd0e0, #d3467f 70%); box-shadow: 0 0 16px 4px rgba(230, 80, 140, .45); transform: translateY(6px); }
.field-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 6px 0; }
.diff-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.diff {
  min-height: 64px; padding: 10px 12px; border-radius: 14px; text-align: left;
  background: var(--surface2); border: 0; display: flex; flex-direction: column; gap: 3px;
}
.diff b { font-size: 16px; }
.diff small { color: var(--muted); font-size: 12px; }
.diff.on { box-shadow: inset 0 0 0 2px var(--glow); }
.diff.on b { color: #ffd28a; }
.panel-buttons { display: flex; gap: 8px; margin-top: 16px; }
.panel-buttons > button { flex: 1 1 0; }
.primary, .secondary { min-height: 46px; padding: 0 18px; border-radius: 12px; font-weight: 700; font-size: 15px; border: 0; }
.primary { background: var(--glow); color: var(--glow-ink); }
.secondary { background: var(--surface2); color: var(--ink); }
.secondary.small { min-height: 40px; font-size: 14px; padding: 0 14px; }
.panel-scroll { max-width: 520px; }
.goods-list { list-style: none; padding: 0 !important; display: grid; gap: 6px; }
.goods-list li { display: flex; align-items: center; gap: 10px; margin: 0; }
.goods-list .card { width: 34px; height: 46px; flex: none; border-radius: 6px; }

.minirow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.coins { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.coins .coin { min-width: 30px; height: 30px; border-radius: 15px; display: grid; place-items: center; font-weight: 800; color: var(--good-ink); background: linear-gradient(165deg, var(--c1), var(--c2)); }
.stat-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.stat-table td { padding: 8px 2px; border-bottom: 1px solid var(--line); }
.stat-table td:last-child { text-align: right; font-weight: 700; }
.stat-table .mini { width: 16px; height: 21px; margin-right: 4px; }
.pile-list { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.pile-list > div { display: flex; align-items: center; gap: 8px; }
.facts { color: var(--muted); }
.log { display: flex; flex-direction: column; max-height: 220px; overflow-y: auto; font-size: 13px; }
.log .line { padding: 5px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.log .line:first-child { color: var(--ink); }
.log .line.rival { color: #bfe6f3; }

.table-wrap { overflow-x: auto; }
.score-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.score-table th, .score-table td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.score-table th:first-child, .score-table td:first-child { text-align: left; color: var(--muted); font-weight: 500; }
.score-table thead th { color: #ffd28a; }
.score-table tr.total td { font-weight: 800; font-size: 16px; color: var(--ink); border-bottom: 0; }
.score-table td.win { color: var(--glow); }
.summary-note { font-size: 13px; color: var(--muted); }
.final-seals { display: flex; justify-content: center; gap: 22px; margin: 6px 0 10px; font-weight: 700; }
.final-seals > div { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.final-seals .seal { width: 20px; height: 20px; }
.round-list { font-size: 13px; color: var(--muted); }
#summary .panel h2, #final .panel h2 { text-align: center; }
#final .lede, #summary .lede { text-align: center; }

@media (min-width: 520px) {
  .title { font-size: 21px; }
  .hand .card { height: 86px; flex-basis: 60px; }
  .herd { width: 62px; height: 86px; }
  .overlay.sheety { align-items: center; padding: 16px; }
  .overlay.sheety .panel { border-radius: 18px; }
}
@media (min-width: 900px) {
  #app { max-width: 620px; gap: 14px; }
  .chips, .hint { max-width: 620px; }
  .hint { text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- online (a table with a friend: tables.js) ---------- */
/* a short notice (connection lost, the table was updated, the friend left) floats over the hint line for a
   few seconds, so the board never moves */
.status { position: relative; }
.net-note { position: absolute; left: 50%; top: -3px; transform: translateX(-50%); z-index: 6; width: max-content; max-width: min(88vw, 360px);
  padding: 4px 12px; border-radius: 12px; background: var(--ink); color: var(--night); font-size: 12.5px; font-weight: 700; line-height: 1.3; text-align: center;
  white-space: normal; box-shadow: 0 4px 14px rgba(0, 0, 0, .45); pointer-events: none; animation: fadeIn .25s ease-out; }
/* a friend whose page stopped checking in */
.pchip.away .av { opacity: .5; }
.pchip .aw { font-style: italic; color: var(--faint); }
/* one divider above the online rows */
.menu #menu-online, .menu #menu-leave { margin-top: 4px; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
.link { display: block; margin: 10px auto 0; min-height: 40px; padding: 0 14px; border: 0; background: none; color: var(--muted); font-weight: 600; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
