:root {
  --bg: #050f0b;
  --bg2: #0a1d16;
  --panel: #0f241c;
  --panel2: #143026;
  --line: #24493a;
  --text: #e9f3ee;
  --muted: #94b3a6;
  --gold: #e3b55a;
  --gold2: #ffe7a3;
  --green: #18a374;
  --red: #ff6b6b;
  --felt: #0d6b4e;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, #12392b 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.55 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--gold2); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h3 { font-size: 15px; color: var(--gold2); margin-bottom: 8px; display: flex; gap: 6px; align-items: baseline; }
h3 small { color: var(--muted); font-weight: 400; }

/* header */
.top { background: linear-gradient(#0a1f17, #06150f); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-inner { max-width: 1180px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 16px; }
.brand img { display: block; height: 52px; width: auto; }
.nav { margin-inline-start: auto; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.nav > span { display: contents; }
.link { background: none; border: 0; padding: 0; color: var(--gold2); cursor: pointer; }
.link:hover { text-decoration: underline; }
.link.small { font-size: 13px; color: var(--muted); }
.ticker { overflow: hidden; white-space: nowrap; border-top: 1px solid #10301f; background: #071a12; font-size: 13px; height: 26px; }
.ticker-track { display: inline-block; padding-inline-start: 100%; animation: tick 40s linear infinite; line-height: 26px; }
.ticker-track span { margin: 0 32px; }
[dir=ltr] .ticker-track { animation-name: tickl; }
@keyframes tick { to { transform: translateX(100%); } }
@keyframes tickl { to { transform: translateX(-100%); } }
@media (prefers-reduced-motion: reduce) { .ticker-track { animation: none; padding: 0 16px; } }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 16px; }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 18px; display: flex; gap: 6px; justify-content: center; align-items: center; }

/* generic */
.card { background: linear-gradient(180deg, var(--panel), #0c1e17); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 7px 14px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: #1b3c30; border-color: #2f6150; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.gold { background: linear-gradient(#f0c56d, #c8932f); color: #2a1a03; border-color: #e3b55a; font-weight: 700; }
.btn.gold:hover { background: linear-gradient(#ffd98a, #d8a03a); }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.danger { border-color: #7a2e2e; color: #ffb4b4; }
input, select { background: #081711; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
input[type=checkbox], input[type=range] { width: auto; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; }
.bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.bar h2 { font-size: 20px; }
.bar-meta { margin-inline-start: auto; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); display: inline-block; }
.help { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* auth */
.auth-wrap { display: grid; grid-template-columns: 1.1fr 1fr; gap: 28px; align-items: center; padding: 24px 0; }
.auth-hero h1 { font-size: 34px; margin: 10px 0; }
.auth-hero p { color: var(--muted); font-size: 17px; }
.hero-stats { list-style: none; padding: 0; display: flex; gap: 22px; margin: 18px 0 0; }
.hero-stats b { display: block; font-size: 26px; color: var(--gold2); }
.hero-stats span { color: var(--muted); font-size: 13px; }
.auth-card { max-width: 440px; width: 100%; justify-self: center; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { flex: 1; background: #0a1a14; border: 1px solid var(--line); border-radius: 9px; padding: 8px; cursor: pointer; }
.tab.active { background: var(--panel2); border-color: var(--gold); color: var(--gold2); }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form-msg { min-height: 1.4em; margin: 0; color: var(--red); font-size: 14px; }
.form-msg.ok { color: #7ee2b8; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.avatar-pick { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.avatar-pick button { padding: 0; border: 2px solid transparent; border-radius: 50%; background: none; cursor: pointer; aspect-ratio: 1; }
.avatar-pick button.sel { border-color: var(--gold); }
.avatar-pick img { width: 100%; display: block; border-radius: 50%; }

/* lobby */
.msgs { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.room { display: flex; gap: 12px; align-items: center; padding: 12px; cursor: pointer; text-align: start; width: 100%; border-radius: var(--radius); border: 1px solid var(--line); background: linear-gradient(180deg, var(--panel), #0c1e17); transition: transform .12s, border-color .12s; }
.room:hover { transform: translateY(-2px); border-color: var(--gold); }
.room.closed { opacity: .55; }
.room .flag { width: 42px; height: 28px; border-radius: 4px; object-fit: cover; background: #133; flex: none; box-shadow: 0 0 0 1px #0006; }
.room .rn { font-weight: 700; }
.room .rm { color: var(--muted); font-size: 13px; }
.room .lock { margin-inline-start: auto; }
.flag-ph { width: 42px; height: 28px; border-radius: 4px; flex: none; display: grid; place-items: center; background: #12392b; }

/* room */
.new-game { margin-inline-start: auto; display: flex; gap: 8px; }
.new-game select { width: auto; }
.room-grid { display: grid; grid-template-columns: 260px 1fr 1.2fr; gap: 12px; min-height: 520px; }
.users, .games, .chat { display: flex; flex-direction: column; min-height: 0; }
.search { margin-bottom: 8px; }
.user-list, .game-list, .viewers ul { list-style: none; padding: 0; margin: 0; overflow: auto; max-height: 560px; }
.user-list li { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 8px; cursor: pointer; position: relative; }
.user-list li:hover { background: #ffffff0d; }
.user-list .av, .game-list .av { width: 30px; height: 30px; border-radius: 50%; flex: none; }
.user-list .fl { width: 20px; height: 13px; border-radius: 2px; flex: none; }
.user-list .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-list .meta { color: var(--muted); font-size: 12px; }
.badge { font-size: 11px; padding: 0 6px; border-radius: 6px; background: #ffffff14; color: var(--muted); }
.badge.play { background: #18a37430; color: #7ee2b8; }
.badge.staff { background: #ff525230; color: #ffb4b4; }
.stars { color: var(--gold); letter-spacing: -1px; font-size: 12px; }
.game-list li { display: flex; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: #0a1b14; }
.game-list .vs { flex: 1; min-width: 0; }
.game-list .vs b { display: block; }
.game-list .gt { font-size: 12px; color: var(--gold2); }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.chat-log { flex: 1; overflow: auto; min-height: 240px; max-height: 470px; padding: 6px; background: #071510; border-radius: 8px; border: 1px solid #10301f; font-size: 14px; }
.chat-log p { margin: 0 0 4px; word-wrap: break-word; }
.chat-log .who { font-weight: 700; cursor: pointer; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 6px; margin-top: 8px; }
.emoji-pop { position: fixed; z-index: 60; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: grid; grid-template-columns: repeat(8, 32px); gap: 2px; box-shadow: var(--shadow); }
.emoji-pop button { background: none; border: 0; font-size: 20px; cursor: pointer; border-radius: 6px; }
.emoji-pop button:hover { background: #ffffff14; }

/* user menu */
.menu { position: fixed; z-index: 55; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px; min-width: 190px; box-shadow: var(--shadow); }
.menu button { display: block; width: 100%; text-align: start; background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: #ffffff12; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .sub { display: flex; gap: 4px; padding: 2px 6px 6px; }
.menu .sub button { flex: 1; text-align: center; border: 1px solid var(--line); font-size: 12px; padding: 4px; }

/* game */
.game-top { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; margin-bottom: 10px; }
.pl { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); transition: border-color .2s, box-shadow .2s; min-height: 64px; }
.pl.right { flex-direction: row-reverse; text-align: end; }
.pl.turn { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 18px #e3b55a55; }
.pl .av { width: 44px; height: 44px; border-radius: 50%; }
.pl .pn { display: block; font-size: 16px; }
.pl .ps { color: var(--muted); }
.pl .pballs { display: flex; gap: 2px; margin-top: 2px; flex-wrap: wrap; }
.pl .pballs canvas { width: 16px; height: 16px; }
.pl .clock { margin-inline-start: auto; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--gold2); min-width: 34px; text-align: center; }
.pl.right .clock { margin-inline-start: 0; margin-inline-end: auto; }
.game-center { text-align: center; }
.gtype { font-family: 'Cinzel', Georgia, serif; color: var(--gold); font-size: 18px; }
.gmsg { color: var(--muted); font-size: 13px; min-height: 1.4em; }
.table-wrap { position: relative; width: 100%; max-width: 1000px; margin: 0 auto; }
#table { width: 100%; height: auto; display: block; border-radius: 18px; touch-action: none; cursor: crosshair; background: #2b160a; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: #0008; border-radius: 18px; text-align: center; }
.overlay .ov-box { background: var(--panel); border: 1px solid var(--gold); border-radius: 14px; padding: 22px 30px; box-shadow: var(--shadow); }
.overlay h2 { font-family: 'Cinzel', Georgia, serif; color: var(--gold2); font-size: 28px; margin-bottom: 6px; }
.controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; max-width: 1000px; margin: 10px auto; }
.power { display: flex; align-items: center; gap: 8px; }
.power input { width: 180px; accent-color: var(--gold); }
.power output { min-width: 28px; color: var(--gold2); font-variant-numeric: tabular-nums; }
.spin { width: 40px; height: 40px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #d9d9d9 60%, #9a9a9a); position: relative; cursor: pointer; flex: none; box-shadow: inset 0 0 0 1px #0004; }
.spin-dot { position: absolute; width: 9px; height: 9px; border-radius: 50%; background: #d43; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.grow { flex: 1; }
.game-bottom { display: grid; grid-template-columns: 1.6fr 1fr; gap: 12px; max-width: 1000px; margin: 0 auto; }
.game-bottom .chat-log { min-height: 160px; max-height: 220px; }
.viewers li { padding: 3px 0; }

/* modal, toasts, pm */
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 70; padding: 16px; }
.modal-box { position: relative; width: min(520px, 100%); max-height: 90vh; overflow: auto; }
.modal-x { position: absolute; top: 6px; inset-inline-end: 10px; background: none; border: 0; font-size: 26px; color: var(--muted); cursor: pointer; }
.modal h2 { margin-bottom: 12px; color: var(--gold2); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat-grid div { background: #0a1b14; border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; }
.stat-grid b { display: block; font-size: 20px; color: var(--gold2); }
.stat-grid span { font-size: 12px; color: var(--muted); }
.prof-head { display: flex; gap: 12px; align-items: center; }
.prof-head img.av { width: 64px; height: 64px; border-radius: 50%; }
.toasts { position: fixed; bottom: 16px; inset-inline-start: 16px; display: grid; gap: 8px; z-index: 80; max-width: min(360px, calc(100vw - 32px)); }
.toast { background: var(--panel2); border: 1px solid var(--line); border-inline-start: 4px solid var(--gold); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); animation: pop .2s ease-out; }
.toast.err { border-inline-start-color: var(--red); }
.toast .actions { display: flex; gap: 6px; margin-top: 8px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.pms { position: fixed; bottom: 0; inset-inline-end: 16px; display: flex; gap: 10px; align-items: flex-end; z-index: 50; }
.pm { width: 270px; background: var(--panel); border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.pm header { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: var(--panel2); border-radius: 10px 10px 0 0; cursor: pointer; font-weight: 700; }
.pm header button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; }
.pm .chat-log { min-height: 160px; max-height: 200px; margin: 6px; }
.pm form { display: flex; gap: 4px; padding: 0 6px 6px; }
.pm.min .chat-log, .pm.min form { display: none; }
.pm.flash header { background: #6b4d14; }
.conn-lost { position: fixed; top: 90px; left: 50%; transform: translateX(-50%); background: #7a2e2e; padding: 8px 18px; border-radius: 20px; z-index: 90; }

/* tables page */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: start; }
.tbl th { color: var(--gold2); font-weight: 600; font-size: 13px; }
.tbl tr:hover td { background: #ffffff08; }
.tbl .fl { width: 20px; height: 13px; border-radius: 2px; vertical-align: middle; }

@media (max-width: 960px) {
  .room-grid { grid-template-columns: 1fr 1fr; }
  .room-grid .chat { grid-column: 1 / -1; }
  .auth-wrap { grid-template-columns: 1fr; }
  .game-bottom { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .brand img { height: 38px; }
  .top-inner { flex-wrap: wrap; gap: 6px; }
  .nav { gap: 10px; font-size: 14px; }
  .room-grid { grid-template-columns: 1fr; }
  .game-top { grid-template-columns: 1fr 1fr; }
  .game-center { grid-column: 1 / -1; order: -1; }
  .pl .av { width: 34px; height: 34px; }
  .power input { width: 120px; }
  .new-game { margin-inline-start: 0; width: 100%; }
  .auth-hero h1 { font-size: 26px; }
  .pms { inset-inline-end: 4px; }
  .pm { width: 220px; }
}
/* bidi fixes: Latin game names and range sliders stay left-to-right inside the RTL layout */
.gtype, .gt, #newType, .ltr { direction: ltr; unicode-bidi: isolate; }
.gt { display: inline-block; }
.power input[type=range] { direction: ltr; }
