/* ===== Ajedrez 3D — interfaz moderna ===== */

:root {
	--panel-bg: rgba(12, 10, 8, 0.78);
	--panel-border: rgba(216, 185, 140, 0.25);
	--gold: #d8b98c;
	--gold-strong: #f0d9a8;
	--text: #efe6d5;
	--muted: #a89878;
	--accent: #4caf6d;
	--danger: #e05545;
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	padding: 0;
	overflow: hidden;
	background: #000;
	font-family: "Segoe UI", Verdana, Arial, sans-serif;
	color: var(--text);
	height: 100%;
}

#game-canvas {
	position: fixed;
	inset: 0;
	display: block;
}

.hidden { display: none !important; }

button {
	font-family: inherit;
	cursor: pointer;
}

/* ================= pantalla de carga ================= */

#loading {
	position: fixed;
	inset: 0;
	background: radial-gradient(ellipse at center, #16100a 0%, #000 75%);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	z-index: 100;
	transition: opacity 0.6s ease;
}

#loading.hidden {
	display: flex !important;
	opacity: 0;
	pointer-events: none;
}

#loading h1 {
	font-family: Georgia, "Times New Roman", serif;
	font-size: 3.2em;
	letter-spacing: 0.35em;
	margin: 0 0 0.2em 0.35em;
	color: var(--gold-strong);
	text-shadow: 0 0 30px rgba(216, 185, 140, 0.45);
	animation: pulse 2.4s ease-in-out infinite;
}

#loading .subtitle {
	color: var(--muted);
	letter-spacing: 0.25em;
	margin-bottom: 3em;
	text-transform: uppercase;
	font-size: 0.85em;
}

@keyframes pulse {
	0%, 100% { text-shadow: 0 0 18px rgba(216, 185, 140, 0.25); }
	50% { text-shadow: 0 0 42px rgba(216, 185, 140, 0.65); }
}

#loading-bar {
	width: min(420px, 70vw);
	height: 10px;
	border: 1px solid var(--panel-border);
	border-radius: 6px;
	overflow: hidden;
	background: rgba(255, 255, 255, 0.04);
}

#loading-fill {
	height: 100%;
	width: 0%;
	background: linear-gradient(90deg, #7a5c30, var(--gold));
	transition: width 0.25s ease;
}

#loading-percent {
	margin-top: 0.7em;
	color: var(--gold);
	font-size: 0.9em;
}

#loading-tip {
	margin-top: 2.2em;
	color: var(--muted);
	font-style: italic;
	font-size: 0.9em;
	min-height: 1.4em;
	text-align: center;
	padding: 0 1em;
}

/* ================= menu principal ================= */

#menu {
	position: fixed;
	inset: 0;
	z-index: 40;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background: radial-gradient(ellipse at center, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0.78) 100%);
}

#menu h1 {
	font-family: Georgia, serif;
	font-size: clamp(2.4em, 6vw, 4em);
	letter-spacing: 0.3em;
	margin: 0 0 0.1em 0.3em;
	color: var(--gold-strong);
	text-shadow: 0 0 35px rgba(216, 185, 140, 0.5);
}

#menu .subtitle {
	color: var(--muted);
	letter-spacing: 0.28em;
	text-transform: uppercase;
	font-size: 0.8em;
	margin-bottom: 2.5em;
}

#menu-cards {
	display: flex;
	gap: 18px;
	flex-wrap: wrap;
	justify-content: center;
	max-width: 900px;
}

.mode-card {
	width: 190px;
	padding: 22px 18px;
	background: var(--panel-bg);
	border: 1px solid var(--panel-border);
	border-radius: 14px;
	text-align: center;
	color: var(--text);
	transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.mode-card:hover {
	transform: translateY(-4px);
	border-color: var(--gold);
	box-shadow: 0 8px 30px rgba(216, 185, 140, 0.18);
}

.mode-card .icon { font-size: 2.4em; display: block; margin-bottom: 10px; }
.mode-card .name { font-weight: 600; font-size: 1.05em; display: block; margin-bottom: 6px; color: var(--gold-strong); }
.mode-card .desc { font-size: 0.8em; color: var(--muted); line-height: 1.4; }

#menu-stats {
	margin-top: 2.6em;
	display: flex;
	gap: 2.2em;
	color: var(--muted);
	font-size: 0.85em;
	flex-wrap: wrap;
	justify-content: center;
}

