/* Mobile-first, one column, thumb-reachable controls at the bottom. */
:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --ink: #1b1c1e;
  --muted: #6c6f74;
  --line: #e3e1da;
  --accent: #16654c;
  --accent-soft: #e3f0ea;
  --danger: #c2412f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .06), 0 6px 18px rgba(20, 20, 20, .07);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --card-w: 84px;
  --card-h: 118px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 12px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; }
.btn:active:not(:disabled) { transform: scale(.98); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); font-weight: 700;
}
.linkish { color: var(--accent); font-weight: 600; min-height: 44px; }

/* ---------- home / waiting ---------- */
.page { max-width: 460px; margin: 0 auto; padding: 28px 20px calc(28px + var(--safe-b)); display: flex; flex-direction: column; gap: 18px; min-height: 100%; }
.brand { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.brand-mark { width: 38px; height: 50px; border-radius: 8px; background: var(--accent); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 6px; right: 6px; top: 6px; height: 10px; border-radius: 3px; background: #fff; }
.brand h1 { font-size: 30px; letter-spacing: -.02em; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.panel h2 { font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; color: var(--muted); }
.field input, .linkbox input, .chat input {
  min-height: 48px; border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; background: var(--surface); color: var(--ink); font-weight: 500; font-size: 16px;
}
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { min-height: 40px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg-note { font-size: 13px; color: var(--muted); min-height: 18px; }
.linkbox { display: flex; gap: 8px; }
.linkbox input { flex: 1; min-width: 0; font-size: 14px; }
.waiting { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite both; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* ---------- game layout ---------- */
.game { height: 100dvh; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.scroll { flex: 1; overflow-y: auto; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px 0; }
.who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left; min-height: 44px; }
.who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .meta { font-size: 13px; color: var(--muted); white-space: nowrap; }
.presence { width: 9px; height: 9px; border-radius: 50%; background: #2fa36b; flex: none; }
.presence.off { background: #c9c6bd; }
.turnbar {
  margin: 8px 12px 0; min-height: 48px; padding: 10px 14px; border-radius: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #e9e7e1; color: var(--muted); font-weight: 600; font-size: 15px;
}
.turnbar-sub { font-size: 13px; font-weight: 600; opacity: .9; text-align: right; }
.turnbar.mine { background: var(--accent); color: #fff; font-size: 18px; font-weight: 800; box-shadow: 0 6px 18px rgba(22, 101, 76, .3); }
.turnbar.arrive { animation: arrive 1.4s ease-out; }
@keyframes arrive { 0% { transform: scale(.96); box-shadow: 0 0 0 0 rgba(22,101,76,.6); } 40% { transform: scale(1.02); box-shadow: 0 0 0 10px rgba(22,101,76,0); } 100% { transform: none; } }
.game.mine .handwrap { background: var(--accent-soft); border-top: 3px solid var(--accent); }
.game:not(.mine) .hand .card { opacity: .75; }
.banner { margin: 8px 12px 0; padding: 10px 12px; border-radius: 12px; background: #fff4d6; color: #6b4e00; font-size: 14px; font-weight: 500; }
.banner.err { background: #fde8e4; color: #8a2a1c; }

.area { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.area-head .chip { text-transform: none; letter-spacing: 0; color: var(--ink); }
.area-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.sets { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
.empty { font-size: 14px; color: var(--muted); padding: 6px 2px; }

.set {
  width: 88px; min-height: 64px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
  overflow: hidden; display: flex; flex-direction: column; text-align: left;
}
.set-top { background: var(--c); color: var(--ci); font-size: 11px; font-weight: 700; padding: 4px 6px; display: flex; justify-content: space-between; gap: 4px; }
.set-top .bld { letter-spacing: .05em; }
.set .pips { display: flex; gap: 3px; padding: 7px 6px 2px; }
.set .pips i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.set .pips i.on { background: var(--c); }
.set .set-rent { font-size: 12px; color: var(--muted); padding: 2px 6px 6px; }
.set.complete { border-color: var(--c); box-shadow: 0 0 0 1px var(--c) inset; }
.set.complete .set-rent { color: var(--ink); font-weight: 600; }
.set.pop { animation: pop .9s ease-out; }
@keyframes pop { 0% { transform: scale(1); } 35% { transform: scale(1.08); box-shadow: 0 0 0 4px var(--c); } 100% { transform: scale(1); } }
.chip { min-height: 32px; padding: 0 10px; border-radius: 9px; background: var(--bg); font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }

.table { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; align-items: center; }
.pile { height: 88px; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); font-weight: 600; }
.pile.deck { background: repeating-linear-gradient(135deg, var(--accent) 0 6px, #1b7559 6px 12px); color: #fff; }
.pile.deck b { font-size: 20px; }
.pile.discard { border: 1.5px dashed var(--line); }
.pile.discard .card { pointer-events: none; }
.status { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.status .turn { font-weight: 700; font-size: 17px; }
.status.mine .turn { color: var(--accent); }
.plays { display: inline-flex; gap: 5px; align-items: center; font-size: 12px; color: var(--muted); font-weight: 600; }
.plays i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--accent); }
.plays i.on { background: var(--accent); }
.recent { display: block; width: 100%; text-align: left; }
.recent .area-head { margin-bottom: 6px; }
.recent .more { color: var(--accent); text-transform: none; letter-spacing: 0; }
.recent ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.recent li.k-steal, .recent li.k-rent { font-weight: 600; }
.recent .empty { padding: 0; }
.logturn { padding: 10px 0; border-bottom: 1px solid var(--line); }
.logturn-head { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.logturn .logline { border: 0; padding: 3px 0 3px 12px; }
.lastlog { font-size: 13px; color: var(--muted); text-align: center; min-height: 32px; padding: 4px 8px; border-radius: 8px; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- hand + dock ---------- */
.handwrap { background: var(--surface); border-top: 1px solid var(--line); padding: 10px 0 calc(10px + var(--safe-b)); }
.hand { display: flex; gap: 8px; overflow-x: auto; padding: 4px 12px 8px; scroll-snap-type: x proximity; scrollbar-width: none; }
.hand::-webkit-scrollbar { display: none; }
.hand .card { scroll-snap-align: start; }
.hand-empty { padding: 30px 14px; color: var(--muted); font-size: 14px; }
.dock { display: flex; align-items: center; gap: 10px; padding: 0 12px; }
.dock .hint { flex: 1; font-size: 13px; color: var(--muted); line-height: 1.25; }
.dock .btn { min-width: 128px; }
.chatbtn { position: relative; }
.badge { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* ---------- cards ---------- */
.card {
  width: var(--card-w); height: var(--card-h); flex: none; border-radius: 10px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(0,0,0,.05); position: relative; overflow: hidden;
  display: flex; flex-direction: column; text-align: left; transition: transform .12s ease, box-shadow .12s ease;
}
.card .band { min-height: 24px; padding: 5px 6px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; line-height: 1.1; }
.card .band.split { min-height: 24px; }
.card .band.rainbow { background: linear-gradient(90deg, #8a5a3b, #8fcfec, #d4438e, #ee8a26, #dd3a31, #f2cc2b, #1f9656, #2445a6); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.card .nm { padding: 6px; font-size: 12px; font-weight: 650; line-height: 1.15; }
.card .val { position: absolute; left: 6px; bottom: 6px; font-size: 11px; font-weight: 700; color: var(--muted); }
.card .tag { position: absolute; right: 6px; bottom: 6px; font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card.k-money .big { margin: auto; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.card.k-money .val { display: none; }
.card.v1 { background: #eef5e8; } .card.v2 { background: #e8f0f8; } .card.v3 { background: #f3ebf6; }
.card.v4 { background: #f8eee1; } .card.v5 { background: #e5f3ef; } .card.v10 { background: #f8f0d5; }
.card.k-action { background: #faf9f5; }
.card.k-action::before { content: ""; height: 6px; background: var(--ink); opacity: .85; }
.card.k-action.a-justSayNo::before { background: var(--danger); opacity: 1; }
.card.k-action.a-dealBreaker::before { background: #6b3fa0; opacity: 1; }
.card.k-action .nm { font-size: 13px; padding-top: 8px; }
.hand .card.playable { box-shadow: 0 0 0 2px var(--accent-soft), 0 2px 6px rgba(0,0,0,.06); }
.hand .card:active { transform: translateY(-3px); }
.card.dim { opacity: .5; }
.card.sel { box-shadow: 0 0 0 3px var(--accent); transform: translateY(-3px); }
.card.sm { --card-w: 64px; --card-h: 90px; }
.card.sm .nm { font-size: 10.5px; padding: 4px 5px; }
.card.sm .tag { display: none; }
.card.sm .band { font-size: 9px; padding: 4px 5px; min-height: 18px; }
.card.sm.k-money .big { font-size: 17px; }
.card.lg { --card-w: 108px; --card-h: 152px; }
.card.lg .nm { font-size: 14px; }
.card.lg.k-money .big { font-size: 28px; }

/* ---------- sheets ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(20, 20, 18, .32); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 16px calc(18px + var(--safe-b));
  box-shadow: 0 -10px 40px rgba(0,0,0,.15); margin: 0 auto; max-width: 620px;
  display: flex; flex-direction: column; gap: 12px;
}
.sheet.enter { animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(40px); } to { transform: none; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 2px; flex: none; }
.sheet .x { position: absolute; right: 10px; top: 10px; width: 40px; height: 40px; border-radius: 12px; font-size: 18px; color: var(--muted); }
.sheet h3 { font-size: 19px; padding-right: 40px; }
.sheet h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 4px; }
.sheet p { margin: 0; }
.sheet-card { display: flex; gap: 14px; align-items: flex-start; }
.sheet-card > div { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt {
  min-height: 52px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  display: flex; align-items: center; gap: 10px; text-align: left; font-weight: 600;
}
.opt b { margin-left: auto; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt:active { background: var(--bg); }
.sw { width: 18px; height: 18px; border-radius: 5px; flex: none; }
.group { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 14px; background: var(--bg); }
.group-title { font-weight: 700; font-size: 15px; }
.grid { display: flex; flex-wrap: wrap; gap: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; }
.setview { display: flex; flex-direction: column; gap: 8px; }
.setview .cap { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.wildmove { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.wildmove .chip { min-height: 36px; }
.paybar { position: sticky; top: -8px; background: var(--surface); padding: 8px 0; display: flex; justify-content: space-between; align-items: center; font-weight: 600; z-index: 1; }
.paybar b { font-size: 20px; }
.paybar b.ok { color: var(--accent); }
.logline { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.logline.k-turn { color: var(--muted); }
.rules p, .rules li { font-size: 14.5px; }
.rules ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.over { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 18px; }
.over .row { justify-content: center; }
.over h3 { font-size: 28px; padding: 0; }

/* ---------- chat ---------- */
.chat {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; height: min(60dvh, 460px);
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.18);
  display: flex; flex-direction: column; padding-bottom: var(--safe-b); max-width: 620px; margin: 0 auto;
  animation: rise .2s ease-out;
}
.chat header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 16px; font-weight: 700; }
.msgs { flex: 1; overflow-y: auto; padding: 4px 14px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 16px; background: var(--bg); align-self: flex-start; font-size: 15px; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.sys { align-self: center; background: none; color: var(--muted); font-size: 13px; }
.chat form { display: flex; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.chat form input { flex: 1; min-width: 0; }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: calc(8px + env(safe-area-inset-top, 0px)); left: 0; right: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 12px; }
.toast {
  max-width: 420px; padding: 9px 14px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px; animation: drop .2s ease-out;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #9aa0a6; flex: none; }
.toast.k-rent::before, .toast.k-pay::before { background: #f2cc2b; }
.toast.k-steal::before, .toast.k-error::before { background: #ff6b57; }
.toast.k-set::before, .toast.k-win::before, .toast.k-turn::before, .toast.k-build::before { background: #4cd68f; }
.toast.k-jsn::before, .toast.k-blocked::before { background: #ff9a3c; }
.toast.out { opacity: 0; transform: translateY(-6px); transition: all .25s ease; }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- larger screens ---------- */
@media (min-width: 600px) {
  :root { --card-w: 96px; --card-h: 134px; }
  .set { width: 104px; }
  .scroll { padding: 14px 16px; gap: 12px; }
  .table { grid-template-columns: 80px 1fr 80px; }
  .pile { height: 104px; }
}
@media (min-width: 1000px) {
  .game { max-width: 820px; }
  .chat { left: auto; right: 20px; bottom: 20px; width: 360px; border-radius: 18px; height: min(70dvh, 560px); margin: 0; }
  .sheet { bottom: 20px; border-radius: 20px; max-height: 80dvh; }
  body.chat-open .game { margin-right: 400px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
