/* TOPOUT design language: monochrome base, one accent, JetBrains Mono, sharp
   corners (zero radius), no decoration. Colors mirror src/ui/top_theme.gd. */

@font-face {
	font-family: "JetBrains Mono";
	src: url("assets/fonts/JetBrainsMono-Regular.ttf") format("truetype");
	font-weight: 400;
	font-display: swap;
}
@font-face {
	font-family: "JetBrains Mono";
	src: url("assets/fonts/JetBrainsMono-Bold.ttf") format("truetype");
	font-weight: 700;
	font-display: swap;
}

:root {
	--bg: #0b0b0d;
	--panel: #141417;
	--grey-dim: #2a2a2f;
	--grey-mid: #6f6f78;
	--grey-hi: #b8b8c0;
	--fg: #f2f2f5;
	--accent: #ff4d4d;
	--font: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
	/* Actual visible viewport (JS sets these from window.visualViewport so the
	   mobile URL bar never cuts off the bottom of the game). */
	--app-w: 100vw;
	--app-h: 100dvh;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
	height: 100%;
	background: var(--bg);
	color: var(--fg);
	font-family: var(--font);
	font-size: 15px;
	overflow: hidden;
	overscroll-behavior: none;
	-webkit-font-smoothing: antialiased;
	-webkit-tap-highlight-color: transparent;
	/* it's a game UI — no accidental text selection / callouts */
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
}
input, textarea { user-select: text; -webkit-user-select: text; }
::selection { background: var(--grey-dim); color: var(--fg); }

#bg-canvas {
	position: fixed;
	top: 0;
	left: 0;
	width: var(--app-w);
	height: var(--app-h);
	z-index: 0;
	pointer-events: none;
}

#app {
	position: fixed;
	top: 0;
	left: 0;
	width: var(--app-w);
	height: var(--app-h);
	z-index: 1;
	overflow: hidden;
}

/* --- generic widgets --- */
button, .btn {
	font-family: var(--font);
	font-size: 15px;
	color: var(--fg);
	background: var(--panel);
	border: 0;
	border-radius: 0;
	padding: 8px 14px;
	cursor: pointer;
	text-align: left;
	transition: background 0.06s;
	outline: none;
	line-height: 1.3;
}
button:hover, .btn:hover { background: var(--grey-dim); }
button:active, .btn:active { background: var(--accent); color: var(--bg); }
button:focus-visible, .btn:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button:disabled:hover { background: var(--panel); }

button.toggle-on { background: var(--accent); color: var(--bg); }

input[type="text"], input[type="number"], input[type="password"], .line-edit {
	font-family: var(--font);
	font-size: 15px;
	color: var(--fg);
	background: var(--bg);
	border: 1px solid var(--grey-dim);
	border-radius: 0;
	padding: 4px 8px;
	outline: none;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="password"]:focus { border-color: var(--accent); }

input[type="range"] {
	-webkit-appearance: none;
	appearance: none;
	height: 20px;
	background: transparent;
	cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
	height: 6px; background: var(--grey-dim); border-radius: 0;
}
input[type="range"]::-moz-range-track { height: 6px; background: var(--grey-dim); }
input[type="range"]::-webkit-slider-thumb {
	-webkit-appearance: none; appearance: none;
	width: 8px; height: 18px; margin-top: -6px;
	background: var(--grey-hi); border-radius: 0; border: 0;
}
input[type="range"]::-moz-range-thumb {
	width: 8px; height: 18px; background: var(--grey-hi); border-radius: 0; border: 0;
}

select {
	font-family: var(--font); font-size: 15px; color: var(--fg);
	background: var(--panel); border: 0; border-radius: 0; padding: 8px 14px;
	cursor: pointer; outline: none;
}
select:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }

input[type="checkbox"] {
	appearance: none; -webkit-appearance: none;
	width: 18px; height: 18px; background: var(--bg);
	border: 1px solid var(--grey-mid); cursor: pointer; vertical-align: middle;
	position: relative; flex: 0 0 auto;
}
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::after {
	content: ""; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px;
	border: solid var(--bg); border-width: 0 2px 2px 0; transform: rotate(45deg);
}

