/*
 * Carried over from the original single-file app: same design, same theme variables. The radar
 * rings and the interactive elements have since been reworked.
 */

/* Default: Dark Theme */
:root {
	--bg: #121316;
	--bg-card: #1c1e24;
	--bg-card-hover: #262932;
	--primary: #3b82f6;
	--primary-glow: rgba(59, 130, 246, 0.25);
	--text: #f3f4f6;
	--text-muted: #9ca3af;
	--border: #2e323b;
	--border-subtle: rgba(255, 255, 255, 0.06);
	--success: #10b981;
	--danger: #ef4444;
	--warning: #f59e0b;
	--shadow: rgba(0, 0, 0, 0.4);
	/* Interactive elements are solid fills rather than outlines, so they need a surface that sits
	   just above the page, and a slightly brighter one for hover. */
	--radius: 6px;
	--surface: #23262e;
	--surface-hover: #2f333d;
	--lift: rgba(0, 0, 0, 0.45);
	/* The rings need their own colour: `--border` is a hairline meant to sit between two surfaces,
	   and is far too dark to read as a wave against the page background. */
	--radar-line: rgba(125, 170, 255, 0.75);
	--radar-glow: rgba(96, 165, 250, 0.28);
	--radar-opacity: 0.55;
	/* Diameter the outermost wave reaches. The viewport terms let it overshoot the screen on phones
	   — so the wave visibly travels past both edges rather than fading out mid-screen — while the
	   height term and the fixed cap keep it from turning into a huge empty circle on a wide
	   desktop. */
	--radar-size: min(150vw, 92vh, 1040px);
	--overlay-bg: rgba(18, 19, 22, 0.85);
}

/* Automatic Light Theme (Follows OS / Device Settings) */
@media (prefers-color-scheme: light) {
	:root {
		--bg: #f8fafc;
		--bg-card: #ffffff;
		--bg-card-hover: #f1f5f9;
		--primary: #2563eb;
		--primary-glow: rgba(37, 99, 235, 0.2);
		--text: #0f172a;
		--text-muted: #64748b;
		--border: #e2e8f0;
		--border-subtle: rgba(0, 0, 0, 0.06);
		--success: #059669;
		--danger: #dc2626;
		--warning: #d97706;
		--shadow: rgba(0, 0, 0, 0.08);
		--surface: #e9eef5;
		--surface-hover: #dce4ee;
		--lift: rgba(15, 23, 42, 0.14);
		--radar-line: rgba(37, 99, 235, 0.6);
		--radar-glow: rgba(37, 99, 235, 0.18);
		--radar-opacity: 0.6;
		--overlay-bg: rgba(248, 250, 252, 0.9);
	}
}

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	-webkit-tap-highlight-color: transparent;
}

html {
	height: 100%;
	overflow: hidden;
}

body {
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
	background: var(--bg);
	color: var(--text);
	height: 100%;
	height: 100dvh;
	display: flex;
	flex-direction: column;
	user-select: none;
	-webkit-user-select: none;
	overflow: hidden;
	position: relative;
	overscroll-behavior: none;
}

/* Radar Background Waves */
.radar-background {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: var(--radar-size);
	height: var(--radar-size);
	pointer-events: none;
	z-index: 0;
	opacity: var(--radar-opacity);
}

/*
 * All three rings are the same size and only differ in animation phase, so each one is a wave
 * travelling from the centre to the edge rather than a fixed circle breathing at its own radius.
 * The delays are negative and split the period into exact thirds, so the waves are evenly spaced
 * from the very first frame instead of queuing up behind the page load.
 */
.radar-circle {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 100%;
	height: 100%;
	transform: translate(-50%, -50%);
	/*
	 * `transform: scale()` shrinks the border and the glow along with the ring, so a fixed width
	 * would render thinner on a large container than a small one at the same on-screen size.
	 * Tying both to the container keeps a ring of a given diameter looking identical everywhere.
	 */
	border: calc(var(--radar-size) * 0.004) solid var(--radar-line);
	border-radius: 50%;
	box-shadow: 0 0 calc(var(--radar-size) * 0.024) var(--radar-glow);
	animation: pulse 4s linear infinite;
}

.radar-circle:nth-child(2) { animation-delay: -1.333s; }
.radar-circle:nth-child(3) { animation-delay: -2.667s; }

/* Born at the centre, holds its brightness across most of the travel, then fades out as it
   reaches the edge — the fade is saved for the part where the ring is the least interesting. */
@keyframes pulse {
	0% {
		transform: translate(-50%, -50%) scale(0.08);
		opacity: 0;
	}
	12% {
		opacity: 1;
	}
	60% {
		opacity: 0.85;
	}
	100% {
		transform: translate(-50%, -50%) scale(1);
		opacity: 0;
	}
}

/* Keep the motif without the motion: the same three radii, standing still. */
@media (prefers-reduced-motion: reduce) {
	.radar-circle {
		animation: none;
		opacity: 1;
		transform: translate(-50%, -50%) scale(1);
	}

	.radar-circle:nth-child(1) { transform: translate(-50%, -50%) scale(0.35); }
	.radar-circle:nth-child(2) { transform: translate(-50%, -50%) scale(0.7); }
}

