:root {
	--bg: #ffffff;
	--text: #111827;
	--muted: #6b7280;
	--accent: #16a34a; /* green-600 */
	--accent-pressed: #15803d; /* green-700 */
	--surface: #f3f4f6; /* gray-100 */
	--surface-2: #e5e7eb; /* gray-200 */
	--border: #d1d5db; /* gray-300 */
	--yellow: #facc15; /* golden yellow */
}

/* RuneScape font faces */
@font-face {
	font-family: 'RuneScape';
	src: url('../fonts/runescape.ttf') format('truetype');
	font-weight: 400;
	font-style: normal;
	font-display: swap;
}
@font-face {
	font-family: 'RuneScape';
	src: url('../fonts/runescape_bold.ttf') format('truetype');
	font-weight: 700;
	font-style: normal;
	font-display: swap;
}
@font-face {
	font-family: 'RuneScape Small';
	src: url('../fonts/runescape_small.ttf') format('truetype');
	font-weight: 400;
	font-style: normal;
	font-display: swap;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html {font-family: 'RuneScape', Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, Noto Sans, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 20px;}
body {
	margin: 0;
		/* Coffee brown background with enhanced crumpled-paper texture + vignette */
		background-color: var(--bg);
		/* CSS vars allow randomized offsets (set in JS) to avoid obvious repeating seams */
		--paper-x1: 0px; --paper-y1: 0px;
		--paper-x2: 0px; --paper-y2: 0px;
		--paper-x3: 0px; --paper-y3: 0px;
		background-image:
			radial-gradient(closest-side, rgba(255,255,255,0.08), rgba(255,255,255,0) 60%),
			radial-gradient(farthest-corner, rgba(0,0,0,0.12), rgba(0,0,0,0) 60%),
			radial-gradient(closest-side, rgba(255,255,255,0.05), rgba(255,255,255,0) 70%),
			radial-gradient(closest-corner at 50% 50%, rgba(0,0,0,0) 55%, rgba(0,0,0,0.18) 100%);
		background-size: 240px 240px, 320px 320px, 280px 280px, 100% 100%;
		background-position: var(--paper-x1) var(--paper-y1), var(--paper-x2) var(--paper-y2), var(--paper-x3) var(--paper-y3), center;
		background-repeat: repeat, repeat, repeat, no-repeat;
		background-blend-mode: multiply, multiply, multiply, multiply;
	color: var(--text);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}
.site-header {
	position: sticky;
	top: 0;
	z-index: 10;
	background: var(--bg);
	border-bottom: 1px solid var(--border);
	/* approximate header height variable for layout math */
	--header-h: 72px;
}
.header-inner {
	/* Use full page width so the title doesn't get clipped */
	max-width: none;
	width: 100%;
	margin: 0 auto;
	padding: 0.75rem 1rem;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
}
.header-actions { display: inline-flex; align-items: center; gap: 12px; flex-wrap: nowrap; flex: 0 1 auto; min-width: 0; }
.header-actions .header-sep { margin-left: 20px; }
.site-title { font-size: 1.75rem; margin: 0; font-family: 'RuneScape', serif; letter-spacing: .5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-left { display: inline-flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.site-title .site-subtitle {
	font-size: 0.9rem;
	font-family: 'RuneScape Small', 'RuneScape', serif;
	margin-left: 8px;
	opacity: 0.9;
}

/* Volume slider control in header */
.volume-control { display: inline-flex; align-items: center; gap: 8px; min-width: 180px; }
.volume-control .volume-icon { font-size: 1rem; opacity: 0.9; }
.volume-control .volume-value { font-size: 0.9rem; color: var(--muted); width: 44px; text-align: right; }
.volume-slider {
	-webkit-appearance: none;
	appearance: none;
	width: 140px;
	height: 6px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 999px;
}
.volume-slider:focus { outline: none; box-shadow: 0 0 0 2px rgba(22,163,74,0.25); }
.volume-slider::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 16px; height: 16px;
	background: var(--accent);
	border: 1px solid var(--accent-pressed);
	border-radius: 50%;
	cursor: pointer;
}
.volume-slider::-moz-range-thumb {
	width: 16px; height: 16px;
	background: var(--accent);
	border: 1px solid var(--accent-pressed);
	border-radius: 50%;
	cursor: pointer;
}

/* theme-switch removed; theme is locked to dark */
.board-switch { display: inline-flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--muted);} 
.board-switch .switch {
	position: relative;
	width: 48px;
	height: 28px;
	border: none;
	background: transparent;
	padding: 0;
	cursor: pointer;
}
.board-switch .switch:focus-visible { outline: 2px solid var(--border); outline-offset: 2px; border-radius: 999px; }
.board-switch .switch .switch-track {
	position: absolute; inset: 0;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 999px;
	transition: background-color .2s ease, border-color .2s ease;
}
.board-switch .switch .switch-thumb {
	position: absolute; top: 2px; left: 2px;
	width: 24px; height: 24px;
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: 50%;
	transition: transform .2s ease, background-color .2s ease, border-color .2s ease;
}
.board-switch .switch[aria-checked="true"] .switch-track {
	background: var(--accent);
	border-color: var(--accent-pressed);
}
.board-switch .switch[aria-checked="true"] .switch-thumb {
	transform: translateX(20px);
	background: #fff;
	border-color: var(--accent-pressed);
}

.site-main {
	min-height: calc(100dvh - var(--header-h, 72px));
	display: grid;
	padding: 1rem;
}

.main-wrap { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; max-width: 1600px; margin: 0 auto; }
.boards-wrap { display: grid; grid-auto-flow: column; align-items: start; justify-content: center; gap: 100px; }
.bonus-wrap { display: grid; gap: 8px; align-items: start; }
.bonus-title { text-align: center; font-weight: 700; font-family: 'RuneScape', serif; }
.grid-wrap {
	/* Ensure the square grid never exceeds viewport height minus header and main padding */
	width: min(92vmin, 1000px, calc(100dvh - var(--header-h, 72px) - 2rem));
	aspect-ratio: 1 / 1;
	display: grid;
	justify-self: center;
}
.side-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 16px; }
.panel-section { display: grid; gap: 8px; }
.panel-section[hidden] { display: none !important; }
.panel-header { font-weight: 700; color: var(--text); font-family: 'RuneScape', serif; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.selected-task .task-image { width: 100%; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.panel-actions .btn { flex: 1 0 auto; }
.status.muted { color: var(--muted); font-size: 1rem; }
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.muted { color: var(--muted); }
.options-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.options-list li.option { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); overflow: hidden; }
.options-list li.option { cursor: pointer; }
.options-list li.option .opt-left { min-width: 0; }
.options-list li.option .opt-right { display: flex; align-items: center; gap: 8px; align-self: start; }
.options-list li.option .task-title { font-weight: 600; display: block; white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.25; }
.options-list li.option .points-pill { display: inline-block; padding: 4px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: .9rem; }
/* Difficulty color overlay */
.options-list li.option::before { content: ""; position: absolute; inset: 0; border-radius: inherit; opacity: 0.12; pointer-events: none; background: transparent; transition: opacity .15s ease; }
.options-list li.option.opt-easy::before { background: #16a34a; }
.options-list li.option.opt-medium::before { background: #f59e0b; }
.options-list li.option.opt-hard::before { background: #ef4444; }
.options-list li.option:hover { background: var(--surface); }
.instructions { color: var(--muted); font-size: .95rem; }
.instructions ul { margin: 0; padding-left: 1.1rem; display: grid; gap: .35rem; }
.instructions li { line-height: 1.25rem; }
.btn { padding: 8px 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; cursor: pointer; font-family: 'RuneScape', inherit; }
.btn:hover { background: var(--surface-2); }
.btn.youtube { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.45); color: var(--text); text-decoration: none; }
.btn.youtube:hover { background: rgba(239, 68, 68, 0.28); border-color: rgba(239, 68, 68, 0.6); }
.btn.primary { background: var(--accent); border-color: var(--accent-pressed); color: var(--text); }
.btn.success { background: #22c55e; border-color: #16a34a; color: var(--text); }
.btn.danger { background: #ef4444; border-color: #b91c1c; color: #fff; }
.btn.danger:hover { background: #dc2626; border-color: #991b1b; }

@media (max-width: 1000px) {
	.main-wrap { grid-template-columns: 1fr; }
	.boards-wrap { grid-auto-flow: row; justify-content: center; }
	.grid-wrap { justify-self: center; }
}

/* Portrait-ish layout adjustments: trigger on device portrait, narrow width, or tall windows */
@media (orientation: portrait), (max-aspect-ratio: 1/1), (max-width: 720px) {
	/* Reduce padding to maximize space */
	.site-main { padding: 0.5rem; }
	.header-inner { gap: 0.5rem; padding: 0.5rem 0.75rem; flex-wrap: wrap; }
	/* Hide big title to save vertical space */
	.site-title { display: none; }

	/* Stack everything vertically: bonus grid on top, then main, then panel */
	.main-wrap { grid-template-columns: 1fr; gap: 10px; }
	.boards-wrap { grid-auto-flow: row; gap: 10px; }
		/* Center bonus grid horizontally */
		.bonus-wrap { justify-items: center; }
		#bonus-grid.grid { justify-self: center; margin-inline: auto; }
		.side-panel { order: 3; margin-bottom: 110px;  }

	/* Bonus grid sideways: 7 columns x 2 rows */
	#bonus-grid.grid {
		--bonus-cols: 7;
		--bonus-rows: 2;
		aspect-ratio: var(--bonus-cols) / var(--bonus-rows);
	}
	.bonus-title { margin-top: 6px; }

	/* Fit grid better on narrow screens */
		.grid-wrap {
			width: min(98vmin, 1000px, calc(100dvh - var(--header-h, 72px) - 1rem));
			padding: 8px; /* small inner margin so grid doesn't touch screen edge */
		}

	/* Tighter controls */
	.header-actions { gap: 8px; flex-wrap: wrap; width: 100%; justify-content: space-between; }
		/* Hide volume on mobile/portrait to keep buttons on one row */
		.volume-control { display: none !important; }
	.volume-control .volume-value { display: none; }
	.volume-slider { width: clamp(90px, 40vw, 140px); }
}

/* JS fallback: apply the same portrait-ish rules when body has .is-portrait */
body.is-portrait .site-main { padding: 0.5rem; }
body.is-portrait .header-inner { gap: 0.5rem; padding: 0.5rem 0.75rem; flex-wrap: wrap; }
body.is-portrait .site-title { display: none; }
body.is-portrait .main-wrap { grid-template-columns: 1fr; gap: 10px; }
body.is-portrait .boards-wrap { grid-auto-flow: row; gap: 10px; }
/* JS fallback: center bonus grid horizontally in portrait */
body.is-portrait .bonus-wrap { justify-items: center; }
body.is-portrait #bonus-grid.grid { justify-self: center; margin-inline: auto; }
/* JS fallback: add bottom margin so coffee button doesn't cover content */
body.is-portrait .side-panel { margin-bottom: 110px; }
body.is-portrait .side-panel { order: 3; }
body.is-portrait #bonus-grid.grid { --bonus-cols: 7; --bonus-rows: 2; aspect-ratio: var(--bonus-cols) / var(--bonus-rows); }
body.is-portrait .bonus-title { margin-top: 6px; }
body.is-portrait .grid-wrap {
	width: min(98vmin, 1000px, calc(100dvh - var(--header-h, 72px) - 1rem));
	padding: 8px; /* small inner margin in JS-driven portrait mode */
}
body.is-portrait .header-actions { gap: 8px; flex-wrap: wrap; width: 100%; justify-content: space-between; }
/* JS fallback: also hide volume in portrait-mode class */
body.is-portrait .volume-control { display: none !important; }
body.is-portrait .volume-control .volume-value { display: none; }
body.is-portrait .volume-slider { width: clamp(90px, 40vw, 140px); }

button {
	font: inherit;
}

/* Utility */
.sr-only {
	position: absolute;
	width: 1px; height: 1px;
	padding: 0; margin: -1px;
	overflow: hidden; clip: rect(0,0,0,0);
	border: 0;
}

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: grid; place-items: center; z-index: 50; }
.modal-dialog { width: min(90vw, 420px); background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); }
.modal-dialog.modal-wide { width: min(96vw, 980px); max-height: 88vh; display: grid; grid-template-rows: auto auto 1fr auto; gap: 12px; }
.modal-title { font-weight: 600; margin-bottom: 8px; }
.modal-body { color: var(--muted); margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Ensure hidden attribute actually hides the modal despite default display */
.modal-backdrop[hidden] { display: none !important; }

/* Points banner at top of right panel */
.points-banner {
	text-align: center;
	font-weight: 700;
	font-size: 1.125rem;
	padding: 6px 8px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 8px;
    color: var(--text);
}

/* Hide headers when section hidden */
#options-section[hidden] > .panel-header,
#selected-section[hidden] > .panel-header {
	display: none;
}

/* Donate: fixed bottom-right container and link */
.donate-coffee-wrap {
	position: fixed;
	right: 12px;
	bottom: 12px;
	z-index: 40; /* below modal (50) but above main */
	display: grid;
	gap: 6px;
	justify-items: end;
	max-width: min(92vw, 420px);
	
	padding-top: 26px;
}
.donate-coffee-wrap:focus-within .donate-dismiss,
.donate-coffee-wrap:hover .donate-dismiss { opacity: 1; transform: translateY(0); pointer-events: auto; }
.donate-dismiss {
	position: absolute;
	right: 0;
	top: 2px; 
	width: 20px; height: 20px;
	line-height: 18px;
	border-radius: 50%;
	border: 1px solid #b91c1c;
	background: #ef4444; /* red-500 */
	color: #fff;
	font-weight: 700;
	font-size: 14px;
	display: grid; place-items: center;
	padding: 0;
	cursor: pointer;
	opacity: 0; pointer-events: none; transform: translateY(4px);
	transition: opacity .15s ease, transform .15s ease;
}
.donate-dismiss:hover { background: #dc2626; border-color: #991b1b; }
.donate-prompt {
	font-size: 0.85rem;
	color: var(--muted);
	background: transparent;
	user-select: none;
}
.donate-coffee {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: 0.95rem;
	background: var(--surface);
	color: var(--text);
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 8px 14px;
	text-decoration: none;
	box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.donate-coffee:hover { background: var(--surface-2); }
.donate-note {
	font-size: 0.8rem;
	color: var(--muted);
	line-height: 1.2;
	text-align: right;
	white-space: nowrap; 
	overflow: hidden;
	text-overflow: ellipsis; 
}

/* Journey modal */
.journey-summary { display: grid; grid-auto-flow: column; justify-content: start; gap: 16px; }
.journey-summary .summary-item { display: inline-flex; align-items: baseline; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 6px 10px; }
.journey-summary .summary-item span { color: var(--muted); font-size: .9rem; }
.journey-summary .summary-item strong { font-weight: 700; }
.journey-body { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); padding: 8px; overflow: auto; max-height: 60vh; }
.journey-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.journey-item { display: grid; grid-template-columns: 100px 1fr 120px; gap: 10px; align-items: start; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.journey-item .time { color: var(--muted); font-size: .9rem; }
.journey-item .desc { display: grid; gap: 4px; }
.journey-item .meta { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: flex-end; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); font-size: .85rem; }
.badge.diff-easy { background: #16a34a22; border-color: #16a34a; }
.badge.diff-medium { background: #f59e0b22; border-color: #f59e0b; }
.badge.diff-hard { background: #ef444422; border-color: #ef4444; }
.badge.points-plus { background: #22c55e33; border-color: #16a34a; }
.badge.points-minus { background: #ef444433; border-color: #b91c1c; }
.journey-empty { color: var(--muted); text-align: center; padding: 16px; }
.journey-export { display: grid; gap: 8px; margin-top: 10px; }
.journey-export .export-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.journey-code { width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); padding: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: .85rem; }
