/* Shared theme for the quiz pages (guest, yogini, admin).

   Light and warm: cream surfaces, aubergine ink, and four deep accents taken
   from the plaque colors (plum, terracotta, sky blue, navy). The accent -- and
   the pastel wash behind the cards -- follows the game's phase: set
   `data-phase` on <body> to waiting | answering | revealed | final (nothing
   set = waiting). The admin page sets data-surface="plain" for a flat,
   photo-free background.

   Every color the pages use lives in :root below; contrast-check.mjs
   (make contrast) validates the text/background pairs. */

@font-face {
	font-family: "Cormorant Garamond";
	font-style: italic;
	font-weight: 600;
	font-display: swap;
	src: url("fonts/cormorant-garamond-latin-600-italic.woff2") format("woff2");
}
@font-face {
	font-family: "Cormorant Garamond";
	font-style: normal;
	font-weight: 600;
	font-display: swap;
	src: url("fonts/cormorant-garamond-latin-600-normal.woff2") format("woff2");
}
@font-face {
	font-family: "Montserrat";
	font-style: normal;
	font-weight: 100 900;
	font-display: swap;
	src: url("fonts/montserrat-latin-wght-normal.woff2") format("woff2");
}

/* Registered so the wash can cross-fade between phases instead of snapping. */
@property --wash {
	syntax: "<color>";
	inherits: true;
	initial-value: #b79ad6;
}

:root {
	/* Surfaces */
	--cream-50: #fffdf8;   /* cards */
	--cream-100: #f8f3e9;  /* page base, text on dark accents */
	--cream-200: #ece3d2;  /* hairlines, quiet borders */
	--line: #8f8576;       /* borders of things you tap or type into (3:1) */

	/* Ink */
	--ink: #2a2235;        /* body text */
	--ink-soft: #62566f;   /* secondary text */

	/* Plaque accents (deep: text and fills on cream) */
	--plum: #4a3365;
	--terracotta: #8a4a2a;
	--sky: #2f5a78;
	--navy: #1f3350;

	/* The same four hues as soft washes (tinted pills, backdrop) */
	--plum-wash: #b79ad6;
	--terracotta-wash: #f0a77f;
	--sky-wash: #8fc0e3;
	--navy-wash: #7f95c4;
	--plum-tint: #ece4f4;
	--terracotta-tint: #f8e6da;
	--sky-tint: #deedf7;
	--navy-tint: #e0e6f1;

	/* Right / wrong (always paired with an icon, never color alone) */
	--ok: #2b6a4b;
	--ok-tint: #dcefe4;
	--bad: #9b2c3b;
	--bad-tint: #f6dde0;

	/* Gold for the podium's first place */
	--gold: #7a5c0c;
	--gold-tint: #f7ecc6;

	/* Active accent: phase-driven, see the data-phase rules below */
	--accent: var(--plum);
	--accent-tint: var(--plum-tint);
	--wash: var(--plum-wash);
	--on-accent: var(--cream-100);

	/* Type */
	--font-display: "Cormorant Garamond", Georgia, serif;
	--font-ui: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
	--fs-xs: 0.8125rem;
	--fs-sm: 0.9375rem;
	--fs-md: 1.0625rem;
	--fs-lg: 1.25rem;
	--fs-xl: 1.5rem;
	--fs-display: clamp(2rem, 8vw, 3rem);

	/* Shape */
	--r-sm: 10px;
	--r-md: 16px;
	--r-lg: 24px;
	--r-pill: 999px;
	--shadow-card: 0 1px 2px rgba(42, 34, 53, 0.06), 0 12px 32px rgba(42, 34, 53, 0.12);
	--shadow-press: 0 1px 2px rgba(42, 34, 53, 0.1);
	--tap: 3.5rem; /* minimum height of anything tapped during play */
	--ring: 0 0 0 3px var(--cream-50), 0 0 0 5px var(--accent);
}

body[data-phase="answering"] {
	--accent: var(--sky); --accent-tint: var(--sky-tint); --wash: var(--sky-wash);
}
body[data-phase="revealed"] {
	--accent: var(--terracotta); --accent-tint: var(--terracotta-tint); --wash: var(--terracotta-wash);
}
body[data-phase="final"] {
	--accent: var(--navy); --accent-tint: var(--navy-tint); --wash: var(--navy-wash);
}

* { box-sizing: border-box; }
[hidden], .hidden { display: none !important; }

