/*
 * Live & social panels on the home page (src/routes/social.ts, /social.js): DADCON, the
 * global anxiety meter, the live world map, the check feed, and milestone toasts.
 * Uses the design tokens from /styles.css.
 */

:root {
	--wm-land: #d3cab6;
	--wm-sea: var(--paper);
	--dc-5: #2a5bd7;
	--dc-4: #1e9e4a;
	--dc-3: #f5c400;
	--dc-2: #e0281b;
	--dc-1: #f7f7f2;
	--g-calm: #1fbf63;
	--g-elevated: #f2c200;
	--g-frantic: #ff8a00;
	--g-meltdown: #e0281b;
}
@media (prefers-color-scheme: dark) {
	:root {
		--wm-land: #3b362c;
	}
}

/* Tablet: the narrow panels take the whole row rather than leave half of one empty. */
@media (max-width: 64rem) {
	.social-md-wide {
		grid-column: 1 / -1;
	}
}

/* ─── DADCON ──────────────────────────────────────────────────────────── */

.dadcon {
	--dc-on: var(--dc-5);
	display: grid;
	gap: 0.9rem;
	padding: clamp(0.85rem, 2vw, 1.2rem);
	color: #e9ecf2;
	background:
		repeating-linear-gradient(0deg, rgb(255 255 255 / 0.025) 0 1px, transparent 1px 3px),
		#0b0d12;
	border: 1px solid #000;
	border-radius: var(--radius);
	box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.06), inset 0 0 40px rgb(0 0 0 / 0.6);
}
.dadcon[data-level='4'] {
	--dc-on: var(--dc-4);
}
.dadcon[data-level='3'] {
	--dc-on: var(--dc-3);
}
.dadcon[data-level='2'] {
	--dc-on: var(--dc-2);
}
.dadcon[data-level='1'] {
	--dc-on: var(--dc-1);
}
.dadcon[data-level='0'] {
	--dc-on: #ffb000;
}
.dadcon > * {
	margin: 0;
}
.dadcon-readout {
	font-family: var(--font-display);
	font-weight: 900;
	font-stretch: 125%;
	font-size: clamp(1.35rem, 3.2vw, 2.1rem);
	line-height: 1.05;
	letter-spacing: 0.01em;
	text-transform: uppercase;
	color: var(--dc-on);
	text-shadow: 0 0 18px color-mix(in srgb, var(--dc-on) 55%, transparent);
}
.dadcon-scale {
	display: grid;
	grid-template-columns: repeat(6, minmax(0, 1fr));
	gap: 0.35rem;
	list-style: none;
	margin: 0;
	padding: 0;
}
.dc {
	--c: var(--dc-5);
	--ink-on: #fff;
	display: grid;
	justify-items: center;
	align-content: center;
	gap: 0.2rem;
	min-width: 0;
	min-height: 4.6rem;
	margin: 0;
	padding: 0.45rem 0.2rem;
	text-align: center;
	color: color-mix(in srgb, var(--c) 70%, #fff);
	background: color-mix(in srgb, var(--c) 12%, #0b0d12);
	border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
	border-radius: 2px;
	opacity: 0.55;
}
.dc-4 {
	--c: var(--dc-4);
}
.dc-3 {
	--c: var(--dc-3);
	--ink-on: #111;
}
.dc-2 {
	--c: var(--dc-2);
}
.dc-1 {
	--c: var(--dc-1);
	--ink-on: #111;
}
.dc-0 {
	--c: #ffb000;
	--ink-on: #111;
}
.dc.is-active {
	color: var(--ink-on);
	background: var(--c);
	border-color: var(--c);
	opacity: 1;
	box-shadow: 0 0 0 2px #0b0d12, 0 0 0 3px var(--c), 0 0 24px color-mix(in srgb, var(--c) 60%, transparent);
	animation: dc-glow 2.4s ease-in-out infinite;
}
.dc-0.is-active {
	background: linear-gradient(135deg, #ffb000, #ff5fa2);
}
.dc-n {
	font: 900 clamp(1.6rem, 3.4vw, 2.3rem) / 1 var(--font-display);
	font-stretch: 110%;
}
.dc-name {
	max-width: 100%;
	font: 600 0.55rem/1.2 var(--font-mono);
	letter-spacing: 0.04em;
	text-transform: uppercase;
	overflow-wrap: anywhere;
}
.dadcon-desc {
	color: #c9ced8;
	font-size: 0.95rem;
	max-width: 40rem;
}
.dadcon.is-escalating .dadcon-readout {
	animation: dc-alert 0.5s steps(2) 4;
}
@media (max-width: 34rem) {
	.dc {
		min-height: 3.4rem;
	}
	.dc-name {
		display: none;
	}
}
@keyframes dc-glow {
	50% {
		box-shadow: 0 0 0 2px #0b0d12, 0 0 0 3px var(--c), 0 0 8px color-mix(in srgb, var(--c) 40%, transparent);
	}
}
@keyframes dc-alert {
	50% {
		color: #0b0d12;
		background: var(--dc-on);
	}
}

/* ─── Global anxiety meter ────────────────────────────────────────────── */

.anxiety {
	--g-on: var(--g-calm);
	display: grid;
	justify-items: center;
	gap: 0.35rem;
	text-align: center;
}
.anxiety[data-level='elevated'] {
	--g-on: var(--g-elevated);
}
.anxiety[data-level='frantic'] {
	--g-on: var(--g-frantic);
}
.anxiety[data-level='meltdown'] {
	--g-on: var(--g-meltdown);
}
.anxiety > p {
	margin: 0;
}
.gauge {
	display: block;
	width: 100%;
	max-width: 18rem;
	height: auto;
	overflow: visible;
}
.g-arc {
	fill: none;
	stroke-width: 18;
	opacity: 0.28;
	transition: opacity 0.4s;
}
.g-calm {
	stroke: var(--g-calm);
}
.g-elevated {
	stroke: var(--g-elevated);
}
.g-frantic {
	stroke: var(--g-frantic);
}
.g-meltdown {
	stroke: var(--g-meltdown);
}
.anxiety[data-level='calm'] .g-calm,
.anxiety[data-level='elevated'] .g-elevated,
.anxiety[data-level='frantic'] .g-frantic,
.anxiety[data-level='meltdown'] .g-meltdown {
	opacity: 1;
}
.gauge-ticks path {
	stroke: var(--panel);
	stroke-width: 2;
}
.gauge-needle {
	fill: var(--ink);
	transform: rotate(var(--angle, -80deg));
	transform-origin: 100px 100px;
	transform-box: view-box;
	transition: transform 1.4s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.gauge-needle circle {
	fill: var(--ink);
	stroke: var(--panel);
	stroke-width: 2;
}
.gauge-wobble {
	transform-origin: 100px 100px;
	transform-box: view-box;
}
.anxiety[data-level='frantic'] .gauge-wobble {
	animation: g-wobble 0.6s ease-in-out infinite alternate;
}
.anxiety[data-level='meltdown'] .gauge-wobble {
	animation: g-wobble-hard 0.18s linear infinite alternate;
}
.anxiety-label {
	font-family: var(--font-display);
	font-weight: 900;
	font-stretch: 125%;
	font-size: clamp(1.5rem, 3vw, 2rem);
	line-height: 1;
	letter-spacing: 0.02em;
	color: color-mix(in srgb, var(--g-on) 75%, var(--ink));
}
.anxiety-rate {
	color: var(--ink-2);
}
.anxiety-desc {
	max-width: 26rem;
}
@keyframes g-wobble {
	from {
		transform: rotate(-2.5deg);
	}
	to {
		transform: rotate(2.5deg);
	}
}
@keyframes g-wobble-hard {
	from {
		transform: rotate(-5deg);
	}
	to {
		transform: rotate(5deg);
	}
}

/* ─── Live world map ──────────────────────────────────────────────────── */

.wm {
	position: relative;
}
.wm-stage {
	display: grid;
	place-items: center;
	aspect-ratio: 1000 / 435;
	overflow: hidden;
	background:
		linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 2.5rem 2.5rem,
		linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 2.5rem 2.5rem,
		var(--wm-sea);
	border: 1px solid var(--rule);
	border-radius: var(--radius);
}
.wm-stage > svg {
	display: block;
	width: 100%;
	height: 100%;
}
.wm-fallback {
	max-width: 30rem;
	margin: 0;
	padding: 1rem;
	text-align: center;
	color: var(--ink-2);
	font-size: 0.92rem;
}
.wm-stage[data-state='loading'] .wm-fallback {
	animation: blink 1.6s steps(1) infinite;
}
.wm-land path,
.wm-dots circle {
	fill: var(--wm-land);
	stroke: var(--wm-sea);
	stroke-width: 0.5;
	transition: fill 0.8s;
}
.wm-stage [data-heat='1'] {
	fill: color-mix(in srgb, var(--accent) 22%, var(--wm-land));
}
.wm-stage [data-heat='2'] {
	fill: color-mix(in srgb, var(--accent) 38%, var(--wm-land));
}
.wm-stage [data-heat='3'] {
	fill: color-mix(in srgb, var(--accent) 55%, var(--wm-land));
}
.wm-stage [data-heat='4'] {
	fill: color-mix(in srgb, var(--accent) 72%, var(--wm-land));
}
.wm-stage [data-heat='5'] {
	fill: color-mix(in srgb, var(--accent) 90%, var(--wm-land));
}
.wm-stage .is-pulse {
	animation: wm-pulse 1.6s ease-out;
}
.wm-ripple {
	fill: none;
	stroke: var(--accent);
	stroke-width: 2;
	transform-box: fill-box;
	transform-origin: center;
	animation: wm-ripple 1.6s ease-out forwards;
	pointer-events: none;
}
.wm-vibes {
	position: absolute;
	inset: 0;
	overflow: hidden;
	pointer-events: none;
}
.wm-vibe {
	position: absolute;
	font-size: clamp(1.35rem, 3vw, 2.1rem);
	line-height: 1;
	transform: translate(-50%, -50%);
	will-change: transform, opacity;
	animation: wm-vibe 2.6s cubic-bezier(0.2, 0.6, 0.3, 1) forwards;
}
.wm-vibe.is-static {
	animation: wm-fade 1.4s ease-out forwards;
}
@keyframes wm-pulse {
	0%,
	20% {
		fill: var(--yes);
	}
}
@keyframes wm-ripple {
	from {
		transform: scale(0.3);
		opacity: 1;
	}
	to {
		transform: scale(4);
		opacity: 0;
	}
}
@keyframes wm-vibe {
	0% {
		transform: translate(-50%, -50%) scale(0.4);
		opacity: 0;
	}
	15% {
		opacity: 1;
	}
	100% {
		transform: translate(calc(-50% + var(--drift, 0px)), calc(-50% - 5.5rem)) scale(1.15);
		opacity: 0;
	}
}
@keyframes wm-fade {
	0%,
	60% {
		opacity: 1;
	}
	100% {
		opacity: 0;
	}
}

/* ─── Who just checked ────────────────────────────────────────────────── */

.checkfeed {
	display: grid;
	gap: 0.55rem;
	list-style: none;
	margin: 0;
	padding: 0;
}
.checkfeed > li {
	margin: 0;
	padding: 0.15rem 0 0.15rem 0.7rem;
	border-left: 3px solid var(--rule-2);
	line-height: 1.4;
}
.checkfeed > .cf-item:first-child {
	border-left-color: var(--accent);
}
.checkfeed-idle {
	color: var(--ink-2);
	font-style: italic;
}
.cf-time {
	display: block;
	font: 500 0.66rem/1.3 var(--font-mono);
	letter-spacing: 0.06em;
	color: var(--ink-3);
}
.cf-tail {
	font-weight: 700;
	color: var(--accent-text);
}
.cf-item.is-new {
	animation: cf-in 0.45s ease-out;
}
.cf-item:nth-child(n + 6) {
	opacity: 0.7;
}
@keyframes cf-in {
	from {
		transform: translateY(-0.4rem);
		opacity: 0;
	}
}

/* ─── Milestone toast + confetti ──────────────────────────────────────── */

.social-toast {
	position: fixed;
	left: 50%;
	bottom: max(1.25rem, env(safe-area-inset-bottom));
	z-index: 95;
	max-width: min(92vw, 34rem);
	padding: 0.85rem 1.15rem;
	font: 800 1rem/1.35 var(--font-body);
	color: var(--paper);
	background: var(--ink);
	border: 2px solid var(--accent);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	transform: translate(-50%, 160%);
	opacity: 0;
	transition:
		transform 0.45s cubic-bezier(0.2, 1.4, 0.4, 1),
		opacity 0.3s;
	cursor: pointer;
}
.social-toast.is-shown {
	transform: translate(-50%, 0);
	opacity: 1;
}
.social-confetti {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	z-index: 94;
	pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
	.dc.is-active,
	.dadcon.is-escalating .dadcon-readout,
	.gauge-wobble,
	.wm-stage .is-pulse,
	.wm-stage[data-state='loading'] .wm-fallback,
	.cf-item.is-new {
		animation: none !important;
	}
	.gauge-needle,
	.social-toast {
		transition: none;
	}
	.wm-stage .is-pulse {
		fill: var(--yes);
	}
}
