/* Base
--------------------------------------------- */

html,
body {
	font-family: "Geo", sans-serif;
	font-size: 20px;
	line-height: 1.1;
}

/* Japanese: Geo has no kana or kanji, so the whole page uses the system font (SF with Hiragino on Apple), which keeps
   Latin and Japanese matched in a line instead of mixing Geo's letters into a Japanese font */
html:lang(ja),
html:lang(ja) body {
	font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
	line-height: 1.3;
}

h1,
h2,
h3,
h4,
h5,
h6 {
	line-height: 1.25;
}

/* Touch: no grey flash on tap (the buttons have their own press), and no zoom by pinching or double-tapping, which
   touch-action does in browsers; the viewport tag in index.html does it in the app's WebView. Panning still works. */
html,
body {
	-webkit-tap-highlight-color: transparent;
	touch-action: pan-x pan-y;
}

/* Touch screens only, so desktop keeps selecting and copying text: no selection, magnifier or long-press menu, no
   rubber-band bounce of the page (a modal that scrolls keeps its scrolling to itself). The level code stays selectable. */
@media (pointer: coarse) {
	html,
	body {
		-webkit-user-select: none;
		user-select: none;
		-webkit-touch-callout: none;
		overscroll-behavior: none;
	}

	.modal-box {
		overscroll-behavior: contain;
	}

	.code {
		-webkit-user-select: text;
		user-select: text;
	}
}

/* A swipe on the board moves the bot, so it must not scroll the page (Phaser sets this too). The canvas is the game
   upscaled by a whole factor (js/game/index.js) and shrunk to the stage here: smoothly, over Phaser's inline pixelated
   style, so its pixel blocks come out the same size with soft edges instead of uneven ones. */
#game__container canvas {
	touch-action: none;
	image-rendering: auto !important;
}

/* Level codes: a system monospace, as Geo's digits are sized oddly and its 0 and O look alike. All of these fonts
   slash or dot the zero, or give it a narrower shape than the O. 35% smaller than the text around it, which it would
   otherwise outsize. Don't nest it (the size compounds). */
.code {
	font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
	font-size: .65em;
}

/* The Generate dialog's code field: monospace like the codes, shown in upper case (the value is cleaned up when it is
   opened), and 16px so iOS doesn't zoom in on focus */
.code-input {
	font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
	font-size: 16px;
	text-transform: uppercase;
}

/* Game
--------------------------------------------- */

/* An 8px frame hugging the canvas, in the Phaser backgroundColor (js/game/index.js), with the neon glow around it. It is
   all box-shadow (a 0-blur 8px spread for the frame, the glow layers spread by the same 8px), which takes no layout
   space, and sits in the 8px padding around #game__container (Phaser's FIT ignores a parent's padding, so the padding
   is on the wrapper in index.html). The level thumbnails (index.html, levels view) share it at --fs, a size scale. */
#game__container canvas,
.level-thumb {
	--fs: 1;
	--frame: #F2ECFF;
	--frame-edge: #c9c0e6;   /* the 12px bottom edge, a bit darker than the frame (the 12px sits in the wrapper's bottom padding) */
	--glow: color-mix(in srgb, var(--frame) var(--glow-strength), transparent);
	box-shadow:
		0 0 0 calc(8px * var(--fs)) var(--frame),
		0 calc(12px * var(--fs)) 0 calc(8px * var(--fs)) var(--frame-edge),
		0 calc(13px * var(--fs)) calc(2px * var(--fs)) calc(8px * var(--fs)) var(--glow),
		0 calc(14px * var(--fs)) calc(5px * var(--fs)) calc(8px * var(--fs)) var(--glow),
		0 calc(16px * var(--fs)) calc(10px * var(--fs)) calc(8px * var(--fs)) var(--glow);
}

/* Half size; the frame colour is also the background while the thumbnail renders. The frame is a shadow, which takes
   no space, so a margin as wide as it keeps its outer edge on the card's edge (in line with the back button above).
   The width is explicit: Safari stretches an aspect-ratio flex item to its parent's full width and puts the margins
   outside it. */
.level-thumb {
	--fs: .5;
	margin: calc(8px * var(--fs));
	width: calc(100% - 16px * var(--fs));
	background-color: var(--frame);
}

/* The level drawn into a thumbnail (js/renderer showLevel): centred, with sharp pixels. Any spare width shows the frame colour,
   which is the canvas's own background. */
.level-thumb {
	display: flex;
	align-items: center;
	justify-content: center;
}

.level-thumb canvas {
	display: block;
	flex-shrink: 0;
	image-rendering: pixelated;
}