/* Header */
header {
	position: relative;
	z-index: 10;
	padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	max-width: 1000px;
	width: 100%;
	margin: 0 auto;
	flex-shrink: 0;
}

/* Help button, top-left */
.help-btn {
	width: 32px;
	height: 32px;
	flex-shrink: 0;
	border-radius: var(--radius);
	background: var(--surface);
	border: none;
	color: var(--text-muted);
	font-family: inherit;
	font-size: 15px;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition:
		background 0.15s ease,
		color 0.15s ease,
		transform 0.15s ease,
		box-shadow 0.15s ease;
}

.help-btn:hover,
.help-btn:focus-visible {
	background: var(--surface-hover);
	color: var(--text);
	transform: translateY(-1px);
	box-shadow: 0 4px 12px var(--lift);
	outline: none;
}

.help-btn:active {
	transform: translateY(0);
	box-shadow: none;
}

.status-pill {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	padding: 6px 12px;
	border-radius: var(--radius);
	background: var(--surface);
	border: none;
	color: var(--text-muted);
}

.status-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--danger);
	transition: background 0.3s;
}

.status-pill.online .status-dot {
	background: var(--success);
	box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.status-pill.online {
	color: var(--text);
}

/* Main Center Area */
main {
	position: relative;
	z-index: 5;
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 12px 16px;
	max-width: 900px;
	width: 100%;
	margin: 0 auto;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
}

.devices-container {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: center;
	gap: 24px;
	width: 100%;
	padding: 10px 0;
}

/* Peer Device Circle */
.device-node {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 10px;
	cursor: pointer;
	position: relative;
	transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
	touch-action: manipulation;
}

.device-node:hover, .device-node:active {
	transform: scale(1.06);
}

.device-avatar {
	width: 76px;
	height: 76px;
	border-radius: 50%;
	background: var(--bg-card);
	border: 2px solid var(--border);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 32px;
	box-shadow: 0 6px 18px var(--shadow);
	position: relative;
	transition: all 0.3s ease;
}

.device-node:hover .device-avatar {
	border-color: var(--primary);
	box-shadow: 0 0 25px var(--primary-glow);
}

.device-node.connected .device-avatar {
	border-color: var(--success);
	box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}

.device-node.busy .device-avatar {
	border-color: var(--warning);
	animation: pulse-border 1.5s infinite;
}

@keyframes pulse-border {
	0%, 100% { border-color: var(--warning); }
	50% { border-color: rgba(245, 158, 11, 0.2); }
}

.device-details {
	text-align: center;
	max-width: 130px;
}

.device-label {
	font-size: 13px;
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.device-sub {
	font-size: 11px;
	color: var(--text-muted);
	margin-top: 2px;
}

/* Empty state */
.empty-state {
	text-align: center;
	color: var(--text-muted);
	max-width: 320px;
	line-height: 1.5;
	font-size: 13px;
	padding: 0 10px;
}

.empty-icon {
	font-size: 40px;
	margin-bottom: 8px;
	opacity: 0.6;
}

.empty-title {
	font-size: 16px;
	font-weight: 600;
	color: var(--text);
	margin-bottom: 4px;
}

/* Drop overlay when dragging files into browser */
.drag-overlay {
	position: fixed;
	inset: 0;
	background: var(--overlay-bg);
	backdrop-filter: blur(8px);
	z-index: 100;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 16px;
	border: 3px dashed var(--primary);
	margin: 16px;
	border-radius: 24px;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s ease;
}

.drag-overlay.active {
	opacity: 1;
	pointer-events: auto;
}

.drag-overlay-icon {
	font-size: 54px;
}

.drag-overlay-text {
	font-size: 18px;
	font-weight: 600;
	text-align: center;
	padding: 0 16px;
}

/* Footer - My Device Identity */
footer {
	position: relative;
	z-index: 10;
	padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px));
	text-align: center;
	font-size: 12px;
	color: var(--text-muted);
	border-top: 1px solid var(--border-subtle);
	background: var(--bg);
	flex-shrink: 0;
}

.my-identity {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 14px;
	border-radius: var(--radius);
	background: var(--surface);
	border: none;
	color: var(--text);
	font-weight: 500;
	margin-bottom: 4px;
	font-size: 12px;
}

