/******************************
**
**	HSK Advent Calendar
**	Colours and font from the main site (css/root.css)
**
*******************************/

:root {
	--navy: #002456;
	--red: #EF3742;
	--orange: #EF6821;
	--blue: #00AEEF;
	--midblue: #0087CD;
	--purple: #AB4399;
	--teal: #009191;
	--green: #79BC43;

	--font: "Source Sans 3", system-ui, sans-serif;

	/* closed doors are see-through, so the artwork shows */
	--door-bg: transparent;
	--door-border: rgba(255, 255, 255, 0.9);
	--door-number: #fff;
	/* a door that has been opened (fully or a little) is solid */
	--door-open-bg: #fff;
	--door-open-number: var(--navy);
	--door-back: #d9e6f2;
	--door-radius: 14px;
	--crack: -38deg;            /* how far a past door stands open */
	--swing: 0.9s;              /* advent.js waits this long before the popup */

	/* landscape: the area the doors are scattered over */
	--grid-top: 5%;
	--grid-side: 6%;
	--grid-bottom: calc(var(--logo-h) + 56px);  /* clear of the logos */
	/* these two must match the adventLayout() call in index.php */
	--area-aspect: 2.1;         /* the width / height the layout was made for */
	--door-ratio: 4 / 3;        /* width / height of a door */

	--logo-h: 56px;
}

/* portrait: phones and tall windows */
@media (orientation: portrait) {
	:root {
		--grid-top: 4%;
		--grid-side: 4%;
		--area-aspect: 0.57;
		--door-ratio: 5 / 6;
		--door-radius: 10px;
		--logo-h: 40px;
	}
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
	background: var(--navy);
	color: var(--navy);
	font-family: var(--font);
	font-size: 18px;
	line-height: 1.5;
}

