* { box-sizing: border-box; }

#the_canvas {
	margin: 0;
	padding: 0;
	position: absolute;
}

#sidebar {
	background: #f2f3f6;
	margin: 0;
	position: absolute;
	display: flex;
	padding: 10px;
	gap: 8px;
}

#sidebar_buttons {
	display: flex;
	gap: 7px;
}

#sidebar button {
	border: none;
	border-radius: 10px;
	background: #ffffff;
	color: #2c2c3a;
	font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	padding: 6px 8px;
	box-shadow: 0 1px 3px rgba(30, 30, 60, 0.12);
	transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease;
}

#sidebar button:hover:not(:disabled) {
	background: #6c5ce7;
	color: #ffffff;
	box-shadow: 0 4px 12px rgba(108, 92, 231, 0.4);
	transform: translateY(-1px);
}

#sidebar button:active:not(:disabled) {
	transform: translateY(1px);
	box-shadow: 0 1px 2px rgba(30, 30, 60, 0.2);
}

#sidebar button:disabled {
	opacity: 0.45;
	cursor: default;
}

/* a document button split into a wide "read" half and a narrow "destroy" (throw-it-around) half */
.split_button {
	display: flex;
	gap: 6px;
}
.split_button .read_half {
	flex: 1 1 auto;
	min-width: 0;
}
.split_button .destroy_half {
	flex: 0 0 auto;
	width: 2.8em;
	padding: 4px;
	font-size: 16px;
}

/* placeholder for a future ad unit */
#ad_slot {
	/* the slot IS the lavender card; the ad images are transparent ball+wordmark and letterbox
	   into it invisibly at any slot ratio (both the sidebar rectangle and the banner flex). */
	border-radius: 10px;
	background: #ece8fa;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	padding: 6px;
	box-sizing: border-box;
}
#ad_slot img { max-width: 100%; max-height: 100%; object-fit: contain; display: none; }

/* the chapter objective, above the buttons. Hidden on pages that have none. */
#objective_panel {
	flex: 0 0 auto;
	background: #ffffff;
	border-radius: 10px;
	border-left: 4px solid #6c5ce7;
	padding: 7px 9px;
	font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
	color: #2c2c3a;
	font-size: 12px;
	line-height: 1.35;
}

#objective_panel.hidden { display: none; }

#objective_label {
	display: block;
	font-size: 9px;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: #6c5ce7;
	margin-bottom: 2px;
}

/* quiet progress, shown only once you are on the right track */
#objective_progress {
	display: block;
	margin-top: 3px;
	font-size: 10px;
	font-weight: 600;
	color: #8b90a0;
}

/* done: the objective goes green and gets a tick */
#objective_panel.done { border-left-color: #2f9e5e; }
#objective_panel.done #objective_label { color: #2f9e5e; }
#objective_panel.done #objective_text::before { content: "\2713  "; font-weight: 700; color: #2f9e5e; }

@media screen and (orientation: landscape) {
	#the_canvas { top: 0; left: 0; width: 80%; height: 100%; }
	#sidebar { top: 0; left: 80%; width: 20%; height: 100%; flex-direction: column; }
	/* Grid, not flex, so every row is EXACTLY the same height. With `flex: 1 1 0` the plain buttons and the
	   split-button pairs still came out at different heights (82px vs 70px) because flex sizing falls back
	   on each item's own content; `grid-auto-rows: 1fr` makes the rows equal by construction.
	   min-height:0 lets them shrink - a grid/flex item defaults to min-height:auto and will not go below
	   its own content, which is what pushed the last buttons out of sight behind the ad slot. */
	#sidebar_buttons { flex: 1 1 auto; min-height: 0; display: grid; grid-auto-rows: 1fr; gap: 7px; }
	#sidebar_buttons > button, #sidebar_buttons > .split_button { min-height: 0; }
	.split_button > button { min-height: 0; }
	/* the ad yields space when the column is tight, instead of squeezing the buttons out */
	#ad_slot { flex: 0 1 220px; min-height: 110px; }
	#ad_slot .ad-landscape { display: block; }
}

