/* Shared look for the login, registration and game pages */
:root {
	--sky-top: #6cc3f0;
	--sky-bottom: #c9ecff;
	--grass: #6aa82f;
	--grass-dark: #4c7f1e;
	--parchment: #fffaf0;
	--parchment-edge: #e7d3a8;
	--wood: #6b4423;
	--wood-dark: #4a2e12;
	--gold-top: #ffe27a;
	--gold-bottom: #f3b33d;
	--gold-edge: #b7791f;
	--text: #3b2a1a;
	--muted: #7a6650;
	--error-bg: #fdecea;
	--error-text: #a1261b;
	--ok-bg: #eaf6e4;
	--ok-text: #2f6b1a;
	--focus: #2f86c9;
	--radius: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	color: var(--text);
	background:
		radial-gradient(max(140vw, 900px) 34vh at 50% 100%, var(--grass) 0 70%, transparent 70.5%),
		linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 70%, var(--grass) 70.1%, var(--grass-dark) 100%);
	background-attachment: fixed;
}

a { color: var(--wood); font-weight: 600; }
a:hover { color: var(--wood-dark); }

/* ---------- Auth pages (login / register) ---------- */

.auth {
	position: relative;
	min-height: 100vh;
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 24px 16px 32px;
	gap: 18px;
}

.auth-logo {
	width: min(260px, 70vw);
	height: auto;
	filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .25));
}

.server-badge {
	margin-top: -10px;
	padding: 5px 14px;
	border-radius: 999px;
	background: var(--wood-dark);
	border: 2px solid var(--gold-bottom);
	color: var(--gold-top);
	font-family: "Cinzel", Georgia, "Times New Roman", serif;
	font-weight: 700;
	font-size: .95rem;
	letter-spacing: .03em;
	text-align: center;
	box-shadow: 0 4px 10px rgba(0, 0, 0, .25);
}

.card {
	width: 100%;
	max-width: 400px;
	background: var(--parchment);
	border: 3px solid var(--parchment-edge);
	border-radius: var(--radius);
	box-shadow: 0 12px 30px rgba(40, 60, 20, .35), inset 0 0 0 1px #fff;
	padding: 26px 24px 22px;
}

.card.wide { max-width: 560px; }

.card h1 {
	font-family: "Cinzel", Georgia, "Times New Roman", serif;
	font-size: 1.55rem;
	margin: 0;
	color: var(--wood-dark);
	text-align: center;
}

.card .subtitle {
	margin: 4px 0 20px;
	text-align: center;
	color: var(--muted);
	font-size: .95rem;
}

.alert {
	border-radius: 10px;
	padding: 10px 12px;
	margin-bottom: 16px;
	font-size: .92rem;
	font-weight: 600;
}
.alert.error { background: var(--error-bg); color: var(--error-text); }
.alert.ok { background: var(--ok-bg); color: var(--ok-text); }

.field { margin-bottom: 16px; }

.field label {
	display: block;
	font-weight: 700;
	font-size: .9rem;
	margin-bottom: 6px;
}

.field .hint {
	display: block;
	margin-top: 5px;
	font-size: .8rem;
	color: var(--muted);
}

.input, select.input {
	width: 100%;
	height: 44px;
	padding: 0 12px;
	font-size: 1rem;
	color: var(--text);
	background: #fff;
	border: 2px solid var(--parchment-edge);
	border-radius: 10px;
	transition: border-color .15s, box-shadow .15s;
}
.input:focus {
	outline: none;
	border-color: var(--focus);
	box-shadow: 0 0 0 3px rgba(47, 134, 201, .2);
}

.password-wrap { position: relative; }
.password-wrap .input { padding-right: 76px; }
.toggle-pass {
	position: absolute;
	right: 6px;
	top: 50%;
	transform: translateY(-50%);
	border: 0;
	background: transparent;
	color: var(--wood);
	font-weight: 700;
	font-size: .8rem;
	padding: 8px;
	cursor: pointer;
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .row { grid-template-columns: 1fr; } }

.btn {
	display: block;
	width: 100%;
	height: 50px;
	margin-top: 6px;
	border: 2px solid var(--gold-edge);
	border-radius: 12px;
	background: linear-gradient(180deg, var(--gold-top), var(--gold-bottom));
	color: var(--wood-dark);
	font-size: 1.1rem;
	font-weight: 800;
	letter-spacing: .02em;
	cursor: pointer;
	box-shadow: 0 4px 0 var(--gold-edge);
	transition: transform .05s, box-shadow .05s, filter .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-edge); }
.btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.advanced {
	margin: 4px 0 16px;
	border-top: 1px dashed var(--parchment-edge);
	padding-top: 10px;
}
.advanced summary {
	cursor: pointer;
	font-size: .88rem;
	color: var(--muted);
	font-weight: 600;
}
.advanced[open] summary { margin-bottom: 12px; }

