:root {
	--bg: #111;
	--fg: #f5f5f5;
	--muted: #9a9a9a;
	--accent: #22c55e;
	--card: #1e1e1e;
	--error: #f87171;
}
* { box-sizing: border-box; }
html, body {
	margin: 0;
	height: 100%;
	background: var(--bg);
	color: var(--fg);
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main {
	max-width: 560px;
	margin: 0 auto;
	/* bottom padding clears the fixed footer */
	padding: 5px 5px calc(120px + env(safe-area-inset-bottom));
	display: flex;
	flex-direction: column;
	gap: 10px;
}
/* Start button, fixed at the bottom within thumb reach */
footer {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 1;
	padding: 2px 1px calc(4px + env(safe-area-inset-bottom));
	background: var(--bg);
	border-top: 1px solid #2a2a2a;
}
/* Scan and Search fill the footer, up to the content column's width */
.footer-buttons {
	display: flex;
	gap: 8px;
	max-width: 528px;
	margin: 0 auto;
}
button#start { flex: 1; min-width: 0; }
header {
	background: hsl(0 0% 50%);
	border-radius: 13px;
	padding: 5px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 5px;
}
.account {
	font: inherit;
	font-size: 0.95rem;
	font-weight: 600;
	padding: 10px 14px;
	border: 1px solid #333;
	border-radius: 10px;
	background: var(--card);
	color: var(--fg);
	text-decoration: none;
	white-space: nowrap;
	cursor: pointer;
}
.account[hidden] { display: none; }
#accountMsg:empty { display: none; }
#accountMsg, #status { text-align: center; }
p { margin: 0; color: var(--muted); }
/* Scan and Search buttons */
footer button {
	font: inherit;
	font-size: 1.75rem;
	font-weight: 600;
	padding: 12px;
	border: 1px solid white;
	border-radius: 14px;
	background: radial-gradient(black, hsl(0 0% 30% / 1));
	color: white;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
}
button#install {
	font: inherit;
	font-weight: 600;
	padding: 14px;
	border: 1px solid #333;
	border-radius: 14px;
	background: var(--card);
	color: var(--fg);
	cursor: pointer;
}
button#install[hidden] { display: none; }
button#start:disabled { opacity: 0.4; cursor: not-allowed; }
button#start.loading:disabled { opacity: 0.85; cursor: progress; }
.spinner {
	width: 1.1em;
	height: 1.1em;
	border: 3px solid rgba(5, 46, 18, 0.25);
	border-top-color: currentColor;
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
	flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
	.spinner { animation-duration: 2.4s; }
}
.card {
	background: var(--card);
	border-radius: 10px;
	padding: 5px;
}
.panel { position: relative; }
.panel .close {
	position: absolute;
	top: 0px;
	right: 0px;
	width: 36px;
	height: 36px;
	padding: 0;
	font: inherit;
	font-size: 1.5rem;
	line-height: 1;
	border: 0;
	border-radius: 50%;
	background: none;
	color: var(--muted);
	cursor: pointer;
}
#searchForm { display: flex; gap: 8px; }
#searchInput {
	flex: 1;
	min-width: 0;
	font: inherit;
	padding: 10px 12px;
	border: 1px solid #333;
	border-radius: 10px;
	background: var(--bg);
	color: var(--fg);
}
#searchView { display: flex; flex-direction: column; gap: 10px; }
#searchView[hidden] { display: none; }
#searchMsg:empty { display: none; }
#searchList { list-style: none; margin: 0; padding: 0; }
#searchList button {
	width: 100%;
	display: flex;
	gap: 5px;
	padding: 2px 0;
	font: inherit;
	text-align: left;
	border: 0;
	border-top: 1px solid hsl(0 0% 30%);
	background: none;
	color: var(--fg);
	cursor: pointer;
}
#searchList li:first-child button { border-top: 0; }
#searchList img, #searchList .no-image {
	flex: none;
	/* 140px, but at most 30% of the row on narrow screens */
	width: min(140px, 30%);
	height: auto;
	aspect-ratio: 1;
	object-fit: contain;
	background: #fff;
	border-radius: 6px;
}
#searchList .no-image { background: #2a2a2a; }
#searchList .text { flex: 1; min-width: 0; }
#searchList small { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.details .price { color: var(--fg); font-weight: 600; }
.details .per { color: var(--muted); font-weight: normal; }
#searchList .aisle { color: var(--muted); }
/* nutrition rating badge, colored by score */
.rating {
	margin-top: 4px;
	padding: 1px 8px;
	border-radius: 999px;
	font-size: 0.8rem;
	font-weight: 600;
    text-shadow: 0 2px 4px black;
    color: white;
}
#searchList .name { font-weight: bold; }
#searchList .details { margin-top: 4px; font-size: 1rem; }
.details .rating { margin-top: 0; padding: 1px 6px; font-size: 1rem; font-weight: bold; }
/* aisle card: the same details line, then the ingredients, under the aisle locations */
#productDetails { margin-top: 12px; color: var(--muted); font-size: 1rem; }
#productIngredients { margin-top: 8px; font-size: 0.9rem; }
#productDetails[hidden], #productIngredients[hidden] { display: none; }
.panel > .label { padding: 0px 44px 0px 0; } /* keeps text clear of the close button */
.panel .close:hover { background: #2a2a2a; color: var(--fg); }
body.panel-open #resultCard, body.panel-open #aisleCard, body.panel-open #historyCard { display: none; }
.label {
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--muted);
	margin-bottom: 6px;
}
#result {
	color: hsl(0 0 50%);
	font-family: ui-monospace, Menlo, Consolas, monospace;
	font-size: 1.8rem;
	font-weight: 600;
	word-break: break-all;
}
#history { list-style: none; margin: 0; padding: 0; }
#history button {
	width: 100%;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px 0;
	font: inherit;
	text-align: left;
	border: 0;
	border-top: 1px solid hsl(0 0% 30%);
	background: none;
	color: var(--fg);
	cursor: pointer;
}
#history li:first-child button { border-top: 0; }
#history img, #history .no-image {
	flex: none;
	width: 80px;
	height: 80px;
	object-fit: contain;
	background: #fff;
	border-radius: 6px;
}
#history .no-image { background: #2a2a2a; }
#history .name { display: block; font-weight: bold; }
#history .text { flex: 1; min-width: 0; }
#history .details { margin-top: 4px; font-size: 1rem; }
#history small { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.error { color: var(--error); }
#resultCard, #aisleCard { text-align: center; }
#submit { font-size: 0.95rem; margin-top: 10px; color: var(--muted); }
#submit:empty { display: none; }
#submit.success { color: var(--accent); }
#productName {
	text-align: center;
	font-size: 1.6rem;
	font-weight: 600;
	margin-bottom: 12px;
}
/* Store button: takes the rest of the header, long names are truncated */
#changeStore {
	flex: 1;
	min-width: 0;
	text-align: left;
}
#storeName, #profileName {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
}
#profileBtn { min-width: 0; max-width: 45%; }
#profileView { display: flex; flex-direction: column; gap: 10px; }
#profileView[hidden], #profileForm[hidden] { display: none; }
#profileForm { display: flex; gap: 8px; }
#profileMsg:empty, #profileIdEl:empty { display: none; }
#profileIdEl { color: var(--muted); word-break: break-all; }
#storeList small { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
#storePicker { display: flex; flex-direction: column; gap: 10px; }
#storePicker[hidden] { display: none; }
#storeForm { display: flex; gap: 8px; }
#zip, #nameInput {
	flex: 1;
	min-width: 0;
	font: inherit;
	padding: 10px 12px;
	border: 1px solid #333;
	border-radius: 10px;
	background: var(--bg);
	color: var(--fg);
}
#storeMsg:empty { display: none; }
#storeList { list-style: none; margin: 0; padding: 0; }
#storeList button {
	width: 100%;
	font: inherit;
	text-align: left;
	padding: 10px 0;
	border: 0;
	border-top: 1px solid #2a2a2a;
	background: none;
	color: var(--fg);
	cursor: pointer;
}
#storeList li:first-child button { border-top: 0; }
#aisles {
	width: 100%;
	text-align: center;
	border-collapse: collapse;
	font-size: 1.6rem;
}
#aisles[hidden], #noAisles[hidden] { display: none; }
#aisles th {
	font-weight: 600;
	font-size: 0.9rem;
	color: var(--muted);
	padding: 0 8px 4px 0;
}
#aisles td {
	padding: 0px 8px 0px 0;
	border-top: 1px solid #2a2a2a;
	vertical-align: middle;
}
#productImage {
	display: block;
	width: 100%;
	max-width: 320px;
	aspect-ratio: 1;
	margin: 0 auto 16px;
	object-fit: contain;
	background: #fff;
	border-radius: 10px;
}
#productImage[hidden] { display: none; }

