:root {
  --bg: #14163a;
  --bg2: #1a1d45;
  --panel: #1f2352;
  --panel2: #272b63;
  --line: #3a3f80;
  --text: #f6efe1;
  --muted: #a9acd6;
  --gold: #f2b134;
  --rose: #ec5f7a;
  --teal: #5cc9b8;
  --danger: #ff7b8f;
  --radius: 14px;
  --font: 'Nunito', system-ui, sans-serif;
  --display: 'Baloo 2', 'Nunito', system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 400 17px/1.65 var(--font);
  background-image: radial-gradient(circle at 20% -10%, #262a6b 0, transparent 45%), radial-gradient(circle at 100% 110%, #2a1f55 0, transparent 40%);
  background-attachment: fixed;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 2.1rem; } h2 { font-size: 1.45rem; } h3 { font-size: 1.15rem; color: var(--muted); font-family: var(--font); font-weight: 600; margin-top: 1em; }
p { margin: 0 0 .8em; }
a { color: var(--teal); }
b { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.center { justify-content: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--gold); color: #1a1d45; padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; border-radius: 6px; }
main { max-width: 1120px; margin: 0 auto; padding: 22px 16px 60px; }
main:focus, main:focus-visible { outline: none; }
.loading { text-align: center; color: var(--muted); padding: 80px 0; }

/* ---------- উপরের বার ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px dashed var(--line); }
.topbar[hidden] { display: none; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font: 600 1.5rem var(--display); }
.brand svg { width: 34px; height: 34px; }
.bx { stroke: var(--gold); stroke-width: 4.5; stroke-linecap: round; fill: none; }
.bo { stroke: var(--rose); stroke-width: 4.5; fill: none; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { position: relative; padding: 6px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 500; }
nav a:hover { color: var(--text); background: var(--panel); }
nav a[aria-current] { color: #1a1d45; background: var(--gold); }
.dot { position: absolute; top: 2px; right: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--rose); border: 2px solid var(--bg); }

/* ---------- বাটন ও ফর্ম ---------- */
.btn { font: 600 1rem var(--font); display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 18px; min-height: 44px;
  border-radius: 999px; border: 1.5px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; text-decoration: none; transition: transform .12s, background .15s, border-color .15s; }
.btn:hover:not(:disabled) { border-color: var(--muted); background: #30357a; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #1a1d45; }
.btn.primary:hover:not(:disabled) { background: #ffc35a; border-color: #ffc35a; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: rgba(255, 123, 143, .14); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: var(--panel); color: var(--text); border-color: transparent; }
.btn.small { min-height: 36px; padding: 4px 14px; font-size: .92rem; }
.btn.big { min-height: 54px; padding: 12px 28px; font-size: 1.15rem; }
.btn.wide { width: 100%; }
.btn[aria-busy] { opacity: .7; }
.linkish { background: none; border: 0; color: var(--teal); font: inherit; cursor: pointer; padding: 2px 0; text-align: left; }
.linkish:hover { text-decoration: underline; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > span { font-weight: 500; font-size: .95rem; }
input, select { font: 400 1rem var(--font); color: var(--text); background: var(--bg); border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 12px; min-height: 44px; width: 100%; }
input::placeholder { color: #7a7eb0; }
input:hover, select:hover { border-color: var(--muted); }
input:focus-visible, select:focus-visible { outline: 3px solid var(--teal); outline-offset: 1px; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--gold); }
.form-error { background: rgba(255, 123, 143, .13); border: 1px solid var(--danger); color: #ffd0d8; padding: 9px 12px; border-radius: 10px; margin: 0 0 14px; }
.form-error.info { background: rgba(92, 201, 184, .12); border-color: var(--teal); color: #c8f1ea; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin: 14px 0; }
.inline-form .field { margin: 0; flex: 1 1 160px; }
.inline-form[hidden] { display: none; }

.panel { background: var(--panel); border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.panel.narrow { max-width: 520px; margin: 40px auto; }
.panel.empty, .empty { color: var(--muted); text-align: center; padding: 22px 12px; }
.table-wrap { overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: .92rem; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }

.avatar { --h: 200; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: hsl(var(--h) 45% 32%); color: hsl(var(--h) 80% 90%); font: 600 .85rem var(--font); vertical-align: middle; }
.avatar.lg { width: 54px; height: 54px; font-size: 1.4rem; }
.avatar.xl { width: 78px; height: 78px; font-size: 2rem; }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--line); color: var(--text); margin-left: 6px; }
.tag.x { background: rgba(242, 177, 52, .22); color: var(--gold); }
.tag.o { background: rgba(236, 95, 122, .22); color: #ff9db0; }
.tag.spec { background: rgba(92, 201, 184, .18); color: var(--teal); }
.tag.admin { background: rgba(242, 177, 52, .22); color: var(--gold); }
.you { font-size: .75rem; background: var(--teal); color: #10213a; padding: 0 7px; border-radius: 999px; font-weight: 600; }

/* ---------- টোস্ট ---------- */
#toasts { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--panel2); border: 1.5px solid var(--line); padding: 11px 16px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: toastIn .25s ease-out; }
.toast-error { border-color: var(--danger); background: #3a2040; }
.toast.out { opacity: 0; transition: opacity .35s; }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } }
#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 50; display: none; }
#confetti.on { display: block; }

/* ---------- লগইন ---------- */
.auth { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; align-items: center; min-height: calc(100vh - 140px); max-width: 960px; margin: 0 auto; }
.auth-art { text-align: center; }
.mini-board { width: min(300px, 70%); height: auto; margin-bottom: 8px; }
.stitch-grid { stroke: var(--muted); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 3 11; fill: none; opacity: .8; }
.mk { fill: none; stroke-width: 11; stroke-linecap: round; }
.mk.x { stroke: var(--gold); } .mk.o { stroke: var(--rose); }
.wordmark { font-size: clamp(3rem, 8vw, 4.6rem); margin: 0; background: linear-gradient(100deg, var(--gold), var(--rose)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-art p { color: var(--muted); font-size: 1.1rem; }
.auth-card { background: var(--panel); border: 1.5px dashed var(--line); border-radius: 20px; padding: 28px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 16px; font-size: .95rem; }

/* ---------- লবি ---------- */
.lobby-head { margin-bottom: 18px; }
.lobby-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.lobby-actions .panel { margin: 0; }
.action-new { background: linear-gradient(135deg, #3a2f6e, var(--panel)); }
.room-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.room-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); text-decoration: none; color: var(--text); }
.room-item:hover { border-color: var(--teal); }
.vs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seat-empty { color: var(--muted); font-style: italic; }
.meta { display: flex; align-items: center; gap: 12px; font-size: .9rem; }
.live { color: #10213a; background: var(--teal); padding: 0 10px; border-radius: 999px; font-weight: 600; font-size: .82rem; }
.wait { color: var(--gold); }

/* ---------- রুম ---------- */
.room-top { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: stretch; margin-bottom: 18px; }
.seat { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius); background: var(--panel); border: 2px dashed var(--line); transition: border-color .2s, background .2s; min-width: 0; }
.seat-o { flex-direction: row-reverse; text-align: right; }
.seat.active { border-style: solid; background: var(--panel2); }
.seat-x.active { border-color: var(--gold); } .seat-o.active { border-color: var(--rose); }
.seat.winner { border-style: solid; border-color: var(--teal); background: #1f3a55; }
.seat-mark svg { width: 44px; height: 44px; display: block; }
.seat-info { display: flex; flex-direction: column; min-width: 0; flex: 1; align-items: flex-start; gap: 2px; }
.seat-o .seat-info { align-items: flex-end; }
.seat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.seat-score { font: 600 2rem var(--display); min-width: 38px; text-align: center; color: var(--text); }
.pres { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #6a6d9c; margin-right: 6px; }
.pres.on { background: var(--teal); }
.seat-o .pres { margin: 0 0 0 6px; order: 2; }
.status { text-align: center; align-self: center; min-width: 190px; }
.status-title { font: 600 1.6rem/1.2 var(--display); }
.status-title.finished { color: var(--gold); }
.status-sub { font-size: .92rem; }
.countdown { font-variant-numeric: tabular-nums; font-size: .95rem; color: var(--teal); min-height: 1.4em; }

.room-body { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 22px; align-items: start; }
.board-col { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.board { position: relative; width: min(100%, 460px); aspect-ratio: 1; }
.board .grid, .board .winline { position: absolute; inset: 0; width: 100%; height: 100%; }
.board .winline { pointer-events: none; }
.frame { fill: var(--bg2); stroke: var(--line); stroke-width: 3; stroke-dasharray: 2 10; stroke-linecap: round; }
.board.my-turn .frame { stroke: var(--teal); }
.cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 3.3%; }
.cell { position: relative; background: none; border: 0; padding: 0; cursor: default; border-radius: 16px; }
.cell svg { width: 100%; height: 100%; display: block; }
.cell[aria-disabled="true"] { cursor: default; }
.cell:not([aria-disabled="true"]) { cursor: pointer; }
.cell:not([aria-disabled="true"]):hover { background: rgba(255, 255, 255, .05); }
.ghost-mark { position: absolute; inset: 0; opacity: 0; transition: opacity .15s; pointer-events: none; }
.cell:hover .ghost-mark, .cell:focus-visible .ghost-mark { opacity: .28; }
.cell .mk { stroke-width: 9; }
.stitch { fill: none; stroke: var(--bg); stroke-width: 2.2; stroke-linecap: round; stroke-dasharray: 1 9; opacity: .65; }
.cell.won { background: rgba(92, 201, 184, .12); }
.mk.draw { stroke-dasharray: 120; stroke-dashoffset: 120; animation: drawIn .38s ease-out forwards; }
.mk.o.draw { stroke-dasharray: 160; stroke-dashoffset: 160; }
@keyframes drawIn { to { stroke-dashoffset: 0; } }
.win { stroke-width: 9; stroke-linecap: round; stroke-dasharray: 400; stroke-dashoffset: 400; animation: drawIn .6s .15s ease-out forwards; filter: drop-shadow(0 0 8px currentColor); }
.win.x { stroke: var(--gold); color: var(--gold); } .win.o { stroke: var(--rose); color: var(--rose); }

.timer { width: min(100%, 460px); height: 8px; border-radius: 999px; background: var(--bg2); overflow: hidden; }
.timer[hidden] { display: none; }
.timer-bar { height: 100%; width: 100%; transform-origin: left; background: var(--gold); transition: transform .25s linear; }
.timer[data-turn="O"] .timer-bar { background: var(--rose); }
.timer.low .timer-bar { background: var(--danger); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 44px; }
.share { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; font-size: .95rem; }
.code { font: 600 1.15rem ui-monospace, Consolas, monospace; letter-spacing: .08em; background: var(--bg2); padding: 2px 10px; border-radius: 8px; }
.viewers { color: var(--teal); }

.chat { background: var(--panel); border: 1.5px dashed var(--line); border-radius: var(--radius); display: flex; flex-direction: column; height: min(640px, 78vh); position: sticky; top: 76px; }
.chat-head { padding: 12px 14px 8px; border-bottom: 1px solid var(--line); }
.chat-head h2 { margin: 0 0 4px; }
.chat-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.switch { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); cursor: pointer; }
.switch[hidden] { display: none; }
.chat-list { list-style: none; margin: 0; padding: 12px 14px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; align-self: flex-start; }
.msg[hidden] { display: none; }
.msg.mine { align-self: flex-end; }
.msg-head { display: flex; align-items: center; gap: 2px; font-size: .85rem; margin-bottom: 2px; }
.msg.mine .msg-head { justify-content: flex-end; }
.msg-head time { margin-left: 8px; font-size: .75rem; }
.msg-body { background: var(--panel2); padding: 7px 12px; border-radius: 14px 14px 14px 4px; overflow-wrap: anywhere; }
.msg.mine .msg-body { background: #3b3f86; border-radius: 14px 14px 4px 14px; }
.msg.from-spec .msg-body { background: transparent; border: 1px dashed var(--line); }
.msg.system { align-self: center; color: var(--muted); font-size: .85rem; }
.chat-empty { align-self: center; text-align: center; margin: auto; padding: 12px; }
.quick { display: flex; gap: 6px; padding: 6px 12px; overflow-x: auto; border-top: 1px solid var(--line); }
.quick[hidden] { display: none; }
.chip { flex: none; font: 500 .85rem var(--font); background: var(--bg2); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 4px 12px; cursor: pointer; min-height: 32px; }
.chip:hover { border-color: var(--gold); }
.chat-form { display: flex; gap: 8px; padding: 10px 12px 12px; }
.chat-form input { flex: 1; min-width: 0; }

/* ---------- লিডারবোর্ড ---------- */
.board-page > p { margin-bottom: 20px; }
.podium { list-style: none; padding: 0; margin: 0 0 22px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; align-items: end; max-width: 620px; }
.podium li { background: var(--panel); border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 14px 8px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.podium .rank { font: 600 1.6rem var(--display); color: var(--gold); }
.podium-1 { order: 2; padding-bottom: 28px; border-color: var(--gold) !important; border-style: solid !important; }
.podium-2 { order: 1; } .podium-3 { order: 3; }
.lb tr.me td { background: rgba(242, 177, 52, .08); }
.lb td .avatar { margin-right: 6px; }
td.w { color: var(--teal); } td.l { color: var(--danger); }
.rate { display: inline-block; min-width: 56px; padding: 1px 8px; border-radius: 999px; background: linear-gradient(90deg, rgba(92, 201, 184, .35) calc(var(--p) * 1%), transparent 0); border: 1px solid var(--line); text-align: right; }
.h2h-bar { display: flex; height: 16px; border-radius: 999px; overflow: hidden; background: var(--bg2); margin: 10px 0; gap: 2px; }
.h2h-bar .a { background: var(--teal); } .h2h-bar .d { background: var(--muted); } .h2h-bar .b { background: var(--rose); }
.h2h-nums { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

/* ---------- প্রোফাইল ---------- */
.profile-head { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; }
.profile-head h1, .profile-head p { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; }
.stat b { font: 600 2.1rem/1.2 var(--display); color: var(--gold); }
.stat span { color: var(--muted); font-size: .9rem; }
.profile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.profile-grid .panel { margin: 0; }
.profile-grid + .panel, .profile-grid ~ .panel { margin-top: 18px; }
.history { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.history li { display: grid; grid-template-columns: 56px 1fr auto auto; gap: 12px; align-items: center; padding: 8px 12px; background: var(--bg2); border-radius: 10px; font-size: .95rem; }
.res { font-weight: 700; text-align: center; border-radius: 999px; padding: 0 8px; }
.res-win .res { background: rgba(92, 201, 184, .2); color: var(--teal); }
.res-loss .res { background: rgba(255, 123, 143, .18); color: var(--danger); }
.res-draw .res { background: var(--line); }

/* ---------- অ্যাডমিন ---------- */
.admin h1 { margin-bottom: 16px; }
.req-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.req-list li { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 12px; background: var(--bg2); border-radius: 12px; }
.note { color: var(--gold); font-size: .92rem; }
.users td { font-size: .95rem; }
.users select { min-height: 36px; padding: 4px 8px; width: auto; }
.perm-row td { background: var(--bg2); }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.perm-item { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); }
.perm-item.allow { border-color: var(--teal); } .perm-item.deny { border-color: var(--danger); }
.perm-item select { min-height: 34px; padding: 3px 8px; }
.matrix th[scope=row] { color: var(--text); font-weight: 400; white-space: normal; }
.matrix td { text-align: center; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 18px; margin-bottom: 8px; }

/* ---------- ছোট পর্দা ---------- */
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; gap: 14px; min-height: 0; }
  .auth-art { order: -1; } .mini-board { width: 120px; }
  .auth-art p { display: none; }
  .lobby-actions { grid-template-columns: 1fr; }
  .room-body { grid-template-columns: 1fr; }
  .chat { position: static; height: 420px; }
  .room-top { grid-template-columns: 1fr 1fr; }
  .status { grid-column: 1 / -1; order: -1; }
  .hide-sm { display: none; }
}
@media (max-width: 520px) {
  body { font-size: 16px; }
  h1 { font-size: 1.7rem; }
  main { padding: 14px 12px 48px; }
  .topbar { padding: 8px 10px; } .brand span { display: none; }
  nav a { padding: 6px 10px; }
  .seat { padding: 8px 10px; gap: 8px; } .seat-mark svg { width: 34px; height: 34px; } .seat-score { font-size: 1.5rem; }
  .history li { grid-template-columns: 48px 1fr; } .history li > :nth-child(n+3) { grid-column: 2; }
  .auth-card { padding: 20px; }
  .podium { gap: 6px; } .avatar.lg { width: 42px; height: 42px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
  .mk.draw, .win { stroke-dashoffset: 0; }
}
