:root {
	--bg: #0f172a;
	--panel: #1e293b;
	--panel-2: #27364d;
	--text: #e2e8f0;
	--muted: #94a3b8;
	--accent: #fbbf24;
	--line: #334155;
}

* {
	box-sizing: border-box;
}

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

/* Background photo: Shreyas Sane. A fixed pseudo-element rather than `background-attachment:
   fixed`, which iOS Safari mishandles. The scrim is deliberately light so the
   sunset reads through; text not inside an opaque `.card` carries its own
   contrast backstop (see `.item-head`, `#item-back`, `.banner`, `footer`).
   `center 68%` frames the horizon and camels instead of empty sky, because
   `cover` crops this tall photo hard on wide viewports. */
body::before {
	content: "";
	position: fixed;
	inset: 0;
	z-index: -1;
	pointer-events: none;
	background:
		linear-gradient(
			180deg,
			rgba(15, 23, 42, 0.86) 0%,
			rgba(15, 23, 42, 0.42) 45%,
			rgba(15, 23, 42, 0.88) 100%
		),
		url("/static/backgrounds/shreyas-sane-camel.webp") center 68% / cover
			no-repeat;
}

header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 14px 24px;
	background: var(--panel);
	border-bottom: 1px solid var(--line);
	position: sticky;
	top: 0;
	z-index: 10;
	flex-wrap: wrap;
}

.brand {
	display: flex;
	align-items: center;
	gap: 10px;
}

/* Decorative: the wordmark beside it already names the site. */
.brand-logo {
	width: 32px;
	height: 32px;
	border-radius: 8px;
	flex: none;
}

.brand h1 {
	margin: 0;
	font-size: 20px;
	letter-spacing: 0.5px;
	color: var(--accent);
}
.brand .muted {
	font-size: 12px;
	display: block;
}

nav {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
}
nav button {
	background: transparent;
	color: var(--muted);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: 7px 14px;
	cursor: pointer;
	font-size: 14px;
}
nav button:hover {
	color: var(--text);
	border-color: var(--accent);
}
nav button.active {
	color: #0f172a;
	background: var(--accent);
	border-color: var(--accent);
	font-weight: 600;
}

main {
	max-width: 1400px;
	margin: 0 auto;
	padding: 24px;
}

h2 {
	font-size: 16px;
	margin: 0 0 12px;
}
.muted {
	color: var(--muted);
	font-size: 13px;
}
.link {
	background: none;
	border: none;
	color: var(--accent);
	cursor: pointer;
	padding: 0;
	font-size: 14px;
	margin-bottom: 8px;
}
.link:hover {
	text-decoration: underline;
}

/* Only `#item-back` sits outside a card, directly on the photo. */
#item-back {
	background: rgba(15, 23, 42, 0.72);
	backdrop-filter: blur(6px);
	border-radius: 8px;
	padding: 6px 10px;
	margin-bottom: 12px;
}

.card {
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 16px;
	margin-bottom: 20px;
}

.kpis {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
	gap: 16px;
	margin-bottom: 20px;
}
.kpi {
	margin: 0;
	text-align: center;
}
.kpi-value {
	font-size: 26px;
	font-weight: 700;
	color: var(--accent);
}
.kpi-label {
	color: var(--muted);
	font-size: 13px;
}

.grid-2 {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 20px;
}
.grid-2 .wide {
	grid-column: span 1;
}
@media (max-width: 900px) {
	.grid-2 {
		grid-template-columns: 1fr;
	}
}

.chart-card {
	height: 380px;
	position: relative;
}
.chart-card canvas {
	max-height: 310px;
}
.chart-card h2 button.link {
	font-size: 12px;
	margin: 0 0 0 4px;
	vertical-align: baseline;
}
#chart-supply {
	cursor: grab;
}
#chart-supply:active {
	cursor: grabbing;
}

/* Every table sits in one of these: the dashboard is table-heavy and the
   columns are deliberately `nowrap`, so on a narrow screen the table scrolls
   inside its card instead of stretching the whole page (which used to clip the
   header and every other card at the viewport edge). */
