:root {
	--hud-h: 34px;
	--game-w: 480px;
	--game-h: 320px;
	--side-w: 0px;
	--rail-w: 120px;
	--cross: 132px;
	--gap: 8px;
	--safe-t: env(safe-area-inset-top, 0px);
	--safe-b: env(safe-area-inset-bottom, 0px);
	--safe-l: env(safe-area-inset-left, 0px);
	--safe-r: env(safe-area-inset-right, 0px);
}

html, body {
	margin: 0;
	height: 100%;
	overflow: hidden;
	overscroll-behavior: none;
	background-color: #0b0b0f;
	font-family: 'Calibri', 'Verdana', sans-serif;
	/* No pan, no pinch, no double-tap zoom, anywhere on the page. */
	touch-action: none;
	-ms-touch-action: none;
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

body {
	display: flex;
	box-sizing: border-box;
	align-items: center;
	justify-content: center;
	touch-action: none;
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
	-webkit-tap-highlight-color: transparent;
}

#game {
	position: relative;
	width: min(100vw, calc((100vh - var(--hud-h)) * 1.5));
	aspect-ratio: 3 / 2;
	flex: 0 0 auto;
}

/* Puerta de entrada. Sustituye al cartel de "hay otra persona jugando": ya
   no hay turnos, el save lo fusiona el servidor y juega todo el mundo a la
   vez, pero hace falta saber quién es cada uno. */
#gate {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 10;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 24px;
	background: #0b0b0f;
	color: #ddd;
	font-size: 18px;
	line-height: 1.5;
}

#gate form {
	display: flex;
	flex-direction: column;
	gap: 10px;
	width: 100%;
	max-width: 320px;
}

#gate h1 {
	margin: 0;
	font-size: 22px;
	color: #fff;
}

#gate p {
	margin: 0 0 6px;
	font-size: 14px;
	color: #9a9aa5;
}

#gate input {
	padding: 12px 14px;
	border: 1px solid #2a2a35;
	border-radius: 10px;
	background: #15151c;
	color: #eee;
	font-size: 16px; /* menos de 16 y iOS hace zoom al enfocar */
}

#gate button {
	padding: 12px 14px;
	border: 0;
	border-radius: 10px;
	background: #cc0000;
	color: #fff;
	font-size: 16px;
	font-weight: bold;
	cursor: pointer;
}

#gate button[disabled] {
	opacity: .6;
	cursor: default;
}

#gateError {
	min-height: 18px;
	font-size: 13px;
	color: #ff8080;
}

#aviso {
	display: none;
	position: fixed;
	top: max(10px, env(safe-area-inset-top));
	left: 50%;
	transform: translateX(-50%);
	z-index: 9;
	padding: 8px 14px;
	border-radius: 999px;
	background: rgba(204, 0, 0, .92);
	color: #fff;
	font-size: 14px;
	font-weight: bold;
	pointer-events: none;
}

#quienBox {
	position: fixed;
	top: max(6px, env(safe-area-inset-top));
	right: 10px;
	z-index: 8;
	font-size: 12px;
	color: #6e6e7a;
}

#quienBox a {
	text-decoration: none;
	font-size: 14px;
}

#screen, #crash {
	display: block;
	width: 100%;
	height: 100%;
	image-rendering: -webkit-optimize-contrast;
	image-rendering: -moz-crisp-edges;
	image-rendering: pixelated;
}

#screen.dead {
	display: none;
}

/* ------------------------------------------------------------------
   Keyboard hint bar (desktop only)
   ------------------------------------------------------------------ */

#hud {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	height: var(--hud-h);
	margin: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 16px;
	background: rgba(0, 0, 0, 0.55);
	color: #ddd;
	font-size: 13px;
	white-space: nowrap;
	overflow-x: auto;
}

#hud span {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

#hud kbd {
	display: inline-block;
	min-width: 12px;
	text-align: center;
	padding: 2px 6px;
	border-radius: 4px;
	background: #2a2a33;
	border: 1px solid #4a4a55;
	color: #fff;
	font-size: 12px;
	font-family: inherit;
	box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset;
}

.btn-group {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 1px;
}

.btn-group .btn-primary {
	font-size: 100%;
}

.btn-group .btn-secondary {
	font-size: 10%;
	opacity: 0.5;
	gap: 3px;
}

.btn-group .btn-secondary kbd {
	font-size: 6px;
	min-width: 8px;
	padding: 1px 3px;
}

/* ==================================================================
   Touch control deck
   Hidden by default; index.html adds .touch to <body> on coarse
   pointers and drives --game-w / --game-h / --side-w / --cross.
   ================================================================== */

#deck {
	display: none;
}

body.touch #hud {
	display: none;
}

body.touch {
	--hud-h: 0px;
}

body.touch #game {
	width: var(--game-w);
	height: var(--game-h);
	aspect-ratio: auto;
}

/* --- shared control chrome --- */

.pad,
.nub,
.pill {
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	background: linear-gradient(180deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.035));
	border: 1px solid rgba(255, 255, 255, 0.15);
	color: rgba(255, 255, 255, 0.42);
	transition: background 60ms linear, color 60ms linear, border-color 60ms linear;
}

.pad.active,
.nub.active,
.pill.active {
	background: linear-gradient(180deg, rgba(122, 190, 255, 0.38), rgba(122, 190, 255, 0.16));
	border-color: rgba(155, 208, 255, 0.65);
	color: rgba(255, 255, 255, 0.9);
}

