/* ============================================================
   soph · cute pixel envelope letter
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&family=Silkscreen:wght@400;700&display=swap");

:root {
	/* warm tan background like the reference photo */
	--bg: #d29a68;
	--bg-deep: #b07f4f;
	--bg-grain: #c08a58;

	/* envelope */
	--paper: #efe6d4;
	--paper-warm: #e8dec8;
	--paper-shade: #c9b48b;
	--ink: #2d2549;
	--accent: #4a3a78; /* deep purple */
	--accent-mid: #6a5aa0;
	--accent-soft: #8a7ac4;
	--accent-bg: #a89ade;

	/* fonts */
	--f-pixel: "Press Start 2P", "Silkscreen", monospace;
	--f-pixel-soft: "Silkscreen", "Press Start 2P", monospace;
	--f-body: "VT323", "Courier New", monospace;
}

* {
	box-sizing: border-box;
}

html,
body,
#root,
.app {
	margin: 0;
	padding: 0;
	height: 100%;
	width: 100%;
	overflow: hidden;
}

body {
	background: var(--bg);
	color: var(--ink);
	font-family: var(--f-body);
	font-size: 18px;
	/* subtle pixel-grain — looks like paper/wood texture */
	background-image:
		radial-gradient(
			circle at 20% 30%,
			rgba(0, 0, 0, 0.04) 1px,
			transparent 1.5px
		),
		radial-gradient(
			circle at 70% 60%,
			rgba(0, 0, 0, 0.04) 1px,
			transparent 1.5px
		),
		radial-gradient(
			circle at 40% 80%,
			rgba(255, 240, 200, 0.06) 1px,
			transparent 1.5px
		),
		linear-gradient(180deg, #d8a06e 0%, #c8915d 100%);
	background-size:
		7px 7px,
		11px 11px,
		9px 9px,
		100% 100%;
	image-rendering: pixelated;
	-webkit-font-smoothing: none;
	font-smooth: never;
}

.app {
	position: relative;
}

.scene {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity 400ms ease;
}

.scene.is-hidden {
	opacity: 0;
	pointer-events: none;
}

.scene.is-active {
	opacity: 1;
}

/* Room scene stays visible always — the envelope morphs on top of it */
.scene--room {
	opacity: 1 !important;
}

/* But once the envelope is selected, the room becomes non-interactive
   and the mini envelope on the desk hides so we don't see two */
.scene--room.is-hidden {
	pointer-events: none;
}
.scene--room.is-hidden .envelope-hotspot,
.scene--room.is-hidden .room-caption {
	opacity: 0;
	transition: opacity 300ms ease;
	pointer-events: none;
}
.scene--room.is-active .envelope-hotspot,
.scene--room.is-active .room-caption {
	opacity: 1;
	transition: opacity 300ms ease 200ms;
}

/* When the user hits CLOSE while the letter is out, snap everything
   to its final state with no transitions — kill all the reverse-animations
   that would otherwise play (flap re-closing, seal flying back, letter
   shrinking, envelope scaling). */
.scene--envelope.closing-fast,
.scene--envelope.closing-fast * {
	transition: none !important;
	animation: none !important;
}
.scene--envelope.closing-fast {
	opacity: 0 !important;
}

/* ============================================================
   ROOM SCENE
   ============================================================ */

.room-wrap {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 20px;
}

.room-stage {
	position: relative;
	width: min(86vw, 1080px);
	aspect-ratio: 240 / 160;
	background: #000;
	border: 6px solid var(--accent);
	box-shadow:
		0 0 0 3px var(--paper-shade),
		0 0 0 8px var(--accent),
		0 18px 0 -3px rgba(0, 0, 0, 0.18),
		0 40px 60px -20px rgba(0, 0, 0, 0.35);
	border-radius: 4px;
	overflow: hidden;
}

.room-canvas {
	display: block;
	width: 100%;
	height: 100%;
	image-rendering: pixelated;
	image-rendering: crisp-edges;
}

/* ENVELOPE HOTSPOT — positioned on the desk */
.envelope-hotspot {
	position: absolute;
	/* desk top area in canvas coords: ~(140, 86) in 240x160 → 58.3% x, 53.7% y */
	left: 58.5%;
	top: 53.5%;
	transform: translate(-50%, -50%);
	width: 9%; /* scales with the stage */
	aspect-ratio: 5 / 3;
	padding: 0;
	border: 0;
	background: transparent;
	cursor: pointer;
	outline: none;
	display: grid;
	place-items: center;
	animation: hotspot-bob 2.4s ease-in-out infinite;
}

@keyframes hotspot-bob {
	0%,
	100% {
		transform: translate(-50%, -50%);
	}
	50% {
		transform: translate(-50%, -58%);
	}
}

.envelope-hotspot:focus-visible {
	outline: 2px dashed #fff;
	outline-offset: 4px;
}

.mini-env {
	position: relative;
	width: 100%;
	height: 100%;
	display: block;
	filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
	image-rendering: pixelated;
}

.envelope-hotspot:hover .mini-env {
	filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.4)) brightness(1.08);
}