.table-wrap {
	overflow-x: auto;
	/* a focused/sorted header's outline should not be clipped at the edges */
	margin: -2px -4px;
	padding: 2px 4px;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
	scrollbar-color: var(--line) transparent;
}

/* A wide table could only be panned with the scroll bar *below* it, so a long
   table had to be scrolled to its end before it could be moved sideways.  The
   `.table-top` twin above it — an empty spacer as wide as the table, built by
   app.js — mirrors the table's scroll position; it is hidden while the table
   fits and shares the wrapper's padding so both scroll ranges match. */
.table-top {
	overflow-x: auto;
	margin: 2px -4px 0;
	padding: 0 4px;
	scrollbar-width: thin;
	scrollbar-color: var(--line) transparent;
}
.table-top[hidden] {
	display: none;
}
.table-top-spacer {
	height: 1px;
}

table {
	width: 100%;
	border-collapse: collapse;
	font-size: 14px;
}
th,
td {
	padding: 8px 10px;
	text-align: left;
	border-bottom: 1px solid var(--line);
	white-space: nowrap;
}
th {
	color: var(--muted);
	font-weight: 600;
	font-size: 13px;
}
th button {
	background: none;
	border: 0;
	padding: 0;
	font: inherit;
	color: var(--muted);
	cursor: pointer;
	user-select: none;
}
th button:hover,
th button.active {
	color: var(--accent);
}
th button.sort-min::after {
	content: " ↑";
}
th button.sort-max::after {
	content: " ↓";
}
tbody tr:hover {
	background: var(--panel-2);
}
.num {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.item-link {
	color: #7dd3fc;
	text-decoration: none;
}
.item-link:hover {
	text-decoration: underline;
}

.badge {
	display: inline-block;
	padding: 1px 8px;
	border: 1px solid var(--line);
	border-radius: 999px;
	font-size: 11px;
	vertical-align: middle;
}
.badge.expired {
	color: #fbbf24;
	border-color: #fbbf24;
}
.badge.removed {
	color: #38bdf8;
	border-color: #38bdf8;
}
.badge.craftable {
	color: #2dd4bf;
	border-color: #2dd4bf;
}
.badge.event {
	color: #f472b6;
	border-color: #f472b6;
}

.up {
	color: #4ade80;
}
.down {
	color: #f87171;
}

.controls {
	display: flex;
	gap: 10px;
	align-items: center;
	margin-bottom: 16px;
	flex-wrap: wrap;
}
.controls input[type="search"] {
	background: var(--panel);
	border: 1px solid var(--line);
	color: var(--text);
	border-radius: 8px;
	padding: 8px 12px;
	min-width: 260px;
	font-size: 14px;
}
.controls select {
	background: var(--panel);
	border: 1px solid var(--line);
	color: var(--text);
	border-radius: 8px;
	padding: 8px 10px;
	font-size: 14px;
}
.controls button {
	background: var(--panel);
	border: 1px solid var(--line);
	color: var(--text);
	border-radius: 8px;
	padding: 8px 12px;
	cursor: pointer;
}

.search-box {
	position: relative;
	flex: 0 1 auto;
}
.search-box input[type="search"] {
	width: 100%;
}

/* Type-ahead under the search box: an overlay, so opening it never moves the
   results table.  It tracks the box on a phone and widens to a readable size
   on desktop, still capped to the viewport. */
.suggestions {
	position: absolute;
	top: calc(100% + 4px);
	left: 0;
	z-index: 20;
	width: max-content;
	min-width: 100%;
	max-width: min(420px, calc(100vw - 32px));
	max-height: 340px;
	overflow-y: auto;
	margin: 0;
	padding: 4px;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 10px;
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.suggestions[hidden] {
	display: none;
}
.suggestion {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-radius: 7px;
	cursor: pointer;
}
.suggestion:hover,
.suggestion.active {
	background: var(--panel-2);
}
.suggestion-text {
	flex: 1 1 auto;
	min-width: 0;
}
.suggestion-name,
.suggestion-sub {
	display: block;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}
.suggestion-sub {
	color: var(--muted);
	font-size: 12px;
}
.suggestion mark {
	background: none;
	color: var(--accent);
	font-weight: 600;
}
.suggestion-tags {
	flex: 0 0 auto;
}
.suggestion-none {
	padding: 10px;
	color: var(--muted);
}

.banner {
	background:
		linear-gradient(rgba(251, 191, 36, 0.12), rgba(251, 191, 36, 0.12)),
		rgba(15, 23, 42, 0.75);
	border: 1px solid var(--accent);
	color: var(--accent);
	border-radius: 12px;
	padding: 14px 18px;
	margin-bottom: 20px;
	backdrop-filter: blur(6px);
}
.banner code {
	background: rgba(0, 0, 0, 0.3);
	padding: 2px 6px;
	border-radius: 6px;
}

/* The selected best-value definition's explanation: hidden until the visitor
   changes the definition, so the tab opens as a table, not a wall of text. */
.definition {
	margin: 0 0 16px;
	padding: 10px 12px;
	border-left: 3px solid var(--accent);
	border-radius: 8px;
	background: var(--panel-2);
}

.item-head {
	display: flex;
	align-items: flex-start;
	gap: 16px;
	margin-bottom: 16px;
	background: rgba(15, 23, 42, 0.72);
	backdrop-filter: blur(6px);
	border-radius: 12px;
	padding: 16px;
}
.item-head-text {
	min-width: 0;
}
.item-head h2 {
	font-size: 22px;
	margin: 0;
	word-break: break-all;
	white-space: normal;
}
.item-head .muted {
	font-size: 14px;
}
.item-icon {
	flex: 0 0 auto;
	width: 64px;
	height: 64px;
	border: 1px solid var(--line);
	border-radius: 10px;
	background-color: var(--panel-2);
	background-repeat: no-repeat;
	image-rendering: pixelated;
}
.item-icon-inline {
	display: inline-block;
	width: 20px;
	height: 20px;
	margin-right: 6px;
	vertical-align: middle;
	border-radius: 4px;
	background-color: var(--panel-2);
	background-repeat: no-repeat;
	image-rendering: pixelated;
}
.suggestion .item-icon-inline {
	flex: 0 0 auto;
	width: 28px;
	height: 28px;
	margin-right: 0;
}

/* Crafting / dismantle material lists on the item page (icon links +
   quantity + optional per-unit price). */
.materials {
	list-style: none;
	margin: 0;
	padding: 0;
}
.materials .material {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 6px 0;
	border-bottom: 1px solid var(--line);
}
.materials .material:last-child {
	border-bottom: 0;
}
.materials .item-icon-inline {
	width: 28px;
	height: 28px;
	margin-right: 0;
}
.materials .material-name {
	flex: 1 1 auto;
}
.materials .material-qty,
.materials .material-price {
	flex: 0 0 auto;
	color: var(--muted);
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}
.materials-total {
	margin: 12px 0 0;
}
a.material-icon {
	display: inline-flex;
	line-height: 0;
}

/* Backstop so the footer and item header stay readable over the photo. */
footer {
	text-align: center;
	padding: 28px;
	border-top: 1px solid var(--line);
	background: rgba(15, 23, 42, 0.72);
	backdrop-filter: blur(6px);
}
footer code {
	color: var(--accent);
}

footer .credit,
footer .notice {
	margin: 10px 0 0;
	font-size: 13px;
}

footer .credit a,
footer .notice a {
	color: var(--text);
	text-decoration-color: var(--line);
	text-underline-offset: 2px;
}

footer .credit a:hover,
footer .credit a:focus-visible,
footer .notice a:hover,
footer .notice a:focus-visible {
	color: var(--accent);
}

/* --- narrow screens --------------------------------------------------------
   A phone (≤640px) gets the same views, only tighter: the tabs stay on one
   scrollable row instead of wrapping into three, the wide tables scroll inside
   their card (see .table-wrap), the KPI cards pair up, and the charts lose
   some height. Nothing is hidden — every column is still reachable by
   scrolling the table sideways. */
@media (max-width: 640px) {
	body {
		font-size: 14px;
	}

	header {
		padding: 10px 14px;
		gap: 8px;
	}
	.brand-logo {
		width: 28px;
		height: 28px;
	}
	.brand h1 {
		font-size: 18px;
	}
	nav {
		/* one horizontal row, scrolled, rather than three wrapped ones: the
		   sticky header then costs ~90px instead of ~190px of a small screen */
		flex-wrap: nowrap;
		overflow-x: auto;
		width: 100%;
		padding-bottom: 2px;
		scrollbar-width: thin;
		scrollbar-color: var(--line) transparent;
	}
	nav button {
		flex: 0 0 auto;
		padding: 6px 12px;
		font-size: 13px;
	}

	main {
		padding: 14px;
	}
	.card {
		padding: 14px;
		border-radius: 10px;
	}
	h2 {
		font-size: 15px;
	}

	.kpis {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 12px;
	}
	.kpi {
		padding: 12px 8px;
	}
	.kpi-value {
		font-size: 20px;
		overflow-wrap: anywhere;
	}
	.kpi-label {
		font-size: 12px;
	}

	.chart-card {
		height: 300px;
	}
	.chart-card canvas {
		max-height: 240px;
	}
	.grid-2 {
		gap: 16px;
	}

	.controls {
		gap: 8px;
	}
	.search-box {
		flex: 1 1 100%;
	}
	.controls input[type="search"] {
		min-width: 0;
		flex: 1 1 100%;
	}
	.search-box input[type="search"] {
		width: 100%;
	}
	.suggestions {
		max-width: 100%;
	}
	.controls select {
		flex: 1 1 auto;
		max-width: 100%;
	}
	/* the best-value definition selector gets its own line on a phone */
	#value-definition {
		width: 100%;
		margin: 6px 0;
	}

	table {
		font-size: 13px;
	}
	th,
	td {
		padding: 7px 8px;
	}

	/* One card per row instead of a table that scrolls sideways, so *every*
	   column stays readable: each cell becomes a label/value line, the label
	   copied from its column header by app.js (`data-label`).  A sortable
	   table keeps its header buttons above the cards — they are the only way
	   to sort on a phone — under a "Sort:" hint; a table without them has
	   nothing to show once the labels moved into the cards.  The rules are
	   grouped by increasing specificity (the linter asks for it). */
	table,
	tbody,
	tr,
	td {
		display: block;
		width: 100%;
	}
	thead {
		display: none;
	}
	tbody tr {
		border: 1px solid var(--line);
		border-radius: 10px;
		padding: 2px 10px;
		margin-bottom: 10px;
	}
	tbody td {
		padding: 7px 0;
		border-bottom: 1px solid var(--line);
		white-space: normal;
		text-align: right;
	}
	tbody td::before {
		content: attr(data-label);
		float: left;
		margin-right: 12px;
		color: var(--muted);
		font-size: 12px;
	}
	table.sortable thead {
		display: block;
		margin: 0 0 10px;
	}
	tbody td:last-child {
		border-bottom: 0;
	}
	/* the "nothing here" row spans the table: a centred note, not a card */
	tbody td[colspan] {
		border-bottom: 0;
		text-align: center;
	}
	table.sortable thead tr {
		display: flex;
		flex-wrap: wrap;
		gap: 6px;
	}
	table.sortable thead th {
		padding: 0;
		border: 0;
	}
	tbody td[colspan]::before {
		content: none;
		margin: 0;
	}
	table.sortable thead tr::before {
		content: "Sort:";
		align-self: center;
		color: var(--muted);
		font-size: 12px;
	}

	.item-head {
		gap: 12px;
		padding: 12px;
	}
	.item-head h2 {
		font-size: 18px;
	}
	.item-icon {
		width: 52px;
		height: 52px;
	}
	.materials .material {
		flex-wrap: wrap;
	}

	footer {
		padding: 20px 14px;
	}
}
