/* =============================================================
   CHUCKWATCH™ — vintage Iowa agricultural instrument panel
   crossed with a train-station split-flap board.

   Narrow-first + container queries: the widget sizes itself to
   its own container, never the viewport. Nothing overflows.
   ============================================================= */

.chuckwatch-scope {
	container-type: inline-size;
	container-name: chuckwatch;
	width: 100%;
}

.chuckwatch,
.chuckwatch * {
	box-sizing: border-box;
	min-width: 0;
}

.chuckwatch {
	--cw-bg: #f4ecd8;
	--cw-paper: #fbf7ec;
	--cw-ink: #2b2620;
	--cw-accent: #8a1f1f;
	--cw-border-style: solid;
	--cw-caricature-size: 280px;
	--cw-steel: #3a352e;
	--cw-brass: #b08d3f;

	position: relative;
	width: 100%;
	max-width: 720px;
	margin: 1.5rem auto;
	background:
		radial-gradient(ellipse at 50% 0%, rgba(255,255,255,0.35), transparent 60%),
		repeating-linear-gradient(0deg, rgba(0,0,0,0.03) 0 1px, transparent 1px 3px),
		var(--cw-bg);
	color: var(--cw-ink);
	font-family: "Courier New", Courier, ui-monospace, "SFMono-Regular", monospace;
	font-size: 14px;
	line-height: 1.4;
	border: 3px var(--cw-border-style) var(--cw-steel);
	border-radius: 10px;
	box-shadow:
		inset 0 0 0 2px var(--cw-brass),
		inset 0 0 0 7px var(--cw-paper),
		0 10px 30px rgba(0,0,0,0.35),
		0 2px 6px rgba(0,0,0,0.25);
	overflow: hidden;
	padding-bottom: 12px;
}

.chuckwatch--full-width { max-width: 100%; }
.chuckwatch--compact    { max-width: 340px; }

/* Neutralize theme typography inside the panel */
.chuckwatch h2,
.chuckwatch h3,
.chuckwatch p {
	font-family: inherit;
	color: inherit; /* stop theme heading colors bleeding in (dark-on-dark bug) */
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	text-shadow: none;
	max-width: none;
}

/* ---------- Corner rivets ---------- */