.hotspot-label {
	position: absolute;
	bottom: 100%;
	left: 50%;
	transform: translate(-50%, -8px);
	font-family: var(--f-pixel);
	font-size: 10px;
	color: var(--accent);
	background: var(--paper);
	border: 2px solid var(--accent);
	padding: 4px 6px;
	border-radius: 3px;
	white-space: nowrap;
	box-shadow: 0 2px 0 var(--accent);
	pointer-events: none;
}

.envelope-hotspot:hover {
	animation-play-state: paused;
	transform: translate(-50%, -62%);
}

.room-caption {
	font-family: var(--f-pixel);
	font-size: 11px;
	color: #3a2a18;
	background: var(--paper);
	border: 3px solid var(--accent);
	padding: 10px 18px;
	border-radius: 4px;
	box-shadow: 0 4px 0 var(--accent);
	display: flex;
	align-items: center;
	gap: 10px;
	letter-spacing: 0.5px;
}

.room-caption b {
	color: var(--accent);
}

.cap-dot {
	width: 10px;
	height: 10px;
	background: #d44a4a;
	border: 2px solid #8a2820;
	display: inline-block;
	animation: blink 1.4s steps(2, end) infinite;
}

@keyframes blink {
	0%,
	50% {
		opacity: 1;
	}
	50.01%,
	100% {
		opacity: 0.3;
	}
}

/* ============================================================
   ENVELOPE CLOSE-UP
   ============================================================ */

.env-wrap {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	width: 100%;
	height: 100%;
	justify-content: center;
	gap: 32px;
}

.is-open .env-wrap {
	gap: 16px;
}

.back-btn {
	position: absolute;
	top: 24px;
	left: 24px;
	font-family: var(--f-pixel);
	font-size: 10px;
	color: var(--accent);
	background: var(--paper);
	border: 3px solid var(--accent);
	padding: 8px 12px;
	border-radius: 4px;
	box-shadow: 0 3px 0 var(--accent);
	cursor: pointer;
	letter-spacing: 0.5px;
	z-index: 50;
}

.back-btn:hover {
	background: var(--paper-warm);
}
.back-btn:active {
	transform: translateY(2px);
	box-shadow: 0 1px 0 var(--accent);
}

.env-stage {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 40px;
	perspective: 1400px;
	transition: gap 700ms ease;
	width: 820px;
	max-width: 92vw;
	min-height: 480px;
}

.is-open .env-stage {
	gap: 24px;
}

.env-shadow {
	position: absolute;
	bottom: -10px;
	width: 480px;
	height: 30px;
	background: radial-gradient(
		ellipse at center,
		rgba(0, 0, 0, 0.4) 0%,
		transparent 70%
	);
	z-index: 0;
	transition:
		opacity 600ms ease,
		transform 600ms ease;
}

.is-open .env-shadow {
	opacity: 0.6;
	transform: scale(0.85);
}

/* Big envelope */
.big-envelope {
	position: relative;
	width: 480px;
	max-width: 88vw;
	aspect-ratio: 8 / 5;
	transform-style: preserve-3d;
	z-index: 2;
}

.is-open .big-envelope {
	transform: translateY(180px) scale(0.55);
	opacity: 0.85;
	transition:
		transform 700ms cubic-bezier(0.3, 0.6, 0.3, 1.2),
		opacity 600ms ease;
}