/* Fullscreen camera view */
#scanner {
	position: fixed;
	inset: 0;
	z-index: 2;
	background: #000;
	display: none;
	cursor: pointer;
	user-select: none;
	-webkit-user-select: none;
	touch-action: manipulation;
}
#scanner.active { display: block; }
#scanner video {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
}
#live {
	position: absolute;
	left: 16px;
	right: 16px;
	bottom: calc(24px + env(safe-area-inset-bottom));
	padding: 14px 16px;
	border-radius: 12px;
	background: rgba(0, 0, 0, 0.7);
	text-align: center;
	font-family: ui-monospace, Menlo, Consolas, monospace;
	word-break: break-all;
}
#hint {
	position: absolute;
	top: calc(16px + env(safe-area-inset-top));
	left: 0;
	right: 0;
	text-align: center;
	font-size: 0.95rem;
	color: #fff;
	text-shadow: 0 1px 3px #000;
}

/* Welcome screen: shown until a store is chosen, with only the store picker below it */
#welcome { text-align: center; padding: 24px 8px 8px; }
#welcome[hidden] { display: none; }
#welcome img { display: block; margin: 0 auto 12px; border-radius: 16px; }
#welcome h1 { margin: 0 0 8px; font-size: 1.6rem; }
#welcome p { margin: 0; color: var(--muted); }
body.welcome header, body.welcome footer, body.welcome #storePicker .close,
body.welcome #storePicker > .label, body.welcome #storeAddress,
body.welcome #profileView, body.welcome #searchView, body.welcome #install,
body.welcome #resultCard, body.welcome #aisleCard, body.welcome #historyCard { display: none; }
#historyCard { margin-top: 10px; }
