/* Chronicles of Lirien — runtime styles
 *
 * The aesthetic: dark, atmospheric, prose-forward. Vollkorn serif for
 * body text. Dark translucent panels float over a full-bleed AI
 * atmosphere image. The prose is the surface; everything else gets
 * out of the way.
 *
 * Title screen + chrome share the landing page's palette so the
 * front-cover-then-page-turn experience reads as one piece of work:
 *   void/parchment/cream typography, gold accents, lavender italics.
 */

:root {
	--void:         #08060f;
	--mist:         #a89ec0;
	--ash:          #7a7090;
	--lavender:     #b8a8cc;
	--cream:        #ede5d4;
	--parchment:    #f5eed8;
	--gold:         #c4935a;
	--gold-bright:  #e0b070;
}

@font-face {
	font-family: 'Vollkorn';
	src: url('fonts/Vollkorn-Regular.ttf') format('truetype');
	font-weight: normal;
	font-style: normal;
	font-display: swap;
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	padding: 0;
	height: 100dvh;
	overflow: hidden;
	background: #000;
	color: #f5ebd2;
	font-family: 'Vollkorn', Georgia, serif;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
}

/* ----- background image ----- */

.bg {
	position: fixed;
	inset: 0;
	background-color: #0d0e10;
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	transition: background-image 0.8s ease;
	z-index: 0;
}

/* ----- title screen (front cover) -----
 *
 * Mirrors the landing page hero: Cormorant Garamond at 300 weight,
 * gold eyebrow, parchment title with lavender italic accent, lavender
 * tagline, and a vertical-line + "Enter" hint at the bottom. The
 * full-bleed art is the user-supplied wide ash-plain shot at
 * /spiral_stone.png (one level up from this stylesheet).
 */

.title-screen {
	position: fixed;
	inset: 0;
	z-index: 100;
	display: flex;
	flex-direction: column;
	align-items: center;
	/* flex-start + top padding sits the title in the upper third so
	   the figure on the ash plain remains the visual anchor, not
	   something the tagline lies on top of. */
	justify-content: flex-start;
	padding: clamp(80px, 12vh, 160px) 2rem 2rem 2rem;
	text-align: center;
	font-family: 'Cormorant Garamond', 'Vollkorn', Georgia, serif;
	color: var(--parchment);
	background:
		linear-gradient(to bottom,
			rgba(8, 6, 15, 0.55) 0%,
			rgba(8, 6, 15, 0.25) 30%,
			rgba(8, 6, 15, 0.10) 55%,
			rgba(8, 6, 15, 0.55) 100%),
		url("../spiral_stone.png") center/cover no-repeat,
		var(--void);
	opacity: 0;
	transition: opacity 1.6s ease-in;
}
.title-screen.visible    { opacity: 1; }
.title-screen.dismissed  { opacity: 0; transition: opacity 1.4s ease-out; pointer-events: none; }
.title-screen[hidden]    { display: none; }

.title-content {
	max-width: min(960px, 92vw);
}
.title-eyebrow {
	font-size: clamp(13px, 1.4vw, 17px);
	font-weight: 400;
	letter-spacing: 0.4em;
	text-transform: uppercase;
	color: var(--gold-bright);
	margin-bottom: 1.6rem;
	text-shadow:
		0 0 10px rgba(196, 147, 90, 0.85),
		0 0 24px rgba(196, 147, 90, 0.5),
		0 0 0 rgba(0, 0, 0, 0.8);
}
.title-main {
	font-family: inherit;
	font-size: clamp(44px, 8vw, 96px);
	font-weight: 300;
	line-height: 1.05;
	letter-spacing: 0.005em;
	margin: 0 0 1.5rem 0;
	color: var(--parchment);
	text-shadow: 0 0 26px rgba(0, 0, 0, 0.9);
}
.title-main em {
	font-style: italic;
	/* Lavender works on the landing page's near-black void; the title
	   screen sits on a much lighter purple sky, so the italic accent
	   needs to go darker for contrast — same family, deeper value. */
	color: #1c1828;
	text-shadow: 0 0 14px rgba(245, 238, 216, 0.45);
}
.title-tagline {
	font-style: italic;
	font-weight: 400;
	font-size: clamp(15px, 1.7vw, 21px);
	line-height: 1.55;
	color: #1c1828;
	margin: 0;
	text-shadow: 0 0 14px rgba(245, 238, 216, 0.55);
}

