/* Puzzle dashboard. Colours are tokens; dark values apply when the system is
   dark (unless the user picked light) or when the user picked dark. */

:root {
	color-scheme: light;
	--bg: #ffffff;
	--surface: #f6f7f9;
	--fg: #1b1d21;
	--muted: #5d6470;
	--border: #d9dde3;
	--link: #1a5fb4;
	--accent: #2f6fd6;
	--row-meta: #e8eaee;
	--row-solved: #d3f0da;
	--row-solved-meta: #b7e3c3;
	--row-hover: #eef2f8;
	--badge-viewer: #e3e6eb;
	--badge-lead: #fbe3b4;
	--badge-superuser: #f6c9cf;
	--notice: #fff3cd;
	--focus: #2f6fd6;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--bg: #15171a;
		--surface: #1d2024;
		--fg: #e6e8eb;
		--muted: #a0a7b2;
		--border: #343941;
		--link: #8ab4f8;
		--accent: #6ea0f0;
		--row-meta: #2a2e34;
		--row-solved: #1f4a2c;
		--row-solved-meta: #2b6340;
		--row-hover: #23272d;
		--badge-viewer: #343941;
		--badge-lead: #5c4614;
		--badge-superuser: #5e2a31;
		--notice: #4a3d12;
		--focus: #8ab4f8;
	}
}

:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #15171a;
	--surface: #1d2024;
	--fg: #e6e8eb;
	--muted: #a0a7b2;
	--border: #343941;
	--link: #8ab4f8;
	--accent: #6ea0f0;
	--row-meta: #2a2e34;
	--row-solved: #1f4a2c;
	--row-solved-meta: #2b6340;
	--row-hover: #23272d;
	--badge-viewer: #343941;
	--badge-lead: #5c4614;
	--badge-superuser: #5e2a31;
	--notice: #4a3d12;
	--focus: #8ab4f8;
}

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

html { scroll-padding-top: 4.5rem; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--fg);
	font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--link); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.visually-hidden {
	position: absolute; width: 1px; height: 1px; overflow: hidden;
	clip: rect(0 0 0 0); white-space: nowrap;
}

button, .button {
	font: inherit;
	color: var(--fg);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 0.3rem 0.7rem;
	cursor: pointer;
	text-decoration: none;
	display: inline-block;
}
.button { background: var(--accent); color: #fff; border-color: var(--accent); padding: 0.55rem 1.1rem; }

/* ---- Top bar ---- */
.topbar {
	position: sticky; top: 0; z-index: 10;
	display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
	padding: 0.6rem 1rem;
	background: var(--bg);
	border-bottom: 1px solid var(--border);
}
.topbar .logo { height: 30px; width: auto; }
.hunt-name { font-size: 1.15rem; margin: 0; flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; }
.search { flex: 1 1 14rem; }
.search input {
	width: 100%; font: inherit; color: var(--fg); background: var(--surface);
	border: 1px solid var(--border); border-radius: 6px; padding: 0.35rem 0.6rem;
}
.user { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.user-name { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout { margin: 0; }
.badge { font-size: 0.75rem; padding: 0.1rem 0.45rem; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-viewer { background: var(--badge-viewer); }
.badge-lead { background: var(--badge-lead); }
.badge-superuser { background: var(--badge-superuser); }
.sidebar-toggle { display: none; }

/* ---- Layout ---- */
.layout { display: flex; align-items: flex-start; }
.sidebar {
	position: sticky; top: 3.6rem;
	flex: 0 0 15rem;
	max-height: calc(100vh - 3.6rem); overflow-y: auto;
	padding: 1rem;
	border-right: 1px solid var(--border);
}
.sidebar .total { margin: 0 0 0.75rem; font-size: 1.05rem; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.2rem 0; }
.sidebar li a { overflow-wrap: anywhere; }
.sidebar li.solved a::after { content: " ✓"; }
.count { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.puzzles { flex: 1 1 auto; min-width: 0; padding: 0.5rem 1rem 3rem; }
.meta h2 { font-size: 1.1rem; margin: 1.25rem 0 0.4rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 0.85rem; }
th button { border: 0; background: none; padding: 0; color: inherit; font-weight: inherit; }
th[aria-sort="ascending"] button::after { content: " ▲"; }
th[aria-sort="descending"] button::after { content: " ▼"; }
.col-name { overflow-wrap: anywhere; }
.col-links { white-space: nowrap; width: 6.5rem; }
.col-links a, .col-links .nolink { display: inline-block; width: 1.8rem; text-align: center; text-decoration: none; }
.col-links .nolink { color: var(--muted); }
.col-answer { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; width: 30%; }
tbody tr:hover { background: var(--row-hover); }
tr.is-meta { background: var(--row-meta); font-weight: 600; }
tr.is-solved { background: var(--row-solved); }
tr.is-meta.is-solved { background: var(--row-solved-meta); }

.empty, .no-matches { color: var(--muted); padding: 1rem 0; }

/* ---- Login ---- */
.login { max-width: 26rem; margin: 12vh auto; padding: 0 1rem; text-align: center; }
.login .logo { height: auto; }
.notice { background: var(--notice); padding: 0.6rem 0.8rem; border-radius: 6px; }
.muted { color: var(--muted); }

/* ---- Narrow screens: sidebar becomes a toggled panel ---- */
@media (max-width: 760px) {
	html { scroll-padding-top: 9rem; }
	.topbar { gap: 0.5rem; padding: 0.5rem 0.75rem; }
	.topbar .logo { display: none; }
	.sidebar-toggle { display: inline-block; }
	.search { order: 10; flex-basis: 100%; }
	.user-name { max-width: 8rem; }
	.layout { display: block; }
	.sidebar { display: none; position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--border); }
	body.sidebar-open .sidebar { display: block; }
	.puzzles { padding: 0.25rem 0.75rem 3rem; }
	th, td { padding: 0.35rem 0.3rem; }
	.col-links { width: 5.5rem; }
	.col-links a, .col-links .nolink { width: 1.6rem; }
}
