/* CSS custom properties. The --color-* set is also the room-theme
   contract: shared components (comment thread, forms, buttons,
   pagination, reactions) take their colors only from these properties,
   so a page theme restyles every shared component by overriding the
   properties inside its page-scope class — never by forking component
   rules. The nav, footer, and flash messages render outside any page
   scope and keep the base look. */
:root {
	--color-bg: #f0eeeb;
	--color-bg-gradient: linear-gradient(145deg, #f0eeeb 0%, #e6e2dd 100%);
	--color-surface: #fff;
	--color-nav: #1e1e1e;
	--color-nav-text: #888;
	--color-nav-text-active: #f0f0f0;
	--color-text: #1a1a1a;
	--color-text-muted: #777;
	--color-link: #001329;
	--color-link-hover: #225942;
	--color-border: rgba(0, 0, 0, 0.08);
	--color-post-border: #eee;
	--color-accent: #225942;
	--color-new: #e03030;
	/* Scheme-invariant: the missing dark-mode overrides are deliberate. */
	--color-danger: #c44;
	--color-danger-hover: #e55;
	/* Flash state palettes sit outside the --color-* contract and are
	   scheme-invariant: dark toast panels in light and dark mode alike. */
	--flash-success-bg: #1b3d2a;
	--flash-success-text: #a8d5b5;
	--flash-success-border: #2d6644;
	--flash-error-bg: #3d1b1b;
	--flash-error-text: #d5a8a8;
	--flash-error-border: #662d2d;
	--flash-warning-bg: #3d3419;
	--flash-warning-text: #d5caa8;
	--flash-warning-border: #66582d;
	--flash-info-bg: #193d3d;
	--flash-info-text: #a8d5d5;
	--flash-info-border: #2d6666;
	--shadow-card: 0 2px 20px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
	--radius-card: 14px;
	--radius-small: 6px;
	--font-stack: -apple-system, system-ui, sans-serif;
	--font-mono: ui-monospace, "Cascadia Code", "Fira Code", monospace;
	--font-display: "Fraunces", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
	:root {
		color-scheme: dark;
		--color-bg: #141210;
		--color-bg-gradient: #141210;
		--color-surface: #1c1916;
		--color-nav: #151210;
		--color-nav-text: #6a5f50;
		--color-nav-text-active: #d4a853;
		--color-text: #e8dcc8;
		--color-text-muted: #8a7e6e;
		--color-link: #d4a853;
		--color-link-hover: #e8c070;
		--color-border: #302a22;
		--color-post-border: #2a2420;
		--color-accent: #d4a853;
		--color-new: #d4a853;
		--shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4), 0 0 0 1px #302a22;
	}
}

/* Fraunces — characterful display serif, self-hosted, exposed as
   --font-display. */
@font-face {
	font-family: "Fraunces";
	font-style: normal;
	font-weight: 400 700;
	font-display: swap;
	src: url("../font/fraunces-latin.5d2835174326.woff2") format("woff2");
	unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
		U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
		U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
	font-family: "Fraunces";
	font-style: normal;
	font-weight: 400 700;
	font-display: swap;
	src: url("../font/fraunces-latin-ext.3592119408ee.woff2") format("woff2");
	unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
		U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
		U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
		U+A720-A7FF;
}

/* Minimal reset */
*,
*::before,
*::after {
	box-sizing: border-box;
}

html {
	scrollbar-gutter: stable;
	scrollbar-color: var(--color-post-border) transparent;
	scrollbar-width: thin;
}

body {
	margin: 0;
	font-family: "Twemoji Country Flags", var(--font-stack);
	background: var(--color-bg-gradient);
	color: var(--color-text);
	padding: 0;
}

/* Layout */
#wrapper {
	max-width: 42em;
	margin: 0 auto;
	background: var(--color-surface);
}

main {
	padding: 1.5em;
}

/* Nav */
nav {
	background: var(--color-nav);
}

nav ul {
	list-style: none;
	margin: 0;
	padding: 0.75em 1em;
	display: flex;
	flex-wrap: wrap;
	gap: 0.25em;
}

nav li {
	display: block;
}

nav a,
nav a:visited {
	color: var(--color-nav-text);
	text-decoration: none;
	padding: 0.35em 0.6em;
	border-radius: var(--radius-small);
	display: inline-block;
	text-transform: uppercase;
	letter-spacing: 1px;
	font-size: 0.75rem;
}

nav a:hover,
nav button:hover {
	color: var(--color-nav-text-active);
}

nav a.active {
	color: var(--color-nav-text-active);
}

nav form {
	display: contents;
}

