/* Pixel Conclave — retro pixel-art council chamber.
   Vanilla CSS, no frameworks. System font stack falls back gracefully; the
   pixel feel comes from chunky borders, hard shadows, and the canvas avatars.

   Theming: all colors are custom properties. Light is the default palette (on
   :root); [data-theme="dark"] overrides it. theme.js applies the saved choice
   before first paint. */

:root {
	--pixel: 4px;

	/* ---- Light theme (default): aged parchment & ink ---- */
	--bg: #ece0c4;
	--bg2: #ddcaa2;
	--glow: #f7ead0;
	--panel: #fbf5e6;
	--panel-edge: #c7ad78;
	--field: #fffdf4;
	--ink: #2c2440;
	--ink-dim: #6a5c46;
	--gold: #a06a16;
	--violet: #6c34c0;
	--ok: #2f8f55;
	--err: #c23b34;
	--shadow: #b9a070;
	--btn-ink: #fff6e2;
	--title-glow: #a06a1622;
	--arbiter-bg1: #f6eccf;
	--arbiter-bg2: #efe2c2;
	/* Avatar frame interior stays dark in BOTH themes — the pixel-art portraits are
	   drawn against dark and wash out on parchment. Same value as dark mode so the
	   portraits look identical regardless of theme. */
	--avatar-bg: #0c0a18;
}

:root[data-theme="dark"] {
	/* ---- Dark theme: twilight violet chamber ---- */
	--bg: #0d0b1a;
	--bg2: #15112b;
	--glow: #2a1f55;
	--panel: #1d1838;
	--panel-edge: #322a5e;
	--field: #0c0a18;
	--ink: #e8e3ff;
	--ink-dim: #9c93c9;
	--gold: #ffcf5c;
	--violet: #b98cff;
	--ok: #6ee7a0;
	--err: #ff7a8a;
	--shadow: #05040c;
	--btn-ink: #1a1030;
	--title-glow: #ffcf5c44;
	--arbiter-bg1: #241a47;
	--arbiter-bg2: #1a1436;
	--avatar-bg: #0c0a18;
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	padding: 0;
	background: var(--bg);
	color: var(--ink);
	font-family: "Courier New", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
	font-size: 16px;
	line-height: 1.55;
	min-height: 100%;
}

body {
	background:
		radial-gradient(circle at 50% -10%, var(--glow) 0%, transparent 55%),
		linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
	background-attachment: fixed;
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	image-rendering: pixelated;
}

