:root {
  --ink: #241910;
  --paper: #f4efe2;
  --felt: #0e4d3a;
  --felt-deep: #083528;
  --wood: #7a4a2a;
  --wood-light: #c4956a;
  --cinnabar: #9c2b2b;
  --gold: #e6c98a;
  --wan: #a33b32;
  --tiao: #1d7a45;
  --tong: #1d4e89;
  --muted: #6d6256;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background: #1a120c;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: KaiTi, STKaiti, serif; font-weight: 500; }

.screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.card {
  width: min(440px, 100%);
  background: var(--paper);
  border: 1px solid var(--wood-light);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}
.brand { text-align: center; margin-bottom: 18px; }
.brand h1 { margin: 0; font-size: 40px; letter-spacing: .08em; }
.brand p { margin: 6px 0 0; color: var(--muted); }
label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 14px; }
input, select {
  width: 100%;
  border: 1px solid #d9cbb6;
  background: #fffdf8;
  border-radius: 10px;
  padding: 10px 12px;
}
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--cinnabar);
  color: white;
}
.btn.secondary { background: transparent; color: var(--ink); border: 1px solid #c8b59a; }
.btn.gold { background: #8a6232; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.tabs button { flex: 1; }
.tabs .on { background: var(--ink); color: white; }
.err { color: var(--cinnabar); min-height: 1.2em; font-size: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: #241910; color: white; padding: 10px 16px; border-radius: 999px; z-index: 20;
}

.topbar, .lobby-bar {
  display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap;
  color: var(--gold); padding: 10px 14px;
}
.panel .btn.secondary.on { background: var(--cinnabar); color: white; border-color: transparent; }
.lobby-bar .btn.secondary, .topbar .btn.secondary {
  color: var(--paper); border-color: rgba(244, 239, 226, .55);
}
.topbar .actions, .lobby-bar .actions { margin-top: 0; }
.lobby { width: min(920px, 100%); margin: 0 auto; color: var(--paper); }
.lobby-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 16px; }
.panel {
  background: rgba(244, 239, 226, .96); color: var(--ink);
  border-radius: 16px; padding: 18px; border: 1px solid var(--wood-light);
}
.panel h2 { margin: 0 0 8px; }
.code { font-size: 32px; letter-spacing: .24em; font-family: KaiTi, serif; }
.seat-list { display: grid; gap: 8px; margin: 12px 0; }
.seat-pill {
  display: flex; justify-content: space-between; padding: 8px 12px;
  background: #fff; border-radius: 10px; border: 1px dashed #d9cbb6;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.table-page { min-height: 100vh; display: flex; flex-direction: column; }
.felt {
  flex: 1; margin: 0 10px 10px; border-radius: 18px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255,255,255,.06), transparent 42%),
    var(--felt);
  border: 8px solid #5b351c;
  box-shadow: inset 0 0 0 3px #c4956a, inset 0 0 40px rgba(0,0,0,.25);
  display: grid;
  grid-template-columns: 150px 1fr 150px;
  grid-template-rows: auto minmax(180px, 1fr) auto;
  min-height: 0;
}
.seat { position: relative; padding: 8px; color: var(--gold); }
.seat.top { grid-column: 1 / -1; grid-row: 1; }
.seat.left { grid-column: 1; grid-row: 2; align-self: center; }
.seat.right { grid-column: 3; grid-row: 2; align-self: center; }
.seat.self { grid-column: 1 / -1; grid-row: 3; color: var(--paper); }
.seat .who { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.seat.current .who strong { color: white; }
.river {
  grid-column: 2; grid-row: 2; display: grid; grid-template-columns: 1fr 1.4fr 1fr;
  grid-template-rows: auto 1fr auto; gap: 6px; align-items: center; justify-items: center;
}
.discards { display: flex; flex-wrap: wrap; gap: 3px; max-width: 280px; justify-content: center; }
.discards.left { grid-column: 1; grid-row: 2; }
.discards.right { grid-column: 3; grid-row: 2; }
.discards.top { grid-column: 2; grid-row: 1; }
.discards.self { grid-column: 2; grid-row: 3; }
.center-info { grid-column: 2; grid-row: 2; text-align: center; color: var(--gold); }
.marker { display: flex; gap: 8px; justify-content: center; margin-bottom: 6px; }
.hand { display: flex; gap: 4px; align-items: flex-end; min-height: 72px; padding-top: 16px; overflow-x: auto; }
.melds { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.meld { display: flex; gap: 2px; align-items: flex-end; }
.meld .tag { font-size: 11px; color: var(--gold); }

.tile {
  flex: 0 0 auto;
  width: 44px; height: 62px;
  border: 0; padding: 0; background: transparent;
  position: relative;
}
.tile .body {
  display: block; height: 100%; border-radius: 4px 4px 5px 5px; overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,.9), transparent 28%),
    linear-gradient(#fffdf8, #f0e2c8);
  box-shadow:
    inset 0 0 0 1px rgba(120, 90, 40, .25),
    0 2px 0 #d7c4a2,
    0 4px 0 #a88458,
    0 5px 0 #6d5232,
    0 7px 8px rgba(0,0,0,.28);
}
.tile .glyph { width: 100%; height: 100%; display: block; }
.tile.small { width: 30px; height: 42px; }
.tile.small .body { box-shadow: inset 0 0 0 1px rgba(120, 90, 40, .25), 0 2px 0 #a88458, 0 3px 4px rgba(0,0,0,.25); }
.tile.selected { transform: translateY(-14px); }
.tile.drawn { margin-left: 12px; }
.tile.cai .body { box-shadow: inset 0 0 0 2px var(--gold), 0 4px 0 #a88458, 0 5px 0 #6d5232, 0 7px 8px rgba(0,0,0,.28); }
.tile.back .body {
  background:
    linear-gradient(180deg, rgba(255,255,255,.28), transparent 34%),
    repeating-linear-gradient(45deg, rgba(242, 212, 138, .95) 0 1px, transparent 1px 6px),
    repeating-linear-gradient(-45deg, rgba(242, 212, 138, .95) 0 1px, transparent 1px 6px),
    linear-gradient(#a12836, #6d1520);
  box-shadow: inset 0 0 0 2px var(--gold), 0 3px 0 #4a1018, 0 4px 0 #2a090e;
}
.bubble {
  position: absolute; z-index: 4; max-width: 150px;
  background: #fffdf8; color: var(--ink);
  border-radius: 12px 12px 12px 4px;
  padding: 6px 10px; font-size: 13px;
  box-shadow: 0 6px 16px rgba(0,0,0,.28);
}
.seat.top .bubble, .seat.left .bubble { left: 8px; top: 26px; }
.seat.right .bubble { right: 8px; top: 26px; }
.seat.self .bubble { left: 58px; top: 28px; }
.seat.self .who { min-height: 24px; padding-left: 52px; }
.chat-dock { position: absolute; left: 8px; top: 2px; z-index: 5; }
.chat-btn {
  width: 42px; height: 42px; border-radius: 50%; padding: 0;
  border: 2px solid var(--gold); background: rgba(16, 10, 6, .78); color: var(--gold);
}
.phrase-pop {
  position: absolute; left: 0; bottom: 48px; width: 136px;
  background: rgba(255, 250, 240, .98); color: var(--ink);
  border-radius: 12px; padding: 6px; display: grid; gap: 2px;
  box-shadow: 0 12px 28px rgba(0,0,0,.32);
}
.phrase {
  border: 0; background: transparent; color: var(--ink);
  text-align: left; border-radius: 8px; padding: 7px 8px;
}
.phrase:hover { background: #f3e6d0; }
.backs { display: flex; }
.backs .tile { margin-left: -14px; }
.backs .tile:first-child { margin-left: 0; }

.play-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin: 0 0 4px; }
.play-actions .btn.secondary { background: var(--paper); color: var(--ink); border-color: transparent; }
.log { color: #d7ecdf; font-size: 13px; min-height: 1.2em; }

.mask {
  position: fixed; inset: 0; background: rgba(20, 12, 8, .62);
  display: grid; place-items: center; padding: 18px; z-index: 10;
}
.sheet { width: min(640px, 100%); max-height: min(80vh, 720px); overflow: auto; }
.dice { font-size: 42px; letter-spacing: .2em; }

@media (max-width: 800px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .felt { grid-template-columns: 84px 1fr 84px; margin: 0 4px 4px; border-width: 5px; }
  .tile { width: 34px; height: 48px; }
  .tile.small { width: 22px; height: 32px; }
  .brand h1 { font-size: 32px; }
}
