/* Alo's page: the opening chat, the hero-card hub, stories and the letter. Pair worlds are in worlds.css. */

@font-face {
	font-family: "Silkscreen";
	src: url("../assets/fonts/silkscreen-latin-400-normal.woff2") format("woff2");
}

@font-face {
	font-family: "Cozette";
	src: url("../assets/fonts/CozetteVector.woff2") format("woff2");
}

/* World heading and story fonts (SIL Open Font License) */
@font-face {
	font-family: "Cinzel Decorative";
	font-weight: 700;
	src: url("../assets/fonts/cinzel-decorative-latin-700-normal.woff2") format("woff2");
}

@font-face {
	font-family: "Pirata One";
	src: url("../assets/fonts/pirata-one-latin-400-normal.woff2") format("woff2");
}

@font-face {
	font-family: "UnifrakturMaguntia";
	src: url("../assets/fonts/unifrakturmaguntia-latin-400-normal.woff2") format("woff2");
}

@font-face {
	font-family: "IM Fell English";
	src: url("../assets/fonts/im-fell-english-latin-400-normal.woff2") format("woff2");
}

@font-face {
	font-family: "IM Fell English";
	font-style: italic;
	src: url("../assets/fonts/im-fell-english-latin-400-italic.woff2") format("woff2");
}

:root {
	--ink: #3b1f5c;
	--paper: #fffafd;
	--pink: #ff9cc8;
	--yellow: #ffe14d;
	--gold: #c98a1d;
	--gold-light: #ffe58a;
	--card-w: min(40vw, 160px);
	/* Pixel-art rounded corner: three steps of 2px, 8px across */
	--pixel-round: polygon(
		0 8px, 2px 8px, 2px 4px, 4px 4px, 4px 2px, 8px 2px, 8px 0,
		calc(100% - 8px) 0, calc(100% - 8px) 2px, calc(100% - 4px) 2px, calc(100% - 4px) 4px, calc(100% - 2px) 4px, calc(100% - 2px) 8px, 100% 8px,
		100% calc(100% - 8px), calc(100% - 2px) calc(100% - 8px), calc(100% - 2px) calc(100% - 4px), calc(100% - 4px) calc(100% - 4px), calc(100% - 4px) calc(100% - 2px), calc(100% - 8px) calc(100% - 2px), calc(100% - 8px) 100%,
		8px 100%, 8px calc(100% - 2px), 4px calc(100% - 2px), 4px calc(100% - 4px), 2px calc(100% - 4px), 2px calc(100% - 8px), 0 calc(100% - 8px)
	);
}

* {
	box-sizing: border-box;
}

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

body {
	height: 100svh;
	overflow: hidden;
	background: #e9dcff;
}

[hidden] {
	display: none !important;
}

/* ---------- Stage ---------- */

