:root {
  --felt: #1E4D3A;
  --felt-dark: #173D2E;
  --ivory: #FAF8F2;
  --ivory-edge: #D6D0C2;
  --jade: #2F6B4F;
  --red: #D2151C;
  --ink: #151515;
  --gold: #E7C46A;
  --text: #F4F1E8;
  --muted: #B9C7BE;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; } /* keep LINE / iOS text zoom from blowing up the table */
body {
  background: var(--felt);
  color: var(--text);
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
#app { position: fixed; inset: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* ---------- portrait warning (table only) ---------- */
#rotate { display: none; }
@media (orientation: portrait) {
  body.at-table #rotate {
    display: flex; position: fixed; inset: 0; z-index: 50; background: var(--felt);
    flex-direction: column; align-items: center; justify-content: center; font-size: 28px; font-weight: 700;
  }
}
.rotate-icon { font-size: 64px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 22%; transform: translateX(-50%); z-index: 60;
  background: rgba(0,0,0,.78); color: #fff; padding: 10px 22px; border-radius: 999px;
  font-size: 20px; font-weight: 700; opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ---------- 吃碰槓胡 big call ---------- */
#call { display: none; position: fixed; z-index: 35; pointer-events: none; transform: translate(-50%, -50%);
  filter: drop-shadow(0 6px 4px rgba(0,0,0,.5)) drop-shadow(0 10px 18px rgba(0,0,0,.45)); }
#call.show { animation: callpop .28s cubic-bezier(.2, 1.6, .5, 1); }
#call { display: none; grid-template-areas: "g"; }
#call.show { display: grid; }
#call i { grid-area: g; display: block; width: clamp(120px, 42vh, 210px); aspect-ratio: 1; }
#call .edge { background: #fff; -webkit-mask: var(--e) center / contain no-repeat; mask: var(--e) center / contain no-repeat; }
#call .ink { background: linear-gradient(#ff3b3b, var(--red) 55%, #9e0c12);
  -webkit-mask: var(--g) center / contain no-repeat; mask: var(--g) center / contain no-repeat; }
.peek-back { position: fixed; z-index: 40; right: calc(10px + env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom));
  padding: 16px 28px; border-radius: 999px; font-size: 22px; font-weight: 800; background: var(--gold); color: var(--ink);
  box-shadow: 0 4px 14px rgba(0,0,0,.45); }
@keyframes callpop { from { transform: translate(-50%, -50%) scale(.3); opacity: 0; } }