/* Progress modal bar */
.progress-card {
	position: fixed;
	top: 20px;
	left: 50%;
	transform: translateX(-50%) translateY(-100px);
	background: var(--bg-card);
	border: 1px solid var(--border);
	box-shadow: 0 12px 30px var(--shadow);
	border-radius: 14px;
	padding: 12px 20px;
	z-index: 250;
	width: min(90vw, 360px);
	transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.progress-card.show {
	transform: translateX(-50%) translateY(0);
}

.progress-title {
	font-size: 13px;
	font-weight: 600;
	display: flex;
	justify-content: space-between;
	gap: 10px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.progress-meta {
	display: inline-flex;
	align-items: baseline;
	gap: 8px;
	flex-shrink: 0;
}

#progressSpeed {
	font-size: 11px;
	font-weight: 500;
	color: var(--text-muted);
	/* Fixed-ish width so the percentage does not jitter as the number changes. */
	min-width: 52px;
	text-align: right;
}

.progress-bar-bg {
	width: 100%;
	height: 6px;
	background: var(--border);
	border-radius: 999px;
	overflow: hidden;
}

.progress-bar-fill {
	height: 100%;
	width: 0%;
	background: var(--primary);
	transition: width 0.1s linear;
}

/* Modal Dialogs (Text & Confirmation) */
.modal-backdrop {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.65);
	backdrop-filter: blur(6px);
	z-index: 300;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.25s ease;
}

.modal-backdrop.show {
	opacity: 1;
	pointer-events: auto;
}

.modal-box {
	background: var(--bg-card);
	border: 1px solid var(--border);
	border-radius: 16px;
	padding: 22px;
	max-width: 400px;
	width: 100%;
	box-shadow: 0 20px 40px var(--shadow);
	transform: scale(0.92);
	transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.modal-backdrop.show .modal-box {
	transform: scale(1);
}

.modal-title {
	font-size: 16px;
	font-weight: 600;
	color: var(--text);
}

.modal-desc {
	font-size: 13px;
	color: var(--text-muted);
	line-height: 1.5;
	word-break: break-word;
	/* A batch of files is listed one per line. */
	white-space: pre-line;
	max-height: 40vh;
	overflow-y: auto;
}

.modal-textarea {
	width: 100%;
	height: 110px;
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 12px;
	color: var(--text);
	font-family: inherit;
	font-size: 14px;
	resize: none;
	outline: none;
}

.modal-textarea:focus {
	border-color: var(--primary);
}

.modal-actions {
	display: flex;
	justify-content: flex-end;
	gap: 10px;
	margin-top: 4px;
}

/* Usage guide */
.guide-box {
	max-height: 85vh;
	overflow-y: auto;
	gap: 16px;
}

/* The same-network requirement, deliberately the only highlighted block on the page. */
.guide-lead {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	padding: 12px 14px;
	border-radius: 12px;
	background: var(--primary-glow);
	border: 1px solid var(--primary);
}

.guide-lead-icon {
	font-size: 20px;
	line-height: 1.3;
}

.guide-lead strong {
	font-size: 13.5px;
	font-weight: 600;
	color: var(--text);
}

.guide-lead p {
	margin-top: 4px;
	font-size: 12.5px;
	color: var(--text-muted);
	line-height: 1.55;
}

.guide-section {
	display: flex;
	flex-direction: column;
}

.guide-heading {
	margin-bottom: 6px;
	font-size: 13px;
	font-weight: 600;
	color: var(--text);
}

.guide-list {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.guide-list li {
	position: relative;
	padding-left: 16px;
	font-size: 12.5px;
	color: var(--text-muted);
	line-height: 1.55;
}

.guide-list li::before {
	content: '•';
	position: absolute;
	left: 2px;
	color: var(--primary);
}

.guide-list b {
	font-weight: 600;
	color: var(--text);
}

.guide-note {
	padding-top: 12px;
	border-top: 1px solid var(--border-subtle);
	font-size: 12px;
	color: var(--text-muted);
	text-align: center;
}

.btn {
	padding: 9px 16px;
	border-radius: var(--radius);
	font-family: inherit;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	border: none;
	transition:
		background 0.15s ease,
		color 0.15s ease,
		transform 0.15s ease,
		box-shadow 0.15s ease;
}

/* Solid rather than outlined: hierarchy comes from the fill, not from a hairline. */
.btn-secondary {
	background: var(--surface);
	color: var(--text-muted);
}

.btn-secondary:hover {
	background: var(--surface-hover);
	color: var(--text);
	transform: translateY(-1px);
	box-shadow: 0 4px 12px var(--lift);
}

.btn-primary {
	background: var(--primary);
	color: #fff;
}

.btn-primary:hover {
	filter: brightness(1.12);
	transform: translateY(-1px);
	box-shadow: 0 6px 16px var(--primary-glow);
}

.btn:active {
	transform: translateY(0);
	box-shadow: none;
}

/* Toast Notification */
.toast {
	position: fixed;
	bottom: calc(64px + env(safe-area-inset-bottom, 0px));
	left: 50%;
	transform: translateX(-50%) translateY(100px);
	background: var(--bg-card);
	color: var(--text);
	border: 1px solid var(--border);
	padding: 10px 18px;
	border-radius: 12px;
	font-size: 13px;
	font-weight: 500;
	box-shadow: 0 10px 30px var(--shadow);
	z-index: 200;
	opacity: 0;
	transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
	display: flex;
	align-items: center;
	gap: 10px;
	pointer-events: none;
	max-width: 90vw;
	text-align: center;
}

.toast.show {
	transform: translateX(-50%) translateY(0);
	opacity: 1;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.info { border-color: var(--primary); }

/* Hidden file input */
#fileInput {
	display: none;
}