.alt {
	text-align: center;
	margin: 18px 0 0;
	font-size: .95rem;
}

.auth-footer {
	font-size: .78rem;
	color: rgba(255, 255, 255, .9);
	text-shadow: 0 1px 2px rgba(0, 0, 0, .4);
	text-align: center;
}

/* Avatar picker */
.avatar-picker { display: flex; gap: 14px; align-items: flex-start; }
.avatar-preview {
	flex: none;
	width: 88px;
	height: 88px;
	border-radius: 12px;
	border: 3px solid var(--parchment-edge);
	background: #fff;
	object-fit: cover;
}
.avatar-grid {
	flex: 1;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
	gap: 6px;
	max-height: 164px;
	overflow-y: auto;
	padding: 4px;
	background: #fff;
	border: 2px solid var(--parchment-edge);
	border-radius: 10px;
}
.avatar-grid input { position: absolute; opacity: 0; pointer-events: none; }
.avatar-grid label {
	display: block;
	border-radius: 8px;
	border: 2px solid transparent;
	cursor: pointer;
	line-height: 0;
}
.avatar-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.avatar-grid input:checked + label { border-color: var(--gold-edge); box-shadow: 0 0 0 2px var(--gold-top); }
.avatar-grid input:focus-visible + label { outline: 3px solid var(--focus); }
@media (max-width: 420px) {
	.avatar-picker { flex-direction: column; align-items: center; }
	.avatar-grid { width: 100%; }
}

/* ---------- Game page ---------- */

body.game {
	height: 100vh;
	height: 100dvh;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	background: #3f6a1c;
}

.topbar {
	flex: none;
	display: flex;
	align-items: center;
	gap: 12px;
	height: 48px;
	padding: 0 12px;
	background: linear-gradient(180deg, #8cc63f, #6aa82f);
	border-bottom: 3px solid var(--wood);
	color: var(--wood-dark);
}
.topbar img.logo { height: 34px; width: auto; }
.topbar .spacer { flex: 1; }
.topbar .player {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: .92rem;
	white-space: nowrap;
	overflow: hidden;
}
.topbar .player img {
	width: 30px;
	height: 30px;
	border-radius: 7px;
	border: 2px solid var(--parchment-edge);
	object-fit: cover;
	background: #fff;
}
.topbar .player .name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; }
.topbar .level {
	background: var(--gold-top);
	border: 1px solid var(--gold-edge);
	border-radius: 999px;
	padding: 1px 8px;
	font-size: .78rem;
	font-weight: 800;
}
.topbar-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	height: 32px;
	padding: 0 10px;
	border-radius: 8px;
	border: 2px solid var(--gold-edge);
	background: linear-gradient(180deg, var(--gold-top), var(--gold-bottom));
	color: var(--wood-dark);
	font-weight: 700;
	font-size: .85rem;
	text-decoration: none;
	cursor: pointer;
	white-space: nowrap;
}
.topbar-btn:hover { filter: brightness(1.06); color: var(--wood-dark); }
.topbar-btn svg { width: 16px; height: 16px; }
@media (max-width: 560px) {
	.topbar .version, .topbar-btn .label { display: none; }
	.topbar img.logo { height: 28px; }
}
.topbar .version { font-size: .75rem; opacity: .8; }

.stage {
	flex: 1;
	min-height: 0;
	position: relative;
	overflow: hidden;
	background: #3f6a1c;
}
/* size, position and scale are set by js/fit_stage.js */
.stage ruffle-player, .stage embed {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	display: block;
	transform-origin: 0 0;
}
.stage.fixed ruffle-player, .stage.fixed embed { box-shadow: 0 0 24px rgba(0, 0, 0, .35); }

/* phones held upright: the 760x600 game ends up small, suggest rotating */
.rotate-hint {
	display: none;
	flex: none;
	padding: 8px 12px;
	background: var(--parchment);
	border-bottom: 2px solid var(--parchment-edge);
	color: var(--wood-dark);
	font-size: .85rem;
	text-align: center;
}
@media (orientation: portrait) and (max-width: 700px) {
	.rotate-hint { display: block; }
}

/* ES | EN language switch */
.lang-switch {
	display: inline-flex;
	border: 2px solid var(--gold-edge);
	border-radius: 999px;
	overflow: hidden;
	background: var(--parchment);
	box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}