/* ---------- lobby screens ---------- */
.screen.room { flex-direction: row; gap: 36px; }
.room-col { display: flex; flex-direction: column; align-items: center; gap: 12px; }
@media (orientation: portrait) { .screen.room { flex-direction: column; gap: 18px; } }
.screen { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 20px; text-align: center; overflow-y: auto; }
.brand { font-size: 34px; font-weight: 800; color: var(--gold); letter-spacing: 2px; }
.brand small { display: block; font-size: 15px; color: var(--muted); font-weight: 500; letter-spacing: 0; }
.big { font-size: 24px; font-weight: 800; padding: 16px 34px; border-radius: 16px; background: var(--red); color: #fff; min-width: 220px; }
.big.secondary { background: var(--jade); }
.big:disabled { background: #6b7a72; color: #cfd8d2; }
.link { background: none; color: var(--muted); font-size: 18px; text-decoration: underline; }
input.field {
  font-size: 26px; padding: 12px 16px; border-radius: 12px; border: 0; width: 240px; text-align: center;
  background: var(--ivory); color: var(--ink); -webkit-user-select: text; user-select: text;
}
input.code { letter-spacing: 10px; font-weight: 800; }
.row { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }
.countdown { font-size: 20px; color: var(--muted); }
.countdown b { font-size: 34px; color: var(--gold); margin-right: 4px; }
.code-big { font-size: 56px; font-weight: 900; letter-spacing: 12px; color: var(--gold); line-height: 1; }
.hint { color: var(--muted); font-size: 17px; }
.seats { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.seat-card { width: 96px; padding: 10px 4px; border-radius: 14px; background: var(--felt-dark); display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 18px; font-weight: 700; }
.seat-card.empty { color: var(--muted); font-weight: 500; border: 2px dashed #3d6b57; background: none; }

/* ---------- avatar ---------- */
.avatar {
  width: var(--a, 44px); height: var(--a, 44px); border-radius: 50%; flex: none;
  background: var(--jade) center/cover; display: grid; place-items: center;
  font-weight: 800; font-size: calc(var(--a, 44px) * .45); color: #fff; border: 3px solid transparent;
}
.avatar.bot { background: #55645c; }
.avatar.away { opacity: .45; }
.turn .avatar, .avatar.turn { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(231,196,106,.35); }

/* ---------- tiles ---------- */
.tile {
  --w: 56px;
  position: relative; flex: none; width: var(--w); height: calc(var(--w) * 1.3);
  background: var(--ivory); border-radius: calc(var(--w) * .12);
  box-shadow: inset 0 0 0 1px var(--ivory-edge), 0 calc(var(--w) * .07) 0 var(--jade), 0 calc(var(--w) * .07 + 2px) 3px rgba(0,0,0,.35);
}
.tile i {
  position: absolute; inset: 6% 6% 8%;
  -webkit-mask: var(--g) center / contain no-repeat; mask: var(--g) center / contain no-repeat;
}
.tile.red i { background: var(--red); }
.tile.black i { background: var(--ink); }
.tile.back { background: var(--jade); box-shadow: inset 0 0 0 1px #3f8463, 0 calc(var(--w) * .07) 0 var(--ivory-edge), 0 calc(var(--w) * .07 + 2px) 3px rgba(0,0,0,.35); }

/* ---------- table ---------- */
.table {
  height: 100%; display: grid; gap: 4px; padding: 6px 10px;
  grid-template-columns: 74px 1fr 74px;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top top top" "left across right" "left center right" "me me me";
}
.topbar { grid-area: top; display: flex; align-items: center; gap: 12px; min-height: 40px; }
.topbar .status { font-size: 18px; font-weight: 700; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .meta { font-size: 15px; color: var(--muted); white-space: nowrap; }
.chip { background: var(--felt-dark); padding: 6px 12px; border-radius: 999px; font-size: 15px; }

.opp { display: flex; align-items: center; gap: 6px; position: relative; }
.opp .name { font-size: 15px; font-weight: 700; white-space: nowrap; }
.opp.across { grid-area: across; justify-content: center; }
.backs { display: flex; gap: 2px; }
.side-col { display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; min-height: 0; overflow: hidden; }
.left { grid-area: left; }
.right { grid-area: right; }
.sides { display: flex; flex-direction: column; gap: 2px; }
.side { width: 28px; height: clamp(4px, 2.2vh, 9px); border-radius: 3px; background: var(--ivory); box-shadow: inset 0 0 0 1px var(--ivory-edge); }
.left .side { border-right: 6px solid var(--jade); }
.right .side { border-left: 6px solid var(--jade); }

.melds { display: flex; gap: 6px; flex-wrap: wrap; }
.side-col .melds { flex-direction: column; align-items: center; }
.meld { display: flex; gap: 1px; }

.center { grid-area: center; position: relative; border-radius: 18px; background: radial-gradient(ellipse at center, #24583F 0%, #1B4534 75%); overflow: hidden; }
.pool { position: absolute; inset: 0; padding: 10px 14px; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 8px 4px; overflow: hidden; }
.discard { flex: none; }
.discard.fresh { animation: glow 1s ease-in-out infinite alternate; border-radius: 6px; }
@keyframes glow { from { filter: drop-shadow(0 0 0 var(--gold)); } to { filter: drop-shadow(0 0 7px var(--gold)); } }
.wallinfo { position: absolute; right: 10px; bottom: 8px; font-size: 14px; color: var(--muted); }

.me { grid-area: me; display: flex; align-items: flex-end; gap: 10px; }
.me .mine { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.hand { display: flex; gap: 5px; align-items: flex-end; }
.hand .tile { cursor: pointer; transition: transform .12s; }
.hand .tile:active { transform: translateY(-8px); }
.hand .tile.drawn { margin-left: 12px; }
.hand.waiting .tile { filter: brightness(.92); }
.actions { display: grid; grid-template-columns: repeat(3, 58px); gap: 6px; }
.act { height: var(--act-h, 50px); border-radius: 12px; font-size: 24px; font-weight: 900; background: var(--ivory); color: var(--ink); box-shadow: 0 3px 0 var(--ivory-edge); }
.act.hu { background: var(--red); color: #fff; box-shadow: 0 3px 0 #8f0e13; }
.act.draw { grid-column: span 2; background: var(--jade); color: #fff; box-shadow: 0 3px 0 #1d4532; font-size: 22px; }
.act.draw.go { background: var(--gold); color: var(--ink); box-shadow: 0 3px 0 #a88a3c; animation: pulse 1s ease-in-out infinite alternate; }
.act:active { transform: translateY(2px); box-shadow: none; }
@keyframes pulse { to { transform: scale(1.06); } }

.bubble {
  position: absolute; z-index: 20; background: #fff; color: var(--ink); font-size: 20px; font-weight: 800;
  padding: 6px 16px; border-radius: 999px; box-shadow: 0 2px 8px rgba(0,0,0,.35); white-space: nowrap;
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

/* ---------- result overlay ---------- */
.overlay { position: fixed; inset: 0; z-index: 40; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); background: rgba(10,30,22,.86); display: flex; align-items: center; justify-content: center; }
.result { text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; max-height: 100%; overflow-y: auto; padding: 14px; }
.result h2 { margin: 0; font-size: 28px; color: var(--gold); }
@media (max-height: 420px) { .result h2 { font-size: 22px; } .result .fan { font-size: 16px; } .result .big { padding: 10px 26px; font-size: 20px; } }
.result .fan { font-size: 20px; }
.result .hands { display: flex; flex-direction: column; gap: 6px; }
.result .hrow { display: flex; align-items: center; gap: 8px; }
.result .hrow .who { width: 72px; text-align: right; font-weight: 700; }
.result .hrow.win .who { color: var(--gold); }
.result .hrow .tile.drawn { margin-left: 8px; box-shadow: 0 0 0 2px var(--gold), 0 0 10px 2px rgba(231,196,106,.7); }
.result .row .big { min-width: 0; }

.menu { position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; }
.menu-box { background: var(--felt); border-radius: 18px; padding: 20px 26px; display: flex; flex-direction: column; gap: 12px; align-items: center; min-width: 280px; }
.seg { display: flex; border-radius: 12px; overflow: hidden; }
.seg button { padding: 10px 16px; background: var(--felt-dark); font-size: 18px; }
.seg button.on { background: var(--gold); color: var(--ink); font-weight: 800; }

/* ---------- whose turn: a gold frame around that player's hand ---------- */
[data-hand] { border: 3px solid transparent; padding: 3px; border-radius: 9px; }
.turn [data-hand] { border-color: var(--gold); box-shadow: 0 0 10px 1px rgba(231,196,106,.6); animation: turnglow 1.1s ease-in-out infinite alternate; }
@keyframes turnglow { from { box-shadow: 0 0 4px 0 rgba(231,196,106,.4); } to { box-shadow: 0 0 14px 3px rgba(231,196,106,.75); } }
