/* Kingbar — modern UI */
:root {
	--bg: #0a0b14;
	--bg-2: #10121f;
	--surface: rgba(255, 255, 255, .045);
	--surface-2: rgba(255, 255, 255, .075);
	--line: rgba(255, 255, 255, .09);
	--line-2: rgba(255, 255, 255, .16);
	--text: #eef0fa;
	--muted: #9095b0;
	--accent: #2ee6f0;
	--accent-2: #ff3fa4;
	--banker: #ff4d5e;
	--player: #3d8bff;
	--win: #2fd98a;
	--lose: #ff5d6c;
	--tie: #f5c24b;
	--radius: 18px;
	--radius-sm: 12px;
	--font: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
	--font-num: "Space Grotesk", "IBM Plex Sans Thai", sans-serif;
	color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	min-height: 100vh;
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
	font-family: var(--font);
	font-size: 16px;
	line-height: 1.55;
	color: var(--text);
	background:
		radial-gradient(900px 520px at 10% -10%, rgba(46, 230, 240, .13), transparent 60%),
		radial-gradient(800px 520px at 100% 0%, rgba(255, 63, 164, .12), transparent 60%),
		var(--bg);
	background-attachment: fixed;
	-webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 700; }
p { margin: 0; }
svg { width: 1em; height: 1em; fill: currentColor; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
	appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: .5em;
	min-height: 48px;
	padding: 0 20px;
	border: 1px solid transparent;
	border-radius: var(--radius-sm);
	font: inherit;
	font-weight: 600;
	color: var(--text);
	background: var(--surface-2);
	cursor: pointer;
	transition: transform .15s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease, opacity .2s;
	-webkit-tap-highlight-color: transparent;
	user-select: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .6; cursor: default; transform: none; }
.btn-block { width: 100%; }
.btn-lg { min-height: 54px; font-size: 1.05rem; }
.btn svg { font-size: 1.25em; }