nav button {
	all: unset;
	color: var(--color-nav-text);
	cursor: pointer;
	padding: 0.35em 0.6em;
	border-radius: var(--radius-small);
	display: inline-block;
	text-transform: uppercase;
	letter-spacing: 1px;
	font-size: 0.75rem;
	font-family: var(--font-stack);
}

.icon {
	display: inline-block;
	width: 1em;
	height: 1em;
	background: currentColor;
	mask: var(--icon) center / contain no-repeat;
	-webkit-mask: var(--icon) center / contain no-repeat;
}

.icon-arrow-left {
	--icon: url("../vendor/lucide/arrow-left.76acdfafa973.svg");
}

.icon-calendar-days {
	--icon: url("../vendor/lucide/calendar-days.32065998d7e0.svg");
}

.icon-check-circle {
	--icon: url("../vendor/lucide/check-circle.4b83e1954ddb.svg");
}

.icon-circle-x {
	--icon: url("../vendor/lucide/circle-x.0712fc0d822a.svg");
}

.icon-file-text {
	--icon: url("../vendor/lucide/file-text.c42a3ba3b75d.svg");
}

.icon-key-round {
	--icon: url("../vendor/lucide/key-round.e97be1d2e304.svg");
}

.icon-lock {
	--icon: url("../vendor/lucide/lock.3b0362e088c1.svg");
}

.icon-log-in {
	--icon: url("../vendor/lucide/log-in.24b453d6e352.svg");
}

.icon-log-out {
	--icon: url("../vendor/lucide/log-out.e359d736d093.svg");
}

.icon-map-pin {
	--icon: url("../vendor/lucide/map-pin.9d6bd793e5f6.svg");
}

.icon-pencil {
	--icon: url("../vendor/lucide/pencil.2a5e6f70fd2d.svg");
}

.icon-reply {
	--icon: url("../vendor/lucide/reply.45bc64271c15.svg");
}

.icon-rotate-ccw {
	--icon: url("../vendor/lucide/rotate-ccw.b93ebf0a0659.svg");
}

.icon-send {
	--icon: url("../vendor/lucide/send.3a29252f3513.svg");
}

.icon-smile {
	--icon: url("../vendor/lucide/smile.4e14808d88bf.svg");
}

.icon-smile-plus {
	--icon: url("../vendor/lucide/smile-plus.4bb97d0f8c42.svg");
}

.icon-trash-2 {
	--icon: url("../vendor/lucide/trash-2.e7f85b7fbd55.svg");
}

.icon-user-round {
	--icon: url("../vendor/lucide/user-round.673bbc411a00.svg");
}

.icon-users {
	--icon: url("../vendor/lucide/users.0a3766bad1cb.svg");
}

nav a.nav-auth-control,
nav a.nav-auth-control:visited,
nav button.nav-auth-control {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2rem;
	height: 1.4rem;
	padding: 0;
	vertical-align: top;
}

.nav-auth-icon {
	width: 1rem;
	height: 1rem;
}

.section-hint {
	color: var(--color-new);
	font-weight: 700;
}

/* Footer */
footer {
	background: var(--color-nav);
	color: var(--color-nav-text);
	text-align: center;
	padding: 1.5em 0;
}

/* Links */
a,
a:visited {
	color: var(--color-link);
}

a:hover {
	color: var(--color-link-hover);
}

/* Focus */
:focus-visible {
	outline: 2px solid var(--color-accent);
	outline-offset: 2px;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
	letter-spacing: -0.3px;
}

/* Forms */
input,
select,
textarea,
button {
	font: inherit;
	border-radius: var(--radius-small);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="url"],
input[type="number"],
input[type="date"],
select,
textarea {
	display: block;
	width: 100%;
	padding: 0.5em 0.65em;
	border: 1px solid var(--color-post-border);
	background: var(--color-surface);
	color: var(--color-text);
}

input[type="text"]:focus-visible,
input[type="password"]:focus-visible,
input[type="email"]:focus-visible,
input[type="search"]:focus-visible,
input[type="url"]:focus-visible,
input[type="number"]:focus-visible,
input[type="date"]:focus-visible,
select:focus-visible,
textarea:focus-visible {
	outline: 2px solid var(--color-accent);
	outline-offset: -1px;
	border-color: var(--color-accent);
}

textarea {
	width: 100%;
	field-sizing: content;
	min-height: 3em;
	max-height: 16em;
	resize: vertical;
}

label {
	display: block;
	font-size: 0.9em;
	font-weight: 500;
	margin-top: 0.75em;
	margin-bottom: 0.25em;
}

form > .btn {
	margin-top: 0.75em;
}

.errorlist {
	margin: 0.25em 0;
	padding: 0;
	list-style: none;
	color: var(--color-new);
	font-size: 0.9em;
}

