:root {
  --felt: #1b6e46;
  --felt-dark: #114a2f;
  --gold: #e6c15a;
  --gold-bright: #ffd970;
  --ink: #eef3ee;
  --panel: #17251d;
  --panel-2: #1f3128;
  --red: #d9484f;
  --accent: #4fa3ff;
  --muted: #9ab3a3;
  --radius: 12px;
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: radial-gradient(ellipse at 50% -20%, #234d38 0%, #0d1a13 70%) fixed;
  color: var(--ink);
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .85rem; }
button { font-family: inherit; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel-2); color: var(--ink);
  border: 1px solid #3a5546; border-radius: 10px;
  padding: 10px 18px; font-size: 1rem; cursor: pointer;
  transition: transform .06s, filter .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-sm { padding: 6px 12px; font-size: .85rem; border-radius: 8px; }
.btn-gold {
  background: linear-gradient(180deg, var(--gold-bright), #c99b2f);
  border-color: #8a6a1c; color: #33270a; font-weight: 700;
}
.btn-discord { background: #5865F2; border-color: #4752c4; color: #fff; font-weight: 600; width: 100%; }
.btn-danger { background: var(--red); border-color: #a03038; color: #fff; }
.icon-btn {
  background: none; border: none; color: var(--muted); font-size: 1.1rem;
  cursor: pointer; padding: 6px;
}
.icon-btn:hover { color: var(--ink); }

/* ---------- login ---------- */
#login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.login-card {
  background: var(--panel); border: 1px solid #2c4436; border-radius: 20px;
  padding: 40px 36px; width: 360px; max-width: 100%; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-logo { font-size: 56px; }
.login-card h1 { margin: 8px 0 4px; letter-spacing: .1em; }
.login-sub { color: var(--muted); margin: 0 0 24px; font-size: .85rem; }
.login-divider {
  display: flex; align-items: center; gap: 12px; color: var(--muted);
  margin: 18px 0; font-size: .8rem;
}
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 1px; background: #2c4436; }
#guest-form { display: flex; gap: 8px; }
#guest-form input {
  flex: 1; min-width: 0; background: #0e1813; color: var(--ink);
  border: 1px solid #2c4436; border-radius: 10px; padding: 10px 12px; font-size: 1rem;
}
.login-msg { color: var(--red); min-height: 1.2em; font-size: .85rem; }

/* ---------- topbar ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: rgba(13, 22, 17, .85); backdrop-filter: blur(8px);
  border-bottom: 1px solid #24382c; position: sticky; top: 0; z-index: 50;
}
.brand { font-size: 1.15rem; font-weight: 800; letter-spacing: .08em; cursor: pointer; }
.brand span { color: var(--gold); }
.top-right { display: flex; align-items: center; gap: 10px; }
.chip-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #0e1813; border: 1px solid #34503f; border-radius: 999px;
  padding: 6px 14px; font-weight: 700; color: var(--gold-bright); font-size: .95rem;
}
button.chip-pill { cursor: pointer; }
.chip-pill.bonus { color: var(--ink); }
#my-chips { display: inline-block; transition: color .2s; }
#my-chips.chip-bump { animation: chip-bump .5s ease-out; }
@keyframes chip-bump {
  0% { transform: scale(1); color: var(--gold-bright); }
  30% { transform: scale(1.35); color: #7bffb0; text-shadow: 0 0 12px rgba(123,255,176,.8); }
  100% { transform: scale(1); }
}
.chip-pill.bonus:disabled { opacity: .5; cursor: default; }
.me { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.avatar { width: 28px; height: 28px; border-radius: 50%; border: 1px solid #3a5546; }

/* ---------- lobby ---------- */
#main { padding: 18px; max-width: 1280px; margin: 0 auto; }
.lobby-grid { display: grid; grid-template-columns: 1fr 320px; gap: 18px; }
@media (max-width: 900px) { .lobby-grid { grid-template-columns: 1fr; } }

.game-banners { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
@media (max-width: 700px) { .game-banners { grid-template-columns: 1fr; } }
.game-banner {
  border: none; border-radius: var(--radius); padding: 22px 16px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,.45); transition: transform .12s, box-shadow .12s;
}
.game-banner:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(0,0,0,.4); }
.game-banner.holdem { background: linear-gradient(135deg, #1e7a4e, #0f3d27); }
.game-banner.blackjack { background: linear-gradient(135deg, #24427c, #101f42); }
.game-banner.roulette { background: linear-gradient(135deg, #8c2f39, #45121a); }
.gb-emoji { font-size: 2rem; }
.gb-name { font-size: 1.25rem; font-weight: 800; letter-spacing: .15em; }
.gb-sub { font-size: .75rem; opacity: .8; }

.panel {
  background: var(--panel); border: 1px solid #24382c; border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 18px;
}
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.panel-head h2 { font-size: 1rem; margin: 0; flex: 1; letter-spacing: .05em; }

.table-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 10px; background: var(--panel-2); margin-bottom: 8px;
}
.table-row .t-game { font-size: 1.3rem; width: 34px; text-align: center; }
.table-row .t-info { flex: 1; min-width: 0; }
.table-row .t-name { font-weight: 700; }
.table-row .t-meta { font-size: .78rem; color: var(--muted); }
.table-row .t-status { font-size: .85rem; color: var(--gold); white-space: nowrap; }

#leaderboard { margin: 0; padding: 0 0 0 4px; list-style: none; counter-reset: lb; }
#leaderboard li {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px;
  border-bottom: 1px dashed #24382c; font-size: .9rem;
}
#leaderboard li::before {
  counter-increment: lb; content: counter(lb);
  width: 22px; height: 22px; border-radius: 50%; background: var(--panel-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .75rem; color: var(--muted); flex: none;
}
#leaderboard li:nth-child(1)::before { background: var(--gold); color: #332708; font-weight: 800; }
#leaderboard li:nth-child(2)::before { background: #c0c8cf; color: #26313a; font-weight: 800; }
#leaderboard li:nth-child(3)::before { background: #b8804d; color: #3a2410; font-weight: 800; }
#leaderboard .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaderboard .lb-chips { color: var(--gold-bright); font-weight: 700; }

/* ---------- chat ---------- */
.chat-panel { display: flex; flex-direction: column; max-height: 380px; }
.chat-log { flex: 1; overflow-y: auto; min-height: 120px; font-size: .88rem; padding: 4px 2px; }
.chat-log .chat-line { margin-bottom: 6px; word-break: break-word; }
.chat-log .chat-line b { color: var(--gold); font-weight: 600; }
.chat-log .chat-line time { color: var(--muted); font-size: .7rem; margin-right: 6px; }
.chat-form { display: flex; gap: 8px; margin-top: 8px; }
.chat-form input {
  flex: 1; min-width: 0; background: #0e1813; color: var(--ink);
  border: 1px solid #2c4436; border-radius: 8px; padding: 8px 10px;
}

/* ---------- table view ---------- */
#table-topline { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
#table-title { flex: 1; font-weight: 700; letter-spacing: .05em; }
#game-container { position: relative; }
.table-chat {
  position: fixed; right: 14px; bottom: 14px; width: 300px; max-width: calc(100vw - 28px);
  background: var(--panel); border: 1px solid #2c4436; border-radius: var(--radius);
  padding: 10px; z-index: 60; display: flex; flex-direction: column; max-height: 320px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}

/* ---------- dialog ---------- */
dialog {
  background: var(--panel); color: var(--ink); border: 1px solid #2c4436;
  border-radius: 16px; padding: 22px; width: 340px; max-width: 92vw;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 14px; font-size: 1.1rem; }
dialog label { display: block; margin-bottom: 12px; font-size: .88rem; color: var(--muted); }
dialog input, dialog select {
  display: block; width: 100%; margin-top: 4px; background: #0e1813; color: var(--ink);
  border: 1px solid #2c4436; border-radius: 8px; padding: 9px 10px; font-size: .95rem;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- toasts ---------- */
#toasts {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--panel-2); border: 1px solid #3a5546; color: var(--ink);
  border-radius: 10px; padding: 10px 18px; font-size: .9rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.45); animation: toast-in .18s ease-out;
  max-width: 90vw;
}
.toast.error { border-color: var(--red); color: #ffb3b8; }
.toast.info { border-color: var(--gold); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- shared casino surfaces & chips ---------- */
/* 絨布桌面:多層徑向漸層 + 細噪點,營造質感 */
.felt-surface {
  background:
    radial-gradient(ellipse at 50% 38%, #2a8659 0%, #1c6b45 42%, #114a2f 100%);
  position: relative;
}
.felt-surface::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background-image: radial-gradient(rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 4px 4px; mix-blend-mode: overlay; opacity: .5;
}
.felt-surface::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 90px rgba(0,0,0,.55); /* 內陰影暈角 */
}
.wood-rail {
  border: 14px solid transparent;
  border-image: linear-gradient(135deg, #6b3f21, #99623a 20%, #5a3319 50%, #90592f 80%, #4d2c14) 30;
  box-shadow: 0 10px 40px rgba(0,0,0,.5), inset 0 0 0 2px rgba(0,0,0,.3);
}
.gold-trim { box-shadow: inset 0 0 0 2px var(--gold), 0 4px 20px rgba(0,0,0,.4); }

/* 賭場籌碼(可放金額/圖示) */
.casino-chip {
  --chip: #b23; width: 44px; height: 44px; border-radius: 50%; flex: none;
  background:
    repeating-conic-gradient(#fff 0deg 10deg, var(--chip) 10deg 20deg) padding-box;
  border: 3px solid var(--chip);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .72rem; color: #fff; position: relative;
  box-shadow: 0 3px 6px rgba(0,0,0,.5), inset 0 0 0 4px rgba(255,255,255,.15);
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.casino-chip::before {
  content: ''; position: absolute; inset: 7px; border-radius: 50%;
  background: var(--chip); box-shadow: inset 0 0 0 2px rgba(255,255,255,.35);
}
.casino-chip > * { position: relative; z-index: 1; }
.chip-50 { --chip: #2b7; } .chip-100 { --chip: #2a8; } .chip-500 { --chip: #7b3fd0; }
.chip-1k { --chip: #c98a1e; } .chip-5k { --chip: #c33; } .chip-red { --chip: #c33; }
.chip-black { --chip: #333; } .chip-gold { --chip: #c99b2f; }
.casino-chip.selected { outline: 3px solid var(--gold-bright); outline-offset: 2px; transform: translateY(-4px); }

/* 共用動畫 keyframes(遊戲視圖可套用) */
@keyframes fly-in { from { opacity: 0; transform: translateY(-40px) scale(.6); } to { opacity: 1; transform: none; } }
@keyframes glow-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(230,193,90,.0); } 50% { box-shadow: 0 0 18px 4px rgba(230,193,90,.7); } }
@keyframes win-flash { 0%,100% { filter: none; } 40% { filter: brightness(1.5) drop-shadow(0 0 12px var(--gold-bright)); } }
@keyframes card-flip-in {
  from { transform: rotateY(90deg) scale(.9); opacity: .3; }
  to { transform: none; opacity: 1; }
}
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
.anim-glow { animation: glow-pulse 1.2s ease-in-out infinite; }
.anim-winflash { animation: win-flash 1s ease-in-out 2; }

/* ---------- cards (shared) ---------- */
.card {
  display: inline-flex; flex-direction: column; justify-content: space-between;
  width: 56px; height: 78px; border-radius: 7px;
  background: linear-gradient(150deg, #ffffff 0%, #f4f4ea 60%, #e8e8dc 100%);
  color: #1a1a1a; position: relative;
  box-shadow: 0 2px 6px rgba(0,0,0,.35), inset 0 0 0 1px rgba(0,0,0,.08);
  font-weight: 700; user-select: none; flex: none;
}
.card.red { color: #c1272d; }
.card .c-corner { font-size: .82rem; line-height: 1; padding: 5px 0 0 6px; text-align: left; }
.card .c-corner small { display: block; font-size: .8em; }
.card .c-pip { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 1.7rem; }
.card .c-bottom { transform: rotate(180deg); padding: 5px 0 0 6px; font-size: .82rem; line-height: 1; }
.card.back {
  background: repeating-linear-gradient(45deg, #7a1f2b 0 6px, #5d1620 6px 12px);
  border: 3px solid #fdfdf6; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.card.back > * { visibility: hidden; }
.card.small { width: 40px; height: 56px; border-radius: 5px; }
.card.small .c-corner { font-size: .68rem; padding: 3px 0 0 4px; }
.card.small .c-pip { font-size: 1.15rem; }
.card.small .c-bottom { font-size: .68rem; padding: 3px 0 0 4px; }
.card.deal-anim { animation: card-deal .28s ease-out; }
@keyframes card-deal {
  from { opacity: 0; transform: translateY(-26px) scale(.7) rotate(-6deg); }
  to { opacity: 1; transform: none; }
}

/* generic seat avatar bubble used by games */
.seat-user { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.seat-user img, .seat-user .avatar-fallback {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid #3a5546;
  background: var(--panel-2); display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--gold);
}