/* --- layout primitives --- */
.screen { position: absolute; inset: 0; }
.center-col {
	position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
	display: flex; flex-direction: column; gap: 10px;
}
.scroll-screen {
	position: absolute; inset: 40px 80px; overflow-y: auto; overflow-x: hidden;
}
.title { font-size: 28px; color: var(--fg); font-weight: 400; }
.title-big { font-size: 56px; color: var(--fg); }
.caption { font-size: 13px; color: var(--grey-mid); }
.section { font-size: 15px; color: var(--grey-hi); margin-top: 10px; }
.dim { color: var(--grey-mid); }
.accent { color: var(--accent); }
.hi { color: var(--grey-hi); }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1 1 auto; }

.stat-row { display: flex; align-items: baseline; }
.stat-row .k { width: 220px; font-size: 14px; color: var(--grey-mid); }
.stat-row .v { font-size: 18px; }

canvas.board, canvas.opp, canvas.piece { display: block; }

.mode-btn { display: flex; flex-direction: column; justify-content: center; gap: 3px; width: 440px; min-height: 62px; padding: 8px 14px; }
.mode-name { font-size: 20px; }
.mode-desc { font-size: 12px; color: var(--grey-mid); }
.mode-btn:active .mode-desc, .mode-btn:active .mode-name { color: var(--bg); }
.big-btn { display: flex; align-items: center; justify-content: flex-start; min-height: 44px; width: 100%; }