.form-help {
	margin-top: 0.25em;
	color: var(--color-text-muted);
	font-size: 0.85em;
}

.form-help ul {
	margin: 0;
	padding-left: 1.2em;
}

/* Button */
.btn {
	display: inline-block;
	padding: 0.45em 0.85em;
	border: 1px solid var(--color-border);
	border-radius: var(--radius-small);
	text-decoration: none;
	color: var(--color-link);
	background: transparent;
	cursor: pointer;
	min-height: 2.25em;
}

.btn:hover {
	border-color: var(--color-link-hover);
	color: var(--color-link-hover);
}

/* Flash messages */
.flash {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.75em 1em;
	margin: 0.5em 1em;
	border-radius: var(--radius-small);
	border: 1px solid var(--color-border);
	background: var(--color-surface);
}

.flash-success {
	background: var(--flash-success-bg);
	color: var(--flash-success-text);
	border-color: var(--flash-success-border);
}

.flash-error {
	background: var(--flash-error-bg);
	color: var(--flash-error-text);
	border-color: var(--flash-error-border);
}

.flash-warning {
	background: var(--flash-warning-bg);
	color: var(--flash-warning-text);
	border-color: var(--flash-warning-border);
}

.flash-info {
	background: var(--flash-info-bg);
	color: var(--flash-info-text);
	border-color: var(--flash-info-border);
}

.flash-close {
	background: none;
	border: none;
	cursor: pointer;
	font-size: 1.25em;
	line-height: 1;
	padding: 0 0.25em;
	color: inherit;
	opacity: 0.6;
}

.flash-close:hover {
	opacity: 1;
}

/* Avatar */
.avatar {
	width: 2.25em;
	height: 2.25em;
	border-radius: var(--radius-small);
	flex-shrink: 0;
}

/* Danger button (delete confirmations) */
.btn-danger {
	color: var(--color-danger);
	border-color: var(--color-danger);
}

.btn-danger:hover {
	color: var(--color-danger-hover);
	border-color: var(--color-danger-hover);
}

/* Comments */
.comment-new {
	display: inline-block;
	padding: 0.1em 0.45em;
	border: 1px solid color-mix(in srgb, var(--color-new) 55%, var(--color-border));
	border-radius: var(--radius-small);
	color: var(--color-new);
	font-size: 0.75em;
	font-weight: 700;
}

.comments-thread {
	display: grid;
	gap: 1em;
}

.comment-form textarea,
.comment-reply-form textarea {
	min-height: 5em;
}

.comment-reply-form textarea {
	min-height: 4em;
}

.comment-list,
.comment-replies {
	display: grid;
	gap: 0.75em;
	margin: 0;
	padding: 0;
	list-style: none;
}

.comment-list:empty {
	display: none;
}

.comment {
	padding-top: 0.85em;
	border-top: 1px solid color-mix(in srgb, var(--color-post-border) 72%, transparent);
}

.comment-reply {
	margin-left: 1.5em;
	padding-left: 0.75em;
	border-left: 2px solid color-mix(in srgb, var(--color-post-border) 72%, transparent);
}

.comment-body {
	display: flex;
	gap: 0.6em;
}

.comment-main {
	display: grid;
	gap: 0.35em;
	flex: 1;
	min-width: 0;
}

.comment-header {
	display: flex;
	align-items: baseline;
	gap: 0.5em;
	flex-wrap: wrap;
}

.comment-author {
	font-weight: 600;
	font-size: 0.9em;
}

.comment-time {
	color: var(--color-text-muted);
	font-size: 0.78em;
}

.comment-actions {
	display: inline-flex;
	align-items: center;
	gap: 0.35em;
	margin-left: auto;
	opacity: 0;
	transition: opacity 0.15s;
}

.comment:hover .comment-actions,
.comment:focus-within .comment-actions {
	opacity: 1;
}

.comment-actions a,
.comment-actions .reaction-add,
.comment-reply-toggle {
	appearance: none;
	-webkit-appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.25em;
	border: none;
	background: transparent;
	color: var(--color-text-muted);
	cursor: pointer;
	font: inherit;
	font-size: 0.85em;
	padding: 0.15em 0.25em;
	text-decoration: none;
}

.comment-actions a:hover,
.comment-actions .reaction-add:hover,
.comment-reply-toggle:hover {
	color: var(--color-link-hover);
}

.comment-content {
	color: var(--color-text-muted);
	font-size: 0.92em;
	line-height: 1.5;
	overflow-wrap: break-word;
}

.comment-content p {
	margin: 0.25em 0;
}

.comment-edited {
	color: var(--color-text-muted);
	font-size: 0.82em;
	font-style: italic;
}

