/* BitcoinWatch — design system
   Fonts: Red Hat Mono (SIL OFL 1.1), self-hosted. */

@font-face {
	font-family: "Red Hat Mono";
	src: url("../fonts/red-hat-mono-400.woff2") format("woff2");
	font-weight: 400;
	font-display: swap;
}
@font-face {
	font-family: "Red Hat Mono";
	src: url("../fonts/red-hat-mono-500.woff2") format("woff2");
	font-weight: 500;
	font-display: swap;
}
@font-face {
	font-family: "Red Hat Mono";
	src: url("../fonts/red-hat-mono-600.woff2") format("woff2");
	font-weight: 600;
	font-display: swap;
}
@font-face {
	font-family: "Red Hat Mono";
	src: url("../fonts/red-hat-mono-700.woff2") format("woff2");
	font-weight: 700;
	font-display: swap;
}

:root {
	--bg: #0f0f11;
	--panel: #16161a;
	--panel-raised: #1b1b21;
	--line: #2b2822; /* warm, on the brand hue */
	--text: #f2efe9;
	--dim: #9b978e;
	--faint: #6b6862;
	--accent: #f7931a;
	--accent-soft: #f7ab5c; /* AA contrast for small text on dark panels */
	--accent-rail: #f7931a;
	--edge: #7c5514; /* brand hue, low chroma — a full-strength outline on every
	                    card would compete with the values it frames */
	--warn: #ffb454;

	--top-bar-height: 32px;
	--nav-height: 4rem;
	--footer-height: 2rem;
	--safe-bottom: env(safe-area-inset-bottom, 0px);
	/* dvh, not vh: with viewport-fit=cover on iOS, 100vh ignores the browser
	   chrome and pushes the footer under the home indicator */
	--content-area-height: calc(
		100dvh - var(--top-bar-height) - var(--nav-height) - var(--footer-height) -
			var(--safe-bottom)
	);
	--gap: 1rem;
	--radius: 4px; /* every raised surface: cards and popovers */
}

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

html,
body {
	height: 100dvh;
}

body {
	background: var(--bg);
	color: var(--text);
	font-family: "Red Hat Mono", ui-monospace, monospace;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	-webkit-font-smoothing: antialiased;
}

button {
	font: inherit;
	color: inherit;
	background: none;
	border: none;
	cursor: pointer;
}

:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

/* ---- top facts marquee ---- */

#topbar {
	height: var(--top-bar-height);
	flex: none;
	display: flex;
	align-items: center;
	justify-content: center;
	border-bottom: 1px solid var(--line);
	background: var(--bg);
}

.marquee {
	font-size: 11px;
	letter-spacing: 0.18em;
	text-transform: uppercase;
	color: var(--faint);
	transition: opacity 0.4s ease;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	padding: 0 1rem;
}

.marquee.faded {
	opacity: 0;
}

.marquee b {
	color: var(--accent-soft);
	font-weight: 500;
}

/* ---- nav ---- */

#nav {
	height: var(--nav-height);
	flex: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 1rem;
	border-bottom: 1px solid var(--line);
	background: var(--bg);
	position: relative;
}

.wordmark {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	font-weight: 700;
	font-size: 1.05rem;
	letter-spacing: 0.22em;
	text-transform: uppercase;
	color: var(--text);
}

.mark {
	width: 1.7rem;
	height: 1.7rem;
	flex: none;
}

.net-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--faint);
	margin-left: 0.4rem;
	transition: background 0.3s ease;
}

.net-dot.ok {
	background: #3ecf6e;
}

.net-dot.degraded {
	background: var(--warn);
}

.net-dot.down {
	background: #e0492f;
}

.nav-actions {
	display: flex;
	align-items: center;
	gap: 0.25rem;
}

