:root {
	--bg: #eef2f7;
	--card: #ffffff;
	--ink: #111827;
	--muted: #4b5563;
	--line: #e2e8f0;
	--accent: #4f46e5;
	--accent-strong: #4338ca;
	--ok: #059669;
	--good: #16a34a;
	--warn: #d97706;
	--bad: #dc2626;
	--radius: 16px;
	--shadow: 0 10px 25px -5px rgba(15, 23, 42, .15), 0 4px 10px -6px rgba(15, 23, 42, .1);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	background: var(--bg);
	color: var(--ink);
	-webkit-tap-highlight-color: transparent;
}

.page { min-height: 100dvh; display: flex; flex-direction: column; }

button { font: inherit; cursor: pointer; }

h1, h2, p { margin: 0; }

[hidden] { display: none !important; }

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
	pointer-events: none;
}

/* ---------- accesibilidad ---------- */

.skip-link {
	position: absolute;
	top: 10px;
	left: 10px;
	z-index: 100;
	padding: 10px 16px;
	background: #1f2937;
	color: #fff;
	text-decoration: none;
	font-weight: 600;
	border-radius: 10px;
	transform: translateY(-160%);
	transition: transform .15s ease;
}

.skip-link:focus-visible {
	transform: translateY(0);
	outline: 3px solid #93c5fd;
	outline-offset: 2px;
}

a:focus-visible,
button:focus-visible,
summary:focus-visible,
input:focus-visible,
output:focus-visible,
[tabindex]:focus-visible {
	outline: 3px solid #1d4ed8;
	outline-offset: 2px;
}

button:focus:not(:focus-visible) { outline: none; }

.btn-primary:focus-visible {
	outline-color: #fde047;
	outline-offset: 3px;
}

/* ---------- barra superior ---------- */