.auth .lang-switch { position: absolute; top: 14px; right: 16px; }
.lang-switch a {
	padding: 5px 12px;
	font-size: .8rem;
	font-weight: 800;
	color: var(--wood);
	text-decoration: none;
	letter-spacing: .04em;
}
.lang-switch a + a { border-left: 1px solid var(--parchment-edge); }
.lang-switch a[aria-current="true"] {
	background: linear-gradient(180deg, var(--gold-top), var(--gold-bottom));
	color: var(--wood-dark);
}
.lang-switch a:hover { background: #fff3cf; }
.lang-switch.compact a { padding: 4px 9px; font-size: .75rem; }

/* "server unreachable" overlay (js/connection.js) */
.conn-overlay {
	position: fixed;
	inset: 0;
	z-index: 1000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	background: rgba(20, 30, 10, .72);
	backdrop-filter: blur(2px);
}
.conn-overlay[hidden] { display: none; }
.conn-card {
	width: 100%;
	max-width: 420px;
	text-align: center;
	background: var(--parchment);
	border: 3px solid var(--parchment-edge);
	border-radius: var(--radius);
	box-shadow: 0 12px 30px rgba(0, 0, 0, .4);
	padding: 24px 22px 20px;
	color: var(--text);
}
.conn-card h2 {
	font-family: "Cinzel", Georgia, "Times New Roman", serif;
	font-size: 1.25rem;
	margin: 10px 0 8px;
	color: var(--wood-dark);
}
.conn-card p { margin: 0 0 10px; font-size: .95rem; line-height: 1.4; }
.conn-status { color: var(--muted); font-size: .85rem !important; min-height: 1.2em; }
.conn-reload { margin-top: 8px; }
.conn-reload[hidden] { display: none; }
.conn-spinner {
	width: 38px;
	height: 38px;
	margin: 0 auto;
	border-radius: 50%;
	border: 4px solid var(--parchment-edge);
	border-top-color: var(--gold-bottom);
	animation: conn-spin 1s linear infinite;
}
@keyframes conn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .conn-spinner { animation-duration: 3s; } }

/* live events from other players (js/connection.js) */
.toasts {
	position: fixed;
	top: 58px;
	right: 12px;
	z-index: 900;
	display: flex;
	flex-direction: column;
	gap: 8px;
	width: min(340px, calc(100vw - 24px));
	pointer-events: none;
}
.toast {
	pointer-events: auto;
	background: var(--parchment);
	border: 2px solid var(--parchment-edge);
	border-left: 6px solid var(--gold-bottom);
	border-radius: 10px;
	box-shadow: 0 8px 20px rgba(0, 0, 0, .3);
	padding: 10px 12px;
	color: var(--text);
	font-size: .9rem;
	animation: toast-in .25s ease-out;
	transition: opacity .4s, transform .4s;
}
.toast.hide { opacity: 0; transform: translateX(20px); }
.toast p { margin: 0 0 8px; line-height: 1.35; }
.toast-actions { display: flex; gap: 6px; justify-content: flex-end; }
.toast-btn {
	border: 1px solid var(--parchment-edge);
	background: #fff;
	color: var(--wood-dark);
	border-radius: 7px;
	padding: 5px 10px;
	font-weight: 700;
	font-size: .8rem;
	cursor: pointer;
}
.toast-btn.primary {
	border-color: var(--gold-edge);
	background: linear-gradient(180deg, var(--gold-top), var(--gold-bottom));
}
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* Social panel over the game (js/social_drawer.js) */
.topbar-btn { position: relative; }
.topbar-badge {
	position: absolute;
	top: -7px;
	right: -7px;
	min-width: 18px;
	height: 18px;
	padding: 0 5px;
	border-radius: 999px;
	background: #c62828;
	border: 2px solid #fff;
	color: #fff;
	font-size: .68rem;
	font-weight: 800;
	line-height: 14px;
	text-align: center;
}
.social-drawer {
	position: fixed;
	top: 51px; /* below the top bar */
	right: 0;
	bottom: 0;
	z-index: 800;
	width: min(420px, 100vw);
	display: flex;
	flex-direction: column;
	background: var(--parchment);
	border-left: 3px solid var(--wood);
	box-shadow: -8px 0 24px rgba(0, 0, 0, .35);
	animation: drawer-in .2s ease-out;
}
.social-drawer[hidden] { display: none; }
.drawer-bar {
	flex: none;
	display: flex;
	align-items: center;
	gap: 6px;
	height: 40px;
	padding: 0 8px 0 14px;
	background: var(--wood-dark);
	color: var(--parchment);
	font-size: .95rem;
}
.drawer-bar .spacer { flex: 1; }
.drawer-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: var(--parchment);
	cursor: pointer;
}
.drawer-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.drawer-btn:focus-visible { outline: 2px solid var(--gold-top); outline-offset: 1px; }
.drawer-btn svg { width: 18px; height: 18px; }
.social-drawer iframe { flex: 1; width: 100%; border: 0; background: #e9f5d8; }
@keyframes drawer-in { from { transform: translateX(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .social-drawer { animation: none; } }
