:root {
  color-scheme: dark;
  --ink: #eef5ea;
  --muted: #92a89e;
  --gold: #dfb95d;
  --gold-light: #f4d88c;
  --red: #d9574d;
  --felt: #0a4937;
  --felt-dark: #063427;
  --bg: #05100e;
  --panel: #091714;
  --line: rgba(238, 245, 234, 0.12);
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  --sans: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(16, 87, 66, 0.32), transparent 36rem),
    linear-gradient(180deg, #061511 0%, #030b09 100%);
  font-family: var(--sans);
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold-light); outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.noise {
  position: fixed; inset: 0; pointer-events: none; z-index: 20; opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.8'/%3E%3C/svg%3E");
}

.topbar {
  height: 78px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(20px, 4vw, 64px); border-bottom: 1px solid var(--line);
}

.brand { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.brand-mark, .dialog-brand > span {
  display: grid; place-items: center; width: 39px; aspect-ratio: 1; border: 1px solid var(--gold);
  border-radius: 50%; color: var(--gold-light); font-family: var(--mono); font-weight: 500; font-size: 13px;
}
.brand > span:last-child { display: flex; flex-direction: column; line-height: 1; gap: 5px; }
.brand strong { font-size: 14px; letter-spacing: 0.08em; }
.brand small { color: var(--gold); font: 500 9px/1 var(--mono); letter-spacing: 0.28em; }

.topbar-actions { display: flex; align-items: center; gap: 24px; }
.connection { color: var(--muted); font: 11px var(--mono); display: flex; align-items: center; gap: 8px; }
.connection i, .round-pill i { width: 7px; height: 7px; border-radius: 50%; background: #54d39b; box-shadow: 0 0 12px #54d39b; }
.connection.offline i { background: var(--red); box-shadow: 0 0 12px var(--red); }
.player-chip { display: flex; align-items: center; gap: 10px; padding: 0; border: 0; background: none; cursor: pointer; text-align: left; }
.player-chip > span:last-child { display: flex; flex-direction: column; gap: 2px; }
.player-chip small { color: var(--muted); font-size: 10px; }
.player-chip strong { color: var(--gold-light); font: 500 12px var(--mono); }
.avatar { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 50%; background: #153128; color: var(--gold-light); font-weight: 800; }

main { width: min(1500px, calc(100% - 40px)); margin: 0 auto; padding: 60px 0 80px; }
.hero { display: flex; justify-content: space-between; gap: 40px; align-items: flex-end; margin-bottom: 36px; }
.eyebrow { margin: 0 0 13px; color: var(--gold); font: 500 10px var(--mono); letter-spacing: 0.22em; text-transform: uppercase; }
h1 { font-size: clamp(34px, 4.4vw, 68px); line-height: 1.08; letter-spacing: -0.06em; margin: 0; font-weight: 800; }
h1 em { color: var(--muted); font-style: normal; font-weight: 500; }
.rules-summary { max-width: 390px; padding-left: 23px; border-left: 1px solid var(--gold); }
.rules-summary span { color: var(--gold-light); font-size: 12px; font-weight: 700; }
.rules-summary p { color: var(--muted); margin: 8px 0 0; font-size: 13px; line-height: 1.85; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: var(--panel); box-shadow: 0 40px 100px rgba(0,0,0,.35); }
.table-shell { min-width: 0; }
.table-status { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 25px; border-bottom: 1px solid var(--line); }
.round-pill { display: flex; gap: 10px; align-items: center; font-size: 12px; }
.opening-pill { display: flex; align-items: center; gap: 9px; color: #75e1ae; }
.opening-pill > i { width: 7px; height: 7px; border-radius: 50%; background: #54d39b; box-shadow: 0 0 12px #54d39b; }
.opening-pill > span { display: flex; flex-direction: column; line-height: 1.35; }
.opening-pill b { font-size: 10px; }
.opening-pill small { color: var(--muted); font-size: 8px; }
.opening-pill.closed { color: #f08983; }
.opening-pill.closed > i { background: var(--red); box-shadow: 0 0 12px var(--red); }
.timer { display: flex; align-items: baseline; gap: 12px; }
.timer small { color: var(--muted); font-size: 10px; }
.timer strong { font: 500 18px var(--mono); color: var(--gold-light); min-width: 55px; text-align: right; }

.felt {
  position: relative; min-height: 590px; overflow: hidden; padding: 46px 28px 28px;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(17, 111, 80, .85), rgba(4, 49, 37, .85) 67%),
    repeating-linear-gradient(35deg, transparent 0 3px, rgba(255,255,255,.008) 3px 4px);
}
.felt::before { content:""; position:absolute; inset: 14px; border: 1px solid rgba(223,185,93,.28); border-radius: 48% 48% 6px 6px / 25% 25% 6px 6px; pointer-events:none; }
.felt-line { position:absolute; width: 82%; height: 58%; left: 9%; top: 21%; border: 1px solid rgba(238,245,234,.16); border-radius: 50%; }
.dealer-zone { position: relative; z-index: 2; text-align: center; min-height: 155px; }
.seat-label { display: inline-flex; align-items: center; gap: 9px; margin-bottom: 17px; color: var(--muted); font: 500 9px var(--mono); letter-spacing: .18em; }
.seat-label b { display: grid; place-items: center; min-width: 25px; height: 21px; padding: 0 6px; border-radius: 12px; background: rgba(0,0,0,.32); color: var(--gold-light); font: 500 11px var(--mono); letter-spacing: 0; }
.cards { display: flex; justify-content: center; min-height: 97px; padding-left: 20px; }
.card {
  width: 66px; height: 92px; margin-left: -20px; padding: 7px; border-radius: 6px; color: #14201c; background: #f4f1e9;
  box-shadow: 0 8px 18px rgba(0,0,0,.27); font: 700 17px/1 var(--mono); text-align: left; transform: rotate(var(--tilt, 0deg));
}
.card.red { color: #b83d38; }
.card small { display: block; margin-top: 5px; font-size: 16px; }
.card.back {
  position: relative; background: repeating-linear-gradient(45deg, #172a25 0 5px, #dfb95d 5px 6px); border: 4px solid #e7dec8;
}
.card.back::after { content:"21"; position:absolute; inset:8px; display:grid; place-items:center; border:1px solid rgba(255,255,255,.5); border-radius:3px; color:#f7e7b6; font-size:14px; }

.table-center { position: relative; z-index: 1; height: 105px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: rgba(238,245,234,.3); }
.table-center span, .table-center small { font: 500 9px var(--mono); letter-spacing: .18em; }
.table-center strong { color: rgba(223,185,93,.35); font-size: 26px; line-height: 1.2; }
.players-zone { position: relative; z-index: 2; min-height: 220px; display: flex; align-items: flex-end; justify-content: center; gap: clamp(12px, 2.4vw, 36px); }
.empty-table { color: rgba(238,245,234,.38); text-align: center; margin: auto; }
.empty-table span { font-size: 30px; color: rgba(223,185,93,.3); }
.empty-table p { margin: 9px 0; font-size: 12px; }
.player-seat { width: min(165px, 23%); text-align: center; opacity: .7; transition: opacity .2s, transform .2s; }
.player-seat.active { opacity: 1; transform: translateY(-5px); }
.player-seat.self { opacity: 1; }
.player-seat .cards { min-height: 87px; padding-left: 16px; }
.player-seat .card { width: 57px; height: 80px; font-size: 14px; margin-left: -16px; }
.player-seat .card small { font-size: 14px; }
.player-meta { margin-top: 10px; }
.player-meta strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.player-meta small { color: var(--muted); font: 9px var(--mono); }
.player-meta b { color: var(--gold-light); font-weight: 500; }
.result-badge { display: inline-block; margin-bottom: 6px; padding: 3px 7px; border-radius: 10px; background: #153e31; color: #75e1ae; font: 500 9px var(--mono); }
.result-badge.lost { background: #3a1d1b; color: #f08983; }
.result-badge.push { background: #323329; color: #e2ce8e; }

.action-dock { min-height: 92px; display: flex; align-items: center; padding: 16px 24px; border-top: 1px solid var(--line); }
.bet-control, .turn-control { width: 100%; display: flex; align-items: center; gap: 18px; }
.bet-control > div:first-child { margin-right: auto; }
.bet-control label, .turn-control strong { display: block; font-size: 13px; font-weight: 700; }
.bet-control small, .turn-control small, .waiting-message small { color: var(--muted); font-size: 9px; }
.stepper { display: flex; height: 46px; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
.stepper button { width: 39px; border: 0; background: rgba(255,255,255,.035); cursor: pointer; }
.stepper input { width: 94px; border: 0; border-inline: 1px solid var(--line); background: transparent; color: var(--gold-light); text-align: center; font: 500 14px var(--mono); appearance: textfield; }
.stepper input::-webkit-inner-spin-button { display: none; }
.primary-button, .secondary-button { min-height: 46px; padding: 0 24px; border-radius: 3px; cursor: pointer; font-weight: 700; font-size: 12px; }
.primary-button { border: 1px solid var(--gold); background: var(--gold); color: #102019; }
.primary-button:hover:not(:disabled) { background: var(--gold-light); border-color: var(--gold-light); }
.secondary-button { border: 1px solid var(--line); background: transparent; }
.turn-control > div { margin-right: auto; }
.waiting-message { display: flex; align-items: center; gap: 13px; margin: auto; }
.waiting-message div { display: flex; flex-direction: column; }
.waiting-message strong { font-size: 12px; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); animation: pulse 1.5s infinite; }
.hidden { display: none !important; }

.side-panel { display: flex; flex-direction: column; border-left: 1px solid var(--line); background: #081310; }
.panel-block { padding: 24px; border-bottom: 1px solid var(--line); }
.panel-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 21px; font-size: 12px; font-weight: 700; }
.panel-heading small { color: #54d39b; font: 9px var(--mono); letter-spacing: .14em; }
.event-list, .leaderboard { list-style: none; padding: 0; margin: 0; }
.event-list { max-height: 285px; overflow: auto; }
.event-list li { display: grid; grid-template-columns: 8px 1fr; gap: 10px; padding-bottom: 16px; }
.event-list i { width: 5px; height: 5px; margin-top: 7px; border-radius: 50%; background: var(--gold); }
.event-list p { margin: 0 0 4px; color: #c7d4ce; font-size: 11px; line-height: 1.5; }
.event-list time { color: #637a70; font: 8px var(--mono); }
.leaderboard li { display: grid; grid-template-columns: 20px 1fr auto; gap: 8px; align-items: center; padding: 8px 0; font-size: 10px; }
.leaderboard li > span:first-child { color: #647b71; font: 9px var(--mono); }
.leaderboard strong { font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard b { color: var(--gold-light); font: 500 10px var(--mono); }
.fairness-note { margin: auto 24px 24px; padding: 16px; border: 1px solid rgba(223,185,93,.22); background: rgba(223,185,93,.035); }
.fairness-note span { color: var(--gold-light); font-size: 10px; font-weight: 700; }
.fairness-note p { color: var(--muted); font-size: 9px; line-height: 1.7; margin: 7px 0 0; }

dialog { width: min(460px, calc(100% - 32px)); padding: 0; border: 1px solid rgba(223,185,93,.33); border-radius: 5px; background: #091713; color: var(--ink); box-shadow: 0 35px 110px #000; }
dialog::backdrop { background: rgba(1,8,6,.87); backdrop-filter: blur(9px); }
dialog form { padding: 40px; }
.dialog-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 34px; }
.dialog-brand small { color: var(--gold); font: 500 9px var(--mono); letter-spacing: .2em; }
dialog h2 { margin: 0; font-size: 34px; line-height: 1.15; letter-spacing: -.04em; }
.dialog-copy { color: var(--muted); font-size: 11px; line-height: 1.8; margin: 14px 0 24px; }
dialog label { display: block; margin-top: 14px; color: #c6d5ce; font-size: 10px; }
dialog input { display: block; width: 100%; margin-top: 7px; height: 47px; padding: 0 13px; border: 1px solid var(--line); border-radius: 3px; background: rgba(255,255,255,.035); color: var(--ink); }
dialog form > button { width: 100%; margin-top: 20px; }
.form-error { min-height: 16px; color: #ef817b; font-size: 10px; margin: 8px 0 -8px; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: 28px; transform: translate(-50%, 25px); padding: 11px 16px; border: 1px solid var(--line); border-radius: 3px; background: #10231d; color: var(--ink); font-size: 11px; opacity: 0; pointer-events:none; transition: .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes pulse { 50% { transform: scale(1.7); opacity: .35; } }

@media (max-width: 1050px) {
  .game-layout { grid-template-columns: 1fr; }
  .side-panel { border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; }
  .fairness-note { display: none; }
}

@media (max-width: 720px) {
  .topbar { height: 66px; padding-inline: 16px; }
  .connection { display: none; }
  main { width: calc(100% - 20px); padding-top: 34px; }
  .hero { display: block; }
  .rules-summary { margin-top: 25px; max-width: none; }
  .felt { min-height: 540px; padding-inline: 10px; }
  .players-zone { gap: 4px; flex-wrap: wrap; }
  .player-seat { width: 31%; }
  .player-seat .card { width: 48px; height: 69px; }
  .action-dock { padding: 13px; }
  .bet-control { flex-wrap: wrap; gap: 10px; }
  .bet-control > div:first-child { width: 100%; }
  .stepper { flex: 1; }
  .stepper input { width: 74px; }
  .primary-button, .secondary-button { padding-inline: 16px; }
  .turn-control { gap: 8px; }
  .side-panel { display: block; }
  .leaderboard-block { display: none; }
  dialog form { padding: 28px 22px; }
}
  .opening-pill small { display: none; }
