/* =========================================================
   川麻 UI · 主题 + 拟真牌面（FluffyStuff CC0）
   themes: neon | jade | classic
   ========================================================= */

:root,
[data-theme="neon"] {
  --bg0: #07071a;
  --bg1: #12123a;
  --bg2: #1a1a4a;
  --felt0: #0e3d55;
  --felt1: #0a2a3d;
  --felt2: #071e2c;
  --wood: #3d2a18;
  --wood2: #6b4a28;
  --text: #e8ecff;
  --muted: rgba(232, 236, 255, 0.62);
  --gold: #f0c56d;
  --accent: #4facfe;
  --accent2: #00f2fe;
  --pink: #f093fb;
  --ok: #43e97b;
  --danger: #ff6b7a;
  --chip: #ffe08a;
  --glass: rgba(12, 14, 40, 0.72);
  --glass-border: rgba(79, 172, 254, 0.28);
  --glow: rgba(0, 242, 254, 0.35);
  --btn: linear-gradient(135deg, #2b6cff, #00c2ff);
  --btn-accent: linear-gradient(135deg, #f6d365, #fda085);
  --tile-w: 52px;
  --tile-h: 72px;
  --tile-sm-w: 30px;
  --tile-sm-h: 42px;
  --tile-xs-w: 22px;
  --tile-xs-h: 30px;
  --radius: 16px;
  --font: "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

[data-theme="jade"] {
  --bg0: #041510;
  --bg1: #0a2a1f;
  --bg2: #0f3d2e;
  --felt0: #1a6b4e;
  --felt1: #0f4d38;
  --felt2: #0a3326;
  --wood: #5c3a1e;
  --wood2: #8b5a2b;
  --text: #f3f7f2;
  --muted: rgba(243, 247, 242, 0.62);
  --gold: #e2b857;
  --accent: #3d9a6a;
  --accent2: #7dcea0;
  --pink: #e8a0bf;
  --ok: #6ddf9a;
  --danger: #e07070;
  --chip: #f0d78c;
  --glass: rgba(8, 28, 22, 0.75);
  --glass-border: rgba(226, 184, 87, 0.28);
  --glow: rgba(125, 206, 160, 0.3);
  --btn: linear-gradient(135deg, #1f7a54, #2db87a);
  --btn-accent: linear-gradient(135deg, #c4892d, #e2b857);
}

[data-theme="classic"] {
  --bg0: #1a120b;
  --bg1: #2a1c12;
  --bg2: #3a2818;
  --felt0: #1b5e3b;
  --felt1: #145032;
  --felt2: #0d3a24;
  --wood: #6b3f1d;
  --wood2: #a0672d;
  --text: #fff6e8;
  --muted: rgba(255, 246, 232, 0.65);
  --gold: #f0c14a;
  --accent: #c9a227;
  --accent2: #f0d78c;
  --pink: #d4a574;
  --ok: #7bc96f;
  --danger: #d35454;
  --chip: #ffe6a0;
  --glass: rgba(30, 20, 12, 0.78);
  --glass-border: rgba(240, 193, 74, 0.3);
  --glow: rgba(240, 193, 74, 0.28);
  --btn: linear-gradient(135deg, #8a5a1e, #c4892d);
  --btn-accent: linear-gradient(135deg, #1f7a54, #3d9a6a);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg0);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

body {
  background:
    radial-gradient(ellipse at 15% 10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 45%),
    radial-gradient(ellipse at 85% 90%, color-mix(in srgb, var(--pink) 14%, transparent), transparent 40%),
    linear-gradient(160deg, var(--bg0), var(--bg1) 45%, var(--bg2));
  min-height: 100vh;
  min-height: 100dvh;
}

.hidden { display: none !important; }
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px) saturate(1.2);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.06);
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  letter-spacing: .02em;
  transition: transform .1s ease, filter .15s, box-shadow .15s;
  color: #fff;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.97); }
.btn.primary {
  background: var(--btn);
  border: none;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn.accent {
  background: var(--btn-accent);
  color: #1a120b;
  border: none;
}
.btn.danger { background: linear-gradient(135deg, #8b2a2a, #c23b22); border: none; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: 8px; }
.btn.sm { padding: 7px 12px; font-size: 12px; border-radius: 10px; }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }
.btn.hu { background: linear-gradient(135deg, #ff416c, #ff4b2b) !important; border: none; font-size: 18px; min-width: 76px; }
.btn.peng { background: linear-gradient(135deg, #2193b0, #6dd5ed) !important; border: none; }
.btn.gang { background: linear-gradient(135deg, #7f53ac, #647dee) !important; border: none; }

/* ---------- Auth ---------- */
#screen-auth.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}
.auth-orbit {
  position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0;
}
.auth-orbit span {
  position: absolute;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent2);
  opacity: .25;
  animation: floaty 12s linear infinite;
}
@keyframes floaty {
  0% { transform: translateY(100vh) scale(0); opacity: 0; }
  15% { opacity: .5; }
  100% { transform: translateY(-10vh) scale(1); opacity: 0; }
}
.auth-card {
  position: relative; z-index: 1;
  width: min(440px, 100%);
  padding: 28px 26px 22px;
}
.brand { text-align: center; margin-bottom: 18px; }
.brand-seal {
  width: 72px; height: 72px; margin: 0 auto 12px;
  border-radius: 22px;
  display: grid; place-items: center;
  font-size: 32px; font-weight: 900;
  color: var(--gold);
  background: linear-gradient(145deg, rgba(255,255,255,.08), rgba(0,0,0,.2));
  border: 1px solid var(--glass-border);
  box-shadow: 0 0 32px var(--glow);
}
.brand h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: .14em;
  background: linear-gradient(90deg, var(--text), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand .sub { margin: 8px 0 0; color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; padding: 4px; background: rgba(0,0,0,.22); border-radius: 12px; }
.tab {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 10px; border-radius: 10px; cursor: pointer; font-weight: 700;
}
.tab.active {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--glass-border);
}

label.field {
  display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px;
}
label.field input, label.field select, .field-inline select, .field-inline input {
  width: 100%; margin-top: 6px; padding: 12px 14px;
  border-radius: 12px; border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.28); color: var(--text); font-size: 15px; outline: none;
}
label.field input:focus, label.field select:focus, .field-inline select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.avatar-pick { margin: 4px 0 10px; font-size: 12px; color: var(--muted); }
.avatar-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 8px;
}
.avatar {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center; font-size: 22px;
  background: rgba(255,255,255,.06); border: 2px solid transparent; cursor: pointer;
  transition: .15s;
}
.avatar.sm { width: 40px; height: 40px; font-size: 20px; cursor: default; border-radius: 12px; }
.avatar.md { width: 48px; height: 48px; font-size: 24px; cursor: default; border-radius: 14px; }
.avatar.selected, .avatar-grid .avatar.selected {
  border-color: var(--accent2);
  box-shadow: 0 0 16px var(--glow);
  background: color-mix(in srgb, var(--accent) 25%, transparent);
}
.msg { min-height: 1.2em; color: var(--danger); font-size: 13px; text-align: center; }
.hint { font-size: 11px; color: var(--muted); text-align: center; margin-top: 10px; line-height: 1.5; }

/* ---------- Lobby ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; gap: 12px; flex-wrap: wrap;
  border-bottom: 1px solid rgba(255,255,255,.06);
  background: color-mix(in srgb, var(--glass) 80%, transparent);
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(12px);
}
.user-chip { display: flex; gap: 12px; align-items: center; }
.user-chip .name { font-weight: 800; font-size: 15px; }
.user-chip .chips { color: var(--chip); font-size: 13px; font-weight: 700; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.lobby-main {
  display: grid; grid-template-columns: 1.45fr 1fr; gap: 18px;
  padding: 20px; max-width: 1120px; margin: 0 auto;
}
@media (max-width: 860px) { .lobby-main { grid-template-columns: 1fr; } }

.lobby-hero { padding: 24px; }
.lobby-hero h2 { margin: 0 0 8px; font-size: 22px; }
.lobby-hero > p { color: var(--muted); margin: 0 0 18px; font-size: 14px; line-height: 1.55; }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .lobby-grid { grid-template-columns: 1fr; } }

.panel {
  background: rgba(0,0,0,.22); border-radius: 14px; padding: 16px;
  border: 1px solid rgba(255,255,255,.06);
}
.panel h3 { margin: 0 0 12px; font-size: 14px; color: var(--gold); letter-spacing: .06em; }
.field-inline { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }

.side { padding: 16px; max-height: 72vh; overflow: auto; }
.side h3 { margin: 14px 0 8px; font-size: 13px; color: var(--gold); }
.side h3:first-child { margin-top: 0; }
.history-list, .board-list { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.history-list li, .board-list li {
  padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.06); color: var(--muted);
}
.board-list li { display: flex; justify-content: space-between; gap: 8px; color: var(--text); }
.board-list li span:last-child { color: var(--chip); font-weight: 700; }

/* ---------- Table ---------- */
#screen-table { min-height: 100vh; }
.table-wrap { position: relative; min-height: 100vh; padding: 10px 10px 78px; }

.felt {
  position: relative;
  margin: 0 auto;
  width: min(980px, 100%);
  aspect-ratio: 1.08 / 1;
  max-height: calc(100vh - 96px);
  background:
    radial-gradient(ellipse at 50% 42%, color-mix(in srgb, var(--felt0) 90%, #fff 5%), var(--felt1) 48%, var(--felt2));
  border-radius: 28px;
  border: 12px solid var(--wood);
  box-shadow:
    inset 0 0 90px rgba(0,0,0,.4),
    0 0 0 3px var(--wood2),
    0 0 0 6px rgba(0,0,0,.35),
    0 24px 60px rgba(0,0,0,.55),
    0 0 80px var(--glow);
  overflow: hidden;
}
.felt::before {
  content: "";
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(
    -18deg, transparent, transparent 22px, rgba(255,255,255,.015) 22px, rgba(255,255,255,.015) 23px
  );
  pointer-events: none;
}
.felt-ring {
  position: absolute; inset: 14%;
  border: 1px dashed rgba(255,255,255,.08);
  border-radius: 50%; pointer-events: none;
}
.felt-logo {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%);
  font-size: 64px; font-weight: 900; opacity: .06; letter-spacing: .3em;
  pointer-events: none;
}

.table-info {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center;
  font-size: 12px; font-weight: 700;
  background: rgba(0,0,0,.42);
  padding: 6px 14px; border-radius: 999px;
  z-index: 5; border: 1px solid rgba(255,255,255,.08);
  max-width: 92%;
}
.table-info #room-code {
  color: var(--gold); letter-spacing: .14em;
  padding-right: 8px; border-right: 1px solid rgba(255,255,255,.12);
}

.seat { position: absolute; z-index: 2; }
.seat-top { top: 40px; left: 50%; transform: translateX(-50%); text-align: center; width: 72%; }
.seat-bottom { bottom: 10px; left: 50%; transform: translateX(-50%); width: 94%; }
.seat-left { left: 10px; top: 50%; transform: translateY(-52%); width: 130px; }
.seat-right { right: 10px; top: 50%; transform: translateY(-52%); width: 130px; text-align: right; }

.seat-info {
  display: flex; align-items: center; gap: 8px; justify-content: center; margin-bottom: 6px;
}
.seat-left .seat-info, .seat-right .seat-info { flex-direction: column; }
.me-info { margin-top: 8px; }
.sn { font-size: 13px; font-weight: 800; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.sc { font-size: 11px; color: var(--chip); font-weight: 700; }
.sq {
  font-size: 10px; font-weight: 800; padding: 2px 8px; border-radius: 999px;
  background: rgba(0,0,0,.4); display: inline-block; min-height: 16px;
  border: 1px solid rgba(255,255,255,.1);
}
.sq.wan { color: #ff8a80; border-color: rgba(255,138,128,.4); }
.sq.tong { color: #82b1ff; border-color: rgba(130,177,255,.4); }
.sq.tiao { color: #69f0ae; border-color: rgba(105,240,174,.4); }

.hu-badge {
  background: linear-gradient(135deg, #ff416c, #ff4b2b);
  color: #fff; font-size: 11px; font-weight: 900;
  padding: 3px 10px; border-radius: 8px;
  animation: pulse 1.2s infinite;
  box-shadow: 0 0 16px rgba(255,65,108,.45);
}
@keyframes pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.hand-back {
  display: flex; gap: 2px; justify-content: center; flex-wrap: wrap; min-height: 28px;
}
.hand-back.vertical {
  flex-direction: column; align-items: center; max-height: 240px; overflow: hidden;
}

.discards {
  display: flex; flex-wrap: wrap; gap: 3px; justify-content: center;
  max-width: 320px; margin: 4px auto; min-height: 28px;
}
.seat-left .discards, .seat-right .discards {
  max-width: 110px; max-height: 180px; overflow: hidden;
}
.melds {
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 2px 0;
}
.meld-group {
  display: flex; gap: 2px; padding: 3px;
  background: rgba(0,0,0,.25); border-radius: 8px;
  border: 1px solid rgba(255,255,255,.06);
}

.center-pile {
  position: absolute; left: 50%; top: 48%;
  transform: translate(-50%, -50%); text-align: center; z-index: 3;
}
/* 旧中心大牌样式已废弃；真实布局见 table.css .last-tile-wrap */
.last-tile { min-height: 0; display: flex; justify-content: center; filter: none; }
.turn-lamp {
  margin-top: 10px; font-size: 13px; font-weight: 700;
  padding: 6px 16px; border-radius: 999px;
  background: rgba(0,0,0,.45);
  border: 1px solid color-mix(in srgb, var(--gold) 50%, transparent);
  color: var(--gold);
  box-shadow: 0 0 20px var(--glow);
}

/* ---------- Mahjong tiles (SVG) ---------- */
.mj-tile {
  width: var(--tile-w);
  height: var(--tile-h);
  position: relative;
  display: inline-block;
  border-radius: 8px;
  cursor: default;
  transition: transform .14s cubic-bezier(.2,.8,.2,1), filter .14s, box-shadow .14s;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.35));
}
.mj-tile.sm { width: var(--tile-sm-w); height: var(--tile-sm-h); border-radius: 5px; }
.mj-tile.xs { width: var(--tile-xs-w); height: var(--tile-xs-h); border-radius: 4px; }
.mj-tile.vert { width: var(--tile-sm-h); height: var(--tile-sm-w); }
.mj-tile-img {
  width: 100%; height: 100%;
  display: block; border-radius: inherit;
  object-fit: contain;
  pointer-events: none;
  background: transparent;
}
.mj-tile.playable { cursor: pointer; }
.mj-tile.playable:hover {
  transform: translateY(-12px) scale(1.04);
  filter: drop-shadow(0 12px 16px rgba(0,0,0,.4)) drop-shadow(0 0 12px var(--glow));
  z-index: 3;
}
.mj-tile.selected {
  transform: translateY(-16px) scale(1.06);
  filter: drop-shadow(0 14px 18px rgba(0,0,0,.45)) drop-shadow(0 0 18px var(--accent2));
  z-index: 4;
}
.mj-tile.selected::after {
  content: "";
  position: absolute; inset: -3px;
  border-radius: 10px;
  border: 2px solid var(--accent2);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent);
  pointer-events: none;
}
.mj-tile.dim { opacity: .42; filter: grayscale(.15) drop-shadow(0 2px 3px rgba(0,0,0,.3)); }
.mj-tile.drawn::before {
  content: "";
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}
.mj-tile.pop { animation: tileIn .22s ease; }
@keyframes tileIn {
  from { transform: translateY(14px) scale(.88); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.mj-badge {
  position: absolute; right: 2px; top: 2px; z-index: 2;
  min-width: 14px; height: 14px; padding: 0 3px;
  border-radius: 999px; font-size: 9px; font-weight: 900;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #2f9cff, #6fd3ff);
}

.my-hand {
  display: flex; justify-content: center; align-items: flex-end;
  gap: 4px; min-height: 78px; padding: 6px 4px 0; flex-wrap: wrap;
}

/* 旧 absolute 桌布局遗留；现牌桌用 table.css .self-dock，以下默认不 fixed */
.action-bar {
  display: flex; gap: 10px; z-index: 20; flex-wrap: wrap; justify-content: center;
  max-width: 96vw;
}
.action-bar .btn {
  min-width: 72px; font-size: 16px; padding: 12px 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
/* 仅旧 .table-wrap 结构才 fixed（当前 index 已不用） */
.table-wrap > .action-bar {
  position: fixed; left: 50%; bottom: 62px; transform: translateX(-50%);
}

.table-toolbar {
  display: none; /* 已由 game-hud / self-dock 替代 */
}

.side-log {
  display: none; /* 已由 #game-log.live-log 替代 */
}

@media (max-width: 720px) {
  .felt { aspect-ratio: auto; height: calc(100vh - 110px); max-height: none; border-width: 8px; }
  :root {
    --tile-w: 40px; --tile-h: 56px;
    --tile-sm-w: 24px; --tile-sm-h: 34px;
  }
  .seat-left, .seat-right { width: 78px; }
  .my-hand { gap: 2px; }
}

.seat.turn-glow .avatar {
  box-shadow: 0 0 0 3px var(--gold), 0 0 18px var(--glow);
}

/* ---------- Modal / toast ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.58);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px;
  backdrop-filter: blur(6px);
}
.modal-card {
  width: min(440px, 100%);
  padding: 24px;
  max-height: 88vh; overflow: auto;
}
.modal-card h2 { margin: 0 0 8px; text-align: center; font-size: 20px; }
.modal-card .modal-desc { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.modal-actions {
  display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap;
}
.que-btns { display: flex; gap: 14px; justify-content: center; margin-top: 8px; }
.btn.que {
  width: 92px; height: 92px; font-size: 30px; border-radius: 20px; font-weight: 900;
  display: grid; place-items: center; border: none;
}
.btn.que.wan { background: linear-gradient(145deg, #5c1f1f, #a33); color: #ffc9c9; }
.btn.que.tong { background: linear-gradient(145deg, #1a3355, #2a6f97); color: #c5e4ff; }
.btn.que.tiao { background: linear-gradient(145deg, #1a3d28, #2d8a55); color: #c5ffd8; }
.btn.que:hover { transform: translateY(-4px) scale(1.04); }

#settle-body .row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.08); font-size: 14px;
}
#settle-body .win { color: var(--ok); font-weight: 800; }
#settle-body .lose { color: var(--danger); font-weight: 800; }

.settings-grid { display: grid; gap: 10px; }
.settings-grid label.field { margin: 0; }

.toast-host {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--glass); border: 1px solid var(--glass-border);
  color: var(--text); padding: 10px 16px; border-radius: 12px;
  font-size: 13px; font-weight: 700;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  animation: toastIn .25s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

.round-delta { font-size: 12px; color: var(--chip); margin-left: 8px; font-weight: 700; }

/* 预载不可见 */
.tile-preload { position: absolute; width: 0; height: 0; overflow: hidden; opacity: 0; pointer-events: none; }