/* --- solo game screen: responsive grid (desktop side-panels, mobile stacked) --- */
.game-screen { position: absolute; inset: 0; display: grid; gap: 10px; padding: 20px 36px; }
.g-hud { display: contents; }
.g-hold, .g-next { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.g-hold canvas { width: 118px; height: 74px; }
.g-next-pieces { display: flex; flex-direction: column; gap: 4px; }
.g-next-pieces canvas { width: 108px; height: 62px; }
.g-stats { display: flex; flex-direction: column; gap: 2px; }
.g-stat { display: flex; flex-direction: column; }
.g-board { position: relative; min-width: 0; min-height: 0; align-self: stretch; }
.g-board canvas { width: 100%; height: 100%; }
.slot { background: transparent; }
.stat-val { font-size: 22px; color: var(--fg); }

@media (min-width: 760px) {
	.game-screen {
		grid-template-columns: 200px minmax(280px, 50vh) 150px;
		grid-template-rows: auto auto minmax(0, 1fr);
		grid-template-areas: "hold board next" "stats board next" ". board next";
		align-items: start;
		justify-content: center;
		column-gap: 30px;
	}
	.g-hold { grid-area: hold; }
	.g-stats { grid-area: stats; margin-top: 8px; }
	.g-next { grid-area: next; align-items: flex-end; }
	.g-board { grid-area: board; }
}
@media (max-width: 759px) {
	.game-screen { display: flex; flex-direction: column; padding: 8px; gap: 6px; }
	.g-hud { display: flex; flex-direction: row; align-items: flex-start; justify-content: space-between; gap: 8px; }
	.g-hold canvas { width: 56px; height: 38px; }
	.g-next { align-items: flex-end; }
	.g-next-pieces { flex-direction: row; gap: 3px; }
	.g-next-pieces canvas { width: 30px; height: 28px; }
	.g-stats { flex: 1; flex-direction: row; flex-wrap: wrap; gap: 4px 12px; align-content: flex-start; }
	.g-stat { flex-direction: row; align-items: baseline; gap: 4px; }
	.g-stat .caption { font-size: 10px; }
	.stat-val { font-size: 14px; }
	.g-board { flex: 1; }
}

/* Touch devices (landscape): compact HUD hugging the top so the translucent
   on-screen buttons at the bottom don't collide with hold / stats / next. */
@media (pointer: coarse) {
	.g-stats { flex-direction: row !important; flex-wrap: wrap; gap: 2px 10px; align-content: flex-start; }
	.g-stat { flex-direction: row; align-items: baseline; gap: 4px; }
	.g-stat .caption { font-size: 10px; }
	.g-stats .stat-val { font-size: 13px; }
	.g-hold canvas { width: 52px !important; height: 34px !important; }
	.g-next-pieces { flex-direction: row !important; }
	.g-next-pieces canvas { width: 30px !important; height: 26px !important; }
	/* maximise board room; respect notch safe areas */
	.game-screen {
		padding: max(6px, env(safe-area-inset-top)) max(52px, env(safe-area-inset-right))
		         max(6px, env(safe-area-inset-bottom)) max(52px, env(safe-area-inset-left)) !important;
		column-gap: 16px !important; row-gap: 4px !important;
	}
	.vs-screen { padding: max(6px, env(safe-area-inset-top)) max(52px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(52px, env(safe-area-inset-left)); }
}

.countdown { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 72px; color: var(--fg); pointer-events: none; }
@keyframes cd-pop { from { transform: translate(-50%, -50%) scale(1.5); } to { transform: translate(-50%, -50%) scale(1.0); } }
.overlay-msg { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 30px; text-align: center; pointer-events: none; }

/* --- VS / royale: side panel, board, opponent wall --- */
.vs-screen { position: absolute; inset: 0; display: grid; gap: 8px; padding: 14px 22px; }
.vs-side { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.vs-board { position: relative; min-width: 0; min-height: 0; }
.vs-board canvas.board { width: 100%; height: 100%; }
.vs-opps { min-width: 0; min-height: 0; overflow: auto; }

@media (min-width: 900px) {
	.vs-screen { grid-template-columns: 190px minmax(0, 1fr) minmax(320px, 46%); grid-template-areas: "side board opps"; align-items: stretch; }
	.vs-side { grid-area: side; }
	.vs-board { grid-area: board; }
	.vs-opps { grid-area: opps; }
}
@media (max-width: 899px) {
	.vs-screen { display: flex; flex-direction: column; padding: 8px; gap: 6px; }
	.vs-side { flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: 4px 10px; font-size: 12px; }
	.vs-side canvas.piece { width: 40px !important; height: 30px !important; }
	.vs-side .nextrow { display: flex; flex-direction: row !important; gap: 3px; }
	.vs-board { flex: 2 1 0; min-height: 42vh; }
	.vs-opps { flex: 1 1 0; max-height: 34vh; }
	.vs-opps canvas.opp { height: 150px !important; }
}
/* Touch phones/tablets always play in landscape (portrait is gated by the
   rotate overlay). A landscape phone is < 900px wide, so without this it would
   fall into the stacked column layout above and push the board off-screen.
   Force a compact horizontal 3-column grid: narrow side, board fills the
   middle, opponents scroll on the right. */
@media (pointer: coarse) and (orientation: landscape) {
	.vs-screen {
		display: grid !important;
		flex-direction: initial !important;
		grid-template-columns: minmax(60px, 84px) minmax(0, 1fr) minmax(96px, 38%);
		grid-template-areas: "side board opps" !important;
		align-items: stretch !important;
		gap: 6px !important;
		/* gutters reserve the corner buttons' room (must live here — the
		   max-width:899 rule's padding is later in the file and would win) */
		padding: max(6px, env(safe-area-inset-top)) max(52px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(52px, env(safe-area-inset-left)) !important;
	}
	.vs-side {
		grid-area: side;
		flex-direction: column !important;
		flex-wrap: nowrap !important;
		align-items: stretch !important;
		gap: 2px !important;
		font-size: 10px !important;
		overflow-y: auto;
		overflow-x: hidden;
	}
	.vs-side .caption { font-size: 9px !important; }
	.vs-side canvas.piece { width: 100% !important; height: 24px !important; }
	.vs-side button { width: 100% !important; height: 22px !important; font-size: 10px !important; padding: 2px 4px !important; text-align: center; }
	.vs-board { grid-area: board; min-width: 0 !important; min-height: 0 !important; flex: initial !important; }
	.vs-opps { grid-area: opps; max-height: none !important; flex: initial !important; overflow-y: auto; overflow-x: hidden; }
	/* unify both opponent layouts (VS 2-col grid + royale fixed-px wall) into a
	   responsive auto-fit grid that fills the column and scrolls vertically */
	.vs-opps > div {
		display: grid !important;
		grid-template-columns: repeat(auto-fit, minmax(58px, 1fr)) !important;
		column-gap: 3px !important; row-gap: 3px !important;
	}
	.vs-opps canvas.opp { width: 100% !important; height: auto !important; aspect-ratio: 10 / 14; }
	/* spectate board (appended straight to the screen root with hard-coded px) */
	.vs-screen > canvas.board { left: 92px !important; right: 40% !important; top: 6px !important; bottom: 6px !important; }
}

.version { position: absolute; right: 24px; bottom: 24px; font-size: 12px; color: var(--grey-dim); }

/* --- responsive menus + scroll screens --- */
@media (max-width: 620px) {
	.center-col { width: min(92vw, 440px); }
	.center-col > * { width: 100% !important; max-width: 100%; box-sizing: border-box; }
	.title-big { font-size: 44px; }
	.scroll-screen { inset: 12px; }
	.stat-row .k { width: 45%; }
	.mode-btn { width: 100% !important; }
}
@media (max-width: 400px) {
	.title-big { font-size: 36px; }
	.mode-name { font-size: 17px; }
	.mode-desc { font-size: 11px; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--grey-dim); }
::-webkit-scrollbar-track { background: transparent; }

/* --- portrait lock on touch devices: rotate-to-landscape gate --- */
#rotate-overlay {
	display: none;
	position: fixed; top: 0; left: 0; width: var(--app-w); height: var(--app-h); z-index: 1000;
	background: var(--bg);
	flex-direction: column; align-items: center; justify-content: center;
	gap: 18px; text-align: center; padding: 24px;
}
/* only real touch devices held in portrait see it (never desktop) */
@media (orientation: portrait) and (pointer: coarse) { #rotate-overlay { display: flex; } }
.rotate-phone {
	width: 54px; height: 92px; border: 3px solid var(--fg); border-radius: 8px;
	position: relative; transform-origin: 50% 50%;
	animation: rot-hint 2s ease-in-out infinite;
}
.rotate-phone::after {
	content: ""; position: absolute; left: 50%; bottom: 7px; transform: translateX(-50%);
	width: 16px; height: 3px; background: var(--grey-mid);
}
.rotate-title { font-size: 22px; color: var(--fg); }
.rotate-sub { font-size: 13px; color: var(--grey-mid); }
@keyframes rot-hint { 0%, 30% { transform: rotate(0deg); } 65%, 100% { transform: rotate(-90deg); } }

/* corner buttons (touch devices; JS toggles display + also sets inline styles so
   they work even against a stale cached stylesheet) */
#fs-btn {
	position: fixed; top: 8px; right: 8px; z-index: 900;
	width: 44px; height: 44px; padding: 0;
	align-items: center; justify-content: center;
	font-size: 20px; line-height: 1;
	background: rgba(20, 20, 23, 0.78); color: var(--fg);
	border: 1px solid var(--grey-dim);
	display: none;
}
#back-btn {
	position: fixed; top: 8px; left: 8px; z-index: 900;
	width: 44px; height: 44px; padding: 0;
	align-items: center; justify-content: center;
	font-size: 30px; line-height: 1;
	background: rgba(20, 20, 23, 0.78); color: var(--fg);
	border: 1px solid var(--grey-dim);
	display: none;
}

/* leaderboard table (leaderboard_screen.js) */
.lb-table { display: flex; flex-direction: column; border-top: 1px solid var(--grey-dim); }
.lb-row {
	display: flex; align-items: baseline; gap: 10px;
	padding: 6px 8px; font-size: 14px;
	border-bottom: 1px solid var(--grey-dim);
}
.lb-row:nth-child(odd) { background: rgba(255, 255, 255, 0.02); }
.lb-rank { width: 46px; color: var(--grey-mid); font-size: 13px; text-align: right; }
.lb-name { flex: 1 1 auto; color: var(--grey-hi); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-val { color: var(--fg); font-variant-numeric: tabular-nums; }
.lb-you { background: rgba(255, 77, 77, 0.14) !important; }
.lb-you .lb-name { color: var(--accent); }
.lb-you .lb-rank { color: var(--accent); }