/* Body — back face of envelope, visible always */
.env-body {
	position: absolute;
	inset: 0;
	background: var(--paper);
	border: 4px solid var(--accent);
	border-radius: 4px;
	box-shadow:
		inset 0 0 0 2px var(--paper),
		inset 0 -10px 30px rgba(74, 58, 120, 0.08),
		0 10px 0 -4px rgba(0, 0, 0, 0.15);
	overflow: hidden;
}

.env-creases {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}

.env-to {
	position: absolute;
	top: 14%;
	left: 50%;
	transform: translate(-50%, 0);
	font-family: var(--f-pixel);
	font-size: 18px;
	color: var(--ink);
	letter-spacing: 1px;
	white-space: nowrap;
	z-index: 5; /* above the closed flap so the name is visible */
}

.env-to-prefix {
	color: var(--ink);
	margin-right: 4px;
}

.env-to-name {
	background: var(--accent-bg);
	padding: 2px 4px;
	color: var(--ink);
	/* fake selection highlight, like the photo */
}

/* FLAP — top triangle that rotates up on open.
   Sits flush inside the body's border. */
.env-flap {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 50%;
	transform-origin: top;
	transition: transform 800ms cubic-bezier(0.5, 0.1, 0.5, 1.4);
	z-index: 3;
	background: var(--accent);
	clip-path: polygon(0 0, 100% 0, 50% 100%);
	filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.1));
}