.btn-primary {
	color: #061016;
	background: linear-gradient(135deg, var(--accent), #7af5ff);
	box-shadow: 0 8px 24px -8px rgba(46, 230, 240, .55);
}
.btn-primary:hover { box-shadow: 0 12px 30px -8px rgba(46, 230, 240, .7); }
.btn-ghost { background: transparent; border-color: var(--line-2); }
.btn-ghost:hover { background: var(--surface); }
.btn-win {
	min-height: 60px;
	font-size: 1.1rem;
	color: #04150d;
	background: linear-gradient(135deg, var(--win), #8bf5c2);
	box-shadow: 0 10px 28px -10px rgba(47, 217, 138, .6);
}
.btn-tie { background: rgba(245, 194, 75, .12); border-color: rgba(245, 194, 75, .35); color: #ffe3a1; }
.btn-tie:hover { background: rgba(245, 194, 75, .2); }
.btn-next { background: rgba(255, 93, 108, .12); border-color: rgba(255, 93, 108, .35); color: #ffc2c8; }
.btn-next:hover { background: rgba(255, 93, 108, .2); }
.link-btn {
	appearance: none; border: 0; background: none; padding: 4px 0;
	font: inherit; font-size: .875rem; color: var(--muted); cursor: pointer;
}
.link-btn:hover { color: var(--text); }

.spinner {
	display: none;
	width: 18px; height: 18px;
	border: 2px solid currentColor; border-right-color: transparent;
	border-radius: 50%;
	animation: spin .7s linear infinite;
}
.btn.loading .spinner { display: inline-block; }
.btn.loading .btn-label { opacity: .7; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login-body { justify-content: center; }
.login-wrap {
	width: 100%;
	max-width: 420px;
	margin: 0 auto;
	padding: 32px 16px;
}
.login-card {
	padding: 32px 28px;
	border: 1px solid var(--line);
	border-radius: 24px;
	background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.025));
	backdrop-filter: blur(14px);
	-webkit-backdrop-filter: blur(14px);
	box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .8);
	animation: rise .5s ease both;
}
.login-logo { width: 78%; margin: 0 auto 24px; }
.login-card h1 { font-size: 1.5rem; }
.login-card > .muted { margin: 6px 0 24px; font-size: .95rem; }
.login-foot { margin-top: 18px; text-align: center; font-size: .8rem; color: var(--muted); }

.field { display: block; margin-bottom: 16px; }
.field > span:first-child { display: block; margin-bottom: 6px; font-size: .875rem; font-weight: 500; color: #c7cae0; }
.field input {
	width: 100%;
	height: 50px;
	padding: 0 16px;
	border: 1px solid var(--line-2);
	border-radius: var(--radius-sm);
	background: rgba(0, 0, 0, .25);
	color: var(--text);
	font: inherit;
	transition: border-color .2s, box-shadow .2s, background .2s;
}
.field input:focus {
	outline: none;
	border-color: var(--accent);
	background: rgba(0, 0, 0, .35);
	box-shadow: 0 0 0 4px rgba(46, 230, 240, .15);
}
.field-pw { position: relative; display: block; }
.field-pw input { padding-right: 52px; }
.pw-toggle {
	position: absolute; top: 0; right: 0;
	width: 50px; height: 50px;
	display: grid; place-items: center;
	border: 0; background: none; color: var(--muted); cursor: pointer;
	font-size: 1.25rem;
}
.pw-toggle.on, .pw-toggle:hover { color: var(--accent); }
.form-msg { min-height: 24px; margin: -4px 0 12px; font-size: .9rem; }
.form-msg.error { color: var(--lose); }
.form-msg.success { color: var(--win); }

/* ---------- Topbar ---------- */
.topbar {
	position: sticky; top: 0; z-index: 20;
	background: rgba(10, 11, 20, .72);
	backdrop-filter: blur(16px) saturate(140%);
	-webkit-backdrop-filter: blur(16px) saturate(140%);
	border-bottom: 1px solid var(--line);
}
.topbar-inner {
	max-width: 1200px; margin: 0 auto;
	padding: 10px 16px;
	display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar-inner.sub { padding-top: 0; }
.brand img { height: 40px; width: auto; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.user-chip {
	display: inline-flex; align-items: center; gap: 6px;
	height: 34px; padding: 0 12px;
	border: 1px solid var(--line); border-radius: 999px;
	background: var(--surface);
	font-size: .85rem; font-weight: 500; white-space: nowrap;
}
.user-chip svg { color: var(--muted); }
.timer-chip { font-family: var(--font-num), var(--font); font-variant-numeric: tabular-nums; }
.timer-chip svg { color: var(--accent); }
.back-link {
	display: inline-flex; align-items: center; gap: 4px;
	font-size: .9rem; color: var(--muted);
	padding: 4px 8px 4px 0;
}
.back-link:hover { color: var(--text); }
.back-link svg { font-size: 1.2rem; }

/* ---------- Page ---------- */
.page {
	flex: 1;
	width: 100%; max-width: 1200px;
	margin: 0 auto;
	padding: 28px 16px 40px;
}
.page-head { margin-bottom: 24px; animation: rise .4s ease both; }
.page-head h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
.page-head .muted { margin-top: 4px; }
.page-head.with-badge { display: flex; align-items: center; gap: 16px; }
.eyebrow {
	margin-bottom: 6px;
	font-size: .78rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
	color: var(--accent);
}
.page-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 32px; }

/* ---------- Provider cards ---------- */
.provider-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: 14px;
}
.provider-card {
	--c: hsl(var(--hue) 85% 60%);
	position: relative;
	display: flex; align-items: center; gap: 16px;
	padding: 18px;
	border: 1px solid var(--line);
	border-radius: var(--radius);
	background:
		radial-gradient(120% 140% at 0% 0%, hsl(var(--hue) 80% 50% / .16), transparent 55%),
		var(--surface);
	overflow: hidden;
	transition: transform .2s ease, border-color .2s ease, background .2s ease;
	animation: rise .45s ease both;
	animation-delay: var(--d, 0ms);
}
.provider-card:hover { transform: translateY(-3px); border-color: hsl(var(--hue) 80% 60% / .55); }
.provider-card:focus-visible { outline: 2px solid var(--c); outline-offset: 2px; }
.provider-badge {
	--c: hsl(var(--hue) 85% 60%);
	display: grid; place-items: center;
	width: 56px; height: 56px; flex: none;
	border-radius: 16px;
	font-family: var(--font-num); font-weight: 700; font-size: 1.15rem; letter-spacing: .02em;
	color: #0a0b14;
	background: linear-gradient(140deg, hsl(var(--hue) 90% 68%), hsl(calc(var(--hue) + 30) 85% 52%));
	box-shadow: 0 10px 24px -10px hsl(var(--hue) 90% 55% / .8);
}
.provider-badge.lg { width: 64px; height: 64px; font-size: 1.3rem; border-radius: 18px; }
.provider-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.provider-name { font-weight: 700; font-size: 1.08rem; }
.provider-meta { font-size: .85rem; color: var(--muted); }
.chev { font-size: 1.4rem; color: var(--muted); transition: transform .2s, color .2s; }
.provider-card:hover .chev { transform: translateX(3px); color: var(--c); }

/* ---------- Room cards ---------- */
.room-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
	gap: 12px;
}
.room-card {
	display: flex; flex-direction: column; justify-content: flex-end;
	min-height: 104px;
	padding: 14px 16px;
	border: 1px solid var(--line);
	border-radius: var(--radius);
	background:
		linear-gradient(160deg, hsl(var(--hue) 80% 50% / .14), transparent 60%),
		var(--surface);
	transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
	animation: rise .4s ease both;
	animation-delay: var(--d, 0ms);
}
.room-card:hover {
	transform: translateY(-3px);
	border-color: hsl(var(--hue) 80% 60% / .6);
	box-shadow: 0 14px 30px -16px hsl(var(--hue) 90% 55% / .7);
}
.room-card:focus-visible { outline: 2px solid hsl(var(--hue) 85% 60%); outline-offset: 2px; }
.room-label { font-size: .8rem; color: var(--muted); }
.room-id { font-family: var(--font-num); font-weight: 700; font-size: 1.6rem; letter-spacing: .01em; }

/* ---------- Game ---------- */
.page.game { padding-top: 16px; }
.room-strip {
	display: flex; gap: 8px;
	overflow-x: auto;
	padding: 4px 2px 12px;
	margin: 0 -2px 12px;
	scrollbar-width: thin;
	scroll-snap-type: x proximity;
}
.room-strip::-webkit-scrollbar { height: 6px; }
.room-strip::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }
.room-chip {
	flex: none;
	scroll-snap-align: center;
	padding: 7px 14px;
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
	font-family: var(--font-num); font-weight: 500; font-size: .9rem;
	color: #c7cae0;
	transition: background .2s, border-color .2s, color .2s;
}
.room-chip:hover { border-color: var(--line-2); color: var(--text); }
.room-chip.active {
	color: #0a0b14;
	background: hsl(var(--hue) 85% 62%);
	border-color: transparent;
	font-weight: 700;
}

.game-layout {
	display: grid;
	grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
	gap: 16px;
	align-items: start;
}
.panel {
	border: 1px solid var(--line);
	border-radius: 22px;
	background: linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.02));
	padding: 20px;
	animation: rise .4s ease both;
}
.history-panel { animation-delay: 80ms; }

