/* Tiến lên · 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;
	--ink: #1f1a16;
	--red: #b13a31;
	--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);
	--cw: 60px;
	--pcw: 52px;
	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;
	overflow-x: hidden;
}
body::before {
	content: "";
	position: fixed;
	inset: 0;
	pointer-events: none;
	background:
		radial-gradient(60% 45% at 50% -8%, rgba(201, 163, 92, .13), transparent 70%),
		radial-gradient(55% 40% at 50% 52%, rgba(201, 163, 92, .07), 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: 1000px; 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: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	grid-template-rows: auto minmax(150px, 1fr) auto auto;
	grid-template-areas: "left top right" "center center center" "me me me" "status status status";
	gap: 10px;
	width: 100%;
	max-width: 1000px;
	margin: 0 auto;
	padding: 8px 12px 12px;
}
#pos-top { grid-area: top; }
#pos-left { grid-area: left; }
#pos-right { grid-area: right; }
.center { grid-area: center; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 150px; }
.me { grid-area: me; position: relative; }
.status { grid-area: status; margin: 0; min-height: 1.5em; color: var(--text-2); font-size: 13.5px; text-align: center; }
.status b { color: var(--gold-2); font-weight: 500; }

@media (min-width: 820px) {
	.table {
		grid-template-columns: minmax(170px, 1fr) minmax(0, 2.3fr) minmax(170px, 1fr);
		grid-template-rows: auto minmax(220px, 1fr) auto auto;
		grid-template-areas: "left top right" "left center right" "me me me" "status status status";
		gap: 14px;
	}
	#pos-left, #pos-right { align-self: center; }
	#pos-top { justify-self: center; width: min(100%, 240px); }
}

/* Đối thủ */
.seat {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 3px;
	min-width: 0;
	padding: 12px 8px 10px;
	border: 1px solid var(--line);
	background: rgba(21, 19, 17, .6);
	text-align: center;
	transition: border-color .35s var(--ease), box-shadow .35s var(--ease), opacity .35s var(--ease);
}
.seat.turn, .me.turn .me-bar { border-color: rgba(201, 163, 92, .6); box-shadow: 0 0 0 1px rgba(201, 163, 92, .15), 0 16px 40px -24px rgba(232, 203, 142, .5); }
.seat.done { opacity: .72; }
.avatar {
	position: relative;
	display: grid;
	place-items: center;
	flex: none;
	width: 44px;
	height: 44px;
	border: 1px solid var(--line-strong);
	border-radius: 50%;
	background: radial-gradient(circle at 50% 40%, #2a2219, #12100d 70%);
	color: var(--gold-2);
	font: 500 21px/1 var(--serif);
}
.seat.turn .avatar, .me.turn .avatar { border-color: var(--gold); }
.seat .avatar .bot {
	position: absolute;
	right: -3px;
	bottom: -3px;
	padding: 1px 4px;
	border: 1px solid var(--line-strong);
	border-radius: 6px;
	background: #12100d;
	color: var(--text-3);
	font: 500 8px/1.3 var(--sans);
	letter-spacing: .08em;
}
.seat .name { overflow: hidden; max-width: 100%; font: 500 18px/1.15 var(--serif); text-overflow: ellipsis; white-space: nowrap; }
.seat .sub { color: var(--text-3); font-size: 11px; letter-spacing: .03em; }
.seat .sub.online::before, .seat .sub.offline::before {
	content: "";
	display: inline-block;
	width: 6px;
	height: 6px;
	margin-right: 5px;
	border-radius: 50%;
	background: #6fbf8a;
	vertical-align: 1px;
}
.seat .sub.offline::before { background: var(--warn); }
.seat .count { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 12px; }
.mini-back {
	width: 15px;
	height: 21px;
	border: 1px solid rgba(201, 163, 92, .55);
	border-radius: 3px;
	background: repeating-linear-gradient(45deg, #1d1813 0 3px, #241d16 3px 6px);
	box-shadow: 3px -2px 0 -1px #1d1813, 3px -2px 0 0 rgba(201, 163, 92, .35);
}
.seat .score { color: var(--text-3); font-size: 11px; }
.badge {
	position: absolute;
	top: -10px;
	left: 50%;
	z-index: 2;
	padding: 2px 10px;
	transform: translateX(-50%);
	border: 1px solid var(--line-strong);
	background: #12100d;
	color: var(--text-2);
	font-size: 9.5px;
	font-weight: 500;
	letter-spacing: .16em;
	text-transform: uppercase;
	white-space: nowrap;
	animation: pop .25s var(--ease) both;
}
.badge.rank { border-color: rgba(201, 163, 92, .6); color: var(--gold-2); }
.badge.burn { border-color: var(--warn); color: #e3a08c; }

/* Bàn của mình */
.me-bar {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px 12px;
	border: 1px solid var(--line);
	background: rgba(21, 19, 17, .6);
	transition: border-color .35s var(--ease), box-shadow .35s var(--ease);
}
.me-bar .who { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.me-bar .who b { overflow: hidden; font: 500 20px/1.15 var(--serif); text-overflow: ellipsis; white-space: nowrap; }
.me-bar .who small { color: var(--text-3); font-size: 11.5px; }
.me.turn .me-bar .who small { color: var(--gold); }
.tally { display: flex; align-items: baseline; gap: 6px; }
.pts { color: var(--gold-2); font: 500 30px/1 var(--serif); }
.tally small { color: var(--text-3); font-size: 10px; font-weight: 500; letter-spacing: .2em; text-transform: uppercase; }
.hand {
	position: relative;
	height: calc(var(--cw) * 1.42 + var(--cw) * .34 + 6px);
	margin: 6px 0 4px;
	touch-action: none;
}
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions .spacer { flex: 1; }

/* Lá bài */
.card {
	position: absolute;
	top: calc(var(--cw) * .34);
	width: var(--cw);
	height: calc(var(--cw) * 1.42);
	margin: 0;
	padding: 0;
	border: 1px solid rgba(60, 45, 25, .4);
	border-radius: calc(var(--cw) * .1);
	background: linear-gradient(160deg, #fffaf0, #efe5d2);
	box-shadow: 0 6px 14px -6px rgba(0, 0, 0, .75), inset 0 0 0 calc(var(--cw) * .045) #fffaf0, inset 0 0 0 calc(var(--cw) * .058) rgba(201, 163, 92, .55);
	color: var(--ink);
	font: 700 calc(var(--cw) * .33)/1 var(--serif);
	text-align: left;
	cursor: pointer;
	touch-action: none;
	transition: transform .18s var(--ease), left .28s var(--ease), box-shadow .2s var(--ease), filter .2s var(--ease);
}
.card.red { color: var(--red); }
.card .cr { position: absolute; top: 6%; left: 9%; letter-spacing: -.05em; pointer-events: none; }
.card .cs { position: absolute; top: 31%; left: 10%; width: 23%; height: 17%; fill: currentColor; pointer-events: none; }
.card .cp { position: absolute; right: 9%; bottom: 8%; width: 46%; height: 33%; fill: currentColor; opacity: .9; pointer-events: none; }
.card .cf { position: absolute; right: 12%; bottom: 5%; font-size: calc(var(--cw) * .6); font-style: italic; pointer-events: none; }
.card.sel {
	transform: translateY(calc(var(--cw) * -.3));
	box-shadow: 0 10px 18px -8px rgba(0, 0, 0, .8), inset 0 0 0 calc(var(--cw) * .045) #fffaf0, inset 0 0 0 calc(var(--cw) * .058) rgba(201, 163, 92, .55), 0 0 0 2px var(--gold-2);
}
.card.hinted::after {
	content: "";
	position: absolute;
	inset: -4px;
	border: 1px dashed var(--gold-2);
	border-radius: calc(var(--cw) * .14);
	pointer-events: none;
	animation: blink 1.2s ease-in-out infinite;
}
.card:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.hand.wait .card { filter: saturate(.85) brightness(.92); }
.card.back {
	border-color: rgba(201, 163, 92, .55);
	background: repeating-linear-gradient(45deg, #1c1712 0 6px, #231c15 6px 12px);
	box-shadow: 0 6px 14px -6px rgba(0, 0, 0, .75), inset 0 0 0 calc(var(--cw) * .06) #18130f, inset 0 0 0 calc(var(--cw) * .072) rgba(201, 163, 92, .5);
}
.card.back::before {
	content: "CB";
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	color: rgba(232, 203, 142, .75);
	font: 600 calc(var(--cw) * .26)/1 var(--serif);
	letter-spacing: .06em;
}

/* Bộ bài trên bàn */
.pile { position: relative; width: 100%; height: calc(var(--pcw) * 1.42 + 24px); }
.pile .card { --cw: var(--pcw); top: 10px; cursor: default; }
.pile .card.old { filter: brightness(.55) saturate(.7); }
.pile-by { min-height: 1.5em; margin: 4px 0 0; color: var(--text-2); font-size: 13px; text-align: center; }
.pile-by b { color: var(--text); font-weight: 500; }
.pile-by .cut { color: #e8a08a; font-weight: 500; }
.center.flash::before {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	background: radial-gradient(circle, rgba(232, 160, 138, .32), transparent 65%);
	animation: flash .7s var(--ease) both;
	pointer-events: none;
}
.fly { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
.fly .card { position: fixed; top: 0; left: 0; transition: none; }

/* ---------- 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(58px, 15vw, 80px)/.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: 330px; 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: 48px;
	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), opacity .3s var(--ease);
}
.btn:hover { border-color: var(--gold); color: var(--gold-2); }
.btn:disabled { opacity: .38; cursor: default; }
.btn:disabled:hover { border-color: var(--line-strong); color: var(--text); }
.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-primary:disabled:hover { border-color: var(--gold-2); background: var(--gold-2); 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 12px; font-size: 10px; letter-spacing: .12em; }
.actions .btn:not(.btn-small) { min-width: 104px; }
.stack { display: grid; gap: 10px; margin-top: 20px; }
.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, .94); 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.hot { border-color: var(--warn); color: #f0b4a0; }
.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: 400px; 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; }
#menu .panel { text-align: center; }
#menu .field { text-align: left; }
.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; }
.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: 42px; color: var(--text-2); font-size: 11px; font-weight: 500; letter-spacing: .12em; 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; }
.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 { 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 { outline: none; border-color: var(--gold); }
input::placeholder { color: var(--text-3); }
.inline { display: flex; gap: 8px; }
.inline .text { flex: 1; }
.inline .btn { flex: none; }
#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: 10px 0 4px; color: var(--gold-2); font: 600 60px/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); }
.menu-stats { margin: 16px 0 0; color: var(--text-3); font-size: 12px; }

.seats-list, .ranks { margin: 16px 0 0; padding: 0; list-style: none; }
.seats-list li, .ranks li { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.seats-list .n, .ranks .place { color: var(--text-3); font: italic 500 18px/1 var(--serif); }
.ranks li:first-child .place { color: var(--gold); }
.seats-list b, .ranks b { overflow: hidden; font: 500 20px/1.15 var(--serif); text-overflow: ellipsis; white-space: nowrap; }
.seats-list small, .ranks small { display: block; color: var(--text-3); font-size: 11.5px; }
.seats-list .empty b { color: var(--text-3); font-style: italic; }
.ranks .delta { text-align: right; color: var(--text-2); font: 500 26px/1 var(--serif); }
.ranks .delta.plus { color: var(--gold-2); }
.ranks .delta small { font: 400 11px/1.4 var(--sans); }
.ranks li.me b::after { content: "  bạn"; color: var(--gold); font: 500 9.5px/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; vertical-align: middle; }
.notes { margin: 14px 0 0; padding: 0 0 0 18px; color: var(--text-2); font-size: 13px; }
.notes li { margin: 0 0 4px; }
.notes:empty { display: none; }
.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; }
.legend { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.legend li { display: flex; flex-direction: column; }
.legend b { color: var(--text); font: 500 17px/1.25 var(--serif); }
.legend span { color: var(--text-2); font-size: 13px; line-height: 1.5; }

/* ---------- 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: translateX(-50%) scale(.7); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@keyframes flash { from { opacity: 1; transform: scale(.6); } to { opacity: 0; transform: scale(1.4); } }

@media (max-width: 420px) {
	.table { gap: 8px; padding: 6px 8px 10px; }
	.seat { padding: 10px 4px 8px; }
	.seat .avatar { width: 36px; height: 36px; font-size: 18px; }
	.seat .name { font-size: 16px; }
	.me-bar { padding: 6px 10px; }
	.me-bar .who b { font-size: 18px; }
	.pts { font-size: 26px; }
	.actions .btn:not(.btn-small) { min-width: 0; flex: 1; }
	.actions .spacer { display: none; }
	.btn-small { padding: 0 10px; }
}
@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
}
