:root {
  --bg: #14241b;
  --felt: #1b3226;
  --panel: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.12);
  --text: #eef3ee;
  --muted: #9fb3a6;
  --accent: #f2c14e;
  --danger: #e2604a;

  --plains: #efe6c4;  --plains-ink: #5b4a1a;
  --island: #2f78c0;  --island-ink: #fff;
  --swamp: #4a3f55;   --swamp-ink: #f0e8f7;
  --mountain: #c64a32; --mountain-ink: #fff;
  --forest: #2e8048;  --forest-ink: #fff;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
button {
  font: inherit; color: inherit; border: 0; cursor: pointer;
  border-radius: 12px; padding: 12px 16px; background: var(--panel);
  touch-action: manipulation;
}
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: #2a2108; font-weight: 700; }
button.danger { background: var(--danger); color: #fff; }
button.ghost { background: transparent; border: 1px solid var(--line); }

/* ---------- lobby ---------- */
.lobby {
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
  gap: 16px; padding: 24px 16px calc(24px + var(--safe-b)); max-width: 420px; margin: 0 auto;
}
.lobby h1 { margin: 0; font-size: 30px; line-height: 1.1; }
.lobby .pips { font-size: 28px; letter-spacing: 4px; }
.lobby p { color: var(--muted); margin: 0; }
.lobby input {
  font: inherit; width: 100%; padding: 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.lobby .row { display: flex; gap: 8px; }
.lobby .row input { text-transform: uppercase; letter-spacing: 3px; }
.lobby details { color: var(--muted); font-size: 14px; }
.lobby details summary { cursor: pointer; padding: 8px 0; }
.lobby details ul { padding-left: 18px; margin: 4px 0; }
.code-big { font-size: 56px; font-weight: 800; letter-spacing: 10px; text-align: center; color: var(--accent); }

/* ---------- table ---------- */
.table {
  height: 100dvh; display: flex; flex-direction: column;
  padding: calc(6px + var(--safe-t)) 10px calc(8px + var(--safe-b));
  gap: 8px; max-width: 560px; margin: 0 auto;
}
.topbar { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.topbar .spacer { flex: 1; }
.topbar button { padding: 6px 10px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #5c5; display: inline-block; }
.dot.off { background: var(--danger); }

.zone { background: var(--felt); border-radius: 16px; padding: 8px; border: 1px solid var(--line); }
.zone.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.zone-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.zone-head b { color: var(--text); font-size: 15px; }
.zone-head .spacer { flex: 1; }
.chip { background: var(--panel); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.chip.win { background: var(--accent); color: #2a2108; font-weight: 700; }

.lands { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.land {
  border-radius: 10px; padding: 4px; min-height: 64px; position: relative;
  display: flex; align-items: flex-end; justify-content: flex-end;
  border: 2px solid transparent; background-size: cover; background-position: center;
}
.land .badge {
  display: inline-flex; align-items: center; gap: 2px; font-size: 12px; line-height: 1;
  background: rgba(0,0,0,.72); color: #fff; border-radius: 999px; padding: 3px 6px;
}
.land .badge b { font-size: 15px; }
/* Empty columns show no art: just a faint tile in the land's color. */
.land.empty { opacity: 0.25; justify-content: center; align-items: center; }
.land.empty .badge { background: transparent; color: inherit; }
.land.full { border-color: var(--accent); }

.t-plains { background: var(--plains); color: var(--plains-ink); }
.t-island { background: var(--island); color: var(--island-ink); }
.t-swamp { background: var(--swamp); color: var(--swamp-ink); }
.t-mountain { background: var(--mountain); color: var(--mountain-ink); }
.t-forest { background: var(--forest); color: var(--forest-ink); }

.graves { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; font-size: 12px; color: var(--muted); align-items: center; }
.mini { border-radius: 6px; padding: 1px 6px; font-size: 12px; font-weight: 700; }

.backs { display: inline-flex; }
.backs i {
  width: 12px; height: 17px; border-radius: 3px; margin-left: -4px;
  background: linear-gradient(135deg, #6b4b2a, #3d2a17); border: 1px solid #a07a4c;
}

/* ---------- middle ---------- */
.middle { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.status { text-align: center; font-weight: 700; font-size: 17px; }
.status.yours { color: var(--accent); }
.lastlog { text-align: center; color: var(--muted); font-size: 13px; min-height: 1.3em; }
.stack {
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
  background: rgba(0,0,0,.25); border-radius: 14px; padding: 10px;
}
.stack .arrow { color: var(--muted); }
.stack .counter { background: var(--island); color: #fff; border-radius: 8px; padding: 4px 8px; font-size: 13px; font-weight: 700; }
.pill { border-radius: 10px; padding: 6px 10px; font-weight: 700; }
.prompt { display: flex; gap: 8px; }
.prompt button { flex: 1; }
.over { text-align: center; display: flex; flex-direction: column; gap: 10px; }
.over .big { font-size: 26px; font-weight: 800; }

/* ---------- hand ---------- */
.hand {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 2px;
  scroll-snap-type: x proximity; min-height: 104px;
}
.hand::-webkit-scrollbar { display: none; }
.card {
  flex: 1 0 0; min-width: 62px; max-width: 86px; padding: 0; background: none; border-radius: 6px;
  scroll-snap-align: start; box-shadow: 0 2px 6px rgba(0,0,0,.5); border: 2px solid transparent; overflow: hidden;
}
.card img { display: block; width: 100%; aspect-ratio: 488 / 680; object-fit: cover; }
.hand.playable .card { border-color: var(--accent); }
.hand.playable .card:active { transform: translateY(-4px); }
.hand-empty { color: var(--muted); align-self: center; margin: auto; font-size: 14px; }

.actions { display: flex; gap: 8px; }
.actions button { flex: 1; padding: 14px; }

/* ---------- sheet ---------- */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 75dvh; overflow-y: auto;
  background: #203a2c; border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + var(--safe-b));
  max-width: 560px; margin: 0 auto; box-shadow: 0 -8px 30px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 10px;
}
#sheet h2 { margin: 0; font-size: 20px; display: flex; align-items: center; gap: 8px; }
#sheet .rules { color: var(--muted); margin: 0; font-size: 14px; }
#sheet .opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
#sheet .opts button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; font-weight: 700; }
#sheet .opts button .sym { font-size: 24px; }
#sheet .opts button small { font-weight: 400; opacity: .85; }
#sheet .row { display: flex; gap: 8px; }
#sheet .row button { flex: 1; }
.log { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.log div:last-child { color: var(--text); }

#toast {
  position: fixed; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%); z-index: 20;
  background: var(--danger); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

@media (min-height: 760px) {
  .land { min-height: 76px; }
}

/* ---------- home / profile ---------- */
a.button {
  display: block; text-align: center; text-decoration: none; border-radius: 12px; padding: 14px 16px;
}
a.button.primary { background: var(--accent); color: #2a2108; font-weight: 700; }
.small { font-size: 14px; color: var(--muted); margin: 0; }
.legal { font-size: 11px; color: var(--muted); opacity: .8; margin: 8px 0 0; }
.home {
  max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px;
  padding: calc(16px + var(--safe-t)) 16px calc(24px + var(--safe-b));
}
.home h2, .lobby h2 { margin: 8px 0 0; font-size: 18px; }
.home .row { display: flex; gap: 8px; }
.home input {
  font: inherit; flex: 1; min-width: 0; padding: 14px; border-radius: 12px; text-transform: uppercase; letter-spacing: 3px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.play { display: flex; flex-direction: column; gap: 8px; }
.profile { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto; object-fit: cover;
  background: var(--accent); color: #2a2108; display: grid; place-items: center; font-weight: 800; font-size: 20px;
}
.who { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.who b { font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { font-size: 13px; color: var(--muted); }
.small-btn { padding: 6px 10px; font-size: 13px; }

.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.themes.compact { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.theme {
  display: flex; flex-direction: column; gap: 6px; padding: 8px; text-align: left;
  background: var(--felt); border: 2px solid var(--line);
}
.theme.selected { border-color: var(--accent); }
.theme.is-locked { cursor: default; }
.theme-name { font-weight: 700; font-size: 14px; }
.theme-req { font-size: 12px; color: var(--muted); }
.strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; border-radius: 8px; overflow: hidden; height: 46px; position: relative; }
.strip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.strip.locked span { display: grid; place-items: center; font-size: 14px; opacity: .35; }
.strip.locked b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 20px; }
.bar { display: block; height: 5px; border-radius: 3px; background: var(--panel); margin: 4px 0 2px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.stats div { background: var(--felt); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; }
.stats b { font-size: 22px; }
.stats span { font-size: 12px; color: var(--muted); }
.recent { display: flex; flex-direction: column; gap: 6px; }
.recent div { background: var(--felt); border-radius: 10px; padding: 8px 10px; font-size: 14px; border-left: 4px solid var(--muted); }
.recent .r-win { border-left-color: #5c5; }
.recent .r-loss { border-left-color: var(--danger); }
.recent span { display: block; font-size: 12px; color: var(--muted); }

/* ---------- card details ---------- */
.card-head { display: flex; gap: 12px; align-items: flex-start; }
.big-card { width: 42%; max-width: 200px; border-radius: 10px; box-shadow: 0 4px 14px rgba(0,0,0,.5); }
.card-head h2 { margin: 0 0 6px; }
.credit { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.fan { display: flex; gap: 4px; }
.fan img { flex: 1; min-width: 0; border-radius: 6px; }
.chips-row { display: flex; gap: 6px; overflow-x: auto; justify-content: center; flex-wrap: wrap; }
.chip-btn { padding: 6px 10px; font-size: 13px; border-radius: 999px; background: var(--panel); }
.chip-btn.on { background: var(--accent); color: #2a2108; font-weight: 700; }