body {
	margin: 0;
	min-height: 100vh;
	min-height: 100dvh;
	padding: 16px;
	display: grid;
	place-items: center;
	font-family: var(--font-ui);
	font-size: var(--fs-md);
	font-weight: 500;
	line-height: 1.45;
	color: var(--ink);
	background: var(--cream-100);
	transition: --wash 1.2s ease;
	-webkit-text-size-adjust: 100%;
	/* The watercolor, veiled with cream and tinted by the phase wash. Declared
	   here (not on :root) so it picks up the body's phase; the podium overlay
	   reuses it. */
	--backdrop:
		linear-gradient(
			color-mix(in srgb, color-mix(in srgb, var(--wash) 50%, var(--cream-100)) 80%, transparent),
			color-mix(in srgb, color-mix(in srgb, var(--wash) 50%, var(--cream-100)) 80%, transparent)
		),
		url("img/bg-atmosphere.webp") center / cover no-repeat;
}

/* Fixed behind everything; a single static layer, light on a guest's phone. */
body::before {
	content: "";
	position: fixed;
	inset: 0;
	z-index: -1;
	background: var(--backdrop);
}
body[data-surface="plain"]::before { background: var(--cream-100); }

/* Display type: only large, where Cormorant's hairlines stay legible. */
h1, h2, .display {
	font-family: var(--font-display);
	font-style: italic;
	font-weight: 600;
	line-height: 1.1;
	letter-spacing: 0.005em;
	color: var(--accent);
	margin: 0 0 0.5em;
}
h1 { font-size: var(--fs-display); text-align: center; }
h1.compact { font-size: var(--fs-xl); margin-bottom: 0.4em; }
h2 { font-size: 1.875rem; }

/* "ou" style divider between two ways in (guest vs. login). */
.divider {
	display: flex;
	align-items: center;
	gap: 12px;
	margin: 18px 0 14px;
	font-size: var(--fs-xs);
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--ink-soft);
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--cream-200); }
h3 { font-family: var(--font-ui); font-size: var(--fs-md); font-weight: 700; margin: 0 0 0.6em; }
p { margin: 0 0 1em; }
.muted { color: var(--ink-soft); }
.tnum { font-variant-numeric: tabular-nums; }

/* Small uppercase label above a heading or value. */
.eyebrow {
	font-size: var(--fs-xs);
	font-weight: 700;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--accent);
}

/* Cards: near-opaque so text never sits on the watercolor. */
.card {
	width: 100%;
	max-width: 440px;
	background: color-mix(in srgb, var(--cream-50) 94%, transparent);
	border: 1px solid var(--cream-200);
	border-radius: var(--r-lg);
	padding: 24px;
	box-shadow: var(--shadow-card);
}

/* Form fields */
input, select, textarea {
	width: 100%;
	min-height: 3rem;
	padding: 10px 14px;
	font: inherit;
	color: var(--ink);
	background: #fff;
	border: 2px solid var(--line);
	border-radius: var(--r-sm);
	margin-bottom: 12px;
}
input::placeholder { color: var(--ink-soft); opacity: 0.8; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-tint);
}

/* Buttons */
button {
	font: inherit;
	font-weight: 600;
	width: 100%;
	min-height: 3rem;
	padding: 10px 18px;
	color: var(--on-accent);
	background: var(--accent);
	border: 2px solid transparent;
	border-radius: var(--r-pill);
	cursor: pointer;
	transition: transform 0.08s ease, background-color 0.2s ease;
}
button:active:not(:disabled) { transform: scale(0.98); }
button:focus-visible { outline: none; box-shadow: var(--ring); }
button:disabled { opacity: 0.45; cursor: default; }
button.secondary {
	color: var(--accent);
	background: var(--cream-50);
	border-color: var(--accent);
}
button.danger { background: var(--bad); color: #fff; }
.link-btn {
	width: auto;
	min-height: 0;
	padding: 6px 2px;
	color: var(--accent);
	background: none;
	border: 0;
	border-radius: var(--r-sm);
	text-decoration: underline;
	text-underline-offset: 3px;
	font-weight: 500;
}
.error { color: var(--bad); font-size: var(--fs-sm); font-weight: 600; min-height: 1.2em; }

/* Phase banner: the plaque word for the current moment. */
.phase-word {
	font-family: var(--font-display);
	font-style: italic;
	font-weight: 600;
	font-size: clamp(2.25rem, 11vw, 3.5rem);
	line-height: 1;
	text-align: center;
	color: var(--accent);
	margin: 8px 0 6px;
}
.phase-hint { text-align: center; color: var(--ink-soft); font-size: var(--fs-sm); margin: 0; }

/* Countdown: a pill that gets heavier and pulses (not just recolors) when
   the time is nearly up. */
.hud { display: flex; justify-content: flex-end; min-height: 2.25rem; margin-bottom: 10px; }
/* Quiz title on the left, the countdown pill on the right of one row, so the
   pill appearing doesn't push the question down. */
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.quiz-head h1 { margin: 0; text-align: left; min-width: 0; overflow-wrap: anywhere; }
.quiz-head .hud { margin: 0; flex: none; }
.timer, #countdownLabel:not(:empty) {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 14px;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	color: var(--accent);
	background: var(--accent-tint);
	border: 2px solid var(--accent);
	border-radius: var(--r-pill);
}
.timer.urgent, #countdownLabel.urgent {
	color: var(--bad);
	background: var(--bad-tint);
	border-color: var(--bad);
	animation: timer-pulse 1s ease-in-out infinite;
}
@keyframes timer-pulse { 50% { transform: scale(1.06); } }