.icon-btn {
	width: 2.25rem;
	height: 2.25rem;
	display: grid;
	place-items: center;
	color: var(--dim);
	border: 1px solid transparent;
	transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.icon-btn:hover {
	color: var(--accent);
	border-color: var(--line);
	background: var(--panel);
}

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

/* ---- settings popover ---- */

.settings-pop {
	position: absolute;
	top: calc(var(--nav-height) - 0.4rem);
	right: 1rem;
	z-index: 60;
	width: min(24rem, calc(100vw - 2rem));
	background: var(--panel-raised);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 1rem;
}

.settings-pop h2 {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.18em;
	text-transform: uppercase;
	color: var(--accent-soft);
	margin-bottom: 0.75rem;
}

.settings-pop label {
	display: block;
	font-size: 12px;
	color: var(--dim);
	margin-bottom: 0.35rem;
}

.settings-pop input {
	width: 100%;
	font: inherit;
	font-size: 13px;
	color: var(--text);
	background: var(--bg);
	border: 1px solid var(--line);
	padding: 0.5rem 0.6rem;
}

.settings-pop input:focus {
	border-color: var(--accent);
	outline: none;
}

.settings-pop .hint {
	font-size: 11px;
	color: var(--faint);
	margin-top: 0.4rem;
	line-height: 1.5;
}

.settings-pop .hint.err {
	color: var(--warn);
}

.settings-pop .hint.err:empty {
	display: none;
}

.settings-pop .row {
	display: flex;
	gap: 0.5rem;
	margin-top: 0.8rem;
}

.settings-pop .row button {
	font-size: 12px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	padding: 0.45rem 0.8rem;
	border: 1px solid var(--line);
	color: var(--dim);
}

.settings-pop .row button:hover {
	color: var(--accent);
	border-color: var(--accent);
}

/* ---- display grid ---- */

#grid {
	flex: 1;
	overflow: auto;
	padding: var(--gap);
	display: grid;
	grid-template-columns: 1fr;
	gap: var(--gap);
	align-content: start;
}

@media (min-width: 1024px) {
	#grid {
		grid-template-columns: repeat(2, 1fr);
		grid-auto-rows: calc(0.5 * var(--content-area-height) - 1.5 * var(--gap));
	}
}

@media (min-width: 1024px) and (max-height: 600px) {
	#grid {
		grid-auto-rows: calc(var(--content-area-height) - 2 * var(--gap));
	}
}

/* ---- display card ---- */

.card {
	position: relative;
	display: grid;
	grid-template-rows: auto 1fr auto;
	background: var(--panel);
	border: 1px solid var(--edge);
	border-left: 2px solid var(--accent-rail);
	border-radius: var(--radius);
	container-type: size;
	min-height: 9rem;
	padding: 0.9rem 1.1rem;
}

.card-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
}

.card-label {
	font-size: 11px;
	font-weight: 500;
	letter-spacing: 0.22em;
	text-transform: uppercase;
	color: var(--accent-soft);
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.stale-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--warn);
	display: none;
}

.card.stale .stale-dot {
	display: inline-block;
	animation: pulse-dot 1.6s ease-in-out infinite;
}

@keyframes pulse-dot {
	50% {
		opacity: 0.25;
	}
}

.card-controls {
	display: flex;
	align-items: center;
	gap: 0.15rem;
	opacity: 0;
	transition: opacity 0.15s ease;
}

.card:hover .card-controls,
.card:focus-within .card-controls,
.card.picker-open .card-controls {
	opacity: 1;
}

.card-controls .icon-btn {
	width: 1.9rem;
	height: 1.9rem;
}

.card-controls .icon-btn svg {
	width: 1.05rem;
	height: 1.05rem;
}

.card-value {
	align-self: center;
	justify-self: stretch;
	text-align: left;
	font-weight: 700;
	color: var(--text);
	line-height: 1;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	/* auto-fit to text length: monospace advance is ~0.6em, so
	   (150 / char-count)cqi fills ~90% of the card for any value length.
	   --chars is set from JS on every value render. */
	font-size: clamp(2rem, 10vw, 10rem);
	font-size: min(calc(150cqi / var(--chars, 10)), 50cqb, 30rem);
	transition: opacity 0.3s ease;
}

.card.stale .card-value {
	opacity: 0.45;
}

.card-value.flash {
	animation: new-block 0.9s ease;
}

@keyframes new-block {
	0% {
		color: var(--accent);
	}
	100% {
		color: var(--text);
	}
}