.stage {
	position: relative;
	display: grid;
	place-items: center;
	height: 100%;
	overflow: hidden;
	container-type: size;
	background: conic-gradient(#e9dcff 25%, #f4ecff 0 50%, #e9dcff 0 75%, #f4ecff 0) 0 0 / 12px 12px;
	color: var(--ink);
}

/* Phone: the whole stage. Wide screens: a square, centred; parts keep their own sizes inside it. */
.frame {
	position: relative;
	grid-area: 1 / 1;
	width: min(100%, 100cqh);
	height: 100%;
}

/* ---------- Opening chat ---------- */

/* Phone-narrow even when the frame is a wide square */
.window {
	display: flex;
	flex-direction: column;
	width: min(calc(100% - 32px), 440px);
	height: calc(100% - 32px);
	margin: 14px auto 18px;
	border: 3px solid var(--ink);
	background: var(--paper);
	box-shadow: 6px 6px 0 var(--ink);
	font: 19.5px/1.35 "Cozette", monospace;
}

.head {
	display: flex;
	flex: none;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-bottom: 3px solid var(--ink);
	background: var(--pink);
	font: 14px "Silkscreen", monospace;
}

.head .name {
	flex: 1;
}

.pixel-heart {
	display: block;
	width: 18px;
	height: 15px;
	shape-rendering: crispEdges;
}

.log {
	display: flex;
	flex: 1;
	flex-direction: column;
	justify-content: flex-end;
	gap: 10px;
	min-height: 0;
	padding: 14px 12px;
	overflow-y: auto;
}

.msg-row {
	display: flex;
	flex-direction: column;
	gap: 4px;
	max-width: 88%;
}

.msg-row.in {
	align-self: flex-start;
	align-items: flex-start;
}

.msg-row.out {
	align-self: flex-end;
	align-items: flex-end;
}

.sender {
	padding: 0 2px;
	color: #8a6aab;
	font: 12px "Silkscreen", monospace;
}

.msg,
.typing {
	padding: 8px 12px;
	clip-path: var(--pixel-round);
	overflow-wrap: anywhere;
}

.msg.in,
.typing {
	background: var(--yellow);
}

.msg.out {
	background: var(--pink);
}

.typing {
	display: inline-flex;
	align-self: flex-start;
	gap: 5px;
	padding: 12px 14px;
}

.typing i {
	display: block;
	width: 7px;
	height: 7px;
	background: var(--ink);
	animation: typing 1.2s ease-in-out infinite;
}

.typing i:nth-child(2) {
	animation-delay: 0.15s;
}

.typing i:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes typing {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
	30% { transform: translateY(-4px); opacity: 1; }
}

/* The reply button always holds its space; the idle box sits in the same cell until it shows. */
.reply {
	display: grid;
	flex: none;
	padding: 10px;
	border-top: 3px solid var(--ink);
}

.reply > * {
	grid-area: 1 / 1;
}

.choice {
	padding: 9px;
	border: 3px solid var(--ink);
	background: var(--pink);
	box-shadow: 3px 3px 0 var(--ink);
	color: var(--ink);
	font: inherit;
	cursor: pointer;
}

.choice:active {
	box-shadow: none;
	transform: translate(3px, 3px);
}

.idle {
	padding: 9px;
	border: 3px dashed #c9b6e6;
}

/* ---------- Envelope: 32×22 pixel art, seal on the flap's tip ---------- */

.envelope {
	--px: 4px;
	position: relative;
	display: block;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

.envelope:focus-visible {
	outline: 3px dashed var(--ink);
	outline-offset: 4px;
}

.envelope svg {
	display: block;
	shape-rendering: crispEdges;
}

.envelope .art {
	width: calc(32 * var(--px));
	height: calc(22 * var(--px));
	filter: drop-shadow(3px 3px 0 rgba(59, 31, 92, 0.3));
}

.envelope .seal {
	position: absolute;
	left: calc(12 * var(--px));
	top: calc(9 * var(--px));
	width: calc(8 * var(--px));
	height: calc(7 * var(--px));
}

/* Waits to be opened. Idle animations move in whole pixel steps, like a sprite. */
.waiting {
	animation: hop 2.4s steps(1, end) infinite;
}

@keyframes hop {
	0%, 78% { transform: translateY(0); }
	81% { transform: translateY(-4px); }
	84% { transform: translateY(-8px); }
	88% { transform: translateY(-4px); }
	91% { transform: translateY(0); }
}

/* A pixel sparkle: a cross of five pixels */
.glint {
	position: absolute;
	width: var(--px);
	height: var(--px);
	background: #fff;
	box-shadow: var(--px) 0 #fff, calc(-1 * var(--px)) 0 #fff, 0 var(--px) #fff, 0 calc(-1 * var(--px)) #fff;
	opacity: 0;
	pointer-events: none;
}

.envelope .glint {
	left: calc(21 * var(--px));
	top: calc(8.5 * var(--px));
}

.waiting .glint {
	animation: glint 2.4s steps(1, end) infinite;
}

@keyframes glint {
	0%, 60% { opacity: 0; transform: none; }
	64% { opacity: 1; transform: none; }
	68% { opacity: 1; transform: scale(1.5); }
	72% { opacity: 1; transform: none; }
	76%, 100% { opacity: 0; transform: none; }
}

/* ---------- Hub ---------- */

.hub {
	display: grid;
	grid-template-rows: auto 1fr auto;
	justify-items: center;
	padding: 18px 16px 22px;
}

.counter {
	padding: 6px 12px;
	border: 3px solid var(--ink);
	background: var(--paper);
	box-shadow: 4px 4px 0 var(--ink);
	font: 14px "Silkscreen", monospace;
}

.table {
	position: relative;
	display: grid;
	place-items: center;
	width: 100%;
}

.table > * {
	grid-area: 1 / 1;
}

/* Card pack: pixel art, the top strip tears off */
.pack {
	--px: 5px;
	position: relative;
	display: block;
	width: 150px;
	height: 200px;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
	filter: drop-shadow(5px 5px 0 rgba(59, 31, 92, 0.35));
	-webkit-tap-highlight-color: transparent;
}

.pack:focus-visible {
	outline: 3px dashed var(--ink);
	outline-offset: 6px;
}

.pack svg {
	position: absolute;
	left: 0;
	display: block;
	width: 150px;
	shape-rendering: crispEdges;
}

.pack .strip {
	top: 0;
	height: 40px;
}

.pack .body {
	top: 35px;
	height: 165px;
}

.pack .glint {
	left: 118px;
	top: 58px;
}

/* Tarot cards */
.pull {
	position: relative;
	display: flex;
	justify-content: center;
	gap: 14px;
}

.tarot {
	position: relative;
	width: var(--card-w);
	aspect-ratio: 3 / 5;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	cursor: pointer;
	perspective: 800px;
	-webkit-tap-highlight-color: transparent;
}

.tarot:disabled {
	cursor: default;
}

.tarot-inner {
	position: absolute;
	inset: 0;
	transform-style: preserve-3d;
}

.tarot .side {
	position: absolute;
	inset: 0;
	border: 3px solid var(--ink);
	box-shadow: 4px 4px 0 var(--ink);
	backface-visibility: hidden;
}

/* Back: purple with a pixel diamond pattern and a gold heart */
.tarot .back {
	display: grid;
	place-items: center;
	background: conic-gradient(from 45deg, #7b4bb0 25%, #6a3d9c 0 50%, #7b4bb0 0 75%, #6a3d9c 0) 0 0 / 16px 16px;
	box-shadow: 4px 4px 0 var(--ink), inset 0 0 0 4px #b48be0, inset 0 0 0 7px #6a3d9c, inset 0 0 0 10px #e3c66a;
}

.tarot .back svg {
	width: 48px;
	height: 42px;
	shape-rendering: crispEdges;
}

/* Face: cream with a gold double frame, numeral, portrait, role and name */
.tarot .face {
	display: grid;
	grid-template-rows: auto 1fr auto auto;
	gap: 4px;
	padding: 10px 8px 9px;
	background: #fff6dc;
	box-shadow: 4px 4px 0 var(--ink), inset 0 0 0 3px var(--gold-light), inset 0 0 0 5px var(--gold);
	transform: rotateY(180deg);
	text-align: center;
}

.numeral {
	color: var(--gold);
	font: 14px "Silkscreen", monospace;
}

.portrait {
	min-height: 0;
	border: 3px solid var(--ink);
	background: #ffd6e7;
	overflow: hidden;
}

.portrait img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.role {
	font: 12px "Silkscreen", monospace;
}

.name {
	overflow: hidden;
	font: 13px/1.2 "Cozette", monospace;
	white-space: nowrap;
	text-overflow: ellipsis;
}

/* A collected pair, brought back out of the tray */
.showcase {
	display: grid;
	justify-items: center;
	gap: 18px;
}

.pair {
	display: flex;
	justify-content: center;
	gap: 14px;
}

.tarot.open .tarot-inner {
	transform: rotateY(180deg);
}

/* Same cream and gold frame as the card faces */
.story-button {
	padding: 10px 24px;
	border: 3px solid var(--ink);
	background: #fff6dc;
	box-shadow: 4px 4px 0 var(--ink), inset 0 0 0 3px var(--gold-light), inset 0 0 0 5px var(--gold);
	color: var(--ink);
	font: 14px "Silkscreen", monospace;
	cursor: pointer;
}

.story-button:active {
	box-shadow: inset 0 0 0 3px var(--gold-light), inset 0 0 0 5px var(--gold);
	transform: translate(4px, 4px);
}

/* Collection tray: collected cards bring their pair back out */
.tray {
	display: flex;
	gap: 10px;
}

.slot {
	display: grid;
	place-items: center;
	width: 56px;
	height: 74px;
	padding: 0;
	border: 3px dashed #c9b6e6;
	background: none;
	color: #b39bd6;
	font: 12px "Silkscreen", monospace;
}

button.slot {
	border: 3px solid var(--ink);
	background: #fff6dc;
	box-shadow: 3px 3px 0 var(--ink), inset 0 0 0 3px var(--gold-light);
	color: var(--gold);
	cursor: pointer;
}

/* The pair out on the table: its card lifts and glows gold */
button.slot.current {
	outline: 3px solid #ffd45c;
	outline-offset: 2px;
	translate: 0 -6px;
}

button.slot:active {
	box-shadow: inset 0 0 0 3px var(--gold-light);
	transform: translate(3px, 3px);
}

.slot.ultra {
	border-color: var(--gold);
}

button.slot.ultra {
	border-color: var(--ink);
	background: linear-gradient(135deg, #fff3c2, #ffd45c 45%, #fff3c2 55%, #ffcf4a);
	box-shadow: 3px 3px 0 var(--ink), inset 0 0 0 3px #fff3c2;
}

.slot svg {
	width: 24px;
	height: 21px;
	shape-rendering: crispEdges;
}

/* ---------- UR pull: the final envelope arrives in gold, with rays and sparkles ---------- */

.ur {
	position: absolute;
	inset: 0;
	overflow: hidden;
	pointer-events: none;
}

.ur-glow {
	position: absolute;
	inset: 0;
	background: radial-gradient(circle at 50% 50%, rgba(255, 225, 120, 0.75), rgba(255, 190, 220, 0.35) 35%, transparent 70%);
}

.ur-rays {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 220vmax;
	height: 220vmax;
	margin: -110vmax 0 0 -110vmax;
	background: repeating-conic-gradient(rgba(255, 236, 160, 0.55) 0deg 7deg, transparent 7deg 20deg);
	-webkit-mask: radial-gradient(circle, #000 4%, transparent 30%);
	mask: radial-gradient(circle, #000 4%, transparent 30%);
	animation: rays 40s linear infinite;
}

@keyframes rays {
	to { transform: rotate(1turn); }
}

.ur .glint {
	--px: 5px;
	animation: sparkle var(--duration) steps(1, end) var(--delay) infinite;
}

@keyframes sparkle {
	0%, 55% { opacity: 0; transform: none; }
	60% { opacity: 1; transform: none; }
	66% { opacity: 1; transform: scale(1.6); }
	72% { opacity: 1; transform: none; }
	78%, 100% { opacity: 0; transform: none; }
}

.ur-flash {
	position: absolute;
	inset: 0;
	background: #fff;
	opacity: 0;
}

.envelope.gold {
	--px: 6px;
}

/* ---------- Story and letter windows ---------- */

.story,
.letter,
.achievements {
	position: absolute;
	inset: 0;
	z-index: 10;
	display: grid;
	place-items: center;
	padding: 16px;
	background: rgba(59, 31, 92, 0.45);
}

.story-window,
.letter-window {
	display: flex;
	flex-direction: column;
	width: min(100%, 360px);
	/* Leaves some of the world showing above and below; longer text scrolls inside */
	max-height: 76cqh;
	border: 3px solid var(--ink);
	background: var(--paper);
	box-shadow: 6px 6px 0 var(--ink);
}

.letter-window {
	width: min(100%, 440px);
}

.story-head {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 6px 6px 6px 10px;
	border-bottom: 3px solid var(--ink);
	background: var(--pink);
	font: 13px "Silkscreen", monospace;
}

.letter-window .story-head {
	background: linear-gradient(180deg, #fff3c2, #ffd45c);
}

.story-head button {
	flex: none;
	width: 28px;
	height: 28px;
	border: 3px solid var(--ink);
	background: var(--paper);
	color: var(--ink);
	font: 14px "Silkscreen", monospace;
	cursor: pointer;
}

.story-body {
	min-height: 0;
	padding: 18px 14px;
	overflow-y: auto;
	overscroll-behavior: contain;
	/* A thin scrollbar in the text's own colour, so it suits each world */
	scrollbar-width: thin;
	scrollbar-color: color-mix(in srgb, currentColor 45%, transparent) transparent;
	font: 19.5px/1.35 "Cozette", monospace;
}

.story-body p {
	margin: 0;
}

.story-body p + p {
	margin-top: 0.8em;
}

/* ---------- Achievements ---------- */

.trophies {
	position: absolute;
	top: 18px;
	right: 16px;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 4px 10px 4px 6px;
	border: 3px solid var(--ink);
	background: var(--paper);
	box-shadow: 3px 3px 0 var(--ink);
	color: var(--ink);
	font: 14px "Silkscreen", monospace;
	cursor: pointer;
}

.trophies:active {
	box-shadow: none;
	transform: translate(3px, 3px);
}

.trophy {
	display: block;
	width: 22px;
	height: 22px;
	shape-rendering: crispEdges;
}

.achievement-list {
	margin: 0;
	padding: 6px 14px;
	list-style: none;
}

.achievement {
	display: grid;
	grid-template-columns: auto 1fr;
	align-items: center;
	gap: 0 12px;
	padding: 10px 0;
}

.achievement + .achievement {
	border-top: 3px dashed #e4d6f5;
}

.achievement .trophy {
	grid-row: span 2;
	width: 33px;
	height: 33px;
}

.achievement-name {
	font: 13px "Silkscreen", monospace;
}

.achievement-text {
	color: #8a6aab;
	font: 19.5px/1.2 "Cozette", monospace;
}

.achievement.locked .achievement-name {
	color: #b39bd6;
}

/* Toasts drop in at the top when achievements unlock, stacking downwards */
.toasts {
	position: absolute;
	top: 14px;
	left: 50%;
	z-index: 40;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 10px;
	transform: translateX(-50%);
	pointer-events: none;
}

.toast {
	display: grid;
	grid-template-columns: auto auto;
	align-items: center;
	gap: 2px 12px;
	padding: 8px 16px 8px 10px;
	border: 3px solid #a8641a;
	background: #ffe58a;
	box-shadow: inset 0 0 0 3px #fff3c2, 4px 4px 0 var(--ink);
	color: #5a3510;
	white-space: nowrap;
}

.toast .trophy-icon {
	grid-row: span 2;
}

.toast .trophy {
	width: 33px;
	height: 33px;
}

.toast-title {
	font: 11px "Silkscreen", monospace;
}

.toast-name {
	font: 19.5px/1.1 "Cozette", monospace;
}

@media (prefers-reduced-motion: reduce) {
	.typing i,
	.waiting,
	.waiting .glint,
	.ur-rays,
	.ur .glint {
		animation: none;
	}
}