.visually-hidden {
	position: absolute;
	width: 1px; height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

.preview-bar {
	position: fixed;
	top: 0; left: 0; right: 0;
	z-index: 5;
	background: var(--orange);
	color: #fff;
	text-align: center;
	font-weight: 700;
	font-size: 15px;
	padding: 4px 16px;
}

.notice {
	position: absolute;
	top: 12px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 2;
	width: max-content;
	max-width: calc(100% - 32px);
	margin: 0;
	padding: 8px 20px;
	border-radius: 999px;
	background: #fff;
	font-weight: 700;
	text-align: center;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.preview .notice { top: 44px; }

/* ---------- the stage: the artwork fills the whole window ---------- */

.stage {
	--bg: radial-gradient(circle at 20% 15%, #ffffff22 0 2px, transparent 3px) 0 0 / 60px 60px,
	      radial-gradient(circle at 70% 60%, #ffffff1a 0 2px, transparent 3px) 0 0 / 90px 90px,
	      linear-gradient(160deg, var(--midblue), var(--navy) 75%);
	position: relative;
	display: block;
	width: 100%;
	height: 100vh;
	height: 100svh;
	min-height: 480px;
	overflow: hidden;
	background: var(--bg);
	background-size: cover;
	background-position: center;
}

.grid {
	position: absolute;
	top: var(--grid-top);
	right: var(--grid-side);
	bottom: var(--grid-bottom);
	left: var(--grid-side);
	container-type: size;
}
.preview .grid { top: calc(var(--grid-top) + 30px); }

/* ---------- a door ---------- */

/* Each door's place comes from index.php: --lx/--ly/--lw for landscape, --px/--py/--pw
   for portrait (centre as % of the area, width as % of its width). The width is capped
   by the area's height too, so on a screen of a different shape the doors shrink
   rather than overlap. */
.door {
	--x: var(--lx);
	--y: var(--ly);
	--w: var(--lw);
	position: absolute;
	left: calc(var(--x) * 1%);
	top: calc(var(--y) * 1%);
	width: min(calc(var(--w) * 1cqw), calc(var(--w) * var(--area-aspect) * 1cqh));
	aspect-ratio: var(--door-ratio);
	translate: -50% -50%;
	padding: 0;
	border: 0;
	background: none;
	font: inherit;
	cursor: pointer;
	perspective: 800px;
	container-type: size;
	-webkit-tap-highlight-color: transparent;
}
@media (orientation: portrait) {
	.door { --x: var(--px); --y: var(--py); --w: var(--pw); }
}

.door[aria-disabled="true"] { cursor: default; }

.door:focus-visible {
	outline: 3px solid var(--orange);
	outline-offset: 3px;
	border-radius: var(--door-radius);
}

/* what is behind the door: a colour and the day's number. Hidden while the
   door is shut, because a see-through door would show it */
.door__inside {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	border-radius: var(--door-radius);
	color: #fff;
	font-weight: 900;
	font-size: 48cqmin;
	line-height: 1;
	box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.15), inset 0 6px 14px rgba(0, 0, 0, 0.3);
	text-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
	opacity: 0;
}
.door--past .door__inside,
.door.is-open .door__inside { opacity: 1; }

.door__inside--c1 { background: var(--red); }
.door__inside--c2 { background: var(--blue); }
.door__inside--c3 { background: var(--purple); }
.door__inside--c4 { background: var(--green); }
.door__inside--c5 { background: var(--orange); }
.door__inside--c6 { background: var(--teal); }
.door__inside--c7 { background: var(--midblue); }

/* the door itself, hinged on its left edge */
.door__panel {
	position: absolute;
	inset: 0;
	transform-origin: left center;
	transform-style: preserve-3d;
	transition: transform var(--swing) cubic-bezier(0.45, 0.05, 0.25, 1);
}

.door__front,
.door__back {
	position: absolute;
	inset: 0;
	border-radius: var(--door-radius);
	backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
}

.door__front {
	display: grid;
	place-items: center;
	background: var(--door-bg);
	border: 3px solid var(--door-border);
	color: var(--door-number);
	font-weight: 800;
	font-size: 22cqmin;
	line-height: 1;
	text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
	transition: background-color 0.2s, color 0.2s;
}

/* opened, fully or a little: solid. Only the colour - the "background" shorthand
   would also wipe out the artwork that .has-art puts on the door */
.door--past .door__front,
.door.is-open .door__front {
	background-color: var(--door-open-bg);
	border-color: var(--door-open-bg);
	color: var(--door-open-number);
	text-shadow: none;
	box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

.door__back {
	background: var(--door-back);
	transform: rotateY(180deg);
}

/* With artwork, each door's front shows the piece of picture behind it (advent.js
   works out --art-*), so a shut door blends in and an open one swings the picture
   away. It stays the picture when open, with light and shade to give it depth. */
.has-art .door__front {
	background-image: var(--art);
	background-size: var(--art-w) var(--art-h);
	background-position: var(--art-x) var(--art-y);
	background-origin: border-box;
	background-repeat: no-repeat;
	/* a raised panel: lit from the top left, a shadow below, a touch brighter than the picture */
	box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45),
	            inset 3px 3px 0 rgba(255, 255, 255, 0.35),
	            inset -3px -3px 0 rgba(0, 0, 0, 0.35);
	filter: brightness(1.12) saturate(1.1);
}
.has-art .door--past .door__front,
.has-art .door.is-open .door__front {
	border-color: rgba(255, 255, 255, 0.95);
	color: var(--door-number);
	text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
	box-shadow: 4px 6px 14px rgba(0, 0, 0, 0.5),
	            inset 3px 3px 0 rgba(255, 255, 255, 0.35),
	            inset -3px -3px 0 rgba(0, 0, 0, 0.35);
}
/* the door turned towards the light: a sheen across it, darker at the hinge */
.has-art .door__front::after {
	content: "";
	position: absolute;
	inset: -3px;
	border-radius: inherit;
	background: linear-gradient(90deg, rgba(0, 0, 0, 0.3), rgba(255, 255, 255, 0.18) 70%, rgba(255, 255, 255, 0.05));
	opacity: 0.35;
	transition: opacity var(--swing);
	pointer-events: none;
}
.has-art .door--past .door__front::after,
.has-art .door.is-open .door__front::after { opacity: 1; }

/* an opened door swings out in front of its neighbours, and stays in front
   while it swings shut again (advent.js adds is-closing for that) */
.door--past { z-index: 2; }
.door:hover { z-index: 3; }
.door.is-open,
.door.is-closing { z-index: 10; }
.door__num { position: relative; z-index: 1; } /* above the sheen */

/* see-through doors light up a little on hover */
.door--today:hover .door__front,
.preview .door--future:hover .door__front { background-color: rgba(255, 255, 255, 0.15); }

/* past doors stand a little open, so it's clear they can be clicked */
.door--past .door__panel { transform: rotateY(var(--crack)); }
.door--past:hover .door__panel { transform: rotateY(calc(var(--crack) - 10deg)); }

/* opening */
.door.is-open .door__panel,
.door.is-open:hover .door__panel { transform: rotateY(-115deg); }

/* ---------- logos, over the bottom of the artwork ---------- */

.logos {
	position: absolute;
	left: 50%;
	bottom: 16px;
	transform: translateX(-50%);
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 32px;
	max-width: calc(100% - 32px);
	padding: 10px 24px;
	border-radius: 16px;
	background: #fff;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.logos a { flex: 0 1 auto; min-width: 0; }

.logos img {
	display: block;
	height: var(--logo-h);
	width: auto;
	max-width: 100%;
	object-fit: contain;
}

@media (max-width: 600px) {
	.logos { gap: 16px; padding: 8px 14px; bottom: 10px; }
}

/* ---------- the popup ---------- */

dialog {
	width: min(680px, calc(100vw - 32px));
	max-height: calc(100svh - 48px);
	padding: 0;
	border: 0;
	border-radius: 16px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(246, 196, 83, 0.35);
	color: #eef3fb;
	/* a winter night, with a little snow */
	background:
		radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.16) 0 2px, transparent 3px) 0 0 / 173px 173px,
		radial-gradient(circle at 67% 41%, rgba(255, 255, 255, 0.10) 0 1.5px, transparent 2.5px) 0 0 / 241px 199px,
		radial-gradient(circle at 33% 77%, rgba(255, 255, 255, 0.13) 0 2.5px, transparent 3.5px) 0 0 / 317px 263px,
		radial-gradient(circle at 84% 63%, rgba(255, 255, 255, 0.08) 0 1px, transparent 2px) 0 0 / 131px 157px,
		radial-gradient(circle at 51% 9%, rgba(255, 255, 255, 0.11) 0 1.5px, transparent 2.5px) 0 0 / 389px 347px,
		radial-gradient(130% 90% at 50% 0%, #1f3d74 0%, #0f2148 55%, #081330 100%);
	overflow: hidden;
	/* clip, not just hide: a "hidden" box can still be scrolled by script, and the
	   YouTube player scrolls it when it starts, pushing the header out of view.
	   Only .popup__body scrolls. */
	overflow: clip;
	opacity: 0;
	transform: translateY(16px) scale(0.96);
	transition: opacity 0.3s, transform 0.3s;
}
dialog[open] { display: flex; flex-direction: column; }
dialog.is-shown { opacity: 1; transform: none; }

dialog::backdrop {
	background: rgba(0, 12, 32, 0.75);
}

/* a big festive emoji tucked into the bottom corner */
.popup__emoji {
	position: absolute;
	right: -10px;
	bottom: -14px;
	font-size: 96px;
	line-height: 1;
	transform: rotate(-14deg);
	opacity: 0.9;
	pointer-events: none;
	filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.4));
}

.popup__head {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px 14px 24px;
	background: linear-gradient(135deg, var(--popup-colour, var(--red)), color-mix(in srgb, var(--popup-colour, var(--red)) 60%, #000));
	border-bottom: 3px solid #F6C453;
	color: #fff;
}

.popup__head h2 {
	flex: 1;
	margin: 0;
	font-size: 1.6rem;
	line-height: 1.2;
	text-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.popup__close {
	flex: none;
	width: 44px;
	height: 44px;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	color: #fff;
	font-size: 30px;
	line-height: 1;
	cursor: pointer;
}
.popup__close:hover { background: rgba(255, 255, 255, 0.35); }

.popup__body {
	flex: 1;
	overflow: auto;
	padding: 20px 24px;
}

.popup__body.is-loading { min-height: 160px; }

.popup__body > :first-child { margin-top: 0; }
.popup__body > :last-child { margin-bottom: 0; }
.popup__body h3 { margin: 1.2em 0 0.4em; font-size: 1.35rem; line-height: 1.25; color: #fff; }
.popup__body a { color: #F6C453; }
.popup__body a:hover { color: #fff; }
.popup__body img { max-width: 100%; height: auto; border-radius: 8px; }

/* what kind of day it is: Wellbeing, Craft, Joke, Kindness */
.popup__body .kind {
	margin: 0 0 0.2em;
	color: #F6C453;
	font-size: 0.85rem;
	font-weight: 800;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}
.popup__body .kind + h3 { margin-top: 0; }
/* a second topic further down the same popup */
.popup__body * + .kind { margin-top: 1.6em; padding-top: 1.2em; border-top: 1px solid rgba(255, 255, 255, 0.12); }

/* a picture beside its text: <div class="feature"><img ...><div>text</div></div> */
.popup__body .feature {
	display: grid;
	grid-template-columns: 150px 1fr;
	gap: 18px;
	align-items: start;
	margin: 0.4em 0 0;
}
.popup__body .feature img { width: 100%; height: auto; border-radius: 10px; }
.popup__body .feature p:first-child { margin-top: 0; }
@media (max-width: 600px) {
	.popup__body .feature { grid-template-columns: 96px 1fr; gap: 12px; }
}

/* a list of short ideas, in two columns where there is room */
.popup__body .ideas {
	columns: 2;
	column-gap: 24px;
	margin: 0.4em 0 1em;
	padding-left: 1.2em;
}
.popup__body .ideas li { break-inside: avoid; margin-bottom: 0.2em; }
.popup__body .ideas li::marker { color: #F6C453; }
@media (max-width: 420px) {
	.popup__body .ideas { columns: 1; }
}

/* a joke's punchline, behind a button */
.popup__body .answer summary {
	display: inline-block;
	padding: 6px 18px;
	border-radius: 6px;
	background: #F6C453;
	color: var(--navy);
	font-weight: 800;
	cursor: pointer;
	list-style: none;
}
.popup__body .answer summary:hover { background: #fff; }
.popup__body .answer summary::-webkit-details-marker { display: none; }
.popup__body .answer[open] summary { display: none; }
.popup__body .answer p { margin: 0; font-size: 1.6rem; font-weight: 900; color: #F6C453; }

/* the Cornish word of the day */
.popup__body .cornish {
	margin: 1.2em 0 0;
	padding: 14px 18px;
	border-radius: 10px;
	position: relative;
	padding-right: 92px; /* room for the flag */
	background: rgba(255, 255, 255, 0.07);
}
/* St Piran's flag: a white cross on black */
.popup__body .cornish::after {
	content: "";
	position: absolute;
	top: 16px;
	right: 18px;
	width: 57px;
	height: 38px;
	border-radius: 3px;
	background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 20'%3E%3Crect width='30' height='20' fill='%23000'/%3E%3Crect x='12.5' width='5' height='20' fill='%23fff'/%3E%3Crect y='7.5' width='30' height='5' fill='%23fff'/%3E%3C/svg%3E") center / 100% 100%;
	box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35), 0 4px 10px rgba(0, 0, 0, 0.4);
	transform: rotate(5deg);
}
.popup__body .cornish .video { margin: 0.8em -74px 0 0; } /* full width, under the flag */

/* a YouTube Short (portrait): <div class="video video--short"> - phone-shaped, not stretched */
.popup__body .video.video--short {
	aspect-ratio: 9 / 16;
	width: min(240px, 100%);
	max-height: 60svh;
	margin: 0.8em 0 0;
}

/* A Cornish word with a video: the words on the left, the video beside them, so the
   whole popup fits without scrolling. The flag moves to the right of the words. */
.popup__body .cornish:has(.video) {
	--clip-w: 170px;
	display: grid;
	grid-template-columns: 1fr var(--clip-w);
	grid-auto-rows: min-content;
	column-gap: 18px;
	padding-right: 18px;
}
.popup__body .cornish:has(.video) > p { grid-column: 1; padding-right: 70px; }
.popup__body .cornish:has(.video) .video {
	grid-column: 2;
	grid-row: 1 / span 6;
	width: var(--clip-w);
	margin: 0;
}
.popup__body .cornish:has(.video)::after { right: calc(18px + var(--clip-w) + 18px); }
.popup__body .cornish p { margin: 0; }
.popup__body .cornish__label { font-size: 0.85rem; font-weight: 700; color: #a9bbd6; }
.popup__body .cornish__word { font-size: 1.6rem; font-weight: 900; line-height: 1.2; margin: 0.1em 0; }
.popup__body .cornish__say { font-style: italic; color: #a9bbd6; }
.popup__body .cornish__mean { font-weight: 700; margin-top: 0.3em; }

/* a YouTube video: <div class="video"><iframe ...></iframe></div> */
.popup__body .video {
	aspect-ratio: 16 / 9;
	margin: 1em 0;
	border-radius: 8px;
	overflow: hidden;
	background: #000;
}
.popup__body .video iframe { display: block; width: 100%; height: 100%; border: 0; }

/* the still frame shown until the video is tapped (advent.js stillFrames) */
.popup__body .video__still {
	position: relative;
	display: block;
	width: 100%;
	height: 100%;
	padding: 0;
	border: 0;
	background: #000;
	cursor: pointer;
}
.popup__body .video__still img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 0;
}
.popup__body .video__play {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 60px;
	height: 60px;
	translate: -50% -50%;
	border-radius: 50%;
	background: #F6C453 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M8 5v14l11-7z' fill='%23002456'/%3E%3C/svg%3E") 55% 50% / 30px 30px no-repeat;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
	transition: transform 0.15s;
}
.popup__body .video__still:hover .video__play,
.popup__body .video__still:focus-visible .video__play { transform: scale(1.1); }
.popup__body .video__still:focus-visible { outline: 3px solid #F6C453; outline-offset: 2px; }

.popup__body .button {
	display: inline-block;
	padding: 8px 20px;
	border-radius: 6px;
	background: var(--red);
	color: #fff;
	font-weight: 700;
	text-decoration: none;
}
.popup__body .button:hover { background: var(--orange); color: #fff; }
/* Two or more buttons side by side: <p class="buttons">, a gap when they wrap on a phone */
.popup__body .buttons { display: flex; flex-wrap: wrap; gap: 10px; }

.popup__foot {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 24px 16px;
	padding-right: 96px; /* room for the emoji */
	border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.popup__share {
	padding: 8px 18px;
	border: 2px solid #F6C453;
	border-radius: 6px;
	background: transparent;
	color: #F6C453;
	font: inherit;
	font-weight: 700;
	cursor: pointer;
}
.popup__share:hover { background: #F6C453; color: var(--navy); }
.popup__share { display: inline-flex; align-items: center; gap: 8px; }
.popup__share svg { width: 18px; height: 18px; fill: currentColor; }

.popup__shared { font-size: 0.9rem; }

@media (max-width: 600px) {
	dialog { width: calc(100vw - 16px); max-height: calc(100svh - 16px); }
	.popup__body { padding: 16px; }
	.popup__head { padding-left: 16px; }
	.popup__foot { padding: 10px 80px 14px 16px; }
	.popup__emoji { font-size: 72px; }
	.popup__body .cornish { padding-right: 76px; }
	.popup__body .cornish::after { width: 45px; height: 30px; right: 14px; }
	.popup__body .cornish .video { margin-right: -62px; }
	.popup__body .video.video--short { margin-right: 0; }
	.popup__body .cornish:has(.video) { --clip-w: 120px; column-gap: 12px; padding-right: 14px; }
	.popup__body .cornish:has(.video) > p { padding-right: 0; }
	/* no room for the flag beside the words on a phone: it sits under them instead */
	.popup__body .cornish:has(.video)::after { top: auto; bottom: 16px; left: 18px; right: auto; }
}

/* ---------- falling snow over the whole page (advent.js) ---------- */

#snow {
	position: fixed;
	inset: 0;
	z-index: 4;
	pointer-events: none;
}

/* ---------- a message for a locked door ---------- */

.toast {
	position: fixed;
	left: 50%;
	bottom: 24px;
	transform: translateX(-50%);
	z-index: 10;
	max-width: calc(100vw - 32px);
	padding: 10px 20px;
	border-radius: 999px;
	background: #fff;
	color: var(--navy);
	font-weight: 700;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
	text-align: center;
}

.door.is-shaking .door__panel { animation: shake 0.4s; }
@keyframes shake {
	0%, 100% { translate: 0; }
	25% { translate: -4% 0; }
	75% { translate: 4% 0; }
}

/* ---------- cookie popup (same choices and cookie as the main site) ---------- */

#cookie_popup_message {
	position: fixed;
	z-index: 20;
	bottom: 16px;
	left: 16px;
	width: min(310px, calc(100vw - 32px));
	padding: 12px;
	border-radius: 8px;
	background: #fffffff2;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
	color: #000;
	font-size: 15px;
}
#cookie_popup_message p { margin: 0 0 10px; }
#cookie_popup_message a { color: var(--red); }
.cookie_options_row { display: flex; align-items: center; gap: 10px; }
.cookie_options_label { font-weight: 700; margin-right: 10px; }
.cookie_options_row button {
	padding: 4px 16px;
	border: 0;
	border-radius: 5px;
	background: #666;
	color: #fff;
	font: inherit;
	font-weight: 700;
	cursor: pointer;
}
.cookie_options_row .yes:hover { background: #3c3; }
.cookie_options_row .no:hover { background: #c33; }

/* ---------- people who prefer less motion ---------- */

@media (prefers-reduced-motion: reduce) {
	:root { --swing: 0.01s; }
	dialog { transition: none; }
	.door.is-shaking .door__panel { animation: none; }
}