/* Question and its options. Letters come from a CSS counter, so the markup
   stays a plain list of buttons. */
.question { font-size: var(--fs-lg); font-weight: 700; line-height: 1.3; margin: 0 0 16px; }
#questionBox, .options { counter-reset: opt; }
.option {
	counter-increment: opt;
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	min-height: var(--tap);
	margin-bottom: 10px;
	padding: 12px 16px;
	text-align: left;
	font-size: var(--fs-md);
	color: var(--ink);
	background: #fff;
	border: 2px solid var(--line);
	border-radius: var(--r-md);
	box-shadow: var(--shadow-press);
	transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.08s ease;
}
.option::before {
	content: counter(opt, upper-alpha);
	flex: none;
	display: grid;
	place-items: center;
	width: 2rem;
	height: 2rem;
	font-size: var(--fs-sm);
	font-weight: 700;
	color: var(--accent);
	background: var(--accent-tint);
	border-radius: 50%;
}
@media (hover: hover) {
	.option:hover:not(:disabled) { border-color: var(--accent); }
}
.option.chosen {
	color: var(--on-accent);
	background: var(--accent);
	border-color: var(--accent);
	opacity: 1;
}
.option.chosen::before { color: var(--accent); background: var(--cream-100); }
.option.chosen::after { content: "✓"; margin-left: auto; font-weight: 700; }
.option:disabled:not(.chosen):not(.correct):not(.wrong) { opacity: 0.6; }
.option.correct { color: var(--ok); background: var(--ok-tint); border-color: var(--ok); opacity: 1; }
.option.correct::before { color: #fff; background: var(--ok); }
.option.correct::after { content: "✓ certa"; margin-left: auto; font-size: var(--fs-xs); font-weight: 700; }
.option.wrong { color: var(--bad); background: var(--bad-tint); border-color: var(--bad); opacity: 1; }
.option.wrong::before { color: #fff; background: var(--bad); }
.option.wrong::after { content: "✕ errada"; margin-left: auto; font-size: var(--fs-xs); font-weight: 700; }

/* Result card after a question closes. */
.stats-card {
	background: #fff;
	border: 1px solid var(--cream-200);
	border-radius: var(--r-md);
	padding: 16px;
	margin-bottom: 14px;
}
.stats-card h3 { font-size: var(--fs-md); margin-bottom: 10px; }
.stats-row {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 10px;
	padding: 8px 0;
	font-size: var(--fs-sm);
	border-bottom: 1px solid var(--cream-200);
}
.stats-row:last-child { border-bottom: 0; }
.stats-row .label { color: var(--ink-soft); }
.stats-row .value { font-weight: 700; text-align: right; }
.stats-row.stacked { flex-direction: column; align-items: stretch; gap: 2px; }
.stats-row.stacked .value { text-align: left; }
.verdict {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 14px;
	margin-bottom: 14px;
	font-weight: 700;
	border-radius: var(--r-md);
}
.verdict.ok { color: var(--ok); background: var(--ok-tint); flex-wrap: wrap; }
.verdict .bonus { flex-basis: 100%; font-size: var(--fs-sm); }
.verdict.miss { color: var(--bad); background: var(--bad-tint); }

/* Ranking */
.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li {
	display: flex;
	align-items: center;
	gap: 12px;
	min-height: 3rem;
	padding: 8px 14px;
	margin-bottom: 6px;
	background: #fff;
	border: 1px solid var(--cream-200);
	border-radius: var(--r-md);
}
.leaderboard .rank {
	flex: none;
	min-width: 2rem;
	text-align: center;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	color: var(--ink-soft);
}
.leaderboard .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.leaderboard .score { font-weight: 700; font-variant-numeric: tabular-nums; }
.leaderboard li.top1 { background: var(--gold-tint); border-color: var(--gold); }
.leaderboard li.top1 .rank { color: var(--gold); }
.leaderboard li.me { margin-top: 12px; border: 2px solid var(--accent); background: var(--accent-tint); }
.leaderboard li.me .rank { color: var(--accent); }

/* Nickname chip, fixed to the corner while playing. */
.nickname-corner {
	position: fixed;
	right: 12px;
	bottom: 12px;
	max-width: 60vw;
	padding: 6px 14px;
	font-size: var(--fs-xs);
	font-weight: 700;
	color: var(--accent);
	background: color-mix(in srgb, var(--cream-50) 94%, transparent);
	border: 1px solid var(--cream-200);
	border-radius: var(--r-pill);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Confirmation dialog (yogini's "confirm this answer", admin's confirmations) */
.modal-overlay {
	position: fixed;
	inset: 0;
	z-index: 100;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	background: rgba(42, 34, 53, 0.55);
}
.modal-box {
	width: 100%;
	max-width: 400px;
	max-height: calc(100dvh - 32px);
	overflow-y: auto;
	padding: 24px;
	background: var(--cream-50);
	border-radius: var(--r-lg);
	box-shadow: var(--shadow-card);
}
.modal-box p { font-size: var(--fs-md); font-weight: 600; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions button { flex: 1; }

/* Small tag / status pill */
.pill {
	display: inline-block;
	padding: 3px 12px;
	font-size: var(--fs-xs);
	font-weight: 700;
	color: var(--accent);
	background: var(--accent-tint);
	border-radius: var(--r-pill);
}

/* Final podium overlay: bars rise 3rd, 2nd, then 1st; names pop in on top.
   Transform/opacity only. */
.podium-overlay {
	position: fixed;
	inset: 0;
	z-index: 50;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 16px;
	background: var(--backdrop);
	animation: podium-fade 0.5s ease-out both;
}
.podium-overlay h2 { text-align: center; font-size: 2.25rem; margin-bottom: 20px; }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 8px; width: 100%; max-width: 440px; }
.podium .place { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.podium .who {
	text-align: center;
	font-weight: 700;
	margin-bottom: 8px;
	max-width: 100%;
	overflow-wrap: anywhere;
	line-height: 1.15;
	opacity: 0;
	transform: translateY(14px) scale(0.85);
	animation: podium-pop 0.6s cubic-bezier(.2, 1.4, .4, 1) forwards;
}
.podium .medal { font-size: 2rem; display: block; }
.podium .pts { font-size: var(--fs-xs); font-weight: 500; color: var(--ink-soft); display: block; }
.podium .bar {
	width: 100%;
	border-radius: var(--r-md) var(--r-md) 0 0;
	color: var(--cream-100);
	font-family: var(--font-display);
	font-style: italic;
	font-size: 2.25rem;
	font-weight: 600;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding-top: 8px;
	transform-origin: bottom;
	transform: scaleY(0);
	animation: podium-rise 0.9s ease-out forwards;
}
.podium .p1 .bar { height: 150px; background: var(--gold); }
.podium .p2 .bar { height: 110px; background: var(--sky); }
.podium .p3 .bar { height: 80px; background: var(--terracotta); }
.podium .p3 .bar { animation-delay: 0.4s; }
.podium .p3 .who { animation-delay: 1.3s; }
.podium .p2 .bar { animation-delay: 1.5s; }
.podium .p2 .who { animation-delay: 2.4s; }
.podium .p1 .bar { animation-delay: 2.6s; }
.podium .p1 .who { animation-delay: 3.5s; }
@keyframes podium-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes podium-rise { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes podium-pop { to { opacity: 1; transform: translateY(0) scale(1); } }

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0s !important; transition-duration: 0.01ms !important; }
}
