:root {
	--bg: #070b14;
	--bg-elevated: #0f1626;
	--bg-card: rgba(18, 28, 48, 0.82);
	--border: rgba(148, 163, 184, 0.16);
	--text: #e8eefc;
	--muted: #93a4bd;
	--accent: #34d399;
	--accent-2: #22d3ee;
	--success: #34d399;
	--danger: #f87171;
	--radius: 14px;
	--font: "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
	--header-bg: rgba(7, 11, 20, 0.78);
	color-scheme: dark;
}

:root[data-theme="light"] {
	--bg: #f4f6fb;
	--bg-elevated: #ffffff;
	--bg-card: rgba(255, 255, 255, 0.92);
	--border: rgba(30, 41, 59, 0.12);
	--text: #1a2233;
	--muted: #5b6b85;
	--header-bg: rgba(255, 255, 255, 0.78);
	color-scheme: light;
}

* {
	box-sizing: border-box;
}

html, body {
	margin: 0;
	padding: 0;
	min-height: 100%;
	background: var(--bg);
	color: var(--text);
	font-family: var(--font);
	line-height: 1.65;
}

body {
	position: relative;
	overflow-x: hidden;
}

.bg-orb {
	position: fixed;
	border-radius: 50%;
	filter: blur(60px);
	pointer-events: none;
	z-index: 0;
	opacity: 0.5;
}

.bg-orb-a {
	width: 420px;
	height: 420px;
	top: -120px;
	left: -80px;
	background: rgba(52, 211, 153, 0.3);
}

.bg-orb-b {
	width: 380px;
	height: 380px;
	top: 20%;
	right: -120px;
	background: rgba(34, 211, 238, 0.16);
}

a {
	color: var(--accent-2);
}

.container {
	width: min(900px, calc(100% - 2rem));
	margin: 0 auto;
	position: relative;
	z-index: 1;
}

/* --- ヘッダー --- */
.site-header {
	position: sticky;
	top: 0;
	z-index: 20;
	backdrop-filter: blur(16px);
	-webkit-backdrop-filter: blur(16px);
	background: var(--header-bg);
	border-bottom: 1px solid var(--border);
}

.header-inner {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	min-height: 64px;
	padding: 0.65rem 0;
}

.brand {
	display: inline-flex;
	align-items: center;
	gap: 0.7rem;
	color: var(--text);
	text-decoration: none;
}

.brand-mark {
	display: grid;
	place-items: center;
	width: 36px;
	height: 36px;
	border-radius: 10px;
	color: var(--accent);
	background: linear-gradient(145deg, rgba(52, 211, 153, 0.16), rgba(34, 211, 238, 0.16));
	border: 1px solid rgba(52, 211, 153, 0.28);
}

.brand-text {
	display: flex;
	flex-direction: column;
	line-height: 1.15;
}

.brand-title {
	font-weight: 800;
	letter-spacing: 0.02em;
}

.brand-sub {
	font-size: 0.7rem;
	color: var(--muted);
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.nav {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem 0.4rem;
	align-items: center;
}

.nav a {
	color: var(--muted);
	font-size: 0.88rem;
	font-weight: 600;
	padding: 0.4rem 0.65rem;
	border-radius: 999px;
	text-decoration: none;
}

.nav a:hover {
	color: var(--text);
	background: rgba(148, 163, 184, 0.1);
}

.nav-external {
	border: 1px solid var(--border) !important;
}

#theme-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	margin-left: 0.25rem;
	border-radius: 999px;
	border: 1px solid var(--border);
	background: transparent;
	color: var(--muted);
	cursor: pointer;
}

#theme-toggle:hover {
	color: var(--text);
	background: rgba(148, 163, 184, 0.1);
}

#theme-toggle svg {
	width: 18px;
	height: 18px;
	flex-shrink: 0;
}

#theme-toggle .icon-moon {
	display: none;
}

:root[data-theme="light"] #theme-toggle .icon-sun {
	display: none;
}

:root[data-theme="light"] #theme-toggle .icon-moon {
	display: block;
}

/* --- メイン --- */
.main {
	padding: 2rem 0 3.5rem;
	min-height: calc(100vh - 200px);
}

.hero {
	margin-bottom: 1.5rem;
}

.eyebrow {
	font-size: 0.78rem;
	font-weight: 700;
	color: var(--accent);
	text-transform: uppercase;
	letter-spacing: 0.06em;
	margin: 0 0 0.4rem;
}

.hero h1 {
	margin: 0 0 0.4rem;
}

.lede {
	color: var(--muted);
	margin: 0;
}

.badge {
	font-size: 0.6em;
	background: #f59e0b;
	color: #fff;
	padding: 2px 8px;
	border-radius: 999px;
	vertical-align: middle;
}

.exercise-list {
	list-style: none;
	padding: 0;
}

.exercise-list li {
	background: var(--bg-card);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	margin-bottom: 0.5em;
	overflow: hidden;
}

.exercise-card {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 1em;
	padding: 0.8em 1em;
	color: var(--text);
	text-decoration: none;
}

.exercise-card:hover {
	background: rgba(148, 163, 184, 0.1);
}

.exercise-card:hover .exercise-title {
	text-decoration: underline;
}

.exercise-title {
	font-weight: 600;
}

.exercise-list .meta {
	color: var(--muted);
	font-size: 0.85em;
	white-space: nowrap;
}