.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
	padding: 5px 12px;
	border-radius: 999px;
	background: var(--surface-2);
	font-size: .85rem; font-weight: 500;
}
.tag.strong { background: hsl(var(--hue) 85% 60% / .18); color: hsl(var(--hue) 90% 78%); }
.counter-row { display: flex; gap: 8px; }
.counter {
	display: flex; flex-direction: column; align-items: center;
	min-width: 72px; padding: 6px 12px;
	border: 1px solid var(--line); border-radius: var(--radius-sm);
	background: rgba(0,0,0,.2);
}
.counter-label { font-size: .72rem; color: var(--muted); }
.counter-value { font-family: var(--font-num); font-weight: 700; font-size: 1.3rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.counter-value small { font-size: .7em; color: var(--muted); font-weight: 500; }

.pick-stage { display: flex; flex-direction: column; align-items: center; padding: 28px 0 20px; }
.pick-ring {
	position: relative;
	padding: 10px;
	border-radius: 50%;
	box-shadow: 0 0 60px -10px rgba(46, 230, 240, .35);
}
.pick-ring::before {
	content: "";
	position: absolute; inset: 0;
	border-radius: 50%;
	background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--accent));
	animation: spin 8s linear infinite;
}
.pick {
	--side: var(--player);
	width: clamp(170px, 42vw, 220px);
	aspect-ratio: 1;
	border-radius: 50%;
	display: flex; flex-direction: column; align-items: center; justify-content: center;
	background:
		radial-gradient(circle at 32% 28%, rgba(255,255,255,.35), transparent 40%),
		radial-gradient(circle at 50% 60%, var(--side), color-mix(in srgb, var(--side) 55%, #000) 75%);
	box-shadow: inset 0 -10px 30px rgba(0,0,0,.35), inset 0 0 0 6px rgba(255,255,255,.12);
	position: relative;
	transition: background .2s;
}
.pick[data-side="B"] { --side: var(--banker); }
.pick.flip { animation: flip .45s ease; }
.pick-letter { font-family: var(--font-num); font-weight: 700; font-size: clamp(4.5rem, 14vw, 6rem); line-height: 1; text-shadow: 0 4px 16px rgba(0,0,0,.35); }
.pick-name { font-family: var(--font-num); font-weight: 700; letter-spacing: .25em; font-size: .85rem; opacity: .9; margin-top: 2px; }
@keyframes flip {
	0% { transform: rotateY(0) scale(1); }
	50% { transform: rotateY(90deg) scale(.92); }
	100% { transform: rotateY(0) scale(1); }
}
.pick-note {
	display: flex; align-items: center; gap: 6px;
	margin-top: 22px;
	font-size: .85rem; color: var(--muted); text-align: center;
}
.steps { display: flex; gap: 6px; margin-top: 14px; }
.steps span { width: 34px; height: 6px; border-radius: 3px; background: var(--line-2); transition: background .25s; }
.steps span.on { background: hsl(var(--hue) 85% 62%); }

.actions { display: grid; gap: 10px; }
.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.panel-title h2 { font-size: 1.1rem; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat {
	display: flex; flex-direction: column; align-items: center;
	padding: 10px 6px;
	border-radius: var(--radius-sm);
	background: rgba(0,0,0,.2);
	border: 1px solid var(--line);
}
.stat span { font-family: var(--font-num); font-weight: 700; font-size: 1.5rem; line-height: 1.2; }
.stat small { font-size: .78rem; color: var(--muted); }
.stat.win span { color: var(--win); }
.stat.lose span { color: var(--lose); }

.history {
	list-style: none; margin: 0; padding: 0;
	display: grid; gap: 8px;
	max-height: 440px; overflow-y: auto;
}
.history-empty {
	padding: 28px 12px;
	text-align: center; font-size: .9rem; color: var(--muted);
	border: 1px dashed var(--line-2); border-radius: var(--radius-sm);
}
.history-item {
	display: flex; justify-content: space-between; align-items: center;
	padding: 10px 14px;
	border-radius: var(--radius-sm);
	background: var(--surface);
	border-left: 3px solid var(--line-2);
	animation: slideIn .3s ease both;
}
.history-item span { display: flex; flex-direction: column; font-weight: 500; }
.history-item small { font-size: .78rem; color: var(--muted); font-weight: 400; }
.history-item b { padding: 3px 12px; border-radius: 999px; font-size: .85rem; }
.history-item.win { border-left-color: var(--win); }
.history-item.win b { background: rgba(47, 217, 138, .15); color: var(--win); }
.history-item.lose { border-left-color: var(--lose); }
.history-item.lose b { background: rgba(255, 93, 108, .15); color: var(--lose); }

/* ---------- Modal ---------- */
.modal {
	position: fixed; inset: 0; z-index: 50;
	display: grid; place-items: center;
	padding: 16px;
	background: rgba(4, 5, 10, .7);
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	animation: fade .2s ease both;
}
.modal-card {
	width: 100%; max-width: 360px;
	padding: 28px 24px 22px;
	text-align: center;
	border: 1px solid var(--line-2);
	border-radius: 24px;
	background: var(--bg-2);
	box-shadow: 0 40px 80px -20px rgba(0,0,0,.8);
	animation: pop .3s cubic-bezier(.2, 1.3, .5, 1) both;
}
.modal-card h3 { font-size: 1.25rem; margin-top: 14px; }
.modal-card p { margin: 6px 0 20px; color: var(--muted); font-size: .95rem; }
.modal-icon {
	width: 64px; height: 64px; margin: 0 auto;
	display: grid; place-items: center;
	border-radius: 50%;
	font-size: 2rem; font-weight: 700;
}
.modal-icon.ok { background: rgba(47, 217, 138, .15); color: var(--win); }
.modal-icon.bad { background: rgba(255, 93, 108, .15); color: var(--lose); }
.modal-icon.warn { background: rgba(245, 194, 75, .15); color: var(--tie); }

/* ---------- Footer ---------- */
.site-foot {
	padding: 18px 16px 24px;
	text-align: center;
	font-size: .8rem;
	color: var(--muted);
	border-top: 1px solid var(--line);
}

/* ---------- Animations ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.92); } }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
	.game-layout { grid-template-columns: 1fr; }
	.history { max-height: none; }
}
@media (max-width: 520px) {
	.brand img { height: 32px; }
	.user-chip { height: 30px; padding: 0 10px; font-size: .8rem; }
	.page { padding-top: 20px; }
	.panel { padding: 16px; border-radius: 18px; }
	.room-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
	.room-card { min-height: 84px; padding: 10px 12px; }
	.room-id { font-size: 1.25rem; }
	.counter { min-width: 62px; }
	.login-card { padding: 26px 20px; }
}
@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