/* portrait (e.g. a phone held upright): stack the sidebar below the canvas as two rows of buttons
   with a full-width ad banner at the very bottom. */
@media screen and (orientation: portrait) {
	/* Lay the page out as two rows instead of the fixed 70/30 absolute split used in landscape: the sidebar is
	   only as tall as its own content (the `auto` row), and the canvas fills everything above it (`1fr`). That
	   removes the dead space that a fixed 30% sidebar left below the buttons on tall devices. */
	html, body { height: 100%; margin: 0; }
	body { display: grid; grid-template-rows: 1fr auto; }
	#the_canvas { position: static; width: 100%; height: 100%; min-height: 0; }
	#sidebar { position: static; width: 100%; height: auto; flex-direction: column; }
	/* the button block is only as tall as the buttons; font/padding scale with the viewport (clamped, vh-based)
	   so buttons stay in proportion on any screen yet compact on a short one */
	#sidebar_buttons {
		flex: 0 0 auto; min-height: 0;
		display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
	}
	#ad_slot { flex: 0 0 auto; height: 56px; width: 100%; }
	#ad_slot .ad-portrait { display: block; }
	/* a very long hint scrolls inside a capped box rather than eating into the canvas above it */
	#objective_panel { flex: 0 0 auto; max-height: 22vh; overflow-y: auto; }
	#sidebar button { font-size: clamp(12px, 1.7vh, 17px); padding: clamp(5px, 1.2vh, 13px) 8px; }
	/* keep the throw (💥) glyph proportional to the text on the other half of the split button */
	.split_button .destroy_half { font-size: clamp(14px, 2vh, 20px); }
}

/* the consent banner: a small card in the lower-left corner, out of the way of the sidebar.
   Both buttons are the same size on purpose - the choice is meant to weigh the same. */
#consent_banner {
	position: fixed;
	left: 18px;
	bottom: 18px;
	z-index: 60;
	max-width: 330px;
	background: #ffffff;
	border: 1px solid #d6d9e4;
	border-radius: 12px;
	box-shadow: 0 10px 28px rgba(20, 22, 30, 0.18);
	padding: 14px 16px;
	font-family: 'Cabin', 'Segoe UI', sans-serif;
	color: #262830;
}
#consent_banner p { margin: 0 0 10px 0; font-size: 14px; line-height: 1.45; }
.consent_buttons { display: flex; gap: 8px; }
.consent_buttons button {
	flex: 1 1 0;
	padding: 8px 0;
	border: none;
	border-radius: 8px;
	font-size: 14px;
	cursor: pointer;
}
#consent_accept { background: #6c5ce7; color: #ffffff; }
#consent_accept:hover { background: #5a4bd1; }
#consent_decline { background: #e4e7f0; color: #262830; }
#consent_decline:hover { background: #d6d9e4; }
#consent_banner a { color: #6c5ce7; text-decoration: underline; }

/* ---- dark mode: the DOM chrome follows the canvas. The engine toggles body.dark and
   persists the choice; everything the canvas draws is recoloured at load instead. ---- */
body.dark { background: #24262c; }
body.dark #sidebar { background: #1e2026; }
body.dark #sidebar button { background: #31343d; color: #e3e5ec; border-color: #424653; }
body.dark #sidebar button:hover { background: #3b3f4a; }
body.dark .read_half, body.dark .destroy_half { background: #31343d; color: #e3e5ec; }
body.dark #ad_slot { background: #2e2b3d; }
body.dark #consent_banner { background: #2b2d35; color: #e3e5ec; border-color: #424653; }
body.dark #consent_decline { background: #3b3f4a; color: #e3e5ec; }
body.dark #consent_decline:hover { background: #474c59; }