/* --- Markdown表示（課題文・ヒント共通） --- */
.statement,
.hints,
.card {
	background: var(--bg-card);
	border: 1px solid var(--border);
	padding: 1em 1.4em;
	border-radius: var(--radius);
}

.card + .card {
	margin-top: 1em;
}

.card h2 {
	margin-top: 0;
}

.card ul {
	line-height: 1.8;
	padding-left: 1.4em;
}

.simple-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.92em;
}

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

.simple-table th {
	color: var(--muted);
	font-weight: 600;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
	margin-top: 1.2em;
	margin-bottom: 0.4em;
}

.markdown-body h1:first-child,
.markdown-body h2:first-child {
	margin-top: 0;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol {
	line-height: 1.7;
}

.markdown-body pre {
	background: var(--bg-elevated);
	color: var(--text);
	padding: 0.9em 1em;
	border-radius: 8px;
	overflow-x: auto;
	border: 1px solid var(--border);
}

.markdown-body code {
	font-family: 'Fira Code', 'SFMono-Regular', Consolas, monospace;
	font-size: 0.9em;
}

.markdown-body :not(pre) > code {
	background: rgba(52, 211, 153, 0.12);
	color: var(--accent);
	padding: 0.15em 0.4em;
	border-radius: 4px;
}

/* --- コードエディタ --- */
.editor h2 {
	margin-bottom: 0.5em;
}

.CodeMirror {
	border: 1px solid var(--border);
	border-radius: var(--radius);
	height: 420px;
	font-family: 'Fira Code', 'SFMono-Regular', Consolas, monospace;
	font-size: 0.9rem;
}

.actions {
	margin-top: 0.6em;
	display: flex;
	align-items: center;
	gap: 1em;
}

button {
	display: inline-flex;
	align-items: center;
	gap: 0.5em;
	background: var(--accent);
	color: #062018;
	border: none;
	padding: 0.6em 1.2em;
	border-radius: 999px;
	cursor: pointer;
	font-weight: 700;
}

button:disabled {
	background: var(--muted);
	color: var(--bg);
	cursor: default;
}

.spinner {
	width: 14px;
	height: 14px;
	border: 2px solid rgba(6, 32, 24, 0.35);
	border-top-color: #062018;
	border-radius: 50%;
	animation: dojo-spin 0.7s linear infinite;
}

@keyframes dojo-spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.spinner {
		animation-duration: 1.6s;
	}
}

/* --- ヒント --- */
.hints {
	margin-top: 1.5em;
}

.hint-buttons {
	display: flex;
	flex-direction: column;
	gap: 0.6em;
	align-items: flex-start;
}

.hint-body {
	width: 100%;
	box-sizing: border-box;
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	padding: 0.8em 1em;
	border-radius: var(--radius);
	margin: 0;
}

.hint-buttons button .chevron {
	font-size: 0.7em;
	opacity: 0.8;
}

/* --- 採点結果 --- */
.result {
	margin-top: 1.5em;
	background: var(--bg-card);
	border: 1px solid var(--border);
	padding: 1em 1.4em;
	border-radius: var(--radius);
	border-left: 4px solid var(--muted);
}

.result.result-passed {
	border-left-color: var(--success);
}

.result.result-failed {
	border-left-color: var(--danger);
}

.result-celebration {
	font-size: 3rem;
	text-align: center;
	margin-bottom: 0.4em;
	animation: dojo-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dojo-pop {
	0% {
		transform: scale(0.4);
		opacity: 0;
	}
	60% {
		transform: scale(1.15);
		opacity: 1;
	}
	100% {
		transform: scale(1);
	}
}

@media (prefers-reduced-motion: reduce) {
	.result-celebration {
		animation: none;
	}
}

.confetti-canvas {
	position: fixed;
	inset: 0;
	pointer-events: none;
	z-index: 50;
}

#result-summary {
	font-weight: 600;
	margin-bottom: 0.6em;
}

.compile-hints {
	font-weight: 400;
	margin: 0.6em 0;
	padding-left: 1.2em;
}

.compile-hints li {
	margin-bottom: 0.4em;
	line-height: 1.6;
}

.compile-raw {
	font-weight: 400;
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	padding: 0.7em 0.9em;
	border-radius: 8px;
	white-space: pre-wrap;
	word-break: break-word;
	font-size: 0.85em;
	color: var(--muted);
	margin: 0;
	font-family: 'Fira Code', 'SFMono-Regular', Consolas, monospace;
}

#result-tests {
	list-style: none;
	padding: 0;
}

#result-tests li {
	padding: 0.3em 0;
	border-bottom: 1px solid var(--border);
}

#result-tests li:last-child {
	border-bottom: none;
}

.test-failed {
	color: var(--danger);
}

/* --- フッター --- */
.site-footer {
	border-top: 1px solid var(--border);
	padding: 1.75rem 0 2.5rem;
	color: var(--muted);
	font-size: 0.9rem;
	position: relative;
	z-index: 1;
}

.footer-inner {
	display: flex;
	justify-content: space-between;
	gap: 1.5rem;
	flex-wrap: wrap;
	align-items: flex-start;
}

.footer-brand {
	margin: 0 0 0.25rem;
	color: var(--text);
	font-weight: 700;
}

.muted {
	color: var(--muted);
	margin: 0;
}

.footer-links {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	align-items: flex-end;
}