/* The splash's QR until it is drawn from the level: a dark checker on the frame colour */
.qr-placeholder {
	background-image: conic-gradient(#242234 25%, transparent 0 50%, #242234 0 75%, transparent 0);
	background-size: 20% 20%;
}

/* The levels root's other cards: a square as wide as a thumbnail with its frame, with a 6px edge below it like the
   thumbnail's (12px at --fs .5), drawn as a shadow so the square stays as tall as the card's box. An empty spot (the
   daily, the last played level) has no fill: a dashed outline on the other three sides, the edge and the icon, all in
   the light colour at the opacity of its message below (70%). A folder is styled below. */
.level-slot {
	--slot: color-mix(in srgb, var(--color-base-content) 70%, transparent);
	position: absolute;
	inset: 0;
	border: 4px dashed var(--slot);
	border-bottom: 0;
	box-shadow: 0 6px 0 var(--slot);
	color: var(--slot);
}

/* The Add a QR spot gets the focus back when the Generate dialog closes: no focus ring */
.level-add:focus {
	outline: none;
}

/* A folder looks like the dark buttons (.btn): their background, the icon lit like their labels, the darker edge (here
   the 6px shadow, as tall as a thumbnail's) and the faint light glow, which grows on hover; it presses down like them */
.level-slot-folder {
	--glow: color-mix(in srgb, #f0e9fe 2%, transparent);
	border: 0;
	background-color: var(--color-base-200);
	color: var(--color-base-content);
	box-shadow: 0 6px 0 var(--color-base-300), 0 7px 2px var(--glow), 0 8px 5px var(--glow), 0 10px 10px var(--glow);
	transition: box-shadow .1s;
}

.level-slot-folder svg {
	filter: drop-shadow(0 0 6px color-mix(in srgb, var(--color-base-content) 40%, transparent));
}

a:hover .level-slot-folder {
	box-shadow: 0 6px 0 var(--color-base-300), 0 7px 3px var(--glow), 0 9px 8px var(--glow), 0 11px 14px var(--glow);
}

a:active .level-slot-folder {
	transform: translateY(3px);
	box-shadow: 0 3px 0 var(--color-base-300), 0 4px 2px var(--glow), 0 5px 5px var(--glow), 0 7px 10px var(--glow);
}

/* Safe areas: the page runs under the notch, the status bar and the home indicator (viewport-fit=cover in index.html).
   A view root takes this class instead of p-*: padding is its usual one (--pad, or --pad-top, --pad-x, --pad-bottom). Top and
   bottom add the device's safe-area inset to it, so content keeps its gap below the notch and above the home indicator; the
   sides take whichever is bigger (they only have an inset in landscape). The insets are 0 in most browsers, so nothing
   changes there. */
.safe-area {
	padding-top: calc(var(--pad-top, var(--pad, 1rem)) + env(safe-area-inset-top));
	padding-right: max(var(--pad-x, var(--pad, 1rem)), env(safe-area-inset-right));
	padding-bottom: calc(var(--pad-bottom, var(--pad, 1rem)) + env(safe-area-inset-bottom));
	padding-left: max(var(--pad-x, var(--pad, 1rem)), env(safe-area-inset-left));
}

/* Icons: inline SVGs (Material Symbols, Sharp, Apache 2.0) filled with the text colour
--------------------------------------------- */

.icon {
	width: 1.5rem;
	height: 1.5rem;
	filter: drop-shadow(0 0 2px color-mix(in srgb, currentColor 60%, transparent)) drop-shadow(0 0 6px color-mix(in srgb, currentColor 40%, transparent));
}

/* An icon inside a line of text: no glow, sitting on the text line */
.icon-inline {
	display: inline-block;
	vertical-align: middle;
	flex-shrink: 0;
	filter: none;
}

/* Modals
--------------------------------------------- */

/* daisyUI caps the box at 100vh, which touches both screen edges and, on phones, is taller than the visible area
   (the browser bars). Cap it at the dynamic viewport minus a margin; the box scrolls inside (overflow-y: auto). */
.modal-box {
	max-height: calc(100dvh - 2rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));   /* the box is centred, so this keeps it clear of the notch and the home indicator */
	font-size: .875rem;     /* text-sm; the headings and buttons set their own sizes */
}

/* daisyUI reserves the scrollbar's width when a modal opens (scrollbar-gutter: stable, on the page and on the dialog), which
   on desktop pushes the box off-centre by that width. The page never scrolls and the boxes scroll inside themselves, so
   nothing needs reserving. daisyUI's rules are in :where() (no specificity), so these win. */
:root,
.modal {
	scrollbar-gutter: auto;
}

/* The tutorial dialog: the progress dots, step 2's pieces, the framed sample level and its tips
---------------------------------------------- */

.tutorial-dots {
	display: flex;
	gap: .4rem;
	margin-bottom: .75rem;
}

.tutorial-dots span {
	width: .5rem;
	height: .5rem;
	border-radius: 50%;
	background-color: currentColor;
	opacity: .25;
}

.tutorial-dots span.on {
	opacity: 1;
}

.tutorial-step {
	margin: 1rem 0;
}

.tutorial-step p + p {
	margin-top: .5rem;
}

/* Step 4: room under the first line, and the bot's name close to its description */
.tutorial-step .tutorial-intro {
	margin-bottom: 1.5rem;
}

.tutorial-step .how-part p + p {
	margin-top: .125rem;
}

.tutorial-pieces {
	display: flex;
	flex-direction: column;
	gap: .75rem;
	margin-top: 1rem;
}

.tutorial-pieces li {
	display: flex;
	align-items: center;
	gap: .75rem;
}

.tutorial-pieces .sprite {
	margin: 0;
	flex-shrink: 0;
}

/* The bot and the batteries on the modal itself, not on the floor tile (the target and the pit keep it) */
.tutorial-pieces .sprite-bot,
.tutorial-pieces .sprite-box,
.tutorial-pieces .sprite-box-on {
	background-color: transparent;
	box-shadow: none;
}

/* The sample video at the end of step 2: padding on every side, centred */
.tutorial-video {
	padding: 1.5rem;
}

.tutorial-video video {
	display: block;
	width: 100%;
	max-width: 16rem;
	height: auto;
	margin: 0 auto;
	aspect-ratio: 760 / 784;
}

/* Accordion sections (daisyUI collapse) in the Generate and Info dialogs: the title is a filled bar, and the open content
   hangs under it in a frame of the same colour, so the two read as different things */
.section-collapse > .collapse-title {
	background-color: var(--color-base-300);
}

.section-collapse[open] > .collapse-content {
	border: 4px solid var(--color-base-300);
	border-top: 0;
	padding-top: 1rem;
}

/* The Info dialog's details and report: label and value pairs in two columns, the labels dimmed */
.level-details {
	display: grid;
	grid-template-columns: auto 1fr;
	column-gap: 1rem;
	row-gap: .25rem;
	align-items: baseline;  /* the code is smaller and monospace: it lines up with its label on the text's baseline */
}

.level-details dt {
	opacity: .7;
}

/* Phones: less padding than daisyUI's 1.5rem, to leave more room for the content */
@media (max-width: 767px) {
	.modal-box {
		padding: 1rem;
	}
}

/* Headings
--------------------------------------------- */

/* Tailwind's preflight resets headings to body text, so their sizes are set here (h1 is the logo) */
h2 {
	font-size: 1.75rem;
}

h3 {
	font-size: 1.25rem;
}

/* Highlighted text, used for the dialog headings. Inverted colours give a highlighted-text look; inline-block makes the
   highlight hug the text instead of spanning its container. The soft one uses the default button face colour and keeps
   the normal text colour. */
.highlight,
.highlight-soft {
	display: inline-block;
	padding: 0 .4em;
}

.highlight {
	background-color: var(--color-base-content);
	color: var(--color-base-100);
}

.highlight-soft {
	background-color: var(--color-base-200);
}

/* In a modal the headings sit above the text, so they get some room under them */
.modal-box h2 {
	margin-bottom: .5rem;
}

.modal-box h3,
.modal-box h4 {
	margin-bottom: .25rem;
}

/* The About heading is followed by a paragraph rather than a list, so it gets more room */
.modal-box h3.about-heading {
	margin-bottom: 1rem;
}

/* Paragraphs in a modal: Tailwind's reset removes their margins, so space them out */
.modal-box p + p {
	margin-top: .5rem;
}

/* Game sprites inline in the text (the help). Each file is a vertical strip of square frames; --n is how many
   frames it has and --f the one shown. Scaled up without smoothing, as the game draws them. They sit on the red
   area's floor colour with a wall-coloured edge, so the pale ones (targets) stand out from the modal. */
.sprite {
	display: inline-block;
	width: 1.5rem;
	height: 1.5rem;
	vertical-align: middle;
	margin: 0 .125rem;
	background-color: #F3E0F2;
	box-shadow: 0 0 0 2px #242234;
	background-repeat: no-repeat;
	background-size: 100% calc(var(--n) * 100%);
	background-position: 0 calc(var(--f, 0) / (var(--n) - 1) * 100%);
	image-rendering: pixelated;
}

/* The bots, by colour: green is the classic Bot (versions 1 and 2), the others are the powers of version 3 */
.sprite-bot,
.sprite-bot-red,
.sprite-bot-blue,
.sprite-bot-yellow {
	--n: 4;
}

.sprite-bot {
	background-image: url(../assets/sprites/player_d.png);
}

.sprite-bot-red {
	background-image: url(../assets/sprites/player_a.png);
}

.sprite-bot-blue {
	background-image: url(../assets/sprites/player_b.png);
}

.sprite-bot-yellow {
	background-image: url(../assets/sprites/player_c.png);
}

/* A part of a How to play text: a bot's sprite beside its paragraphs (the Power Bot's three powers) */
.how-part {
	display: flex;
	align-items: center;
	gap: .75rem;
}

.how-part + .how-part {
	margin-top: 1rem;
}

.how-part .sprite {
	margin: 0;
	flex-shrink: 0;
	background-color: transparent;     /* the bot on the modal itself, not on the floor tile (the legend keeps the tile) */
	box-shadow: none;
}

.how-part-lg .sprite {
	width: 3rem;
	height: 3rem;     /* the bot's own dialog: twice the size */
}

.how-part p {
	margin-top: 0;
}

.how-part p + p {
	margin-top: .5rem;
}

.sprite-box,
.sprite-box-on {
	--n: 6;
	background-image: url(../assets/sprites/battery.png);
}

.sprite-box-on {
	--f: 3;
}

.sprite-target,
.sprite-pit {
	--n: 2;
	background-image: url(../assets/sprites/target.png);
}

.sprite-pit {
	--f: 1;
}

/* Accordion
--------------------------------------------- */

/* Each item's header looks like a default button (same face colour and text) without the edge. */
.accordion summary {
	display: flex;
	align-items: center;
	justify-content: space-between;
	min-height: calc(var(--size-field) * 10);   /* the .btn height */
	padding: 0 1rem;
	background-color: var(--color-base-200);
	cursor: pointer;
	list-style: none;
}

.accordion summary::-webkit-details-marker {
	display: none;
}

.accordion summary::after {
	content: "+";
}

.accordion[open] summary::after {
	content: "−";
}

.accordion > div {
	padding: 1.2rem 0;   /* no side padding: the text is as wide as the label box */
}

/* Buttons
--------------------------------------------- */



/* A base-300 edge under every daisyUI button (--edge, 4px). Pressing it slides the face down --press (2px) as the edge shrinks by the same
   amount. The height and margin changes cancel out, so the layout around the button doesn't move. */
.btn {
	--edge: 4px;
	--press: 3px;
	border-bottom: var(--edge) solid var(--color-base-300);
	border-top-width: 0;   /* no daisyUI outline on the other sides */
	border-left-width: 0;
	border-right-width: 0;
	transition-property: color, background-color, border-color, box-shadow;   /* the press itself snaps, or the base wobbles */
	transition-duration: .1s;
	font-weight: normal;
	--gs: .5;   /* glow size scale, 1 on the menu buttons */
	--glow-mix: 2%;   /* the plain (dark) buttons glow in a light colour, wide and faint; the colour styles reset this */
	--glow: color-mix(in srgb, var(--btn-color, #f0e9fe) var(--glow-mix), transparent);
	text-shadow: 0 0 6px color-mix(in srgb, currentColor 40%, transparent);
	box-shadow: 0 calc(1px * var(--gs)) calc(2px * var(--gs)) var(--glow), 0 calc(2px * var(--gs)) calc(5px * var(--gs)) var(--glow), 0 calc(4px * var(--gs)) calc(10px * var(--gs)) var(--glow);   /* y offsets throw the glow toward the bottom */
}

.btn:hover:not(:disabled, [disabled], .btn-disabled) {
	box-shadow: 0 calc(1px * var(--gs)) calc(3px * var(--gs)) var(--glow), 0 calc(3px * var(--gs)) calc(8px * var(--gs)) var(--glow), 0 calc(5px * var(--gs)) calc(14px * var(--gs)) var(--glow);
}

.btn:disabled, .btn[disabled], .btn-disabled {
	box-shadow: none;
}

.btn:active:not(:disabled, [disabled], .btn-disabled) {
	border-bottom-width: calc(var(--edge) - var(--press));
	height: calc(var(--btn-height, var(--size)) - var(--press));
	margin-bottom: var(--press);
	transform: translateY(var(--press));
}

/* Experiment: a tiny label under the icon of an icon button, from its data-label. The button keeps its square size, so
   the icon is a little smaller to make room. */
.btn-labeled {
	flex-direction: column;
	gap: 1px;
	padding-inline: 0;
}

.btn-labeled-wide {
	padding-inline: .65625rem;   /* a label wider than the icon (Save QR, Link copied) sets the width */
}

.btn-labeled .icon {
	width: 1.25rem;
	height: 1.25rem;
}

.btn-labeled::after {
	content: attr(data-label);
	font-size: .5rem;
	line-height: 1;
	text-transform: uppercase;
}

/* Menu button: as tall as the 48px bot image beside it (40px face + 8px edge), with a larger label */
.btn-menu {
	--btn-height: 48px;
	--edge: 8px;
	height: var(--btn-height);
	font-size: 1.25rem;
	text-transform: uppercase;
	--gs: 1;
}

/* The bot images glow in their button's colour (drop-shadow follows the sprite's outline) */
.menu-bot:has(+ .btn-green) { --glow: color-mix(in srgb, #89c658 var(--glow-strength), transparent); }
.menu-bot:has(+ .btn-yellow) { --glow: color-mix(in srgb, #d9bd0d var(--glow-strength), transparent); }
.menu-bot:has(+ .btn-blue) { --glow: color-mix(in srgb, #59aaf5 var(--glow-strength), transparent); }
.menu-bot:has(+ .btn-red) { --glow: color-mix(in srgb, #dd574b var(--glow-strength), transparent); }

.menu-bot {
	filter: drop-shadow(0 0 2px var(--glow)) drop-shadow(0 0 5px var(--glow)) drop-shadow(0 0 10px var(--glow));
}

/* The logo glows in its own light colour, with the buttons' size and downward throw */
.logo-glow {
	--glow: color-mix(in srgb, #f0e9fe var(--glow-strength), transparent);
	filter: drop-shadow(0 1px 2px var(--glow)) drop-shadow(0 2px 5px var(--glow)) drop-shadow(0 4px 10px var(--glow));
}

/* The view wrapper fades out and in around every view swap (FADE_MS in main.js matches the duration) */
.view-fade {
	transition: opacity .4s ease;
}

.view-fade.view-fading {
	opacity: 0;
}

/* Menu rows slide in from the left when the menu opens, staggered with an inline animation-delay. A keyframe
   animation rather than a transition with @starting-style, which older Safari ignores. */
.menu-row {
	animation: menu-slide .75s ease both;
}

/* After the first time in a visit (menu.js) */
.menu-static .menu-row {
	animation: none;
}

@keyframes menu-slide {
	from { transform: translateX(-4rem); }
	to { transform: translateX(0); }
}

.menu-bot {
	height: 48px;
	width: 48px;
}

.menu-bot img {
	height: 100%;
	width: 100%;
	image-rendering: pixelated;
}

/* Tablets and up: the next clean step of the bots' 6×6 pixel grid, 60px (50px face + 10px edge) */
@media (min-width: 768px) {
	.btn-menu {
		--btn-height: 60px;
		--edge: 10px;
		font-size: 1.5rem;
	}

	.menu-bot {
		height: 60px;
		width: 60px;
	}
}

/* Colour styles (dev/buttons/Colors.svg): face, text and bottom edge. Use them with `btn`. */
.btn-green {
	--btn-color: #89c658;
	--btn-fg: #e0fbc0;
	border-bottom-color: #427f3b;
}

.btn-yellow {
	--btn-color: #d9bd0d;
	--btn-fg: #fff6c9;
	border-bottom-color: #988300;
}

.btn-blue {
	--btn-color: #59aaf5;
	--btn-fg: #e7f3ff;
	border-bottom-color: #3e7ab0;
}

.btn-red {
	--btn-color: #dd574b;
	--btn-fg: #ffdad7;
	border-bottom-color: #b03e34;
}

.btn-green, .btn-yellow, .btn-blue, .btn-red {
	--glow-mix: var(--glow-strength);
	text-shadow: 0 0 6px color-mix(in srgb, var(--btn-fg) 55%, transparent), 0 0 14px color-mix(in srgb, var(--btn-color) 70%, transparent);
}

.btn:not(.btn-green, .btn-yellow, .btn-blue, .btn-red) {
	--gs: 1;
}

/* Lighter label on the colour styles and primary (the menu buttons are colour styles too) */
.btn-green, .btn-yellow, .btn-blue, .btn-red, .btn-primary {
	color: color-mix(in srgb, var(--btn-fg) 25%, white);
}

/* Rating icons (the end-game Difficulty row): the tier colours, 1 green … 4 red (ratingColor in app.js). The Levels cards show no rating for now */
.rating-green { color: #89c658; }
.rating-blue { color: #59aaf5; }
.rating-yellow { color: #d9bd0d; }
.rating-red { color: #dd574b; }