.topbar {
	position: sticky;
	top: 0;
	z-index: 20;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
	background: rgba(255, 255, 255, .85);
	backdrop-filter: blur(8px);
	border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
	width: 38px; height: 38px; flex: none;
	display: grid; place-items: center;
	border-radius: 12px;
	background: linear-gradient(135deg, var(--accent), #7c3aed);
	color: #fff; font-size: 22px; line-height: 1;
	box-shadow: var(--shadow);
}

.brand h1 { font-size: 1.15rem; line-height: 1.1; }

.brand p { font-size: .78rem; color: var(--muted); }

.best-pill {
	display: flex; flex-direction: column; align-items: flex-end; gap: 0;
	border: 1px solid var(--line); background: var(--card);
	border-radius: 12px; padding: 4px 12px; color: var(--ink);
}

.best-pill span { font-size: .6rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.best-pill strong { font-size: 1.05rem; color: var(--accent); }

/* ---------- distribución ---------- */

.layout {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 14px;
	width: 100%;
	max-width: 1280px;
	margin: 0 auto;
	padding: 14px 14px calc(24px + env(safe-area-inset-bottom));
}

/* ---------- zona de dibujo ---------- */

.stage {
	position: relative;
	flex: none;
	height: clamp(300px, 58dvh, 480px);
	border-radius: var(--radius);
	overflow: hidden;
	background-color: #fafbff;
	background-image: radial-gradient(circle, rgba(15, 23, 42, .055) 1px, transparent 1.3px);
	background-size: 22px 22px;
	border: 1px solid var(--line);
	box-shadow: var(--shadow);
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
	transition: background-color .3s ease;
}

.stage.quiet {
	background-color: #fff;
	background-image: radial-gradient(circle, rgba(15, 23, 42, .018) 1px, transparent 1.3px);
}

.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

#fitCanvas { pointer-events: none; }

#ghostCanvas { pointer-events: none; }

.stage-hint, .stage-rule, .timer-chip {
	position: absolute;
	pointer-events: none;
	transition: opacity .25s ease, transform .25s ease;
}

.stage-hint {
	top: 12px; left: 12px; right: 12px;
	display: flex; flex-direction: column; gap: 2px;
	padding: 10px 14px;
	background: rgba(255, 255, 255, .9);
	border: 1px solid var(--line);
	border-radius: 12px;
	box-shadow: 0 2px 8px rgba(15, 23, 42, .06);
	font-size: .82rem; line-height: 1.35;
	max-width: 360px;
}

.hint-line { display: flex; align-items: center; gap: 8px; }

.stage-hint strong { font-size: .95rem; }

.stage-hint .muted-txt { color: var(--muted); }

.stage-rule {
	bottom: 12px; left: 12px;
	font-size: .72rem; letter-spacing: .04em; text-transform: uppercase;
	color: #64748b;
}

.timer-chip {
	top: 12px; right: 12px;
	background: rgba(15, 23, 42, .85);
	color: #fff;
	font-size: .9rem; font-weight: 700;
	padding: 8px 14px;
	border-radius: 999px;
	font-variant-numeric: tabular-nums;
}

.stage.drawing .stage-hint,
.stage.drawing .stage-rule { opacity: 0; transform: translateY(-4px); }

.player-dot, .hd-dot {
	flex: none; width: 12px; height: 12px; border-radius: 50%;
	background: var(--pc, var(--accent));
}

.hd-dot { width: 10px; height: 10px; }

/* ---------- panel ---------- */

.panel {
	display: flex; flex-direction: column; gap: 14px;
	min-width: 0;
}

.card {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 16px;
	box-shadow: 0 1px 3px rgba(15, 23, 42, .05);
}

.card h2 { font-size: 1rem; margin-bottom: 6px; }

.muted { color: var(--muted); font-size: .86rem; line-height: 1.45; margin-bottom: 10px; }

/* ---------- resultado ---------- */

.result-card { animation: rise .35s ease; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.result-head { display: flex; align-items: center; gap: 16px; }

.score-badge {
	flex: none; display: flex; align-items: baseline; gap: 2px;
	padding: 6px 14px 6px 16px; border-radius: 14px;
	color: #fff; background: var(--accent); box-shadow: var(--shadow);
}

.score-badge span { font-size: 2rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }

.score-badge em { font-style: normal; font-size: .85rem; opacity: .85; }

.result-txt h2 { font-size: 1.15rem; margin: 0 0 4px; }

.disc-tag {
	display: inline-block;
	font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
	color: #4338ca; background: #e0e7ff; border-radius: 999px;
	padding: 3px 9px; margin-bottom: 6px;
}

.res-diag { font-size: .9rem; color: var(--ink); line-height: 1.5; }

.res-diag small { color: var(--muted); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.chip {
	font-size: .78rem; font-weight: 600;
	background: #eef2ff; color: #3730a3;
	border-radius: 999px; padding: 5px 11px;
}

.chip b { font-weight: 700; }

.chip.warn { background: #fef3c7; color: #92400e; }

.result-card details { margin-top: 12px; }

.result-card summary { cursor: pointer; font-size: .84rem; color: var(--accent); font-weight: 600; }

.orig-list {
	display: grid; grid-template-columns: 1fr auto;
	gap: 6px 14px; margin: 10px 0 0;
	font-size: .84rem;
}

.orig-list dt { color: var(--muted); }

.orig-list dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

.result-hint { margin-top: 10px; font-size: .82rem; color: var(--muted); }

/* ---------- disciplinas ---------- */

.disc-options { display: grid; gap: 10px; margin-bottom: 14px; }

.disc-btn {
	display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
	text-align: left;
	padding: 12px 14px;
	border: 1px solid var(--line); border-radius: 12px;
	background: #fafbff; color: var(--ink);
	transition: border-color .15s ease, background .15s ease;
}

.disc-btn strong { font-size: .98rem; }

.disc-btn span { font-size: .8rem; color: var(--muted); line-height: 1.35; }

.disc-btn.active {
	border-color: var(--accent);
	background: #eef2ff;
	box-shadow: inset 3px 0 0 var(--accent);
}

.disc-btn.active span { color: #4338ca; }

.disc-btn:disabled { opacity: .55; cursor: not-allowed; }

.retos-head {
	margin: 0 0 8px;
	font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
	color: var(--muted);
}

.retos-list { display: flex; flex-wrap: wrap; gap: 8px; }

.reto-chip {
	display: inline-flex; align-items: center; gap: 7px;
	border: 1px solid var(--line); background: #fafbff; color: var(--ink);
	border-radius: 999px; padding: 7px 13px; font-size: .8rem; font-weight: 600;
	transition: background .15s ease, border-color .15s ease;
}

.reto-chip .ck {
	width: 9px; height: 9px; border-radius: 3px;
	border: 2px solid #cbd5e1; background: #fff;
}

.reto-chip.on { background: #eef2ff; border-color: var(--accent); color: #312e81; }

.reto-chip.on .ck { background: var(--accent); border-color: var(--accent); }

.reto-chip:disabled { opacity: .5; cursor: not-allowed; }

.reto-chip small { font-weight: 400; color: var(--muted); }

/* ---------- duelos ---------- */

.variant-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.variant-btn {
	border: 1px solid var(--line); background: #fafbff;
	color: var(--ink); border-radius: 999px;
	padding: 8px 14px; font-size: .82rem; font-weight: 600;
}

.variant-btn.active { background: #eef2ff; border-color: var(--accent); color: #312e81; }

.variant-note { font-size: .82rem; color: var(--muted); line-height: 1.45; margin: 0 0 12px; }

.stepper-row { display: flex; gap: 12px; margin-bottom: 12px; }

.stepper { flex: 1; }

.stepper-label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 6px; }

.stepper-btns {
	display: flex; align-items: center; justify-content: space-between;
	background: #f1f5f9; border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}

.step { border: none; background: transparent; width: 42px; height: 42px; font-size: 1.25rem; color: var(--ink); }

.step:active { background: #e2e8f0; }

.stepper-value { font-weight: 700; min-width: 2ch; text-align: center; }

.player-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.player-row {
	display: flex; align-items: center; gap: 10px;
	padding: 8px 10px;
	border: 1px solid var(--line); border-radius: 12px; background: #fafbff;
}

.player-row .player-dot { width: 14px; height: 14px; }

.name-input {
	flex: 1; border: none; background: transparent; font: inherit; font-weight: 600;
	padding: 4px 0; outline: none; min-width: 0;
}

.name-input:focus-visible { border-bottom: 2px solid var(--accent); }

.name-input::placeholder { color: #9ca3af; font-weight: 400; }

.turn-banner {
	display: flex; align-items: center; gap: 12px;
	padding: 12px; border-radius: 12px; background: #eef2ff;
	margin-bottom: 12px;
}

.turn-banner .player-dot { width: 22px; height: 22px; }

.turn-txt strong { font-size: 1.1rem; display: block; }

.turn-txt span { font-size: .82rem; color: var(--muted); }

.scoreboard { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.score-row {
	display: grid;
	grid-template-columns: auto 1fr auto;
	align-items: center; gap: 10px;
	padding: 9px 12px;
	border: 1px solid var(--line); border-radius: 12px; background: #fafbff;
	transition: background .3s ease;
}

.score-row.active { background: #eef2ff; border-color: #c7d2fe; box-shadow: inset 3px 0 0 var(--accent); }

.score-row.out { opacity: .45; }

.score-name { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.score-val { display: flex; flex-direction: column; align-items: flex-end; }

.score-total { font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; }

.score-last { font-size: .72rem; color: var(--muted); }

.winner { font-size: 1.02rem; font-weight: 700; color: var(--ok); margin: 8px 0 12px; line-height: 1.4; }

.final-rank { margin: 0 0 4px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; counter-reset: rank; }

.final-rank li {
	display: flex; align-items: center; gap: 12px;
	padding: 10px 12px;
	border: 1px solid var(--line); border-radius: 12px; background: #fafbff;
}

.final-rank li::before {
	counter-increment: rank; content: counter(rank);
	flex: none; width: 26px; height: 26px;
	display: grid; place-items: center; border-radius: 50%;
	background: #f1f5f9; font-weight: 700; font-size: .9rem;
}

.final-rank li:first-child { background: #f0fdf4; border-color: #bbf7d0; }

.final-rank li:first-child::before { background: #dcfce7; color: var(--ok); }

.final-rank .f-name { font-weight: 600; flex: 1; }

.final-rank .f-total { font-weight: 800; font-variant-numeric: tabular-nums; }

.btn {
	border: none; border-radius: 12px; padding: 12px 18px;
	font-size: .95rem; font-weight: 600;
	transition: filter .15s ease, transform .08s ease;
}

.btn:active { transform: scale(.98); }

.btn-primary { background: linear-gradient(135deg, var(--accent), #7c3aed); color: #fff; }

.btn-ghost { background: #f1f5f9; color: var(--ink); border: 1px solid var(--line); }

.btn-block { width: 100%; }

.btn-pair { display: flex; gap: 10px; margin-top: 14px; }

.btn-pair .btn { flex: 1; }

/* ---------- camino de la O / historia ---------- */

.story-rotate {
	font-size: .84rem; line-height: 1.55;
	color: var(--muted); font-style: italic;
	margin-bottom: 10px; padding: 10px 12px;
	background: #fafbff; border: 1px dashed var(--line); border-radius: 10px;
	min-height: 3.4em;
}

.giotto-block {
	border: 1px solid var(--line); border-radius: 12px; padding: 12px;
	background: linear-gradient(180deg, #fdfbf3, #fff); margin-bottom: 10px;
}

.giotto-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }

.giotto-head strong { font-size: .9rem; }

.giotto-mark { font-weight: 800; color: #b45309; font-size: 1.3rem; line-height: 1; font-variant-numeric: tabular-nums; }

.giotto-mark span { font-size: .7rem; font-weight: 600; opacity: .75; }

.bar { height: 8px; border-radius: 999px; background: #e7e5e4; overflow: hidden; margin: 10px 0 8px; }

.bar-fill {
	height: 100%; width: 0%; border-radius: 999px;
	background: linear-gradient(90deg, #fbbf24, #d97706);
	transition: width .5s ease;
}

.giotto-msg { font-size: .82rem; color: var(--muted); line-height: 1.5; }

.best-line {
	font-size: .9rem; color: var(--muted); margin-bottom: 8px;
	background: #f1f5f9; border-radius: 10px; padding: 8px 12px; line-height: 1.5;
}

.best-line b { color: var(--accent); font-size: 1.05rem; }

.streak-line {
	font-size: .82rem; font-weight: 600; color: #92400e;
	background: #fef3c7; border-radius: 10px; padding: 7px 11px; margin: 0 0 10px;
}

.card details { margin-top: 6px; }

.card details + details { margin-top: 10px; }

.card summary { cursor: pointer; font-size: .86rem; font-weight: 600; }

.hist-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.hist-item {
	border: 1px solid var(--line); border-radius: 10px;
	background: #fafbff; overflow: hidden;
}

.hist-item.locked { opacity: .55; }

.hist-head {
	display: flex; align-items: center; justify-content: space-between; gap: 10px;
	padding: 8px 12px;
}

.hist-title { font-weight: 700; font-size: .86rem; }

.hist-req { font-size: .72rem; color: var(--muted); white-space: nowrap; }

.hist-item.unlocked summary { color: var(--accent); }

.hist-body { padding: 0 12px 11px; font-size: .84rem; line-height: 1.55; color: #374151; }

.ach-list {
	list-style: none; margin: 10px 0 0; padding: 0;
	display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px;
}

.ach-item {
	display: flex; gap: 8px; align-items: flex-start;
	padding: 8px 10px;
	border: 1px solid var(--line); border-radius: 10px; background: #fafbff;
	font-size: .78rem; line-height: 1.35;
}

.ach-item.done { background: #ecfdf5; border-color: #bbf7d0; }

.ach-state {
	flex: none; width: 20px; height: 20px; border-radius: 50%;
	display: grid; place-items: center;
	font-size: .82rem; font-weight: 800; color: #9ca3af; background: #f1f5f9;
	margin-top: 1px;
}

.ach-item.done .ach-state { color: #047857; background: #d1fae5; }

.ach-name { font-weight: 700; display: block; }

.ach-desc { color: var(--muted); display: block; }

.ach-prog { color: var(--muted); font-size: .7rem; display: block; margin-top: 2px; }

.record-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }

.record-list li {
	display: flex; align-items: center; gap: 9px;
	font-size: .84rem; padding: 7px 10px;
	border-radius: 10px; background: #fafbff; border: 1px solid var(--line);
}

.rec-score {
	flex: none; font-weight: 800; min-width: 3.2ch; text-align: center;
	padding: 2px 8px; border-radius: 8px;
	background: #eef2ff; color: #3730a3; font-variant-numeric: tabular-nums;
}

.record-list li > span:last-child { color: var(--muted); margin-left: auto; white-space: nowrap; font-size: .76rem; }

.record-list li .rec-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.record-list li .rec-name b { color: var(--ink); }

.disc-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.dot-giotto { background: var(--accent); }

.dot-enso { background: var(--warn); }

.footer-note { font-size: .74rem; color: var(--muted); text-align: center; padding: 0 8px 4px; line-height: 1.5; }

/* ---------- escena 95 ---------- */

.modal {
	position: fixed; inset: 0; z-index: 70;
	display: grid; place-items: center;
	background: rgba(15, 23, 42, .55);
	padding: 20px;
	animation: fadeIn .25s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
	width: min(94vw, 430px);
	background: var(--card); border-radius: 20px;
	padding: 30px 26px 26px; text-align: center;
	box-shadow: 0 24px 60px -12px rgba(15, 23, 42, .4);
	animation: pop .35s cubic-bezier(.2, .9, .3, 1.2);
}

@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }

.o-num {
	font-size: 3.6rem; font-weight: 800; line-height: 1;
	background: linear-gradient(135deg, #b45309, #d97706);
	-webkit-background-clip: text; background-clip: text;
	-webkit-text-fill-color: transparent;
	color: #b45309;
	font-variant-numeric: tabular-nums;
}

.o-line { font-size: 1.35rem; font-weight: 700; margin: 8px 0 14px; }

.o-verse { font-size: .9rem; color: #374151; line-height: 1.6; font-style: italic; margin-bottom: 20px; }

/* ---------- toast ---------- */

.toast {
	position: fixed; left: 50%;
	bottom: calc(20px + env(safe-area-inset-bottom));
	transform: translate(-50%, 24px);
	max-width: min(92vw, 480px);
	background: #1f2937; color: #fff;
	font-size: .9rem; font-weight: 500;
	padding: 12px 18px; border-radius: 12px;
	box-shadow: var(--shadow);
	opacity: 0; pointer-events: none;
	transition: opacity .2s ease, transform .2s ease;
	z-index: 80; text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- pantallas grandes ---------- */

@media (min-width: 900px) {
	.layout {
		flex-direction: row; align-items: stretch;
		padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
	}

	.stage {
		flex: 1 1 auto; height: auto;
		min-height: 540px; max-height: calc(100dvh - 120px);
	}

	.panel { flex: 0 0 400px; max-height: calc(100dvh - 120px); overflow-y: auto; }

	.stage-hint { font-size: .9rem; }

	.brand p { font-size: .86rem; }

	.disc-options { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
	.result-card, .modal, .modal-card { animation: none; }
	* { transition-duration: .01ms !important; }
}

/* ---------- contenido editorial (SEO) ---------- */

.seo-article {
	width: calc(100% - 36px);
	max-width: 880px;
	margin: 10px auto calc(30px + env(safe-area-inset-bottom));
	padding: 26px 28px 30px;
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	color: var(--ink);
}

.seo-article h2 {
	font-size: 1.35rem;
	line-height: 1.25;
	margin: 30px 0 10px;
	letter-spacing: -0.01em;
}

.seo-article h2:first-child { margin-top: 0; }

.seo-article p {
	font-size: .96rem;
	line-height: 1.7;
	margin: 0 0 12px;
	color: #374151;
}

.seo-article ul,
.seo-article ol {
	margin: 4px 0 14px;
	padding-left: 22px;
}

.seo-article li {
	font-size: .95rem;
	line-height: 1.6;
	margin-bottom: 6px;
	color: #374151;
}

.seo-article a {
	color: var(--accent-strong);
	text-decoration: underline;
	text-decoration-color: rgba(79, 70, 229, .35);
	text-underline-offset: 2px;
}

.seo-article a:hover { text-decoration-color: currentColor; }

.seo-cta {
	background: #fafbff;
	border: 1px solid var(--line);
	border-radius: 14px;
	padding: 18px 20px;
	margin-top: 24px;
}

.seo-cta h2 { margin-top: 0; font-size: 1.15rem; }

.seo-cta p { margin-bottom: 14px; }

.seo-cta-links {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin: 0;
}

.seo-link {
	display: inline-block;
	padding: 10px 16px;
	border-radius: 12px;
	font-size: .9rem;
	font-weight: 600;
	text-decoration: none;
	border: 1px solid var(--line);
	background: #fff;
	color: var(--ink);
	transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.seo-link:hover { background: #eef2ff; border-color: var(--accent); color: #312e81; }

.seo-link-primary {
	background: linear-gradient(135deg, var(--accent), #7c3aed);
	border-color: transparent;
	color: #fff;
}

.seo-link-primary:hover { background: linear-gradient(135deg, var(--accent-strong), #6d28d9); color: #fff; }