.title-hint {
	position: absolute;
	bottom: 7%;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 14px;
}
.title-hint-loading {
	font-style: italic;
	font-size: clamp(13px, 1.2vw, 16px);
	letter-spacing: 0.18em;
	color: var(--mist);
	opacity: 0.5;
	animation: title-hint-pulse 2.6s ease-in-out infinite;
}
.title-hint-text {
	font-size: clamp(16px, 1.9vw, 24px);
	font-weight: 500;
	letter-spacing: 0.5em;
	text-transform: uppercase;
	color: var(--gold-bright);
	text-shadow:
		0 0 14px rgba(196, 147, 90, 0.85),
		0 0 32px rgba(196, 147, 90, 0.5),
		0 0 60px rgba(196, 147, 90, 0.3);
	animation: title-hint-pulse 2.6s ease-in-out infinite;
}
@keyframes title-hint-pulse {
	0%, 100% { opacity: 0.55; }
	50%      { opacity: 1;    }
}

/* ----- chapter title overlay ----- */

.chapter-title {
	position: fixed;
	top: 0;
	left: 0;
	padding: 44px 56px;
	z-index: 30;
	opacity: 0;
	pointer-events: none;
	transition: opacity 2.5s ease-in-out;
}
.chapter-title.visible { opacity: 1; }

.chapter-number {
	font-size: 22px;
	letter-spacing: 0.18em;
	color: rgba(240, 230, 200, 0.9);
	text-shadow: 0 0 6px rgba(0,0,0,0.8);
	margin-bottom: 12px;
}
.chapter-name {
	font-size: 56px;
	line-height: 1.05;
	color: #f7eed1;
	text-shadow: 0 0 8px rgba(0,0,0,0.85);
}

/* ----- game layer (prose + choices) ----- */

.game {
	position: relative;
	z-index: 10;
	height: 100%;
	pointer-events: none;
}
.game > * { pointer-events: auto; }

/* ----- prose panel: bottom half ----- */

.prose {
	position: absolute;
	left: 80px;
	right: 80px;
	bottom: 56px;
	top: 50%;
	background: rgba(11, 11, 18, 0.55);
	border-radius: 12px;
	overflow-y: auto;
	overflow-x: hidden;
	/* padding-top must stay smaller than .prose-content p { margin-bottom }
	 * (1em = font-size). Otherwise scrollChunkToTop's "scroll to
	 * paragraph.offsetTop - padTop" lands inside the previous paragraph
	 * and the bottom of its last line peeks at the top of the panel. */
	padding: 22px 36px 26px 36px;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
	scrollbar-color: rgba(245, 235, 210, 0.3) transparent;
}
.prose::-webkit-scrollbar { width: 8px; }
.prose::-webkit-scrollbar-track { background: transparent; }
.prose::-webkit-scrollbar-thumb {
	background: rgba(245, 235, 210, 0.3);
	border-radius: 4px;
}

.prose-content {
	font-size: var(--prose-font-size, 36px);
	line-height: 1.4;
	color: #f5ebd2;
}
.prose-content p {
	margin: 0 0 1em 0;
}
.prose-content p:last-child { margin-bottom: 0; }

/* per-character fade reveal — each char is a span with delayed fade-in */
.prose-content .ch {
	opacity: 0;
	animation: ch-fade-in 0.55s ease-out forwards;
}
.prose-content .ch.i { font-style: italic; }
@keyframes ch-fade-in {
	from { opacity: 0; }
	to   { opacity: 1; }
}

