:root {
  --bg: #071C15; --bg-2: #0A2A1F; --primary: #0E4D3B; --primary-2: #146B52; --emerald: #1FA37A;
  --gold: #D4AF37; --gold-2: #F0D77A; --ivory: #F5F0DD; --text: #FFFFFF; --muted: #A9C4B6; --danger: #E05A5A;
  --tile-w: 46px; --tile-h: 64px; --radius: 14px; --shadow: 0 18px 50px rgba(0,0,0,.45);
  --font-display: 'Cinzel', Georgia, serif; --font-body: 'Manrope', 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 15px; line-height: 1.5; -webkit-tap-highlight-color: transparent; overflow-x: hidden; }
body::before { content: ''; position: fixed; inset: 0; z-index: -2; background: radial-gradient(1200px 600px at 20% -10%, rgba(31,163,122,.22), transparent 60%), radial-gradient(900px 500px at 110% 110%, rgba(212,175,55,.14), transparent 60%), var(--bg); }
.noise { position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .06; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
a { color: var(--gold-2); text-decoration: none; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: .02em; margin: 0 0 .5rem; }
h1 { font-size: 2rem; } h2 { font-size: 1.25rem; color: var(--gold-2); }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.kicker { text-transform: uppercase; letter-spacing: .2em; font-size: .72rem; color: var(--gold); font-weight: 700; margin-bottom: .2rem; }
code { background: rgba(255,255,255,.08); padding: .1em .4em; border-radius: 6px; }
::selection { background: var(--gold); color: var(--bg); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 1.5rem; padding: .7rem 1.5rem; background: rgba(7,28,21,.78); backdrop-filter: blur(16px); border-bottom: 1px solid rgba(212,175,55,.18); }
.brand { display: flex; flex-direction: column; line-height: 1; }
.brand-mark { font-family: var(--font-display); font-weight: 900; font-size: 1.5rem; color: var(--gold); letter-spacing: .12em; }
.brand-sub { font-size: .62rem; text-transform: uppercase; letter-spacing: .22em; color: var(--muted); margin-top: .25rem; }
.brand-center { align-items: center; margin-bottom: 1rem; }
.brand-mini .brand-mark { font-size: 1.2rem; }
.topnav { display: flex; gap: 1.25rem; margin-left: 1rem; }
.topnav a { color: var(--muted); font-weight: 600; font-size: .9rem; position: relative; transition: color .2s; }
.topnav a:hover { color: var(--text); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.user-chip { display: flex; align-items: center; gap: .5rem; color: var(--text); font-weight: 600; font-size: .9rem; }
.icon-btn { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); color: var(--text); width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-weight: 700; font-size: .85rem; transition: background-color .2s, transform .15s; }
.icon-btn:hover { background: rgba(255,255,255,.12); transform: translateY(-1px); }

.page { max-width: 1180px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; border: 1px solid transparent; border-radius: 999px; padding: .7rem 1.4rem; font-weight: 700; font-family: var(--font-body); font-size: .95rem; cursor: pointer; color: var(--text); background: rgba(255,255,255,.08); transition: transform .15s, background-color .2s, box-shadow .2s, opacity .2s; min-height: 44px; text-align: center; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-gold { background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: #1a1500; box-shadow: 0 10px 30px rgba(212,175,55,.25); }
.btn-gold:hover { box-shadow: 0 14px 34px rgba(212,175,55,.4); }
.btn-primary { background: var(--primary-2); }
.btn-primary:hover { background: var(--emerald); }
.btn-outline { border-color: var(--gold); color: var(--gold-2); background: transparent; }
.btn-ghost { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.12); }
.btn-danger { background: rgba(224,90,90,.18); border-color: rgba(224,90,90,.4); color: #ffb3b3; }
.btn-sm { padding: .45rem .95rem; font-size: .82rem; min-height: 36px; }
.btn-lg { padding: .95rem 2rem; font-size: 1.05rem; }
.btn-block { width: 100%; }

/* Cards & forms */
.card { background: linear-gradient(160deg, rgba(14,77,59,.55), rgba(7,28,21,.75)); border: 1px solid rgba(212,175,55,.16); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.form { display: flex; flex-direction: column; gap: 1rem; }
.form-compact { gap: .75rem; }
.form label { display: flex; flex-direction: column; gap: .35rem; font-size: .82rem; color: var(--muted); font-weight: 600; flex: 1; }
.form input, .form select, .chat-input input { background: rgba(0,0,0,.3); border: 1px solid rgba(255,255,255,.12); color: var(--text); border-radius: 10px; padding: .7rem .9rem; font-size: 1rem; font-family: inherit; min-height: 44px; outline: none; transition: border-color .2s, box-shadow .2s; }
.form input:focus, .form select:focus, .chat-input input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,175,55,.18); }
.form select option { background: var(--bg-2); }
.form-row { display: flex; gap: .75rem; }
.form .check { flex-direction: row; align-items: center; gap: .5rem; justify-content: flex-start; padding-top: 1.4rem; }
.form .check input { width: 20px; height: 20px; min-height: 0; }
.form-error { background: rgba(224,90,90,.15); border: 1px solid rgba(224,90,90,.4); color: #ffb3b3; padding: .6rem .9rem; border-radius: 10px; font-size: .88rem; }
.code-input { text-transform: uppercase; letter-spacing: .35em; font-family: var(--font-display); font-weight: 700; font-size: 1.3rem !important; }

/* Landing */
.landing .page { display: grid; place-items: center; min-height: 100vh; padding-top: 3rem; }
.hero { max-width: 760px; text-align: left; animation: rise .8s ease both; }
.hero-tiles { display: flex; gap: .5rem; margin-bottom: 1.5rem; }
.hero-tiles .tile { animation: float 4s ease-in-out infinite; }
.hero-tiles .tile:nth-child(2) { animation-delay: .5s; } .hero-tiles .tile:nth-child(3) { animation-delay: 1s; } .hero-tiles .tile:nth-child(4) { animation-delay: 1.5s; }
.hero-kicker { text-transform: uppercase; letter-spacing: .3em; color: var(--gold); font-size: .75rem; font-weight: 700; }
.hero-title { font-size: clamp(4rem, 12vw, 7.5rem); line-height: .9; color: var(--gold); text-shadow: 0 0 40px rgba(212,175,55,.35); margin: 0; }
.hero-subtitle { font-size: clamp(1.3rem, 3.5vw, 2rem); color: var(--text); margin-top: .5rem; }
.hero-tagline { font-family: var(--font-display); color: var(--gold-2); letter-spacing: .3em; text-transform: uppercase; font-size: .9rem; }
.hero-desc { color: var(--muted); font-size: 1.05rem; max-width: 560px; margin: 1.25rem 0 1.75rem; }
.hero-actions { display: flex; gap: .75rem; flex-wrap: wrap; }
.hero-features { list-style: none; padding: 0; margin: 2.5rem 0 0; display: flex; gap: 2rem; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }
.hero-features li::before { content: '◆ '; color: var(--gold); }

/* Auth */
.auth-page .page { display: grid; place-items: center; min-height: 100vh; }
.auth-card { width: min(440px, 100%); padding: 2.25rem; background: linear-gradient(160deg, rgba(14,77,59,.6), rgba(7,28,21,.8)); border: 1px solid rgba(212,175,55,.2); border-radius: 20px; box-shadow: var(--shadow); animation: rise .6s ease both; display: flex; flex-direction: column; gap: 1rem; }
.auth-card h1 { font-size: 1.5rem; }
.auth-switch, .auth-demo { font-size: .85rem; color: var(--muted); text-align: center; margin: 0; }

/* Lobby */
.lobby-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.stat-row { display: flex; gap: 1.5rem; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.stat b { font-family: var(--font-display); font-size: 1.5rem; color: var(--gold-2); }
.stat span { font-size: .72rem; text-transform: uppercase; letter-spacing: .15em; color: var(--muted); }
.banner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; background: rgba(212,175,55,.12); border: 1px solid rgba(212,175,55,.4); border-radius: var(--radius); padding: .9rem 1.25rem; margin-bottom: 1.25rem; }
.lobby-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.card-wide { grid-column: 1 / -1; }
.card-action { background: linear-gradient(160deg, rgba(212,175,55,.22), rgba(14,77,59,.5)); }
.room-list { display: flex; flex-direction: column; gap: .6rem; }
.room-row { display: flex; align-items: center; gap: 1rem; padding: .75rem 1rem; background: rgba(0,0,0,.25); border-radius: 10px; border: 1px solid rgba(255,255,255,.06); }
.room-row b { font-family: var(--font-display); letter-spacing: .15em; color: var(--gold-2); }
.room-row .grow { flex: 1; }

/* Avatars */
.avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; font-weight: 800; font-family: var(--font-display); color: #fff; background: var(--primary-2); border: 2px solid rgba(255,255,255,.25); flex-shrink: 0; }
.avatar-xl { width: 84px; height: 84px; font-size: 2rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.4rem; }
.av-a1 { background: linear-gradient(135deg,#1FA37A,#0E4D3B); } .av-a2 { background: linear-gradient(135deg,#D4AF37,#8a6d1c); } .av-a3 { background: linear-gradient(135deg,#E05A5A,#7a1f1f); }
.av-a4 { background: linear-gradient(135deg,#4A90E2,#1b3f73); } .av-a5 { background: linear-gradient(135deg,#9B59B6,#4a2160); } .av-a6 { background: linear-gradient(135deg,#F39C12,#7d4e04); }
.av-a7 { background: linear-gradient(135deg,#1ABC9C,#0c5d4d); } .av-a8 { background: linear-gradient(135deg,#E91E63,#6d0b2c); } .av-a9 { background: linear-gradient(135deg,#607D8B,#25343b); }
.av-a10 { background: linear-gradient(135deg,#FF7043,#8a2f14); } .av-a11 { background: linear-gradient(135deg,#8BC34A,#3e6318); } .av-a12 { background: linear-gradient(135deg,#00BCD4,#005f6b); }
.av-ai { background: linear-gradient(135deg,#2c3e50,#0d1418); border-style: dashed; }
.avatar-picker { display: flex; gap: .5rem; flex-wrap: wrap; }
.avatar-picker .avatar { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.avatar-picker .avatar.selected { box-shadow: 0 0 0 3px var(--gold); transform: scale(1.1); }

/* Tables */
.table-wrap { overflow-x: auto; padding: 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data-table th, .data-table td { padding: .85rem 1rem; text-align: left; border-bottom: 1px solid rgba(255,255,255,.06); white-space: nowrap; }
.data-table th { color: var(--gold); font-size: .72rem; text-transform: uppercase; letter-spacing: .15em; }
.data-table tr.clickable { cursor: pointer; transition: background-color .15s; }
.data-table tr.clickable:hover { background: rgba(255,255,255,.04); }
.player-cell { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.badge { display: inline-block; padding: .2em .65em; border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.badge-win { background: rgba(212,175,55,.2); color: var(--gold-2); } .badge-lose { background: rgba(224,90,90,.18); color: #ffb3b3; } .badge-draw { background: rgba(255,255,255,.1); color: var(--muted); }
.badge-ai { background: rgba(255,255,255,.1); color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; margin: 1rem 0; }
.stat-grid .stat { background: rgba(0,0,0,.25); border-radius: 10px; padding: .9rem .5rem; }
.profile-head { display: flex; align-items: center; gap: 1.25rem; }
.profile-card { margin-bottom: 1.25rem; }
.tabs { display: flex; gap: .5rem; margin: 1rem 0; flex-wrap: wrap; }
.tab { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); color: var(--muted); border-radius: 999px; padding: .5rem 1rem; cursor: pointer; font-weight: 700; }
.tab.active { background: var(--gold); color: #1a1500; }

/* Toasts & modals */
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; }
.toast { background: rgba(10,42,31,.95); border: 1px solid rgba(212,175,55,.35); color: var(--text); padding: .75rem 1rem; border-radius: 10px; box-shadow: var(--shadow); animation: rise .3s ease both; max-width: 320px; font-size: .9rem; }
.toast-error { border-color: var(--danger); } .toast-success { border-color: var(--emerald); }
.modal { position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.6); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-card { width: min(520px, 100%); max-height: 90vh; overflow: auto; background: linear-gradient(160deg, #0f4a39, #071C15); border: 1px solid rgba(212,175,55,.35); border-radius: 20px; padding: 1.75rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .75rem; animation: rise .35s ease both; }

/* Waiting room */
.room-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.room-code-box { display: flex; flex-direction: column; align-items: center; background: rgba(0,0,0,.3); border: 1px dashed rgba(212,175,55,.5); border-radius: var(--radius); padding: .75rem 1.5rem; gap: .25rem; }
.room-code-box span { font-size: .68rem; letter-spacing: .3em; color: var(--gold); }
.room-code-box b { font-family: var(--font-display); font-size: 2.4rem; letter-spacing: .3em; color: var(--gold-2); }
.room-body { display: grid; grid-template-columns: 1fr 340px; gap: 1.25rem; align-items: stretch; }
.seats { position: relative; display: grid; grid-template-columns: 1fr 1.4fr 1fr; grid-template-rows: auto 1fr auto; gap: .75rem; min-height: 460px; background: radial-gradient(ellipse at center, #135a45 0%, #0E4D3B 55%, #0a3529 100%); border-radius: 24px; border: 6px solid #3b2a12; box-shadow: inset 0 0 60px rgba(0,0,0,.45), var(--shadow); padding: 1rem; }
.seat-top { grid-column: 2; grid-row: 1; } .seat-left { grid-column: 1; grid-row: 2; } .seat-center { grid-column: 2; grid-row: 2; display: grid; place-items: center; text-align: center; }
.seat-right { grid-column: 3; grid-row: 2; } .seat-bottom { grid-column: 2; grid-row: 3; }
.seat { display: grid; place-items: center; }
.table-logo { font-family: var(--font-display); font-size: 2.4rem; color: rgba(212,175,55,.35); letter-spacing: .3em; }
.player-card { display: flex; flex-direction: column; align-items: center; gap: .35rem; background: rgba(0,0,0,.3); border: 1px solid rgba(255,255,255,.1); border-radius: 14px; padding: .75rem 1rem; min-width: 150px; transition: border-color .2s, box-shadow .2s; }
.player-card.ready { border-color: var(--emerald); box-shadow: 0 0 20px rgba(31,163,122,.35); }
.player-card.host .name::after { content: ' ★'; color: var(--gold); }
.player-card .name { font-weight: 700; }
.player-card .sub { font-size: .75rem; color: var(--muted); display: flex; gap: .4rem; align-items: center; }
.player-card.empty { border-style: dashed; color: var(--muted); font-size: .85rem; }
.ping { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: #777; }
.ping-good { background: #2ecc71; } .ping-fair { background: #f1c40f; } .ping-poor { background: var(--danger); }
.room-actions { display: flex; gap: .75rem; margin-top: 1.25rem; flex-wrap: wrap; }
.chat-fab { display: none; }

/* Chat */
.chat-panel { display: flex; flex-direction: column; background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.08); border-radius: var(--radius); min-height: 300px; overflow: hidden; }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: .7rem 1rem; border-bottom: 1px solid rgba(255,255,255,.08); font-weight: 700; color: var(--gold-2); font-family: var(--font-display); }
.chat-close { display: none; }
.chat-messages { flex: 1; overflow-y: auto; padding: .75rem 1rem; display: flex; flex-direction: column; gap: .45rem; font-size: .9rem; min-height: 0; }
.chat-msg { display: flex; flex-direction: column; animation: rise .25s ease both; }
.chat-msg .meta { font-size: .72rem; color: var(--muted); display: flex; gap: .5rem; }
.chat-msg .meta b { color: var(--gold-2); }
.chat-msg .body { background: rgba(255,255,255,.06); padding: .4rem .7rem; border-radius: 10px; align-self: flex-start; max-width: 100%; word-break: break-word; }
.chat-msg.mine .body { background: rgba(31,163,122,.3); align-self: flex-end; }
.chat-msg.mine { align-items: flex-end; }
.chat-msg.system { align-items: center; font-size: .78rem; color: var(--muted); font-style: italic; }
.chat-input { display: flex; gap: .5rem; padding: .6rem; border-top: 1px solid rgba(255,255,255,.08); }
.chat-input input { flex: 1; min-width: 0; }
.chat-input .btn { min-height: 44px; padding: 0 1rem; }
.emoji-bar { display: flex; gap: .25rem; padding: 0 .6rem .5rem; flex-wrap: wrap; }
.emoji-bar button { background: none; border: none; font-size: 1.2rem; cursor: pointer; padding: .2rem; transition: transform .15s; }
.emoji-bar button:hover { transform: scale(1.25); }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(212,175,55,.5); } 50% { box-shadow: 0 0 30px 6px rgba(212,175,55,.55); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