/* Faint starfield — only in the dark chamber. */
.stars {
	position: fixed;
	inset: 0;
	z-index: 0;
	pointer-events: none;
	display: none;
	background-image:
		radial-gradient(1px 1px at 20% 30%, #fff6 0, transparent 100%),
		radial-gradient(1px 1px at 70% 20%, #fff4 0, transparent 100%),
		radial-gradient(1px 1px at 40% 70%, #fff5 0, transparent 100%),
		radial-gradient(1px 1px at 85% 60%, #fff3 0, transparent 100%),
		radial-gradient(1px 1px at 10% 80%, #fff4 0, transparent 100%),
		radial-gradient(1px 1px at 55% 45%, #fff3 0, transparent 100%);
}
[data-theme="dark"] .stars { display: block; }

.masthead, main, .footer { position: relative; z-index: 1; }

/* ---- Theme toggle ---- */
.theme-toggle {
	position: fixed;
	top: 0.9rem;
	right: 0.9rem;
	z-index: 3;
	font: inherit;
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--ink);
	background: var(--panel);
	border: 3px solid var(--panel-edge);
	box-shadow: var(--pixel) var(--pixel) 0 var(--shadow);
	padding: 0.4rem 0.6rem;
	cursor: pointer;
}
.theme-toggle::before { content: "☾ Dark"; }
[data-theme="dark"] .theme-toggle::before { content: "☀ Light"; }
.theme-toggle:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--shadow); }
.theme-toggle:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }

/* ---- Masthead ---- */
.masthead {
	text-align: center;
	padding: 2.4rem 1rem 1rem;
}
.title {
	margin: 0;
	font-weight: 800;
	letter-spacing: 0.12em;
	font-size: clamp(1.8rem, 6vw, 3.2rem);
	color: var(--gold);
	text-shadow:
		var(--pixel) var(--pixel) 0 var(--shadow),
		0 0 18px var(--title-glow);
}
.tagline {
	margin: 0.6rem auto 0;
	max-width: 46ch;
	color: var(--ink-dim);
	font-size: 0.95rem;
}

main {
	flex: 1;
	width: min(960px, 92vw);
	margin: 0 auto;
	padding: 1rem 0 3rem;
}

/* ---- The Roster: who sits the Council ---- */
.roster {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 1.1rem;
	margin-bottom: 1.6rem;
}
.roster-member {
	display: flex;
	flex-direction: column;
	align-items: center;
	width: 96px;
	text-align: center;
	opacity: 1; /* "popped" at rest — full strength before any inquiry */
	transition: opacity 0.25s, transform 0.25s;
}
.roster-member.active { transform: translateY(-3px); }
/* Dim non-active members only while a session is underway (set on the roster). */
.roster.session .roster-member { opacity: 0.5; }
.roster.session .roster-member.active { opacity: 1; }
.roster.session .roster-member.spoken { opacity: 0.85; }
.roster-avatar {
	width: 52px;
	height: 52px;
	image-rendering: pixelated;
	border: var(--pixel) solid var(--panel-edge);
	box-shadow: 3px 3px 0 var(--shadow);
	background: var(--avatar-bg);
}
.roster-member.active .roster-avatar { border-color: var(--gold); }
.roster-member.spoken .roster-avatar { border-color: var(--ok); }
.roster-name {
	margin-top: 0.35rem;
	font-size: 0.66rem;
	font-weight: 700;
	line-height: 1.15;
	color: var(--ink-dim);
}
.roster-member.active .roster-name { color: var(--ink); }
.roster-lens {
	margin-top: 0.15rem;
	font-size: 0.6rem;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--violet);
	opacity: 0.85;
}

/* ---- The Log: JRPG dialogue boxes, one speaker at a time ---- */
.log { display: flex; flex-direction: column; gap: 1.1rem; }

.summoning {
	text-align: center;
	color: var(--ink-dim);
	font-size: 0.85rem;
	padding: 1rem;
	font-style: italic;
}
.summoning::after {
	content: "";
	animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.line {
	display: flex;
	gap: 0.8rem;
	align-items: flex-start;
	/* Visible by default; the animation only adds a slide-in. This must NOT rely
	   on the animation to reach opacity 1, or the global prefers-reduced-motion
	   rule (animation: none) would leave boxes permanently invisible. */
	animation: linein 0.28s ease both;
}
.line.right { flex-direction: row-reverse; }
@keyframes linein {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: none; }
}

.portrait {
	width: 64px;
	height: 64px;
	flex: none;
	image-rendering: pixelated;
	border: var(--pixel) solid var(--panel-edge);
	box-shadow: 3px 3px 0 var(--shadow);
	background: var(--avatar-bg);
}
/* Sprite portraits (transparent art) are letterboxed within the frame so tall
   art like the Arbiter isn't distorted; the themed --avatar-bg fills behind. */
.portrait.sprite, .roster-avatar.sprite { object-fit: contain; }
/* The Arbiter's art is a tall head+hat (64×81); give it a taller frame so it
   shows in full rather than shrinking to fit a square. */
.line.arbiter .portrait {
	align-self: center;
	width: 72px;
	height: 92px;
}
.line.speaking .portrait { border-color: var(--gold); }
.line.done .portrait { border-color: var(--ok); }
.line.failed .portrait { border-color: var(--err); }

.bubble {
	position: relative;
	flex: 1;
	min-width: 0;
	max-width: 46rem;
	background: var(--panel);
	border: var(--pixel) solid var(--panel-edge);
	box-shadow: var(--pixel) var(--pixel) 0 var(--shadow);
	padding: 0.7rem 0.9rem;
}
.line.speaking .bubble { border-color: var(--gold); }
.line.done .bubble { border-color: var(--ok); }
.line.failed .bubble { border-color: var(--err); }

/* Little pixel beak pointing at the portrait. */
.bubble::before {
	content: "";
	position: absolute;
	top: 18px;
	width: 0; height: 0;
	border: 8px solid transparent;
}
.line:not(.right) .bubble::before {
	left: calc(-8px - var(--pixel));
	border-right-color: var(--panel-edge);
}
.line.right .bubble::before {
	right: calc(-8px - var(--pixel));
	border-left-color: var(--panel-edge);
}

.nameplate {
	font-weight: 700;
	font-size: 0.92rem;
	color: var(--gold);
	margin-bottom: 0.35rem;
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0.5rem;
}
.nameplate .role {
	font-weight: 400;
	font-size: 0.66rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--ink-dim);
}
.speech {
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	font-size: 0.95rem;
	color: var(--ink);
}
.speech.error { color: var(--err); font-style: italic; }

