/* Ô ăn quan · giao diện theo bộ nhận diện CB Family */
:root {
	--bg: #0a0908;
	--surface: #151311;
	--line: #262220;
	--line-strong: #3a342e;
	--text: #efe8dc;
	--text-2: #a9a094;
	--text-3: #6f685e;
	--gold: #c9a35c;
	--gold-2: #e8cb8e;
	--warn: #b4664f;
	--serif: "Cormorant Garamond", "Times New Roman", serif;
	--sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
	--ease: cubic-bezier(.2, .7, .2, 1);
	color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; overscroll-behavior: none; }
body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 300 15px/1.6 var(--sans);
	font-feature-settings: "lnum" 1;
	-webkit-font-smoothing: antialiased;
	-webkit-text-size-adjust: 100%;
	-webkit-tap-highlight-color: transparent;
	-webkit-user-select: none;
	user-select: none;
}
body::before {
	content: "";
	position: fixed;
	inset: 0;
	pointer-events: none;
	background:
		radial-gradient(60% 45% at 50% -8%, rgba(201, 163, 92, .14), transparent 70%),
		radial-gradient(50% 40% at 50% 60%, rgba(201, 163, 92, .05), transparent 70%);
}
body::after {
	content: "";
	position: fixed;
	inset: 0;
	z-index: 100;
	pointer-events: none;
	opacity: .05;
	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 type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
a { color: inherit; text-decoration: none; }
em { font-style: italic; color: var(--gold-2); }
:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; }
input { -webkit-user-select: text; user-select: text; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
[hidden] { display: none !important; }

/* ---------- Khung trang ---------- */
.page {
	position: relative;
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	min-height: 100dvh;
	padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.bar {
	position: relative;
	z-index: 5;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	width: 100%;
	max-width: 860px;
	margin: 0 auto;
	padding: 12px 16px 4px;
}
.back {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	color: var(--text-2);
	font-size: 11px;
	font-weight: 500;
	letter-spacing: .22em;
	text-transform: uppercase;
	transition: color .3s var(--ease);
}
.back:hover { color: var(--gold-2); }
.bar-actions { display: flex; gap: 8px; }
.monogram {
	display: inline-grid;
	place-items: center;
	width: 30px;
	height: 30px;
	border: 1px solid var(--gold);
	border-radius: 50%;
	color: var(--gold-2);
	font: 600 11px/1 var(--serif);
	letter-spacing: .04em;
}

/* ---------- Bàn chơi ---------- */
.table {
	position: relative;
	flex: 1;
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 14px;
	width: 100%;
	max-width: 860px;
	margin: 0 auto;
	padding: 8px 16px 16px;
}
#cv {
	position: absolute;
	inset: 0;
	z-index: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
}
.seat {
	position: relative;
	z-index: 1;
	display: grid;
	grid-template-columns: 52px minmax(0, 1fr) auto;
	grid-template-areas: "av who pts" "pile pile pile";
	align-items: center;
	gap: 8px 12px;
	padding: 12px 14px 10px;
	border: 1px solid var(--line);
	background: rgba(21, 19, 17, .55);
	transition: border-color .4s var(--ease), box-shadow .4s var(--ease), transform .5s var(--ease);
}
.seat.active {
	border-color: rgba(201, 163, 92, .55);
	box-shadow: 0 0 0 1px rgba(201, 163, 92, .15), 0 18px 44px -26px rgba(232, 203, 142, .45);
}
.flip .seat.top { transform: rotate(180deg); }
.avatar {
	grid-area: av;
	position: relative;
	display: grid;
	place-items: center;
	width: 52px;
	height: 52px;
	border: 1px solid var(--line-strong);
	border-radius: 50%;
	background: radial-gradient(circle at 50% 40%, #2a2219, #12100d 70%);
	overflow: hidden;
}
.avatar canvas { width: 52px; height: 52px; }
.avatar .initial {
	position: absolute;
	color: var(--gold-2);
	font: 500 24px/1 var(--serif);
}
.avatar.cb .initial { display: none; }
.avatar:not(.cb) canvas { display: none; }
.seat.active .avatar { border-color: var(--gold); }
.who { grid-area: who; display: flex; flex-direction: column; min-width: 0; }
.who b {
	overflow: hidden;
	font: 500 23px/1.1 var(--serif);
	text-overflow: ellipsis;
	white-space: nowrap;
}
.who small { color: var(--text-3); font-size: 11.5px; letter-spacing: .04em; }
.seat.active .who small { color: var(--gold); }
.who .online::before {
	content: "";
	display: inline-block;
	width: 7px;
	height: 7px;
	margin-right: 6px;
	border-radius: 50%;
	background: #6fbf8a;
	vertical-align: 1px;
}
.who .offline::before { background: var(--warn); }
.tally { grid-area: pts; display: flex; align-items: baseline; gap: 6px; }
.pts { color: var(--gold-2); font: 500 38px/1 var(--serif); }
.tally small { color: var(--text-3); font-size: 10px; font-weight: 500; letter-spacing: .2em; text-transform: uppercase; }
.pile { grid-area: pile; height: 46px; }

.board {
	position: relative;
	z-index: 1;
	display: grid;
	grid-template-columns: .82fr repeat(5, 1fr) .82fr;
	grid-template-rows: 1fr 1fr;
	width: 100%;
	aspect-ratio: 6.64 / 2.75;
	max-height: 46vh;
}
.sq {
	position: relative;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	cursor: pointer;
	touch-action: manipulation;
}
.sq[aria-disabled="true"] { cursor: default; }
.sq:focus-visible { outline: 1px solid var(--gold); outline-offset: -6px; }
.sq.qleft { grid-column: 1; grid-row: 1 / span 2; }
.sq.qright { grid-column: 7; grid-row: 1 / span 2; }
.cnt {
	position: absolute;
	top: 5px;
	left: 7px;
	color: var(--text-3);
	font: 500 11px/1 var(--sans);
	letter-spacing: .02em;
	pointer-events: none;
	transition: color .3s var(--ease);
}
.sq.quan .cnt { top: 7px; left: 50%; transform: translateX(-50%); }
.sq.live .cnt { color: var(--gold-2); }

.dirs { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.dir {
	position: absolute;
	display: grid;
	place-items: center;
	width: 46px;
	height: 46px;
	margin: -23px 0 0 -23px;
	padding: 0;
	border: 1px solid var(--gold);
	border-radius: 50%;
	background: rgba(15, 13, 11, .92);
	color: var(--gold-2);
	cursor: pointer;
	pointer-events: auto;
	box-shadow: 0 10px 26px -10px rgba(0, 0, 0, .9), 0 0 0 4px rgba(201, 163, 92, .12);
	animation: pop .25s var(--ease) both;
	touch-action: manipulation;
}
.dir:hover, .dir.hint { background: var(--gold-2); color: #15110b; }
.dir svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.foot {
	position: relative;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	min-height: 40px;
}
.status { margin: 0; color: var(--text-2); font-size: 13.5px; line-height: 1.45; }
.status b { color: var(--gold-2); font-weight: 500; }
.tools { display: flex; flex: none; gap: 8px; }

/* ---------- Chữ & nút ---------- */
.eyebrow {
	margin: 0;
	color: var(--gold);
	font-size: 11px;
	font-weight: 500;
	letter-spacing: .32em;
	text-transform: uppercase;
}
h2 { margin: 12px 0 18px; font: 500 40px/1.02 var(--serif); }
h3 { margin: 24px 0 10px; color: var(--gold); font: 500 11px/1 var(--sans); letter-spacing: .26em; text-transform: uppercase; }
.title { margin: 14px 0 0; font: 500 clamp(56px, 15vw, 76px)/.92 var(--serif); letter-spacing: -.01em; }
.rule { display: block; width: 1px; height: 34px; margin: 18px auto 16px; background: linear-gradient(var(--gold), transparent); }
.lead { margin: 0 auto; max-width: 320px; color: var(--text-2); font-size: 14px; }
.muted { margin: 0; color: var(--text-2); font-size: 14px; }
.small { font-size: 12.5px; }
.label { display: block; margin: 0 0 8px; color: var(--text); font-size: 14px; }

.btn {
	appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 50px;
	padding: 0 20px;
	border: 1px solid var(--line-strong);
	border-radius: 0;
	background: rgba(10, 9, 8, .45);
	color: var(--text);
	font: 500 11.5px/1.2 var(--sans);
	letter-spacing: .18em;
	text-transform: uppercase;
	text-align: center;
	cursor: pointer;
	touch-action: manipulation;
	transition: border-color .3s var(--ease), color .3s var(--ease), background-color .3s var(--ease), transform .2s var(--ease);
}
.btn:hover { border-color: var(--gold); color: var(--gold-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { border-color: var(--gold-2); background: var(--gold-2); color: #15110b; font-weight: 600; }
.btn-primary:hover { border-color: #f3dba6; background: #f3dba6; color: #15110b; }
.btn-ghost { border-color: transparent; background: none; color: var(--text-2); }
.btn-ghost:hover { border-color: transparent; }
.btn-small { min-height: 38px; padding: 0 14px; font-size: 10.5px; letter-spacing: .14em; }
.btn-row { display: grid; gap: 8px; }
.btn-row.two { grid-template-columns: 1fr 1fr; }
.btn-row .btn { padding: 0 8px; letter-spacing: .1em; font-size: 10.5px; }
.stack { display: grid; gap: 10px; margin-top: 20px; }
.link { appearance: none; padding: 0; border: 0; background: none; color: var(--gold-2); font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.icon-btn {
	display: inline-grid;
	place-items: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 1px solid var(--line-strong);
	border-radius: 50%;
	background: rgba(10, 9, 8, .5);
	color: var(--text);
	cursor: pointer;
	transition: border-color .3s var(--ease), color .3s var(--ease);
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold-2); }
.icon-btn svg, .close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Thông báo ---------- */
.toasts {
	position: fixed;
	left: 0;
	right: 0;
	top: calc(env(safe-area-inset-top) + 64px);
	z-index: 30;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	padding: 0 16px;
	pointer-events: none;
}
.toast {
	max-width: 100%;
	padding: 8px 16px;
	border: 1px solid var(--line-strong);
	background: rgba(14, 12, 10, .92);
	color: var(--text);
	font-size: 12.5px;
	font-weight: 500;
	letter-spacing: .03em;
	text-align: center;
	animation: toastIn .35s var(--ease) both;
	transition: opacity .45s var(--ease), transform .45s var(--ease);
}
.toast.gold { border-color: rgba(201, 163, 92, .5); color: var(--gold-2); }
.toast.out { opacity: 0; transform: translateY(-8px); }

/* ---------- Bảng phụ ---------- */
.sheet {
	position: fixed;
	inset: 0;
	z-index: 20;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
	background: rgba(8, 7, 6, .72);
	animation: fadeIn .25s var(--ease) both;
}
.panel {
	position: relative;
	width: 100%;
	max-width: 392px;
	max-height: 100%;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 28px 24px 24px;
	border: 1px solid var(--line);
	outline: 1px solid rgba(232, 203, 142, .09);
	outline-offset: -9px;
	background: rgba(21, 19, 17, .97);
	box-shadow: 0 40px 80px -40px rgba(0, 0, 0, .95);
	animation: rise .45s var(--ease) both;
}
.panel-small { max-width: 340px; text-align: center; }
#menu .panel { text-align: center; }
.close {
	position: sticky;
	top: 0;
	z-index: 2;
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	margin: -16px -12px -24px auto;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(21, 19, 17, .9);
	color: var(--text-2);
	cursor: pointer;
}
.close:hover { color: var(--gold-2); }
.closable .panel > .eyebrow { padding-right: 34px; }

.opponent {
	display: flex;
	align-items: center;
	gap: 14px;
	margin: 22px 0 0;
	padding: 10px 12px;
	border: 1px solid var(--line);
	background: rgba(10, 9, 8, .35);
	text-align: left;
}
.opponent canvas { flex: none; width: 64px; height: 64px; }
.opponent > div { flex: 1; min-width: 0; }
.opponent .muted { margin-bottom: 6px; }
.seg { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; border: 1px solid var(--line-strong); }
.seg label { position: relative; }
.seg input { position: absolute; inset: 0; margin: 0; opacity: 0; }
.seg span {
	display: grid;
	place-items: center;
	height: 40px;
	color: var(--text-2);
	font-size: 11.5px;
	font-weight: 500;
	letter-spacing: .14em;
	text-transform: uppercase;
	cursor: pointer;
	transition: background-color .3s var(--ease), color .3s var(--ease);
}
.seg label + label span { border-left: 1px solid var(--line-strong); }
.seg input:checked + span { background: rgba(201, 163, 92, .16); color: var(--gold-2); }
.seg input:focus-visible + span { outline: 1px solid var(--gold); outline-offset: -4px; }
.menu-stats { margin: 16px 0 0; color: var(--text-3); font-size: 12px; }

.score-line {
	display: flex;
	align-items: baseline;
	justify-content: center;
	gap: 16px;
	margin: 0;
	color: var(--gold-2);
	font: 500 60px/1 var(--serif);
}
.score-line i { color: var(--text-3); font-style: normal; font-size: 34px; }
.score-names { display: flex; justify-content: center; gap: 44px; margin: 6px 0 14px; color: var(--text-3); font-size: 10.5px; font-weight: 500; letter-spacing: .2em; text-transform: uppercase; }

.field { margin: 0; padding: 14px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field label { display: block; margin-bottom: 8px; color: var(--text); font-size: 14px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.switch-row label { margin: 0; }
.switch {
	appearance: none;
	position: relative;
	flex: none;
	width: 46px;
	height: 26px;
	margin: 0;
	border: 1px solid var(--line-strong);
	border-radius: 999px;
	background: #0f0d0b;
	cursor: pointer;
	transition: background-color .3s var(--ease), border-color .3s var(--ease);
}
.switch::after {
	content: "";
	position: absolute;
	top: 3px;
	left: 3px;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: var(--text-3);
	transition: transform .3s var(--ease), background-color .3s var(--ease);
}
.switch:checked { border-color: var(--gold); background: rgba(201, 163, 92, .25); }
.switch:checked::after { transform: translateX(20px); background: var(--gold-2); }
.text, .inline input, .field input:not([type]) {
	width: 100%;
	min-width: 0;
	height: 48px;
	padding: 0 14px;
	border: 1px solid var(--line-strong);
	border-radius: 0;
	background: #0f0d0b;
	color: var(--text);
	font: 400 16px/1 var(--sans);
}
.text:focus, .inline input:focus, .field input:focus { outline: none; border-color: var(--gold); }
input::placeholder { color: var(--text-3); }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.inline .btn { flex: none; min-height: 48px; }
#on-code { text-transform: uppercase; letter-spacing: .3em; }
#on-code::placeholder { letter-spacing: .02em; text-transform: none; }
.or {
	display: flex;
	align-items: center;
	gap: 12px;
	margin: 22px 0 14px;
	color: var(--text-3);
	font-size: 12px;
}
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.room-code {
	margin: 12px 0 4px;
	color: var(--gold-2);
	font: 600 64px/1 var(--serif);
	letter-spacing: .18em;
	text-align: center;
}
.waiting { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); animation: blink 1.2s ease-in-out infinite; }
.status-box { margin: 16px 0 0; padding: 10px 12px; border-left: 2px solid var(--warn); background: rgba(10, 9, 8, .35); color: var(--text-2); font-size: 13px; }
.status-box.ok { border-color: var(--gold); }
.steps { margin: 0; padding-left: 20px; color: var(--text-2); font-size: 14px; }
.steps li { margin: 0 0 9px; padding-left: 4px; }
.steps li::marker { color: var(--gold); font-family: var(--serif); font-style: italic; }
.steps b { color: var(--text); font-weight: 500; }

/* ---------- Chuyển động ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* ---------- Màn hình nhỏ ---------- */
@media (max-width: 560px) {
	/* Điện thoại cầm dọc: bàn cao hơn để ô to, dễ bấm */
	.board { aspect-ratio: 6.64 / 3.5; }
}
@media (max-width: 420px) {
	.table { gap: 10px; padding: 6px 10px 12px; }
	.seat { grid-template-columns: 44px minmax(0, 1fr) auto; padding: 10px 12px 8px; }
	.avatar, .avatar canvas { width: 44px; height: 44px; }
	.who b { font-size: 21px; }
	.pts { font-size: 32px; }
	.pile { height: 38px; }
	.dir { width: 42px; height: 42px; margin: -21px 0 0 -21px; }
	.status { font-size: 12.5px; }
}
@media (max-height: 640px) {
	.title { font-size: 52px; }
	.rule { display: none; }
	.pile { height: 32px; }
}
@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
}