.chuckwatch__rivets i {
	position: absolute;
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: radial-gradient(circle at 35% 30%, #ddd, #7a7468 55%, #3a352e);
	box-shadow: 0 1px 2px rgba(0,0,0,0.5);
	z-index: 6;
}
.chuckwatch__rivets i:nth-child(1) { top: 9px; left: 9px; }
.chuckwatch__rivets i:nth-child(2) { top: 9px; right: 9px; }
.chuckwatch__rivets i:nth-child(3) { bottom: 9px; left: 9px; }
.chuckwatch__rivets i:nth-child(4) { bottom: 9px; right: 9px; }

/* ---------- Header: title left, Grassley right ---------- */

.chuckwatch__header {
	position: relative;
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	gap: 4px;
	padding: 14px 8px 0 14px;
}

.chuckwatch__title {
	flex: 1 1 auto;
	font-family: "Rockwell", "Courier New", Courier, monospace;
	font-size: clamp(16px, 7cqw, 42px);
	line-height: 1;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	font-weight: 900;
	color: var(--cw-accent);
	text-shadow: 2px 2px 0 rgba(0,0,0,0.12);
	white-space: nowrap; /* scales with the container instead of breaking */
	text-align: left;
	align-self: center;
	flex: 0 0 auto; /* the title never yields — Chuck fills what's left */
}

/* The caricature sits BEHIND the timer panel below: lower z-index and a
   negative bottom margin pull the panel up over his suit, so he emerges
   from behind the instrument rather than standing on top of it. */
.chuckwatch__caricature {
	position: relative;
	z-index: 1;
	flex: 0 1 auto; /* shrinks first so it can never crowd the title */
	width: clamp(150px, 62cqw, var(--cw-caricature-size));
	height: auto;
	margin-top: calc(-1 * clamp(2px, 1.5cqw, 10px)); /* head rides a touch higher */
	margin-bottom: calc(-1 * clamp(14px, 6cqw, 34px)); /* suit only — face stays clear */
	filter: drop-shadow(3px 6px 8px rgba(0,0,0,0.4));
}

/* ---------- Operational-age panel (in front of Chuck) ---------- */

.chuckwatch__panel--age {
	position: relative;
	z-index: 2; /* in front of the caricature */
	margin: 0 10px;
	padding: clamp(16px, 5cqw, 26px) 10px clamp(14px, 4cqw, 22px);
	text-align: center;
	background:
		linear-gradient(180deg, rgba(0,0,0,0.05), transparent 20%),
		var(--cw-steel);
	color: var(--cw-paper);
	border-radius: 8px;
	box-shadow:
		inset 0 0 0 1px rgba(255,255,255,0.08),
		inset 0 4px 12px rgba(0,0,0,0.45),
		0 -6px 14px rgba(0,0,0,0.28); /* soft shadow onto Chuck behind */
}

.chuckwatch__panel-label {
	font-size: clamp(8px, 2.8cqw, 12px);
	letter-spacing: 0.26em;
	text-transform: uppercase;
	font-weight: bold;
	opacity: 0.9;
	margin-bottom: clamp(10px, 3.5cqw, 18px);
}

/* Age-panel headline: bold white, one line, as large as the row allows */
.chuckwatch__panel--age > .chuckwatch__panel-label {
	color: #ffffff;
	opacity: 1;
	white-space: nowrap;
	letter-spacing: 0.2em;
	font-size: clamp(12px, 4cqw, 30px);
}

.chuckwatch__lamp {
	display: inline-block;
	width: 7px;
	height: 7px;
	margin-right: 6px;
	border-radius: 50%;
	background: radial-gradient(circle at 35% 30%, #ffd9a0, var(--cw-accent));
	box-shadow: 0 0 6px 2px rgba(200, 60, 40, 0.7);
	vertical-align: middle;
	animation: chuckwatch-lamp 2.4s ease-in-out infinite;
}

@keyframes chuckwatch-lamp {
	0%, 100% { opacity: 1; }
	50%      { opacity: 0.55; }
}

/* Tiles share the row equally and shrink — they can never overflow. */
.chuckwatch__age-display {
	display: flex;
	justify-content: center;
	align-items: stretch;
	gap: clamp(3px, 1cqw, 6px);
	flex-wrap: nowrap;
	width: 100%;
}

.chuckwatch__age-col {
	flex: 1 1 auto; /* DAYS gets the extra room its 3 digits need */
	min-width: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background: linear-gradient(180deg, #16130f 0%, #221d17 48%, #16130f 52%, #221d17 100%);
	border-radius: 5px;
	padding: clamp(9px, 3cqw, 16px) clamp(3px, 1cqw, 8px) clamp(7px, 2.4cqw, 12px);
	box-shadow:
		inset 0 1px 0 rgba(255,255,255,0.12),
		inset 0 -6px 10px rgba(0,0,0,0.5),
		0 2px 4px rgba(0,0,0,0.4);
	position: relative;
}

.chuckwatch__age-col::after {
	content: "";
	position: absolute;
	left: 4px;
	right: 4px;
	top: 46%;
	height: 1px;
	background: rgba(0,0,0,0.85);
	box-shadow: 0 1px 0 rgba(255,255,255,0.06);
}

.chuckwatch__age-value {
	font-size: clamp(26px, 10.5cqw, 64px);
	line-height: 1;
	font-weight: bold;
	font-variant-numeric: tabular-nums;
	color: #f3e9cf;
	text-shadow: 0 0 10px rgba(243, 233, 207, 0.25);
	letter-spacing: 0.01em;
	white-space: nowrap;
}

.chuckwatch__age-unit {
	margin-top: clamp(5px, 1.8cqw, 10px);
	font-size: clamp(7px, 2.2cqw, 12px);
	letter-spacing: 0.18em;
	color: var(--cw-brass);
	font-weight: bold;
	white-space: nowrap;
}

.chuckwatch__noscript-value {
	margin-top: 12px;
	font-size: 12px;
	color: var(--cw-paper);
}

/* ---------- Service-days flip board ---------- */

.chuckwatch__panel--service {
	margin: 10px 10px 0;
	padding: clamp(18px, 5cqw, 28px) clamp(10px, 3cqw, 18px);
	text-align: center;
	background: var(--cw-paper);
	border: 2px var(--cw-border-style) var(--cw-steel);
	border-radius: 8px;
	box-shadow: inset 0 2px 6px rgba(0,0,0,0.1);
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 12px;
}

.chuckwatch__panel--service .chuckwatch__panel-label {
	margin-bottom: 0;
	line-height: 1.7;
	opacity: 0.8;
	color: var(--cw-ink);
	font-size: clamp(12px, 4.4cqw, 20px);
	letter-spacing: 0.22em;
}

.chuckwatch__service-count {
	display: flex;
	justify-content: center;
	gap: clamp(2px, 0.8cqw, 4px);
	width: 100%;
}

.chuckwatch__flip-cell {
	flex: 1 1 0; /* digits stretch so the board fills the panel's full width */
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 0;
	padding: clamp(10px, 3.2cqw, 20px) 2px;
	background: linear-gradient(180deg, #16130f 0%, #26201a 48%, #16130f 52%, #26201a 100%);
	color: #f3e9cf;
	font-size: clamp(24px, 9.5cqw, 60px);
	font-weight: bold;
	font-variant-numeric: tabular-nums;
	border-radius: 4px;
	box-shadow:
		inset 0 1px 0 rgba(255,255,255,0.12),
		0 2px 3px rgba(0,0,0,0.35);
	position: relative;
	white-space: nowrap;
}

.chuckwatch__flip-cell::after {
	content: "";
	position: absolute;
	left: 3px;
	right: 3px;
	top: 48%;
	height: 1px;
	background: rgba(0,0,0,0.8);
}

.chuckwatch__flip-cell--comma {
	flex: 0 0 auto; /* the comma stays narrow; digits take the width */
	background: none;
	box-shadow: none;
	color: var(--cw-ink);
	min-width: 8px;
	padding-left: 0;
	padding-right: 0;
}
.chuckwatch__flip-cell--comma::after { display: none; }

/* ---------- Accessibility ---------- */

.chuckwatch__sr-only {
	position: absolute;
	width: 1px; height: 1px;
	padding: 0; margin: -1px;
	overflow: hidden;
	clip: rect(0,0,0,0);
	white-space: nowrap;
	border: 0;
}

@media (prefers-reduced-motion: reduce) {
	.chuckwatch *,
	.chuckwatch__lamp {
		transition: none !important;
		animation: none !important;
	}
}

/* =============================================================
   WIDE LAYOUT — container ≥ 560px
   ============================================================= */

@container chuckwatch (min-width: 560px) {

	.chuckwatch { font-size: 16px; padding-bottom: 14px; }

	.chuckwatch__header {
		padding: 26px 26px 0 28px;
		gap: 16px;
	}

	.chuckwatch__caricature {
		width: clamp(210px, 40cqw, var(--cw-caricature-size));
		margin-bottom: calc(-1 * clamp(24px, 6cqw, 48px));
	}

	.chuckwatch__panel--age { margin: 0 14px; }

	.chuckwatch__age-display { gap: 8px; }

	.chuckwatch__age-col {
		flex: 1 1 auto;
		padding: 16px 12px 12px;
	}

	.chuckwatch__panel--service { margin: 14px 14px 0; }
}

/* =============================================================
   VERY NARROW — container < 300px: keep the enlarged digits from
   outgrowing the row (they stay as large as the tiles allow).
   ============================================================= */

@container chuckwatch (max-width: 300px) {

	/* Headline: wrapping beats clipping at phone width */
	.chuckwatch__panel--age > .chuckwatch__panel-label {
		white-space: normal;
		font-size: clamp(9px, 4.6cqw, 13px);
		letter-spacing: 0.14em;
		line-height: 1.6;
		margin-bottom: 8px;
	}

	.chuckwatch__lamp {
		width: 5px;
		height: 5px;
		margin-right: 4px;
	}

	.chuckwatch__title { font-size: clamp(13px, 6.6cqw, 19px); }

	.chuckwatch__header { padding: 12px 6px 0 10px; }

	.chuckwatch__age-value { font-size: clamp(15px, 9cqw, 24px); }
	.chuckwatch__age-display { gap: 2px; }
	.chuckwatch__age-col { padding: 8px 2px 6px; border-radius: 4px; }
	.chuckwatch__age-unit {
		font-size: 6px;
		letter-spacing: 0.06em;
		margin-top: 4px;
	}

	.chuckwatch__panel--age { margin: 0 8px; padding-left: 6px; padding-right: 6px; }
	.chuckwatch__panel--service { margin: 8px 8px 0; }

	.chuckwatch__panel--service .chuckwatch__panel-label {
		font-size: clamp(10px, 4.6cqw, 13px);
		letter-spacing: 0.14em;
	}

	.chuckwatch__flip-cell {
		font-size: clamp(16px, 8.5cqw, 26px);
		padding: 8px 1px;
		border-radius: 3px;
	}
	.chuckwatch__service-count { gap: 2px; }
}