/* Rendered markdown inside a testimony / the Edict. */
.speech p { margin: 0 0 0.6rem; }
.speech p:last-child { margin-bottom: 0; }
.speech strong { font-weight: 700; color: var(--gold); }
.line.arbiter .speech strong { color: var(--violet); }
.speech em { font-style: italic; }
.speech code {
	font-size: 0.85em;
	background: var(--field);
	border: 1px solid var(--panel-edge);
	padding: 0 0.25rem;
}
.speech h3, .speech h4, .speech h5, .speech h6 {
	margin: 0.7rem 0 0.3rem;
	font-size: 0.95rem;
	letter-spacing: 0.02em;
	color: var(--gold);
}
.line.arbiter .speech h3, .line.arbiter .speech h4, .line.arbiter .speech h5, .line.arbiter .speech h6 {
	color: var(--violet);
}
.speech ul, .speech ol { margin: 0.3rem 0 0.6rem; padding-left: 1.3rem; }
.speech li { margin: 0.15rem 0; }
.speech li::marker { color: var(--gold); }
.line.arbiter .speech li::marker { color: var(--violet); }

/* Blinking caret while a box is actively printing or awaiting tokens. */
.line.speaking .speech::after {
	content: "▍";
	color: var(--gold);
	animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* ---- The Arbiter's box: the Edict ---- */
.line.arbiter { flex-direction: column; align-items: stretch; }
.edict-banner {
	text-align: center;
	color: var(--violet);
	letter-spacing: 0.2em;
	font-weight: 700;
	margin: 0.4rem 0 0.2rem;
	text-transform: uppercase;
	font-size: 0.8rem;
}
.line.arbiter .bubble {
	max-width: none;
	border-color: var(--violet);
	box-shadow: var(--pixel) var(--pixel) 0 var(--shadow), 0 0 24px #b98cff33;
	background: linear-gradient(180deg, var(--arbiter-bg1), var(--arbiter-bg2));
}
.line.arbiter .bubble::before { display: none; }
.line.arbiter .nameplate { color: var(--violet); justify-content: center; }
.line.arbiter .speech { font-size: 1rem; line-height: 1.65; }
.line.arbiter.done .bubble { border-color: var(--violet); }

/* ---- Petition form ---- */
.petition {
	margin-top: 1.8rem;
	background: var(--panel);
	border: var(--pixel) solid var(--panel-edge);
	box-shadow: var(--pixel) var(--pixel) 0 var(--shadow);
	padding: 1rem;
}
textarea {
	width: 100%;
	resize: vertical;
	background: var(--field);
	color: var(--ink);
	border: 3px solid var(--panel-edge);
	padding: 0.7rem;
	font: inherit;
	font-size: 0.95rem;
}
textarea:focus { outline: none; border-color: var(--gold); }

.examples {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	margin-top: 0.7rem;
}
.examples-label {
	color: var(--ink-dim);
	font-size: 0.72rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
}
.example {
	font: inherit;
	font-size: 0.75rem;
	font-weight: 600;
	letter-spacing: 0;
	text-transform: none;
	color: var(--ink);
	background: var(--field);
	border: 2px solid var(--panel-edge);
	box-shadow: 2px 2px 0 var(--shadow);
	padding: 0.3rem 0.6rem;
	cursor: pointer;
}
.example:hover { border-color: var(--gold); transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--shadow); }
.example:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--shadow); }

/* chips container is layout-transparent so chips flex within .examples */
.example-chips { display: contents; }

/* subtle icon-only reroll button (overrides the gold CTA button styling) */
button.reroll {
	background: transparent;
	box-shadow: none;
	color: var(--ink-dim);
	padding: 0.2rem 0.35rem;
	font-size: 0.95rem;
	line-height: 1;
}
button.reroll:hover { background: transparent; color: var(--gold); transform: none; box-shadow: none; }
button.reroll:active { transform: none; box-shadow: none; }

.petition-row {
	display: flex;
	align-items: center;
	gap: 1rem;
	margin-top: 0.7rem;
}
.hint { color: var(--ink-dim); font-size: 0.8rem; flex: 1; }
.hint.error { color: var(--err); }

button {
	font: inherit;
	font-weight: 700;
	letter-spacing: 0.04em;
	color: var(--btn-ink);
	background: var(--gold);
	border: none;
	box-shadow: var(--pixel) var(--pixel) 0 var(--shadow);
	padding: 0.7rem 1.2rem;
	cursor: pointer;
	text-transform: uppercase;
}
button:hover:not(:disabled) { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--shadow); }
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
button:disabled { background: var(--panel-edge); color: var(--ink-dim); cursor: not-allowed; box-shadow: var(--pixel) var(--pixel) 0 var(--shadow); }

.footer {
	text-align: center;
	padding: 1.2rem;
	color: var(--ink-dim);
	font-size: 0.72rem;
}
.footer span { display: block; }
.footer .credits { margin-top: 0.3rem; font-size: 0.66rem; opacity: 0.85; }
.footer a { color: var(--violet); }

.sr-only {
	position: absolute;
	width: 1px; height: 1px;
	padding: 0; margin: -1px;
	overflow: hidden; clip: rect(0,0,0,0);
	white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
	* { animation: none !important; transition: none !important; }
}
