:root {
	--retro-ink: #191919;
	--retro-muted: #555565;
	--retro-blue: #172f85;
	--retro-blue-bright: #294bb2;
	--retro-purple: #432178;
	--retro-line: #727272;
	--retro-black: #f0efe8;
	--retro-panel: rgba(235, 234, 226, 0.98);
	--retro-yellow: #765a00;
	--retro-link: #142a83;
	--retro-page: #d7dceb;
	--retro-page-image: none;
	--retro-sidebar: rgba(235, 233, 223, 0.98);
	--retro-sidebar-image: none;
	--retro-title: #151824;
	--retro-card-text: #171717;
	--retro-card-muted: #4f586d;
	--retro-nav-text: #171717;
	--retro-control-hover: rgba(39, 61, 143, 0.16);
	--retro-cookie: #ebe9df;
	--retro-frame-outer: #61759e;
	--retro-frame-mid: #a8b4cc;
	--retro-frame-inner: #354a73;
	--retro-frame-shadow: #c2cadb;
	--retro-divider: #8090b1;
	--retro-inset: #dfe4f0;
	--retro-well: rgba(36, 56, 111, 0.12);
	--retro-meta: #59647d;
	--retro-active-bg: #29488f;
	--retro-active-text: #fff;
	--retro-crossword-bg: linear-gradient(180deg, #d9deeb, #c8d0e3);
	--retro-crossword-reload-bg: #ebe4c6;
	--retro-crossword-reload-text: #4a3b10;
	--retro-crossword-button-bg: #294b9f;
}

html.dark-theme {
	--retro-ink: #f0f0f0;
	--retro-muted: #b8b8c1;
	--retro-black: #020305;
	--retro-panel: rgba(0, 0, 0, 0.92);
	--retro-link: #d5d5f0;
	--retro-page: #02030b;
	--retro-page-image: url('/public/images/retro-starfield.png');
	--retro-sidebar: #020817;
	--retro-sidebar-image: url('/public/images/retro-starfield.png');
	--retro-title: #fff;
	--retro-card-text: #eee;
	--retro-card-muted: #c6c6ca;
	--retro-nav-text: #f4f4f4;
	--retro-control-hover: rgba(44, 66, 151, 0.45);
	--retro-cookie: #06070d;
	--retro-yellow: #ffe800;
	--retro-frame-outer: #34509a;
	--retro-frame-mid: #182b61;
	--retro-frame-inner: #07132f;
	--retro-frame-shadow: #01040f;
	--retro-divider: #253b79;
	--retro-inset: #0d1838;
	--retro-well: rgba(16, 33, 82, 0.72);
	--retro-meta: #a0a7cf;
	--retro-active-bg: rgba(39, 61, 143, 0.55);
	--retro-active-text: #ffe800;
	--retro-crossword-bg: linear-gradient(165deg, rgba(32, 28, 93, 0.35), rgba(3, 4, 20, 0.55));
	--retro-crossword-reload-bg: #17152f;
	--retro-crossword-reload-text: #eee;
	--retro-crossword-button-bg: #263f9e;
}

html,
body {
	min-height: 100%;
}

html {
	background-color: var(--retro-page);
	background-image: var(--retro-page-image);
	background-position: center top;
	background-repeat: repeat-y;
	background-size: cover;
}

html.dark-theme,
html.dark-theme body {
	background-color: #020817;
	background-image: url('/public/images/retro-starfield.png');
	background-position: center top;
	background-repeat: repeat-y;
	background-size: cover;
	scrollbar-color: #314a98 #020817;
}

html.dark-theme ::-webkit-scrollbar {
	width: 12px;
	height: 8px;
}

html.dark-theme ::-webkit-scrollbar-track {
	background: #020817;
}

html.dark-theme ::-webkit-scrollbar-thumb {
	background: #314a98;
	border: 2px solid #020817;
}

body {
	font-family: 'Times New Roman', Times, serif;
	font-size: 16px;
	line-height: 1.25;
	color: var(--retro-ink);
	background-color: var(--retro-page);
	background-image: var(--retro-page-image);
	background-position: center top;
	background-repeat: repeat-y;
	background-size: cover;
	background-attachment: fixed;
}

body {
	margin-left: 302px;
}

main {
	max-width: none;
	width: auto;
	padding: 16px 42px 36px 18px;
}

a,
html.dark-theme a {
	color: var(--retro-link);
	text-decoration: none;
}

a:hover {
	color: #0c1f68;
	text-decoration: underline;
}

html.dark-theme a:hover {
	color: #fff;
}

*:focus-visible {
	outline: 2px solid var(--retro-yellow) !important;
	outline-offset: 2px;
}

.sidebar {
	left: 8px;
	top: 7px;
	width: 276px;
	height: calc(100vh - 14px);
	padding: 0 5px 6px;
	background-color: var(--retro-sidebar);
	background-image: var(--retro-sidebar-image);
	background-position: 15% 30%;
	background-size: 880px auto;
	border: 2px solid var(--retro-frame-outer);
	box-shadow: inset 0 0 0 1px var(--retro-frame-inner), inset 0 0 0 3px var(--retro-frame-mid), 0 0 0 1px var(--retro-frame-shadow);
	color: var(--retro-ink);
	font-family: 'Times New Roman', Times, serif;
	font-size: 16px;
	overflow-y: auto;
}

html.dark-theme .sidebar {
	background-color: #020817;
	background-image:
		linear-gradient(rgba(0, 8, 31, 0.18), rgba(0, 8, 31, 0.18)),
		url('/public/images/retro-starfield.png');
	background-position: center top;
	background-size: auto, 920px auto;
}

.sidebar-header {
	padding: 16px 22px 14px;
	background: transparent;
	border-bottom: 2px solid var(--retro-frame-outer);
	box-shadow: 0 1px 0 var(--retro-frame-inner);
}

html.dark-theme .sidebar-header,
html.dark-theme .nav,
html.dark-theme .sidebar-footer {
	background-color: transparent;
	background-image: none;
}

.sidebar-branding {
	gap: 8px;
}

.site-title {
	font-family: 'Times New Roman', Times, serif;
	font-size: 2.2rem;
	font-style: italic;
	font-weight: 700;
	line-height: 1;
	letter-spacing: -0.05em;
	color: var(--retro-title) !important;
	text-shadow: none;
}

.site-subtitle {
	font-size: 1.05rem;
	font-style: italic;
	font-weight: 700;
	color: var(--retro-yellow) !important;
	white-space: nowrap;
}

.progress-text {
	font-size: 1rem;
	color: var(--retro-ink) !important;
	white-space: nowrap;
}

.sidebar-block {
	margin: 0;
}

.sidebar-section-label {
	margin: 0 -1px;
	padding: 4px 14px 3px;
	background: linear-gradient(#2d4db6, #13236c 55%, #0c174a);
	border-top: 1px solid var(--retro-frame-mid);
	border-bottom: 1px solid #050715;
	box-shadow: inset 0 1px 0 #536ad0, 0 1px 0 var(--retro-frame-inner);
	color: #fff;
	font-size: 1.08rem;
	font-weight: 700;
	letter-spacing: 0.02em;
	line-height: 1.1;
	text-shadow: 1px 1px 0 #111;
}

.nav {
	flex: none;
	padding: 8px 0 12px;
	background: transparent;
}

.nav a,
html.dark-theme .nav a {
	position: relative;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 4px 12px;
	color: var(--retro-nav-text);
	font-size: 1.08rem;
	line-height: 1.18;
	text-shadow: none;
}

.nav a span {
	display: inline-block;
}

.nav a:hover,
.nav a.active {
	background: var(--retro-active-bg);
	color: var(--retro-active-text);
	text-decoration: none;
}

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

html.dark-theme .nav a:hover,
html.dark-theme .nav a.active {
	background: var(--retro-active-bg);
	color: var(--retro-active-text);
}

.nav li.blog_nested a {
	margin-left: 28px;
	padding-left: 10px;
	font-size: 1rem;
}

.nav li.blog_nested a::before {
	content: '├';
	position: absolute;
	left: -18px;
	color: var(--retro-frame-mid);
}

.nav li.blog_nested:last-of-type a::before {
	content: '└';
}

.sidebar-footer {
	padding: 0;
	background: transparent;
	gap: 0;
}

.sidebar-controls {
	justify-content: stretch;
	padding: 8px 10px 9px;
}

.toggles {
	align-items: stretch;
	gap: 5px;
	text-align: left;
	width: 100%;
}

.sidebar-toggle,
.sidebar-action,
html.dark-theme .sidebar-toggle,
html.dark-theme .sidebar-action {
	justify-content: flex-start;
	gap: 7px;
	padding: 2px 0;
	border: 0;
	background: transparent;
	color: var(--retro-nav-text);
	font-family: 'Times New Roman', Times, serif;
	font-size: 1rem;
	line-height: 1.2;
	text-align: left;
}

.sidebar-toggle input[type='checkbox'] {
	order: 2;
	margin-left: auto;
	width: 18px;
	height: 18px;
	accent-color: #fff;
}

.sidebar-toggle-icon {
	width: 22px;
	font-size: 1rem;
	text-align: center;
}

.sidebar-action:hover,
.sidebar-toggle:hover {
	background: var(--retro-control-hover);
	color: var(--retro-yellow);
	text-decoration: none;
}

.badges {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 5px;
	padding: 8px 8px 10px;
	background: var(--retro-well);
}

.badges img {
	width: 100%;
	height: 43px;
	object-fit: fill;
	background: var(--retro-inset);
	border: 1px solid var(--retro-frame-mid);
}

.cookie-banner,
html.dark-theme .cookie-banner {
	right: 24px;
	bottom: 24px;
	background: var(--retro-cookie);
	border: 2px solid var(--retro-frame-outer);
	box-shadow: 0 0 0 1px var(--retro-frame-inner);
	color: var(--retro-ink);
}

.cookie-banner-button,
html.dark-theme .cookie-banner-button {
	border: 1px solid var(--retro-frame-mid);
	background: #1b2e7d;
	color: #fff;
}

.home {
	max-width: none;
	margin: 0;
	padding: 0 0 26px;
	gap: 18px;
}

.home-header {
	gap: 8px;
	min-height: 0;
	padding: 20px 22px 8px;
}

.home-title {
	margin: 0;
	font-size: clamp(3.2rem, 4.4vw, 4.4rem);
	font-style: italic;
	font-weight: 700;
	line-height: 0.95;
	color: var(--retro-title);
	text-shadow: none;
}

.home-subtitle {
	margin: 0;
	font-size: clamp(1.25rem, 1.7vw, 1.7rem);
	font-style: italic;
	font-weight: 700;
	color: var(--retro-yellow) !important;
	text-shadow: none;
}

html.dark-theme .site-title,
html.dark-theme .nav a {
	text-shadow: 1px 1px 0 #000;
}

html.dark-theme .home-title {
	text-shadow: 2px 2px 0 #101010;
}

html.dark-theme .home-subtitle {
	text-shadow: 1px 1px 0 #111;
}

.home-grid {
	display: grid;
	grid-template-columns: 1.22fr 1fr 1.17fr;
	grid-template-rows: 428px auto;
	gap: 16px;
}

.home-card,
html.dark-theme .home-card {
	min-width: 0;
	min-height: 0;
	padding: 0 7px 8px;
	background: var(--retro-panel);
	border: 2px solid var(--retro-frame-outer);
	box-shadow: inset 0 0 0 1px var(--retro-frame-inner), inset 0 0 0 3px var(--retro-frame-mid), 0 0 0 1px var(--retro-frame-shadow), 3px 3px 0 var(--retro-frame-shadow);
	gap: 0;
	overflow: hidden;
}

.home-card--wide {
	grid-column: 1 / -1;
	grid-row: 2;
	min-height: 308px;
}

.home-card-header {
	min-height: 40px;
	margin: 0 -1px 6px;
	padding: 5px 12px 4px;
	background: linear-gradient(#2f4eb5, #132467 58%, #0b133d);
	border: 1px solid #10193d;
	box-shadow: inset 0 1px 0 #667bd6, 0 1px 0 var(--retro-frame-mid);
}

.home-card--wide .home-card-header {
	background: linear-gradient(#60349a, #32145e 58%, #1c0b3a);
	box-shadow: inset 0 1px 0 #9169be, 0 1px 0 var(--retro-frame-mid);
}

.home-card-title {
	font-size: 1.2rem;
	font-weight: 700;
	color: #fff !important;
	letter-spacing: 0.02em;
	text-shadow: 1px 1px 0 #111;
}

.home-card-link,
html.dark-theme .home-card-link {
	font-size: 1rem;
	color: #e6ebff;
	text-decoration: underline;
}

.home-list {
	gap: 0;
	overflow: hidden;
}

.home-list-item {
	gap: 4px;
	padding: 7px 30px 8px;
	border-left: 0;
	border-bottom: 1px dotted var(--retro-divider);
}

.home-list-item:last-child {
	border-bottom: 0;
}

.home-list-text,
.home-answer-question,
.home-answer-preview,
.home-note {
	font-family: 'Times New Roman', Times, serif;
	color: var(--retro-card-text) !important;
}

.home-list-text {
	font-size: 1.04rem;
	line-height: 1.12;
}

.home-answer-question {
	font-size: 1.05rem;
	line-height: 1.1;
}

.home-answer-preview {
	font-size: 0.96rem;
	line-height: 1.12;
	color: var(--retro-card-muted) !important;
}

.home-answer-meta,
.home-meta,
html.dark-theme .home-meta {
	font-family: 'Courier New', monospace;
	font-size: 0.82rem;
	color: var(--retro-meta) !important;
	line-height: 1.1;
}

.home-answer-meta {
	font-style: italic;
}

.home-link,
html.dark-theme .home-link {
	font-size: 1.02rem;
	font-weight: 400;
	color: var(--retro-card-text);
	text-decoration: none;
}

.home-empty {
	margin: 12px 16px;
	font-size: 0.95rem;
	color: var(--retro-muted) !important;
}

.home-crossword {
	position: relative;
	min-height: 260px;
	background: var(--retro-crossword-bg);
	overflow: hidden;
}

.home-crossword-target,
.home-crossword-target iframe,
.home-crossword-frame {
	min-height: 252px;
	height: 252px;
	border-color: var(--retro-frame-outer);
	background: var(--retro-inset);
}

.home-crossword-target {
	margin: 8px 22px 0;
}

.home-crossword-reload {
	margin: 8px 22px;
	padding: 7px 10px;
	background: var(--retro-crossword-reload-bg);
	border: 1px solid var(--retro-frame-outer);
	color: var(--retro-crossword-reload-text);
}

.home-crossword-reload-button {
	background: var(--retro-crossword-button-bg);
	border-color: var(--retro-frame-mid);
	color: #fff;
}

/* Carry the retro frame palette through dashboard and thought surfaces. */
.dashboard-stat,
.dashboard-panel-card,
.dashboard-login,
html.dark-theme .dashboard-stat,
html.dark-theme .dashboard-panel-card,
html.dark-theme .dashboard-login {
	background: var(--retro-panel);
	border: 2px solid var(--retro-frame-outer);
	box-shadow: inset 0 0 0 1px var(--retro-frame-inner), 0 0 0 1px var(--retro-frame-shadow);
}

.dashboard-item,
html.dark-theme .dashboard-item {
	background: var(--retro-well);
	border: 1px solid var(--retro-frame-mid);
}

.dashboard-item-answer,
html.dark-theme .dashboard-item-answer {
	border-left-color: var(--retro-divider);
}

.dashboard-button,
.dashboard-tab,
html.dark-theme .dashboard-button,
html.dark-theme .dashboard-tab {
	background: var(--retro-inset);
	border-color: var(--retro-frame-outer);
	color: var(--retro-ink);
}

.dashboard-button:hover,
.dashboard-tab:hover,
html.dark-theme .dashboard-button:hover,
html.dark-theme .dashboard-tab:hover {
	background: var(--retro-well);
}

.dashboard-tab.is-active,
html.dark-theme .dashboard-tab.is-active {
	background: #172f85;
	border-color: #536ad0;
	color: #fff;
}

.dashboard-page .form-field input,
.dashboard-page .form-field textarea,
html.dark-theme .dashboard-page .form-field input,
html.dark-theme .dashboard-page .form-field textarea,
.dashboard-file-preview,
html.dark-theme .dashboard-file-preview {
	background: var(--retro-inset);
	border-color: var(--retro-frame-mid);
	color: var(--retro-ink);
}

.thought,
html.dark-theme .thought {
	background: var(--retro-panel);
	border: 2px solid var(--retro-frame-outer);
	box-shadow: inset 0 0 0 1px var(--retro-frame-inner), 0 0 0 1px var(--retro-frame-shadow);
}

.thought[data-first='true'],
html.dark-theme .thought[data-first='true'] {
	background: var(--retro-well);
}

.thought::before,
html.dark-theme .thought::before {
	background: var(--retro-divider);
}

.thought-media,
.thought-file-link,
html.dark-theme .thought-media,
html.dark-theme .thought-file-link {
	background: var(--retro-inset);
	border-color: var(--retro-frame-mid);
}

.thought-file-link:hover,
.thought-file-link:focus-visible,
html.dark-theme .thought-file-link:hover,
html.dark-theme .thought-file-link:focus-visible {
	background: var(--retro-well);
}

/* Blog, Q&A, and remaining content surfaces share the same theme system. */
.blog-cover,
html.dark-theme .blog-cover {
	background: var(--retro-inset);
	border: 2px solid var(--retro-frame-outer);
	box-shadow: inset 0 0 0 1px var(--retro-frame-inner), 0 0 0 1px var(--retro-frame-shadow);
	color: var(--retro-ink);
}

.blog-body pre,
html.dark-theme .blog-body pre {
	background: var(--retro-inset);
	border-color: var(--retro-frame-mid);
}

.blog-body code,
html.dark-theme .blog-body code {
	background: var(--retro-well);
}

.blog-body pre code,
html.dark-theme .blog-body pre code {
	background: transparent;
}

.sidebar-section,
html.dark-theme .sidebar-section {
	background: var(--retro-panel);
	border: 2px solid var(--retro-frame-outer);
	box-shadow: inset 0 0 0 1px var(--retro-frame-inner), 0 0 0 1px var(--retro-frame-shadow);
	color: var(--retro-ink);
}

.post-preview,
html.dark-theme .post-preview {
	padding: 1.25rem;
	background: var(--retro-panel);
	border: 2px solid var(--retro-frame-outer);
	box-shadow: inset 0 0 0 1px var(--retro-frame-inner), 0 0 0 1px var(--retro-frame-shadow);
}

.post-preview:last-child {
	border-bottom: 2px solid var(--retro-frame-outer);
}

.post-tags .tag,
html.dark-theme .post-tags .tag {
	background: var(--retro-inset);
	border-color: var(--retro-frame-mid);
	color: var(--retro-link);
}

.post-tags .tag:hover,
html.dark-theme .post-tags .tag:hover {
	background: var(--retro-well);
	border-color: var(--retro-frame-outer);
}

.qna-ask,
.qna-item,
html.dark-theme .qna-ask,
html.dark-theme .qna-item {
	background: var(--retro-panel);
	border: 2px solid var(--retro-frame-outer);
	box-shadow: inset 0 0 0 1px var(--retro-frame-inner), 0 0 0 1px var(--retro-frame-shadow);
}

.form-field input,
.form-field textarea,
html.dark-theme .form-field input,
html.dark-theme .form-field textarea {
	background: var(--retro-inset);
	border-color: var(--retro-frame-mid);
	color: var(--retro-ink);
}

.qna-submit,
html.dark-theme .qna-submit {
	background: var(--retro-inset);
	border-color: var(--retro-frame-outer);
	color: var(--retro-ink);
}

.qna-submit:hover,
html.dark-theme .qna-submit:hover {
	background: var(--retro-well);
}

.qna-identifier {
	background: var(--retro-well);
	border-color: var(--retro-frame-mid);
}

.qna-answer,
html.dark-theme .qna-answer {
	border-top-color: var(--retro-divider);
}

@media (max-width: 1100px) {
	body {
		margin-left: 0;
	}

	.sidebar {
		position: relative;
		left: auto;
		top: auto;
		width: calc(100% - 16px);
		height: auto;
		max-height: none;
		margin: 8px;
		padding-bottom: 6px;
		overflow: visible;
		box-shadow: inset 0 0 0 1px var(--retro-frame-inner), inset 0 0 0 3px var(--retro-frame-mid), 0 0 0 1px var(--retro-frame-shadow);
	}

	.sidebar-header {
		padding: 14px 18px 12px;
		padding-right: 18px;
	}

	.nav {
		display: grid;
		grid-template-columns: repeat(3, minmax(0, 1fr));
		gap: 0;
		overflow: visible;
		padding: 8px 6px 10px;
	}

	.nav li {
		min-width: 0;
	}

	.nav a,
	html.dark-theme .nav a {
		padding: 6px 10px;
		background: transparent;
		white-space: normal;
	}

	.nav li.blog_nested a {
		margin-left: 0;
		padding-left: 28px;
	}

	.nav li.blog_nested a::before {
		left: 8px;
	}

	.sidebar-footer {
		height: auto;
		min-height: 0;
		overflow: visible;
		padding: 0;
		background: transparent;
	}

	.sidebar-controls {
		position: static;
		display: block;
		padding: 8px 10px 9px;
	}

	.toggles {
		flex-direction: row;
		align-items: center;
		gap: 8px 18px;
		text-align: left;
	}

	.sidebar-toggle,
	.sidebar-action,
	html.dark-theme .sidebar-toggle,
	html.dark-theme .sidebar-action {
		position: static;
		padding: 5px 8px;
		background: transparent;
	}

	.sidebar-toggle-text {
		position: static;
		width: auto;
		height: auto;
		margin: 0;
		overflow: visible;
		clip: auto;
		white-space: normal;
	}

	.sidebar-toggle input[type='checkbox'] {
		width: 18px;
		height: 18px;
	}

	.sidebar-action[data-cookie-banner-open] {
		display: inline-flex;
	}

	.badges {
		display: grid;
		grid-template-columns: repeat(3, minmax(0, 1fr));
		padding: 8px 10px 10px;
	}

	main {
		padding: 18px 18px 30px;
	}

	.home-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		grid-template-rows: auto;
	}

	.home-card {
		min-height: 360px;
	}

	.home-card--wide {
		grid-column: 1 / -1;
	}
}

@media (max-width: 680px) {
	.sidebar {
		position: sticky;
		top: 0;
		z-index: 1000;
		margin: 0;
		width: 100%;
		border-width: 1px;
		padding: 0;
		box-shadow: 0 5px 12px rgba(0, 0, 0, 0.28);
	}

	.sidebar-header {
		padding: 12px 16px 10px;
	}

	.site-title {
		font-size: 1.9rem;
	}

	.sidebar-menu-block > .sidebar-section-label {
		display: none;
	}

	.nav {
		display: flex;
		gap: 6px;
		padding: 7px 9px 9px;
		overflow-x: auto;
		overflow-y: hidden;
		scrollbar-width: thin;
	}

	.nav li {
		flex: 0 0 auto;
	}

	.nav a,
	html.dark-theme .nav a,
	.nav li.blog_nested a {
		margin-left: 0;
		padding: 5px 9px;
		background: rgba(29, 50, 121, 0.22);
		white-space: nowrap;
	}

	.nav li.blog_nested a::before {
		display: none;
	}

	.sidebar-footer {
		display: none;
	}

	.sidebar-section-label {
		font-size: 1rem;
	}

	.home-title {
		font-size: 3rem;
	}

	.home-grid {
		grid-template-columns: minmax(0, 1fr);
	}

	.home-card--wide {
		grid-column: 1;
	}

	.home-card {
		min-height: 0;
		overflow: visible;
	}

	.home-card--wide {
		min-height: 300px;
	}

	.home-list-item {
		padding-inline: 16px;
	}
}