.card-desc {
	font-size: 12px;
	color: var(--faint);
	letter-spacing: 0.04em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* a display with no modes chosen yet */
.card-value.is-hint {
	font-size: 13px;
	font-weight: 400;
	line-height: 1.5;
	text-align: center;
	white-space: normal;
	color: var(--faint);
	letter-spacing: 0.06em;
}

/* ---- fullscreen mode ---- */

.card.fullscreen {
	position: fixed;
	inset: 0;
	z-index: 90;
	border: none;
	border-left: 3px solid var(--accent-rail);
	border-radius: 0; /* maximized: stay flush to the viewport */
	background: var(--panel);
	padding: max(2rem, env(safe-area-inset-top, 0px)) max(3rem, env(safe-area-inset-right, 0px))
		max(2rem, var(--safe-bottom)) max(3rem, env(safe-area-inset-left, 0px));
}

/* ---- 21-dot ring loader (the 21 million nod) ---- */

.ring {
	position: relative;
	align-self: center;
	justify-self: center;
	width: min(18cqi, 26cqb, 110px);
	aspect-ratio: 1;
}

.ring i {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 9%;
	height: 9%;
	margin: -4.5% 0 0 -4.5%;
	border-radius: 50%;
	background: var(--accent);
	opacity: 0.12;
	animation: ring-pulse 1.6s linear infinite;
}

@keyframes ring-pulse {
	0%,
	100% {
		opacity: 0.12;
	}
	8% {
		opacity: 1;
	}
	30% {
		opacity: 0.12;
	}
}

/* ---- mode picker ---- */

.mode-pop {
	position: absolute;
	top: 2.9rem;
	right: 0.9rem;
	z-index: 70;
	width: min(20rem, calc(100vw - 2.4rem));
	max-height: 80%;
	overflow: auto;
	background: var(--panel-raised);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 0.9rem;
}

.mode-pop h3 {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.18em;
	text-transform: uppercase;
	color: var(--accent-soft);
	margin-bottom: 0.6rem;
}

.mode-row {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	padding: 0.45rem 0.2rem;
	border-bottom: 1px solid var(--line);
	font-size: 13px;
}

.mode-row:last-child {
	border-bottom: none;
}

.mode-row input[type="checkbox"] {
	appearance: none;
	width: 1rem;
	height: 1rem;
	flex: none;
	border: 1px solid var(--faint);
	background: var(--bg);
	display: grid;
	place-items: center;
	cursor: pointer;
}

.mode-row input[type="checkbox"]:checked {
	background: var(--accent);
	border-color: var(--accent);
}

.mode-row input[type="checkbox"]:checked::after {
	content: "";
	width: 0.5rem;
	height: 0.28rem;
	border-left: 2px solid #0f0f11;
	border-bottom: 2px solid #0f0f11;
	transform: rotate(-45deg) translateY(-1px);
}

.mode-row label {
	cursor: pointer;
	flex: 1;
	user-select: none;
}

.mode-row .mode-desc {
	display: block;
	font-size: 11px;
	color: var(--faint);
	margin-top: 0.15rem;
}

/* ---- empty state ---- */

.empty-state {
	grid-column: 1 / -1;
	display: grid;
	place-items: center;
	min-height: calc(var(--content-area-height) - 2 * var(--gap));
}

.empty-state button {
	font-size: 1.1rem;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--accent-soft);
	border: 1px dashed var(--faint);
	padding: 1.2rem 2.2rem;
	transition: color 0.15s ease, border-color 0.15s ease;
}

.empty-state button:hover {
	color: var(--accent);
	border-color: var(--accent);
}

/* ---- footer ---- */

#footer {
	height: calc(var(--footer-height) + var(--safe-bottom));
	flex: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 0 max(1rem, env(safe-area-inset-right, 0px)) var(--safe-bottom)
		max(1rem, env(safe-area-inset-left, 0px));
	border-top: 1px solid var(--line);
	background: var(--bg);
	font-size: 10.5px;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--faint);
}

.foot-status {
	color: var(--dim);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	min-width: 0;
}

.foot-status .ok {
	color: #3ecf6e;
}

.foot-status .bad {
	color: #e0492f;
}

.foot-left,
.foot-right {
	white-space: nowrap;
}

/* tablet: drop the editorial side phrases (they overflow long before 720px) */
@media (max-width: 900px) {
	.foot-left,
	.foot-right {
		display: none;
	}
	#footer {
		justify-content: center;
	}
}

/* phone portrait: drop the instance hostname, keep the live indicators —
   "instance ✓ · price ✓" still reads fine at 360px */
@media (max-width: 520px) {
	.st-node,
	.st-src {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ring i,
	.card-value.flash,
	.marquee,
	.stale-dot {
		animation: none;
		transition: none;
	}
}