.env-flap-inner {
	position: absolute;
	inset: 3px 3px 5px 3px;
	background: var(--paper);
	clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.flap-creases {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}

.is-open .env-flap {
	transform: rotateX(-172deg) translateY(-2px);
}

/* Seal — clickable heart wax seal at center where flap meets.
   Click it to open the envelope. */
.env-seal {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: radial-gradient(
		circle at 35% 30%,
		#e26b6b 0%,
		#b03a3a 70%,
		#7a2222 100%
	);
	border: 3px solid #8a2820;
	display: grid;
	place-items: center;
	z-index: 4;
	box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
	transition:
		transform 500ms cubic-bezier(0.5, 0.1, 0.5, 1.6),
		opacity 400ms ease 300ms,
		box-shadow 200ms ease;
	padding: 0;
	font: inherit;
	cursor: pointer;
}

.env-seal:hover:not(:disabled) {
	box-shadow:
		0 4px 0 rgba(0, 0, 0, 0.28),
		0 0 0 6px rgba(255, 230, 200, 0.22);
}

.env-seal:active:not(:disabled) {
	box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

.env-seal:disabled {
	cursor: default;
}

.seal-hint {
	position: absolute;
	top: calc(100% + 12px);
	left: 50%;
	transform: translateX(-50%);
	font-family: var(--f-pixel);
	font-size: 10px;
	color: var(--accent);
	background: var(--paper);
	border: 2px solid var(--accent);
	padding: 4px 8px;
	border-radius: 4px;
	white-space: nowrap;
	box-shadow: 0 2px 0 var(--accent);
	pointer-events: none;
}

.seal-hint::before {
	content: "";
	position: absolute;
	top: -5px;
	left: 50%;
	transform: translateX(-50%) rotate(45deg);
	width: 6px;
	height: 6px;
	background: var(--paper);
	border-left: 2px solid var(--accent);
	border-top: 2px solid var(--accent);
}

.is-open .env-seal {
	transform: translate(-50%, 200px) rotate(220deg);
	opacity: 0;
	pointer-events: none;
}

.seal-heart {
	color: #fff;
	font-size: 24px;
	line-height: 1;
	filter: drop-shadow(0 1px 0 #5a1818);
	font-family: var(--f-pixel);
}

/* LETTER — sibling of envelope in env-stage; slides up out of the envelope on open */
.env-letter {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 820px;
	max-width: 92vw;
	transform: translate(-50%, -20%) scale(0.35);
	opacity: 0;
	transform-origin: center bottom;
	transition:
		transform 1000ms cubic-bezier(0.2, 0.7, 0.3, 1) 320ms,
		opacity 400ms ease 320ms;
	z-index: 1;
	pointer-events: none;
}

.is-open .env-letter {
	/* center in env-stage */
	transform: translate(-50%, -52%) scale(1);
	opacity: 1;
	pointer-events: auto;
	z-index: 5;
}

/* ============================================================
   LETTER CONTENT
   ============================================================ */

.letter-paper {
	position: relative;
	background:
		repeating-linear-gradient(
			0deg,
			rgba(189, 159, 110, 0.08) 0 1px,
			transparent 1px 32px
		),
		var(--paper);
	border: 4px solid var(--accent);
	border-radius: 4px;
	padding: 22px 30px 18px;
	box-shadow:
		inset 0 0 0 2px var(--paper),
		0 12px 0 -4px rgba(0, 0, 0, 0.18),
		0 30px 60px -10px rgba(0, 0, 0, 0.35);
	font-family: var(--f-body);
	color: var(--ink);
}

.letter-paper::before,
.letter-paper::after {
	/* fold marks (faint) */
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	height: 1px;
	background: rgba(74, 58, 120, 0.12);
	pointer-events: none;
}
.letter-paper::before {
	top: 33%;
}
.letter-paper::after {
	top: 66%;
}

.letter-header {
	text-align: center;
	margin-bottom: 12px;
}

.letter-ornament {
	display: flex;
	align-items: center;
	gap: 8px;
	justify-content: center;
	color: var(--accent);
	margin-bottom: 10px;
}

.lo {
	font-size: 14px;
	font-family: var(--f-pixel);
}
.lo-line {
	width: 100px;
	height: 3px;
	background: repeating-linear-gradient(
		90deg,
		var(--accent) 0 3px,
		transparent 3px 7px
	);
}

.letter-title {
	margin: 0 0 6px;
	font-family: var(--f-pixel);
	font-size: 16px;
	color: var(--accent);
	letter-spacing: 1px;
}

.letter-meta {
	font-family: var(--f-pixel-soft);
	font-size: 12px;
	color: var(--accent-mid);
	letter-spacing: 0.5px;
}
.letter-meta b {
	color: var(--accent);
}

/* Video pane */
.video-pane {
	margin: 10px auto 14px;
	max-width: 86%;
}

.video-frame {
	position: relative;
	width: 100%;
	aspect-ratio: 16 / 9;
	background: repeating-linear-gradient(0deg, #1a1428 0 2px, #251c3a 2px 4px);
	border: 4px solid var(--accent);
	border-radius: 3px;
	box-shadow:
		inset 0 0 0 3px #0e0a1a,
		inset 0 0 40px rgba(74, 58, 120, 0.5);
	overflow: hidden;
}

.video-scan {
	position: absolute;
	inset: 0;
	background: linear-gradient(
		180deg,
		rgba(255, 255, 255, 0) 0%,
		rgba(255, 255, 255, 0.06) 50%,
		rgba(255, 255, 255, 0) 100%
	);
	background-size: 100% 8px;
	pointer-events: none;
	animation: scan 3s linear infinite;
}

@keyframes scan {
	from {
		background-position: 0 -200%;
	}
	to {
		background-position: 0 200%;
	}
}

.video-player {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	background: #000;
	object-fit: contain;
	display: block;
	z-index: 1;
	border: 0;
}

.video-content {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	color: var(--paper);
	font-family: var(--f-pixel);
	text-shadow: 0 2px 0 #000;
	z-index: 2;
}

.video-content.is-overlay {
	cursor: pointer;
	background: linear-gradient(
		180deg,
		rgba(0, 0, 0, 0.15) 0%,
		rgba(0, 0, 0, 0.55) 100%
	);
	transition: opacity 220ms ease;
}

.video-content.is-overlay:hover .play-btn {
	transform: translateY(-2px);
	box-shadow: 0 6px 0 var(--accent);
}

.video-content.is-hidden {
	opacity: 0;
	pointer-events: none;
}

.play-btn {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--paper);
	border: 4px solid var(--accent);
	display: grid;
	place-items: center;
	box-shadow: 0 4px 0 var(--accent);
}

.play-tri {
	display: block;
	width: 0;
	height: 0;
	border-left: 16px solid var(--accent);
	border-top: 10px solid transparent;
	border-bottom: 10px solid transparent;
	margin-left: 4px;
}

.video-label {
	font-size: 11px;
	letter-spacing: 1px;
	color: #f6e8c8;
}

.video-runtime {
	font-family: var(--f-pixel-soft);
	font-size: 11px;
	color: #b0a0d8;
	letter-spacing: 1px;
}

.video-corner {
	position: absolute;
	width: 10px;
	height: 10px;
	border-color: var(--accent-soft);
	border-style: solid;
	border-width: 0;
}
.video-corner--tl {
	top: 6px;
	left: 6px;
	border-top-width: 3px;
	border-left-width: 3px;
}
.video-corner--tr {
	top: 6px;
	right: 6px;
	border-top-width: 3px;
	border-right-width: 3px;
}
.video-corner--bl {
	bottom: 6px;
	left: 6px;
	border-bottom-width: 3px;
	border-left-width: 3px;
}
.video-corner--br {
	bottom: 6px;
	right: 6px;
	border-bottom-width: 3px;
	border-right-width: 3px;
}

/* hide pixel decoration when the frame is fullscreened by the play handler */
.video-frame:fullscreen .video-scan,
.video-frame:fullscreen .video-corner,
.video-frame:-webkit-full-screen .video-scan,
.video-frame:-webkit-full-screen .video-corner {
	display: none;
}

.video-caption {
	margin-top: 6px;
	text-align: center;
	font-family: var(--f-pixel-soft);
	font-size: 11px;
	color: var(--accent-mid);
	letter-spacing: 0.5px;
}

.letter-body {
	font-family: var(--f-body);
	font-size: 20px;
	line-height: 1.5;
	color: #2a1f3a;
	max-width: 46ch;
	margin: 14px auto 0;
	text-wrap: pretty;
	text-align: center;
}

.letter-body p {
	margin: 0 0 14px;
	line-height: 1.5;
}
.letter-body p:last-child {
	margin-bottom: 0;
}

.letter-footer {
	display: flex;
	justify-content: center;
	margin-top: 10px;
}

.letter-stamp {
	font-family: var(--f-pixel);
	font-size: 9px;
	color: var(--accent);
	border: 2px dashed var(--accent);
	padding: 6px 10px;
	letter-spacing: 1px;
	transform: rotate(-3deg);
}

/* ============================================================
   OPEN BUTTON
   ============================================================ */

.open-btn {
	position: absolute;
	top: calc(50% + 180px);
	left: 50%;
	transform: translateX(-50%);
	font-family: var(--f-pixel);
	font-size: 14px;
	color: var(--accent);
	background: var(--paper);
	border: 4px solid var(--accent);
	border-radius: 999px;
	padding: 12px 28px 12px;
	letter-spacing: 2px;
	cursor: pointer;
	box-shadow:
		0 5px 0 var(--accent),
		0 8px 12px rgba(0, 0, 0, 0.2);
	transition:
		transform 120ms ease,
		box-shadow 120ms ease,
		top 500ms cubic-bezier(0.3, 0.6, 0.3, 1);
	z-index: 10;
}

.is-open .open-btn {
	/* slide further down when the letter is out */
	top: calc(50% + 320px);
}

.open-btn::before,
.open-btn::after {
	content: "";
	position: absolute;
	width: 6px;
	height: 6px;
	background: var(--accent);
	top: 50%;
	transform: translateY(-50%);
}
.open-btn::before {
	left: -10px;
}
.open-btn::after {
	right: -10px;
}

.open-btn:hover {
	background: var(--paper-warm);
	transform: translateX(-50%) translateY(-2px);
	box-shadow:
		0 7px 0 var(--accent),
		0 10px 14px rgba(0, 0, 0, 0.25);
}

.open-btn:active {
	transform: translateX(-50%) translateY(3px);
	box-shadow:
		0 2px 0 var(--accent),
		0 4px 6px rgba(0, 0, 0, 0.2);
}

.is-open .open-btn:hover {
	transform: translateX(-50%) translateY(-2px);
}
.is-open .open-btn:active {
	transform: translateX(-50%) translateY(3px);
}

.open-btn--close {
	background: var(--accent);
	color: var(--paper);
	box-shadow:
		0 5px 0 #2a2048,
		0 8px 12px rgba(0, 0, 0, 0.2);
}

.open-btn--close::before,
.open-btn--close::after {
	background: #2a2048;
}

.open-btn--close:hover {
	background: var(--accent-mid);
}

.open-btn-pixel {
	display: inline-block;
}

/* ============================================================
   Small-screen tweaks
   ============================================================ */

@media (max-width: 720px) {
	.env-letter {
		width: 92vw;
	}
	.env-to {
		font-size: 16px;
	}
	.open-btn {
		font-size: 11px;
		padding: 10px 22px;
	}
}