#menu-stats b { color: var(--gold); font-size: 1.25em; display: block; text-align: center; }

/* configuracion de partida */

#menu-config {
	background: var(--panel-bg);
	border: 1px solid var(--panel-border);
	border-radius: 16px;
	padding: 28px 34px;
	width: min(440px, 92vw);
	backdrop-filter: blur(6px);
}

#menu-config h2 { margin: 0 0 1em; color: var(--gold-strong); font-family: Georgia, serif; font-weight: 500; }

#menu-config .row { margin-bottom: 1.1em; }
#menu-config label.row-label { display: block; color: var(--muted); font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.12em; margin-bottom: 0.5em; }

.radio-group { display: flex; gap: 8px; }
.radio-group input { display: none; }
.radio-group span {
	display: inline-block;
	padding: 8px 16px;
	border: 1px solid var(--panel-border);
	border-radius: 8px;
	font-size: 0.9em;
	cursor: pointer;
	color: var(--text);
	transition: all 0.12s ease;
}
.radio-group input:checked + span {
	background: var(--gold);
	color: #1a1208;
	border-color: var(--gold);
	font-weight: 600;
}

select {
	width: 100%;
	padding: 9px 10px;
	background: #1c150c;
	color: var(--text);
	border: 1px solid var(--panel-border);
	border-radius: 8px;
	font-size: 0.95em;
}

.btn {
	padding: 11px 22px;
	border-radius: 10px;
	border: 1px solid var(--panel-border);
	background: rgba(255, 255, 255, 0.05);
	color: var(--text);
	font-size: 0.95em;
	transition: all 0.12s ease;
}
.btn:hover { border-color: var(--gold); background: rgba(216, 185, 140, 0.12); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn:disabled:hover { border-color: var(--panel-border); background: rgba(255,255,255,0.05); }

.btn.primary {
	background: linear-gradient(180deg, #caa768, #9a7b40);
	border-color: #caa768;
	color: #17100a;
	font-weight: 700;
}
.btn.primary:hover { filter: brightness(1.12); }

.btn.danger:hover { border-color: var(--danger); background: rgba(224, 85, 69, 0.15); }

#menu-config .actions { display: flex; justify-content: space-between; margin-top: 1.6em; }

/* ================= HUD en partida ================= */

#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#hud > * { pointer-events: auto; }

#hud-top {
	position: fixed;
	top: 0; left: 0; right: 0;
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 10px 16px;
	background: linear-gradient(180deg, rgba(0,0,0,0.65), transparent);
	pointer-events: none;
}

#hud-mode { color: var(--gold); font-size: 0.9em; letter-spacing: 0.04em; }

#turn-indicator { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.85em; }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid #888; display: inline-block; }
.dot.white { background: #f5efe0; }
.dot.black { background: #17130d; }

#hud-thinking {
	color: var(--muted);
	font-size: 0.85em;
	font-style: italic;
	opacity: 0;
	transition: opacity 0.25s;
}
#hud-thinking.visible { opacity: 1; }
#hud-thinking.visible::after {
	content: "";
	display: inline-block;
	width: 10px; height: 10px;
	margin-left: 8px;
	border: 2px solid var(--gold);
	border-top-color: transparent;
	border-radius: 50%;
	animation: spin 0.9s linear infinite;
	vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* banner de estado (jaque, mate...) */
#estado {
	position: fixed;
	top: 16%;
	left: 50%;
	transform: translateX(-50%) scale(0.9);
	font-family: Georgia, serif;
	font-size: 2em;
	color: #ff6655;
	text-shadow: 0 2px 18px rgba(0,0,0,0.9);
	opacity: 0;
	transition: all 0.25s ease;
	pointer-events: none;
	z-index: 30;
	text-align: center;
}
#estado.visible { opacity: 1; transform: translateX(-50%) scale(1); }

/* relojes */
#clocks {
	position: fixed;
	right: 14px;
	top: 52px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	z-index: 25;
}
.clock {
	background: var(--panel-bg);
	border: 1px solid var(--panel-border);
	border-radius: 10px;
	padding: 8px 14px;
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 130px;
	justify-content: space-between;
	transition: all 0.2s ease;
}
.clock .who { font-size: 0.75em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.clock .time { font-size: 1.35em; font-variant-numeric: tabular-nums; color: var(--text); }
.clock.active { border-color: var(--gold); box-shadow: 0 0 14px rgba(216,185,140,0.25); }
.clock.active .time { color: var(--gold-strong); }
.clock.low.active .time { color: var(--danger); }

/* panel lateral: jugadas y capturas */
#panel {
	position: fixed;
	right: 14px;
	top: 170px;
	bottom: 90px;
	width: 190px;
	background: var(--panel-bg);
	border: 1px solid var(--panel-border);
	border-radius: 12px;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	backdrop-filter: blur(4px);
	z-index: 24;
}