.pad {
	position: relative;
	border-radius: 16px;
	font-size: 42px;
	font-weight: bold;
	letter-spacing: 2px;
	color: rgba(255, 255, 255, 0.2);
}

.pad::after {
	content: attr(data-hint);
	position: absolute;
	bottom: 8px;
	left: 0;
	right: 0;
	text-align: center;
	font-size: 11px;
	font-weight: normal;
	letter-spacing: 1px;
	color: rgba(255, 255, 255, 0.22);
}

.nudge {
	position: relative;
	width: var(--cross);
	height: var(--cross);
	flex: 0 0 auto;
}

.nub {
	position: absolute;
	width: 33.34%;
	height: 33.34%;
	border-radius: 10px;
	font-family: 'Consolas', 'Courier New', monospace;
	font-size: 21px;
	font-weight: bold;
	line-height: 1;
}

/* The ASCII glyphs do not sit on the same optical centre, so nudge them
   into the middle of their box with padding. */
.nub-up    { left: 33.33%; top: 0; padding-top: 12px; }
.nub-down  { left: 33.33%; top: 66.66%; padding-bottom: 4px; }
.nub-left  { left: 0; top: 33.33%; }
.nub-right { left: 66.66%; top: 33.33%; }

.nudge::after {
	content: 'MOVER';
	position: absolute;
	left: 33.33%;
	top: 33.33%;
	width: 33.34%;
	height: 33.34%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 8px;
	letter-spacing: 1px;
	color: rgba(255, 255, 255, 0.18);
	pointer-events: none;
}

.pill {
	height: 38px;
	min-width: 44px;
	padding: 0 12px;
	border-radius: 19px;
	font-size: 12px;
	font-weight: bold;
	letter-spacing: 1px;
	white-space: nowrap;
}

.pill.round {
	width: 46px;
	min-width: 46px;
	padding: 0;
	border-radius: 50%;
	font-size: 17px;
}

#fsBtn {
	font-family: 'Consolas', 'Courier New', monospace;
	font-size: 14px;
	letter-spacing: 0;
}

/* --- portrait: screen on top, control deck underneath --- */

body.touch:not(.landscape) {
	flex-direction: column;
	justify-content: flex-start;
	align-items: center;
	padding-top: var(--safe-t);
}

body.touch:not(.landscape) #deck {
	flex: 1 1 auto;
	width: 100%;
	min-height: 0;
	display: grid;
	box-sizing: border-box;
	grid-template-columns: 1fr var(--cross) 1fr;
	grid-template-rows: auto minmax(0, 1fr);
	grid-template-areas:
		"aux  aux   aux"
		"padL nudge padR";
	gap: var(--gap);
	padding: 10px
		calc(var(--gap) + var(--safe-r))
		calc(var(--gap) + var(--safe-b))
		calc(var(--gap) + var(--safe-l));
	border-top: 1px solid rgba(255, 255, 255, 0.07);
}

body.touch:not(.landscape) #aux {
	grid-area: aux;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
}

body.touch:not(.landscape) #nudge {
	grid-area: nudge;
	align-self: end;
	justify-self: center;
	margin-bottom: 12px;
}

body.touch:not(.landscape) #padL { grid-area: padL; }
body.touch:not(.landscape) #padR { grid-area: padR; }

/* --- landscape: screen centred, controls live in the side rails --- */

body.touch.landscape #deck {
	display: block;
	position: fixed;
	inset: 0;
	z-index: 2;
	pointer-events: none;
}

body.touch.landscape #deck > * {
	pointer-events: auto;
}

body.touch.landscape .pad {
	position: absolute;
	bottom: var(--gap);
	top: calc(var(--cross) + var(--gap) * 2);
	width: calc(var(--side-w) - var(--gap));
}

body.touch.landscape #padL {
	left: calc(var(--gap) + var(--safe-l));
	width: calc(var(--side-w) - var(--gap) - var(--safe-l));
}

body.touch.landscape #padR {
	right: calc(var(--gap) + var(--safe-r));
	width: calc(var(--side-w) - var(--gap) - var(--safe-r));
}

body.touch.landscape #nudge {
	position: absolute;
	top: calc(var(--gap) + var(--safe-t));
	left: calc(var(--gap) + var(--safe-l));
}

body.touch.landscape #aux {
	position: absolute;
	top: calc(var(--gap) + var(--safe-t));
	right: calc(var(--gap) + var(--safe-r));
	width: var(--rail-w);
	display: flex;
	flex-wrap: wrap;
	align-content: flex-start;
	justify-content: flex-end;
	gap: 6px;
}

body.touch.landscape #aux .pill {
	height: 32px;
	font-size: 11px;
	padding: 0 10px;
}

body.touch.landscape #aux .pill.round {
	width: 40px;
	min-width: 40px;
	font-size: 15px;
}

/* The rails may overlap the playfield edges on wide screens, so keep
   the floating clusters see-through until they are actually pressed. */
body.touch.landscape #nudge .nub,
body.touch.landscape #aux .pill {
	background: rgba(20, 22, 30, 0.55);
	border-color: rgba(255, 255, 255, 0.18);
}

body.touch.landscape #nudge .nub.active,
body.touch.landscape #aux .pill.active {
	background: rgba(122, 190, 255, 0.45);
	border-color: rgba(155, 208, 255, 0.7);
	color: rgba(255, 255, 255, 0.95);
}
