:root {
  --felt: #14532d;
  --felt-2: #166534;
  --felt-3: #1d7a42;
  --ink: #1f2328;
  --paper: #fffdf7;
  --text: #f4f7f2;
  --muted: #b7d3c0;
  --gold: #f5c542;
  --danger: #e03131;
  --radius: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--felt);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100%;
}

button {
  font: inherit;
  border: 0;
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
button.secondary { background: rgba(255,255,255,.14); color: var(--text); }
button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: .45; }
button.big { width: 100%; padding: 16px; font-size: 18px; }
button.big + button.big { margin-top: 8px; }

input {
  font: inherit;
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  border: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 18px;
}

/* ---------- home & lobby ---------- */
.home, .lobby {
  max-width: 420px;
  margin: 0 auto;
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.home h1, .lobby h1 { margin: 0; font-size: 34px; text-align: center; }
.home .sub { margin: 0 0 12px; text-align: center; color: var(--muted); }
.home label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.or { text-align: center; color: var(--muted); margin-top: 10px; }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 700; }
.join-row button { flex: 0 0 auto; }

.code {
  text-align: center;
  font-size: 56px;
  font-weight: 800;
  letter-spacing: 10px;
  background: rgba(0,0,0,.2);
  border-radius: var(--radius);
  padding: 10px;
}
.lobby .hint { text-align: center; color: var(--muted); margin: 0; }
.invite { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.2); border-radius: var(--radius); padding: 6px 6px 6px 14px; }
.invite a { flex: 1; min-width: 0; color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.icon { flex: 0 0 auto; padding: 8px; line-height: 0; }
.qr { align-self: center; width: 140px; padding: 6px; background: #fff; border-radius: var(--radius); line-height: 0; }
.qr svg { width: 100%; height: auto; }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plist li { background: rgba(255,255,255,.08); border-radius: var(--radius); padding: 12px 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.plist li .remove { margin-left: auto; padding: 6px 12px; font-size: 13px; }

/* ---------- game layout ---------- */
.game { display: flex; flex-direction: column; min-height: 100dvh; padding-bottom: 210px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--felt-2);
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  font-size: 14px;
}
.topbar .turn { flex: 1; font-weight: 700; font-size: 15px; }
.topbar button { padding: 6px 10px; font-size: 13px; }

.section { padding: 10px 16px 0; }
.section h2 { margin: 6px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }

.opp {
  background: rgba(0,0,0,.18);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 2px solid transparent;
}
.opp.active { border-color: var(--gold); }
.opp-head { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.opp-head b { flex: 1; font-size: 16px; }
.offline { color: #ffb4b4; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chip {
  font-size: 12px; font-weight: 700; color: #fff;
  padding: 2px 8px; border-radius: 99px;
  text-shadow: 0 1px 1px rgba(0,0,0,.4);
}
.chip.full { outline: 2px solid var(--gold); }

.banner {
  margin: 10px 16px 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(245,197,66,.18);
  border: 1px solid rgba(245,197,66,.5);
  font-size: 14px;
}

.groups { display: flex; flex-wrap: wrap; gap: 8px; }
.group {
  background: rgba(0,0,0,.18);
  border-radius: var(--radius);
  padding: 6px;
  border-top: 5px solid var(--c);
}
.group.full { box-shadow: 0 0 0 2px var(--gold); }
.group .gh { font-size: 11px; font-weight: 700; margin-bottom: 4px; white-space: nowrap; }
.group .gcards { display: flex; gap: 3px; }
.empty { color: var(--muted); font-size: 14px; }

.bankrow { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.bankrow .total { font-weight: 800; margin-right: 6px; color: var(--gold); }
.coin {
  font-size: 12px; font-weight: 700; padding: 3px 7px; border-radius: 6px;
  background: #d8f0d2; color: #1b4d1b;
}

/* ---------- hand dock ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: var(--felt-2);
  box-shadow: 0 -3px 10px rgba(0,0,0,.3);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
}
.dock .status { display: flex; align-items: center; gap: 10px; padding: 0 16px 8px; font-size: 14px; }
.dock .status span { flex: 1; font-weight: 700; }
.dock .status button { padding: 8px 14px; }
.dock .status .over { color: var(--gold); }
.hand { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 6px; scroll-snap-type: x proximity; }
.hand .card { flex: 0 0 auto; scroll-snap-align: start; }

/* ---------- cards ---------- */
.card {
  position: relative;
  width: 84px; height: 118px;
  background: var(--paper);
  color: var(--ink);
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,.35);
  overflow: hidden;
  display: flex; flex-direction: column;
  font-size: 11px;
  cursor: pointer;
  user-select: none;
}
.card .band {
  min-height: 34px;
  padding: 4px 5px;
  color: #fff;
  font-weight: 800;
  font-size: 11px;
  line-height: 1.1;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  display: flex; align-items: flex-end;
}
.card .body { flex: 1; padding: 4px 5px; display: flex; flex-direction: column; gap: 2px; }
.card .title { font-weight: 800; font-size: 12px; line-height: 1.1; }
.card .text { font-size: 9.5px; color: #555; line-height: 1.15; }
.card .val {
  position: absolute; right: 4px; bottom: 4px;
  font-weight: 800; font-size: 11px;
  background: #e8f5e3; color: #1b4d1b; border-radius: 99px; padding: 1px 5px;
}
.card .rentlist { font-size: 9px; color: #444; }
.card.k-money { background: #e2f3dc; }
.card.k-money .big { font-size: 26px; font-weight: 900; color: #1b4d1b; margin: auto; }
.card.k-action .band { background: #3b2f6b; }
.card.k-rent .band { background: #444; }
.card.sel { outline: 3px solid var(--gold); transform: translateY(-4px); }

.card.mini { width: 44px; height: 60px; font-size: 8px; }
.card.mini .band { min-height: 0; flex: 1; font-size: 8px; padding: 3px; align-items: flex-start; }
.card.mini .body { display: none; }
.card.mini .val { font-size: 8px; padding: 0 3px; right: 2px; bottom: 2px; }

.card.large { width: 150px; height: 210px; font-size: 14px; }
.card.large .band { min-height: 60px; font-size: 16px; padding: 8px; }
.card.large .title { font-size: 17px; }
.card.large .text { font-size: 13px; }
.card.large .rentlist { font-size: 12px; }
.card.large .val { font-size: 15px; padding: 2px 8px; }
.card.large.k-money .big { font-size: 48px; }

/* ---------- sheets / modals ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto;
  background: #0f3d22;
  border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.sheet h3 { margin: 0; font-size: 20px; }
.sheet p { margin: 0; color: var(--muted); }
.sheet .center { display: flex; justify-content: center; }
.sheet .opts { display: flex; flex-direction: column; gap: 8px; }
.sheet .opts button { text-align: left; }
.sheet .opts .targets { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet .opts .targets button { flex: 1; text-align: center; }
.sheet .pick { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet .who { font-weight: 700; margin-top: 6px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 6px; }

.log { font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.log div { border-bottom: 1px solid rgba(255,255,255,.08); padding-bottom: 6px; }

.winner { text-align: center; font-size: 28px; font-weight: 800; }

#toast {
  position: fixed; left: 16px; right: 16px; top: 16px; z-index: 50;
  background: #2b2b2b; color: #fff; padding: 12px 14px; border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,.4); text-align: center; font-weight: 600;
}
.card.mini.k-money .body { display: flex; padding: 2px; }
.card.mini.k-money .big { font-size: 12px; }

.bot-levels { display: flex; gap: 8px; }
.bot-levels button { flex: 1; }
.card.mini.banked .val {
  top: 50%; bottom: auto; left: 50%; right: auto; transform: translate(-50%, -10%);
  font-size: 12px; font-weight: 900; padding: 1px 5px;
}

/* ---------- discard pile ---------- */
.pile { width: 44px; height: 60px; border-radius: 8px; border: 2px dashed rgba(255,255,255,.25); cursor: pointer; flex: 0 0 auto; }
.pile:has(.card) { border: 0; }
.pile.incoming .card { visibility: hidden; }
.pile-empty { font-size: 9px; color: var(--muted); text-align: center; line-height: 56px; }
.sheet .played { display: flex; flex-wrap: wrap; gap: 10px; }
.sheet .played > div { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 56px; font-size: 11px; color: var(--muted); text-align: center; }
.flying { position: fixed; z-index: 40; pointer-events: none; transform-origin: 42px 59px; display: flex; flex-direction: column; align-items: center; }
.flying .card { box-shadow: 0 8px 20px rgba(0,0,0,.5); }
.flying-who {
  margin-top: 4px; padding: 1px 8px; border-radius: 99px;
  background: var(--gold); color: var(--ink); font-size: 10px; font-weight: 800; white-space: nowrap;
}
.sheet .swap { align-items: center; gap: 8px; }
.sheet .swap .card.large { width: 130px; height: 182px; }
.swap-icon { font-size: 32px; font-weight: 900; color: var(--gold); }
.opp-head .plays { color: var(--gold); font-weight: 700; }
.details { margin: 10px 0; }
.details p { margin: 4px 0 0; }
.card-tip {
  position: fixed; z-index: 50; max-width: 260px; pointer-events: none;
  background: var(--paper); color: var(--ink); border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,.45); font-size: 13px; line-height: 1.35;
  display: none;
}
.card-tip.show { display: block; }
.card-tip .details { margin: 0; }
.sheet .peek { align-self: center; padding: 6px 14px; font-size: 13px; }
.peekbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(0,0,0,.55);
}
.peekbar button { max-width: 520px; }

/* ---------- card tracker ---------- */
.tracker { display: flex; flex-direction: column; }
.trow { display: flex; align-items: center; gap: 8px; padding: 7px 2px; border-bottom: 1px solid rgba(255,255,255,.08); font-size: 15px; }
.trow span { flex: 1; }
.trow em { text-align: right; font-style: normal; font-size: 12px; font-weight: 700; }
.trow b { min-width: 24px; text-align: right; font-size: 17px; }
.trow.gone { color: var(--muted); }
.trow.gone em { color: #8ce99a; }
.trow.last em, .trow.last b { color: var(--gold); }
.trow i { min-width: 44px; text-align: right; font-style: normal; font-size: 14px; color: var(--muted); }
.trow i.zero { opacity: .35; }
.trow.thead { position: sticky; top: -18px; z-index: 1; background: #0f3d22; padding-top: 4px; }
.trow.thead b, .trow.thead i { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); min-width: 0; }
.sheet p b { color: var(--text); }

/* ---------- hand: one row, hold to preview ---------- */
.hand { gap: 4px; overflow: hidden; padding: 4px 8px 6px; touch-action: none; -webkit-touch-callout: none; justify-content: center; }
.hand .card { flex: 0 0 auto; }
.hand .card.held { outline: 3px solid #4ade80; transform: translateY(-6px); }
.dock .status button.sort { padding: 8px 10px; font-size: 13px; }
#hold {
  position: fixed; left: 0; right: 0; bottom: 170px; z-index: 30; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
#hold[hidden] { display: none; }
#hold .card.large { box-shadow: 0 10px 30px rgba(0,0,0,.6); transition: transform .12s; }
#hold .hold-up {
  min-width: 200px; padding: 26px 18px 12px; border-radius: 14px; text-align: center;
  font-weight: 800; font-size: 17px; color: #fff;
  background: linear-gradient(to top, rgba(74,222,128,.55), rgba(74,222,128,0));
  border-top: 2px dashed rgba(74,222,128,.6);
  transition: background .12s;
}
#hold .hold-up.no { background: rgba(0,0,0,.5); border-color: transparent; color: var(--muted); font-size: 14px; }
/* Options stack upwards from the card: the first (most usual) sits nearest it. */
#hold .hold-opts { display: flex; flex-direction: column-reverse; gap: 4px; width: min(300px, 90vw); }
#hold .hold-opt {
  padding: 8px 14px; border-radius: 12px; text-align: center; font-weight: 800; font-size: 15px;
  background: rgba(0,0,0,.6); color: var(--text); border: 2px solid rgba(74,222,128,.35);
}
#hold .hold-opt small { font-weight: 600; opacity: .8; margin-left: 4px; }
#hold .hold-opt.on { background: #22c55e; color: #05290f; border-color: #bbf7d0; transform: scale(1.06); }
#hold .hold-opt.no { border-color: transparent; color: var(--muted); font-size: 14px; }
#hold.zone-play .card.large { transform: translateY(-14px) scale(1.04); outline: 4px solid #4ade80; }
#hold.zone-cancel .card.large { opacity: .45; transform: translateY(10px) scale(.95); }
#hold .hold-down {
  font-size: 12px; font-weight: 700; color: var(--text); text-align: center;
  background: rgba(0,0,0,.55); padding: 4px 12px; border-radius: 99px;
}
#hold.zone-cancel .hold-down { background: var(--danger); }

/* ---------- rent cards stand out in the hand ---------- */
.card.k-rent .band { justify-content: center; align-items: center; text-align: center; min-height: 52px; }
.card .rent-word { font-size: 20px; font-weight: 900; letter-spacing: 1.5px; line-height: 1; text-shadow: 0 1px 3px rgba(0,0,0,.7), 0 0 1px #000; }
.card .rent-who { font-size: 11px; font-weight: 800; color: #222; text-align: center; margin-top: 4px; }
.card.large .rent-word { font-size: 34px; }
.card.large .rent-who { font-size: 15px; }
.card.mini .rent-word { font-size: 9px; letter-spacing: 0; }

/* ---------- just played: green glow that fades ---------- */
@keyframes fresh {
  0%   { box-shadow: 0 0 0 4px #4ade80, 0 0 16px 6px rgba(74,222,128,.95); }
  100% { box-shadow: 0 0 0 4px rgba(74,222,128,0), 0 0 16px 6px rgba(74,222,128,0); }
}
.fresh { animation: fresh 10s ease-in; }

/* ---------- deal breaker picker ---------- */
.sheet .opts button.dbset { display: flex; flex-direction: column; gap: 6px; border-left: 6px solid var(--c); }
.dbhead small { display: block; font-weight: 600; color: var(--muted); margin-top: 2px; }
.dbcards { display: flex; flex-wrap: wrap; gap: 4px; }
.dbcard { position: relative; }
.dbcard i {
  position: absolute; left: 50%; bottom: -4px; transform: translateX(-50%);
  font-style: normal; font-size: 8px; font-weight: 900; padding: 0 4px; border-radius: 4px;
  background: var(--gold); color: var(--ink);
}

/* ---------- log history and going back ---------- */
.log.hist .entry { padding: 6px 8px; border-radius: 8px; border-bottom: 1px solid rgba(255,255,255,.08); cursor: pointer; }
.log.hist .entry div { border: 0; padding: 0; }
.log.hist .entry.picked { background: rgba(245,197,66,.15); outline: 1px solid rgba(245,197,66,.5); }
.log.hist .entry.now { cursor: default; color: var(--muted); }
.log.hist .goback { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.log.hist .tag { display: inline-block; font-size: 11px; font-weight: 800; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; background: rgba(255,255,255,.15); margin-bottom: 2px; }
.log.hist.undo { max-height: 45dvh; overflow-y: auto; }
.log.hist.undo .entry { cursor: default; }
.log.hist.undo .entry.undone { opacity: .3; text-decoration: line-through; }
.log.hist.undo .entry.target { background: rgba(74,222,128,.18); outline: 2px solid #4ade80; }
.log.hist.undo .tag { background: #4ade80; color: var(--ink); }

/* ---------- compact board ---------- */
.compact { margin-top: 6px; display: flex; flex-direction: column; gap: 5px; }
.tiles { display: flex; flex-wrap: wrap; gap: 5px; }
.tile {
  background: rgba(0,0,0,.22); border-radius: 7px; overflow: hidden;
  border-top: 4px solid var(--c); min-width: 44px;
}
.tile.full { box-shadow: 0 0 0 2px var(--gold); }
.tile .th { display: flex; justify-content: space-between; gap: 6px; padding: 2px 5px 0; font-size: 11px; line-height: 1.3; }
.tile .th b { font-weight: 800; }
.tile .th span { color: var(--gold); font-weight: 700; }
.tile .cells { display: flex; gap: 2px; padding: 3px 4px 4px; }
.cell {
  position: relative; width: 22px; height: 26px; border-radius: 4px; cursor: pointer;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 1px;
  font-size: 11px; font-weight: 900; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.8);
}
.cell i { position: absolute; top: -1px; right: 1px; font-style: normal; font-size: 9px; }
.cell.bld { background: rgba(255,255,255,.18); align-items: center; font-size: 13px; text-shadow: none; }
.bankline { font-size: 13px; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.bankline b { color: var(--gold); }
.bankline .notes { font-weight: 700; border-radius: 6px; padding: 0 4px; }
.section h2.toggle { cursor: pointer; }
.opp { padding: 8px 10px; margin-bottom: 6px; }

/* full view, a little tighter so more sets fit side by side */
.groups { gap: 5px; }
.group { padding: 4px 5px 5px; }
.group .gh { font-size: 10px; }
.group .card.mini { width: 38px; height: 52px; }

.version { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0 0; opacity: .7; }
.bot-levels .top-bot { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.bot-levels .top-bot small { font-size: 12px; font-weight: 600; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet .opts .arena-bot { display: flex; flex-direction: column; gap: 2px; }
.sheet .opts .arena-bot span { font-size: 13px; font-weight: 500; color: var(--muted); }
.lb-link { align-self: center; color: var(--muted); font-size: 14px; }