#panel h3 {
	margin: 0;
	padding: 10px 14px 8px;
	font-size: 0.72em;
	text-transform: uppercase;
	letter-spacing: 0.14em;
	color: var(--muted);
	font-weight: 600;
	border-bottom: 1px solid rgba(255,255,255,0.06);
}

#moves-wrap { flex: 1; overflow-y: auto; padding: 6px 12px; }
#moves { list-style: none; margin: 0; padding: 0; counter-reset: mv; font-size: 0.85em; }
#moves li { display: flex; gap: 6px; padding: 2px 0; counter-increment: mv; }
#moves li::before { content: counter(mv) "."; color: var(--muted); width: 2em; flex-shrink: 0; text-align: right; margin-right: 2px; }
#moves .mw, #moves .mb { flex: 1; }
#moves li:last-child { background: rgba(216,185,140,0.08); border-radius: 4px; }

#captured {
	border-top: 1px solid rgba(255,255,255,0.06);
	padding: 8px 12px 10px;
	font-size: 0.8em;
}
#captured .cap-row { display: flex; align-items: center; gap: 4px; min-height: 22px; flex-wrap: wrap; }
#captured .cap-label { color: var(--muted); font-size: 0.85em; margin-right: 4px; }
.cap { font-size: 1.25em; line-height: 1; }
.cap.white-piece { color: #f0e8d8; text-shadow: 0 0 2px #000; }
.cap.black-piece { color: #3a2e1e; text-shadow: 0 0 2px rgba(255,255,255,0.35); }

/* barra de evaluacion */
#eval-wrap {
	position: fixed;
	left: 14px;
	top: 50%;
	transform: translateY(-50%);
	height: min(420px, 60vh);
	width: 18px;
	background: rgba(20, 16, 10, 0.85);
	border: 1px solid var(--panel-border);
	border-radius: 9px;
	overflow: hidden;
	display: flex;
	flex-direction: column-reverse;
	z-index: 24;
}
#eval-fill {
	width: 100%;
	height: 50%;
	background: linear-gradient(180deg, #fdf6e3, #d8cbb0);
	transition: height 0.5s ease;
}
#eval-label {
	position: fixed;
	left: 8px;
	top: calc(50% + min(215px, 30vh) + 8px);
	font-size: 0.7em;
	color: var(--muted);
	width: 34px;
	text-align: center;
}

/* botonera inferior */
#hud-buttons {
	position: fixed;
	bottom: 14px;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	gap: 8px;
	background: var(--panel-bg);
	border: 1px solid var(--panel-border);
	border-radius: 14px;
	padding: 8px 10px;
	backdrop-filter: blur(6px);
	z-index: 26;
	flex-wrap: wrap;
	justify-content: center;
}
#hud-buttons .btn { padding: 8px 14px; font-size: 0.85em; }