/* Down-chevron that pulses + floats whenever the runtime is waiting
 * for a tap. Lives in .game (NOT inside .prose) so it anchors to the
 * viewport edge instead of scrolling with the prose content. Sits in
 * the 56px gap between the prose panel's bottom and the viewport
 * bottom, so it never overlaps the last line of text. The SVG path
 * fills its 24×12 viewBox; thicker stroke + stronger glow reads at
 * a glance. */
.continue-hint {
	position: absolute;
	left: 50%;
	bottom: 18px;
	width: 56px;
	height: 28px;
	color: var(--gold-bright, #e0b070);
	opacity: 0;
	pointer-events: none;
	transform: translateX(-50%);
	transition: opacity 0.6s ease-in-out;
	z-index: 20;
	filter:
		drop-shadow(0 0 8px rgba(224, 176, 112, 0.7))
		drop-shadow(0 0 22px rgba(224, 176, 112, 0.4));
}
.continue-hint svg { display: block; width: 100%; height: 100%; }
.continue-hint.visible {
	opacity: 1;
	animation: hint-float 2.4s ease-in-out infinite;
}
@keyframes hint-float {
	0%, 100% { transform: translate(-50%, 0);   opacity: 0.6; }
	50%      { transform: translate(-50%, 7px); opacity: 1;    }
}
/* Mobile variant — chevron is right-anchored inside the prose corner,
 * so no translateX(-50%) baseline; just bob the Y value. */
@keyframes hint-float-corner {
	0%, 100% { transform: translateY(0);   opacity: 0.6; }
	50%      { transform: translateY(5px); opacity: 1;    }
}

/* ----- choice panel: upper-third, centered ----- */

.choices {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	top: 12%;
	max-height: 30%;
	min-width: 360px;
	max-width: 600px;
	display: none;
	flex-direction: column;
	gap: 12px;
	padding: 18px 24px;
	background: rgba(11, 11, 18, 0.7);
	border-radius: 12px;
}
.choices.visible { display: flex; }

.choice {
	font-family: inherit;
	font-size: 20px;
	color: #f5ebd2;
	background: transparent;
	border: none;
	text-align: left;
	padding: 8px 12px;
	cursor: pointer;
	border-radius: 6px;
	min-height: 44px;
	opacity: 0;
	animation: choice-fade-in 0.4s ease-out forwards;
}
.choice:hover, .choice:focus {
	background: rgba(245, 235, 210, 0.08);
	outline: none;
}
@keyframes choice-fade-in {
	from { opacity: 0; transform: translateY(4px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* ----- settings menu ----- */

.settings-btn {
	position: fixed;
	top: 12px;
	right: 12px;
	width: 36px;
	height: 36px;
	border: none;
	background: transparent;
	cursor: pointer;
	z-index: 50;
	padding: 0;
	color: rgba(240, 225, 195, 0.78);
	transition: color 0.2s ease;
}
.settings-btn:hover { color: #fbf2d4; }
.settings-btn::before {
	content: '';
	display: block;
	width: 100%;
	height: 100%;
	background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='3'/><path d='M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z'/></svg>");
	background-size: contain;
	background-repeat: no-repeat;
	background-position: center;
	color: inherit;
}

.settings-panel {
	position: fixed;
	top: 56px;
	right: 12px;
	background: rgba(11, 11, 18, 0.92);
	border-radius: 12px;
	padding: 18px;
	display: flex;
	flex-direction: column;
	gap: 4px;
	min-width: 220px;
	max-height: 85vh;
	overflow-y: auto;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
	z-index: 50;
}
.settings-panel[hidden] { display: none; }

.settings-heading {
	font-size: 18px;
	color: rgba(245, 230, 200, 1);
	margin-bottom: 8px;
}

.speed-btn,
.size-btn,
.music-btn {
	font-family: inherit;
	font-size: 18px;
	color: rgba(240, 225, 195, 0.85);
	background: transparent;
	border: none;
	text-align: left;
	padding: 6px 10px 6px 24px;
	cursor: pointer;
	border-radius: 4px;
	min-height: 36px;
	position: relative;
}
.speed-btn:hover,
.size-btn:hover,
.music-btn:hover { color: #fbf2d4; background: rgba(245, 235, 210, 0.05); }
.speed-btn.current::before,
.size-btn.current::before,
.music-btn.current::before {
	content: '•';
	position: absolute;
	left: 8px;
	color: #fbf2d4;
}

.settings-divider {
	height: 1px;
	background: rgba(245, 235, 210, 0.15);
	margin: 10px 0 6px 0;
}

/* ----- portrait orientation prompt ----- */

.rotate-prompt {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 999;
	align-items: center;
	justify-content: center;
	background: #000;
	color: rgba(245, 235, 210, 0.92);
	font-size: 20px;
	text-align: center;
	padding: 2rem;
}
@media (orientation: portrait) and (max-aspect-ratio: 1/1) {
	.rotate-prompt { display: flex; }
}

/* ----- dev panel (backtick toggles) -----
 * Hidden in normal play. Lists every bg tag in story.json so testing
 * a specific scene doesn't require play-through. */
.dev-panel {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	background: rgba(11, 11, 18, 0.97);
	border: 1px solid rgba(245, 235, 210, 0.18);
	border-radius: 8px;
	padding: 16px;
	width: min(440px, 90vw);
	max-height: 80vh;
	display: flex;
	flex-direction: column;
	z-index: 1000;
	font-family: 'Vollkorn', Georgia, serif;
	color: rgba(245, 235, 210, 0.92);
}
.dev-panel[hidden] { display: none; }
.dev-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 12px;
	font-size: 16px;
	letter-spacing: 0.04em;
}
.dev-close {
	background: transparent;
	border: none;
	color: rgba(245, 235, 210, 0.75);
	font-size: 24px;
	line-height: 1;
	padding: 0 8px;
	cursor: pointer;
}
.dev-close:hover { color: #fbf2d4; }
.dev-search {
	background: rgba(11, 11, 18, 0.5);
	border: 1px solid rgba(245, 235, 210, 0.18);
	color: rgba(245, 235, 210, 0.92);
	padding: 8px 10px;
	border-radius: 4px;
	font-family: ui-monospace, Menlo, monospace;
	font-size: 14px;
	margin-bottom: 10px;
	outline: none;
}
.dev-search:focus { border-color: rgba(245, 235, 210, 0.45); }
.dev-list {
	overflow-y: auto;
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-height: 60px;
}
.dev-item {
	background: transparent;
	border: none;
	color: rgba(245, 235, 210, 0.85);
	text-align: left;
	padding: 7px 10px;
	font-family: ui-monospace, Menlo, monospace;
	font-size: 13px;
	cursor: pointer;
	border-radius: 4px;
}
.dev-item:hover { background: rgba(245, 235, 210, 0.08); color: #fbf2d4; }
.dev-footer {
	margin-top: 10px;
	padding-top: 10px;
	border-top: 1px solid rgba(245, 235, 210, 0.1);
	font-size: 11px;
	color: rgba(245, 235, 210, 0.5);
	letter-spacing: 0.02em;
}
.dev-footer code {
	background: rgba(245, 235, 210, 0.08);
	padding: 1px 4px;
	border-radius: 3px;
}

/* ----- mobile / small-screen layout -----
 *
 * The desktop layout assumes ~1000px+ horizontal room; on phones (in
 * landscape too — iPhone Pro Max landscape is ~932×430) the panel
 * margins waste real estate and the user-chosen font sizes (28–42)
 * get visually huge. Tighten margins, cap the rendered font size at
 * something readable, and make the settings panel reachable inside
 * a small viewport. The user's chosen size is still respected up to
 * the cap, so the Text size buttons remain meaningful. */

@media (max-width: 700px), (max-height: 500px) {
	/* In-game prose panel + chrome.
	 *
	 * env(safe-area-inset-*) keeps the panel clear of the iPhone
	 * camera island / notch in landscape (where the island sits on
	 * one side, depending on rotation). The chevron moves into the
	 * bottom-right corner so the panel itself can be ~46px taller. */
	.prose {
		left: max(14px, env(safe-area-inset-left));
		right: max(14px, env(safe-area-inset-right));
		bottom: 14px;
		top: 32%;
		padding: 22px 18px 28px 18px;
		border-radius: 8px;
	}
	.prose-content {
		/* Scale the user's chosen size proportionally instead of
		   capping. min(..., 22px) flattened all four presets on phones
		   to the same 22px, so the Text size buttons did nothing. At
		   0.6× the four desktop presets (28/32/36/42) become
		   ~17/19/22/25 on mobile — meaningful range, default still
		   reads at the previous cap. */
		font-size: calc(var(--prose-font-size, 36px) * 0.6);
		line-height: 1.4;
	}
	.continue-hint {
		left: auto;
		right: max(24px, calc(env(safe-area-inset-right) + 10px));
		bottom: 18px;
		width: 36px;
		height: 18px;
		transform: none;
	}
	.continue-hint.visible {
		animation: hint-float-corner 2.4s ease-in-out infinite;
	}
	.choices {
		left: max(12px, env(safe-area-inset-left));
		right: max(12px, env(safe-area-inset-right));
		transform: none;
		min-width: 0;
		max-width: none;
		top: 8%;
	}
	.settings-panel {
		/* Anchor both top AND bottom so the panel's height is fully
		   constrained inside the viewport. Without a hard bottom edge,
		   iOS rubber-bands past the screen and snaps back, which is
		   why the Music section was unreachable: it was visible during
		   the drag but settled off-screen on release. */
		top: 50px;
		right: 8px;
		bottom: 8px;
		max-height: none;
		max-width: calc(100vw - 16px);
		min-width: 0;
	}
	/* Chapter title eyebrow — keep clear of the iPhone camera island
	 * (left or right depending on landscape rotation) and the top
	 * notch in portrait, plus scale down so it doesn't dominate the
	 * smaller viewport. */
	.chapter-title {
		padding:
			max(18px, env(safe-area-inset-top))
			max(28px, calc(env(safe-area-inset-right) + 20px))
			18px
			max(28px, calc(env(safe-area-inset-left) + 20px));
	}
	.chapter-number {
		font-size: 13px;
		letter-spacing: 0.18em;
		margin-bottom: 6px;
	}
	.chapter-name {
		font-size: 24px;
		line-height: 1.1;
	}

	/* Title screen — desktop sizing assumes 1000px+ horizontal room
	 * and >700px vertical. On landscape phones (iPhone Pro Max ≈
	 * 932×430) the eyebrow letter-spacing eats the line, the 74px
	 * Cormorant title pushes to both edges, and there's no vertical
	 * room for the tagline. Tighter scale all around, with a
	 * narrower content column so the layout still feels composed. */
	.title-screen {
		padding: clamp(18px, 5vh, 48px) 1rem 1rem 1rem;
	}
	.title-content {
		max-width: min(440px, 92vw);
	}
	.title-eyebrow {
		font-size: 11px;
		letter-spacing: 0.28em;
		margin-bottom: 0.7rem;
	}
	.title-main {
		font-size: clamp(28px, 6.5vw, 52px);
		margin-bottom: 0.8rem;
	}
	.title-tagline {
		font-size: clamp(13px, 1.7vw, 16px);
		line-height: 1.5;
	}
	.title-hint {
		bottom: 6%;
	}
	.title-hint-text {
		font-size: 13px;
		letter-spacing: 0.42em;
	}
}