.comment-replies,
.comment-reply-form {
	margin-top: 0.65em;
}

/* Form toolbar */
.form-toolbar {
	display: flex;
	align-items: center;
	gap: 0.5em;
	margin-top: 0.75em;
}

.form-toolbar .btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.4em;
	margin-top: 0;
}

.emoji-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 1rem;
	line-height: 1;
	min-width: 2.25em;
}

/* Emoji picker */
.emoji-picker-container {
	margin-top: 0.5em;
}

.emoji-picker-container emoji-picker {
	--border-color: var(--color-post-border);
	--background: var(--color-surface);
	--input-border-color: var(--color-post-border);
	--category-font-color: var(--color-text-muted);
	width: 100%;
	max-width: 22em;
}

/* Reactions */
.reaction-list {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4em;
	margin: 0.5em 0 0;
	padding: 0;
	list-style: none;
}

.reaction-list:empty {
	display: none;
}

.reaction-group {
	display: inline-flex;
	align-items: center;
	gap: 0.35em;
	padding: 0.15em 0.55em;
	border: 1px solid var(--color-post-border);
	border-radius: 999px;
	background: var(--color-surface);
	font-size: 0.85em;
	line-height: 1.4;
}

.reaction-emoji {
	font-size: 1.1em;
	line-height: 1;
}

.reaction-user {
	color: var(--color-text-muted);
}

.reaction-user-own {
	appearance: none;
	-webkit-appearance: none;
	background: none;
	border: none;
	padding: 0;
	font: inherit;
	color: var(--color-link);
	cursor: pointer;
}

.reaction-user-own:hover {
	color: var(--color-link-hover);
	text-decoration: line-through;
}

.reaction-popover {
	position: absolute;
	z-index: 20;
}

.reaction-popover.hidden {
	display: none;
}

.reaction-popover emoji-picker {
	--border-color: var(--color-post-border);
	--background: var(--color-surface);
	--input-border-color: var(--color-post-border);
	--category-font-color: var(--color-text-muted);
}

/* Pagination */
.pagination {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 0.5em;
	padding: 1em 0;
}

.pagination a,
.pagination a:visited {
	color: var(--color-text-muted);
	text-decoration: none;
	padding: 0.35em 0.5em;
	font-size: 0.9em;
}

.pagination a:hover {
	color: var(--color-link);
}

.pagination .current {
	color: var(--color-text-muted);
	font-size: 0.9em;
}

/* Members table */
.members-table {
	width: 100%;
	border-collapse: collapse;
}

.members-table th,
.members-table td {
	padding: 0.5em 0.75em;
	text-align: left;
}

.members-table tbody tr:nth-child(even) {
	background: rgba(128, 128, 128, 0.06);
}

/* Embed container: responsive 16:9 */
.embed-container {
	position: relative;
	padding-bottom: 56.25%;
	height: 0;
	overflow: hidden;
	margin: 0 0.5em;
}

.embed-container iframe,
.embed-container object,
.embed-container embed {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
}

/* Help table */
.help-table {
	width: 100%;
	border-collapse: collapse;
	font-family: var(--font-mono);
	font-size: 0.85em;
}

.help-table th,
.help-table td {
	padding: 0.5em 0.75em;
	text-align: left;
	border-bottom: 1px solid var(--color-border);
}

/* htmx transitions */
.htmx-request .btn[type="submit"] {
	opacity: 0.5;
	pointer-events: none;
}

@keyframes fade-in {
	from { opacity: 0; transform: translateY(-0.5em); }
	to { opacity: 1; transform: translateY(0); }
}

/* Utility */
.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;
}

.hidden {
	display: none;
}

/* Mobile */
@media (max-width: 767px) {
	nav ul {
		padding: 0.5em;
		gap: 0.15em;
		justify-content: center;
	}

	nav a,
	nav a:visited,
	nav button {
		padding: 0.5em 0.5em;
		font-size: 0.7rem;
	}

	main {
		padding: 1em;
	}

	/* Touch devices have no hover, so keep comment actions visible. */
	.comment-actions {
		opacity: 1;
	}

	/* Members table scroll */
	.members-table {
		display: block;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
	}

	/* Embed container full width */
	.embed-container {
		margin: 0;
	}
}

/* Desktop */
@media (min-width: 768px) {
	body {
		padding: 2em;
		background: var(--color-bg-gradient);
	}

	#wrapper {
		box-shadow: var(--shadow-card);
		border-radius: var(--radius-card);
	}

	nav {
		border-radius: var(--radius-card) var(--radius-card) 0 0;
	}

	footer {
		border-radius: 0 0 var(--radius-card) var(--radius-card);
	}

	.avatar {
		width: 2.5em;
		height: 2.5em;
	}
}