/* ================= HUD rafaga de mates ================= */

#puzzle-hud {
	position: fixed;
	top: 0; left: 0; right: 0;
	z-index: 25;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 26px;
	padding: 12px;
	background: linear-gradient(180deg, rgba(0,0,0,0.7), transparent);
	flex-wrap: wrap;
}
#puzzle-hud .pz-box { text-align: center; }
#puzzle-hud .pz-label { font-size: 0.68em; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); }
#puzzle-hud .pz-value { font-size: 1.7em; color: var(--gold-strong); font-variant-numeric: tabular-nums; }
#pz-timer.low { color: var(--danger); animation: pulse-red 1s infinite; }
@keyframes pulse-red { 50% { opacity: 0.5; } }
#pz-side { color: var(--text); font-size: 1em; }
.life { color: var(--danger); font-size: 1.3em; margin: 0 2px; }
.life.lost { color: #3a3a3a; }
#btn-pz-quit { margin-left: 12px; }

/* ================= modales ================= */

#modal-back {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.6);
	z-index: 50;
	backdrop-filter: blur(3px);
}

.modal {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	background: linear-gradient(180deg, #201709, #120d06);
	border: 1px solid var(--gold);
	border-radius: 18px;
	padding: 30px 38px;
	z-index: 55;
	text-align: center;
	min-width: min(360px, 90vw);
	max-width: 92vw;
	box-shadow: 0 20px 80px rgba(0,0,0,0.8);
}

.modal h2 { font-family: Georgia, serif; margin: 0 0 0.4em; font-size: 2em; font-weight: 500; }
.modal h2.win { color: #7ddb96; }
.modal h2.lose { color: var(--danger); }
.modal h2.draw { color: var(--gold); }
.modal p { color: var(--muted); margin: 0.3em 0 1.4em; }
.modal .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* promocion */
#modal-promotion .promo-row { display: flex; gap: 12px; justify-content: center; }
#modal-promotion button {
	font-size: 3em;
	width: 84px;
	height: 84px;
	border-radius: 14px;
	border: 1px solid var(--panel-border);
	background: rgba(255,255,255,0.05);
	color: var(--gold-strong);
	transition: all 0.12s ease;
}
#modal-promotion button:hover {
	border-color: var(--gold);
	background: rgba(216,185,140,0.15);
	transform: translateY(-3px);
}

/* PGN / cargar posicion */
#modal-pgn { max-height: 92vh; overflow-y: auto; }
#modal-pgn textarea {
	width: min(420px, 80vw);
	height: 160px;
	background: #17110a;
	color: var(--text);
	border: 1px solid var(--panel-border);
	border-radius: 8px;
	padding: 10px;
	font-family: Consolas, monospace;
	font-size: 0.85em;
	resize: none;
	margin-bottom: 1em;
}
#modal-pgn input[type="file"] { color: var(--muted); margin-bottom: 1.2em; font-size: 0.85em; }

/* fuentes de carga (PGN / imagen) */
.load-sources {
	display: flex;
	gap: 10px;
	justify-content: center;
	flex-wrap: wrap;
	margin-bottom: 0.4em;
}
.file-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 9px 16px;
	border: 1px solid var(--panel-border);
	border-radius: 10px;
	background: rgba(255,255,255,0.05);
	color: var(--text);
	font-size: 0.85em;
	cursor: pointer;
	transition: all 0.12s ease;
}
.file-btn:hover { border-color: var(--gold); background: rgba(216,185,140,0.12); }
.file-btn input[type="file"] {
	position: absolute;
	width: 1px; height: 1px;
	opacity: 0; overflow: hidden;
	margin: 0; padding: 0;
}

/* editor de posicion detectada en imagen */
#board-vision { margin-top: 1.1em; }
#bv-status { color: var(--gold); font-size: 0.85em; margin-bottom: 0.8em; min-height: 1.1em; }
#bv-editor {
	display: flex;
	gap: 16px;
	justify-content: center;
	align-items: flex-start;
	flex-wrap: wrap;
}
#bv-board {
	display: grid;
	grid-template-columns: repeat(8, 1fr);
	width: min(320px, 78vw);
	aspect-ratio: 1 / 1;
	border: 2px solid var(--gold);
	border-radius: 6px;
	overflow: hidden;
}
.bv-cell {
	border: none;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: clamp(16px, 5.5vw, 30px);
	line-height: 1;
	aspect-ratio: 1 / 1;
	transition: filter 0.1s ease;
}
.bv-cell.light { background: #e8d0a8; }
.bv-cell.dark { background: #9a6b3f; }
.bv-cell:hover { filter: brightness(1.12); }
.bv-piece { pointer-events: none; }
.bv-piece.white-piece { color: #fff; text-shadow: 0 0 2px #000, 0 1px 2px rgba(0,0,0,0.7); }
.bv-piece.black-piece { color: #111; text-shadow: 0 0 2px rgba(255,255,255,0.35); }

#bv-tools { display: flex; flex-direction: column; gap: 12px; }
#bv-palette {
	display: grid;
	grid-template-columns: repeat(6, 1fr);
	gap: 5px;
	max-width: 230px;
}
.bv-brush {
	width: 100%;
	aspect-ratio: 1 / 1;
	border: 1px solid var(--panel-border);
	border-radius: 7px;
	background: rgba(255,255,255,0.06);
	font-size: clamp(15px, 4.5vw, 22px);
	line-height: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--text);
	transition: all 0.1s ease;
}
.bv-brush .white-piece { color: #fff; text-shadow: 0 0 2px #000; }
.bv-brush .black-piece { color: #111; text-shadow: 0 0 2px rgba(255,255,255,0.4); }
.bv-brush.erase { color: var(--muted); }
.bv-brush:hover { border-color: var(--gold); }
.bv-brush.active {
	border-color: var(--gold-strong);
	background: rgba(240,217,168,0.22);
	box-shadow: 0 0 0 1px var(--gold-strong);
}
.bv-controls { display: flex; flex-direction: column; gap: 8px; }
.bv-turn-label { color: var(--muted); font-size: 0.85em; display: flex; align-items: center; gap: 6px; }
.bv-turn-label select {
	background: #17110a;
	color: var(--text);
	border: 1px solid var(--panel-border);
	border-radius: 6px;
	padding: 4px 6px;
}
.bv-controls .btn { padding: 7px 10px; font-size: 0.82em; }
.bv-hint { color: var(--muted); font-size: 0.78em; margin: 0.9em 0 0; }

/* record de rafaga */
#pz-end-record {
	color: #7ddb96;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	font-size: 0.9em;
	margin-bottom: 1em;
	animation: pulse 1.4s infinite;
}
#modal-puzzle-end .big-score {
	font-size: 4em;
	color: var(--gold-strong);
	font-family: Georgia, serif;
	line-height: 1.1;
}

/* toast */
#toast {
	position: fixed;
	bottom: 80px;
	left: 50%;
	transform: translateX(-50%) translateY(20px);
	background: var(--panel-bg);
	border: 1px solid var(--panel-border);
	color: var(--text);
	padding: 10px 22px;
	border-radius: 30px;
	opacity: 0;
	transition: all 0.3s ease;
	z-index: 60;
	pointer-events: none;
	max-width: 80vw;
	text-align: center;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================= responsive ================= */

@media (max-width: 820px) {
	#panel { display: none; }
	#eval-wrap, #eval-label { display: none; }
	#clocks { top: auto; bottom: 90px; right: 8px; flex-direction: row; }
	#hud-buttons { bottom: 8px; }
	.mode-card { width: 150px; padding: 16px 10px; }
}
