/*
 * Earthquake CLI — floating-terminal layout.
 *
 * The MapLibre map fills the whole viewport as a background layer; the xterm.js
 * terminal sits over it as a Linux-style window — centered by default,
 * draggable by its titlebar, minimizable to a top-center dock chip and
 * maximizable to (almost) full screen. Map-plotting commands fade it to a
 * ghost (.ghost) instead of hiding it; clicking the map minimizes it.
 * The window background is translucent glass (rgba +
 * backdrop blur) so the map stays visible through the terminal. A help modal
 * (#help-modal) walks non-technical visitors through the commands.
 */

:root {
	--bg: #0b0f14;
	--panel: #0e141b;
	--border: #1c2632;
	--fg: #c8d3df;
	--muted: #6b7a8d;
	--accent: #35c1e8;
	--ok: #3fb950;
	--warn: #d29922;
	--err: #f85149;
	--glass: rgba(11, 15, 20, 0.62);
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	height: 100%;
}

body {
	background: var(--bg);
	color: var(--fg);
	font-family:
		ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
		"Liberation Mono", monospace;
	overflow: hidden;
}

/* --- Full-screen map layer ------------------------------------------------ */

#map {
	position: fixed;
	inset: 0;
	background: var(--panel);
}

/* MapLibre injects its own canvas; fill the viewport. */
#map .maplibregl-map {
	position: absolute;
	inset: 0;
}

/* --- Floating terminal window ---------------------------------------------- */

.term-window {
	position: fixed;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	width: min(920px, 86vw);
	height: min(500px, 58vh);
	/* dvh tracks the *visible* viewport as mobile browser chrome shows/hides. */
	height: min(500px, 58dvh);
	display: flex;
	flex-direction: column;
	background: var(--glass);
	-webkit-backdrop-filter: blur(10px) saturate(130%);
	backdrop-filter: blur(10px) saturate(130%);
	border: 1px solid rgba(53, 193, 232, 0.25);
	border-radius: 10px;
	box-shadow:
		0 24px 64px rgba(0, 0, 0, 0.55),
		0 0 0 1px rgba(0, 0, 0, 0.4);
	overflow: hidden;
	z-index: 10;
	transition: opacity 0.25s ease;
}

/* Ghost mode: a map-plotting command faded the window (90% transparent) so the
   plotted quakes are visible through it. Hovering previews it; clicking or
   typing in it (JS removes the class) restores it fully. */
.term-window.ghost {
	opacity: 0.1;
}

.term-window.ghost:hover {
	opacity: 1;
}

/* Maximized: pin to the viewport edges (JS clears any drag offsets first). */
.term-window.maximized {
	left: 12px;
	top: 12px;
	right: 12px;
	bottom: 12px;
	width: auto;
	height: auto;
	transform: none;
	border-radius: 8px;
}

/* Minimized: the window disappears; the dock chip stands in for it. */
.term-window.minimized {
	display: none;
}

/* --- Titlebar --------------------------------------------------------------- */

.term-titlebar {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.4rem 0.6rem;
	background: linear-gradient(rgba(28, 38, 50, 0.9), rgba(14, 20, 27, 0.9));
	border-bottom: 1px solid var(--border);
	flex: 0 0 auto;
	user-select: none;
	-webkit-user-select: none;
	touch-action: none;
	cursor: grab;
}

.term-titlebar:active {
	cursor: grabbing;
}

.term-window.maximized .term-titlebar {
	cursor: default;
}

.term-titlebar__title {
	flex: 1 1 auto;
	min-width: 0;
	text-align: center;
	font-size: 0.8rem;
	font-weight: 600;
	letter-spacing: 0.02em;
	color: var(--muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.term-titlebar__controls {
	display: inline-flex;
	gap: 0.35rem;
	flex: 0 0 auto;
}

.term-btn {
	width: 1.45rem;
	height: 1.45rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 1px solid var(--border);
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.05);
	color: var(--muted);
	font: inherit;
	font-size: 0.75rem;
	line-height: 1;
	padding: 0;
	cursor: pointer;
}

.term-btn:hover {
	background: rgba(255, 255, 255, 0.14);
	color: var(--fg);
}

/* The GitHub titlebar button is an <a>; keep it looking like its siblings. */
a.term-btn {
	text-decoration: none;
}

.term-btn svg {
	width: 0.8rem;
	height: 0.8rem;
}

/* Connection status (left slot of the titlebar). */
.status {
	display: inline-flex;
	align-items: center;
	gap: 0.45rem;
	font-size: 0.75rem;
	color: var(--muted);
	flex: 0 0 auto;
}

.status__dot {
	width: 0.55rem;
	height: 0.55rem;
	border-radius: 50%;
	background: var(--muted);
}

.status--connecting .status__dot {
	background: var(--warn);
	animation: pulse 1.1s ease-in-out infinite;
}

.status--open .status__dot {
	background: var(--ok);
}

.status--closed .status__dot {
	background: var(--err);
}

@keyframes pulse {
	0%,
	100% {
		opacity: 1;
	}
	50% {
		opacity: 0.3;
	}
}

/* --- Terminal body ----------------------------------------------------------- */

#terminal {
	flex: 1 1 auto;
	min-height: 0;
	/* Extra bottom padding so the prompt never sits flush against the rounded
	   window edge; small right padding keeps text off the scrollbar gutter. */
	padding: 0.4rem 0.3rem 0.8rem 0.6rem;
	overflow: hidden;
}

/* xterm injects its own viewport; fill the window and keep it see-through
   (the terminal theme background is transparent; the glass is on .term-window). */
#terminal .xterm,
#terminal .xterm-viewport,
#terminal .xterm-screen {
	height: 100% !important;
}

#terminal .xterm-viewport {
	background: transparent !important;
	/* Firefox: thin, theme-coloured scrollbar instead of the default white one. */
	scrollbar-width: thin;
	scrollbar-color: rgba(53, 193, 232, 0.35) transparent;
}

/* WebKit/Blink: replace the opaque white native scrollbar with a subtle glass one. */
#terminal .xterm-viewport::-webkit-scrollbar {
	width: 8px;
}

#terminal .xterm-viewport::-webkit-scrollbar-track {
	background: transparent;
}

#terminal .xterm-viewport::-webkit-scrollbar-thumb {
	background: rgba(53, 193, 232, 0.35);
	border-radius: 4px;
}

#terminal .xterm-viewport::-webkit-scrollbar-thumb:hover {
	background: rgba(53, 193, 232, 0.55);
}

/* --- Dock chip (minimized state) --------------------------------------------- */

.term-dock {
	position: fixed;
	left: 50%;
	top: 14px;
	transform: translateX(-50%);
	z-index: 10;
	display: none;
	align-items: center;
	gap: 0.5rem;
	padding: 0.45rem 0.8rem;
	background: var(--glass);
	-webkit-backdrop-filter: blur(10px);
	backdrop-filter: blur(10px);
	border: 1px solid rgba(53, 193, 232, 0.35);
	border-radius: 8px;
	color: var(--fg);
	font: inherit;
	font-size: 0.8rem;
	cursor: pointer;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.term-dock.visible {
	display: inline-flex;
}

.term-dock:hover {
	border-color: var(--accent);
}

.term-dock__icon {
	color: var(--accent);
	font-weight: 700;
}

/* An alert arrived while minimized: pulse until the terminal is restored. */
.term-dock--alert {
	border-color: var(--warn);
	animation: pulse 1.1s ease-in-out infinite;
}

/* --- Map chrome (controls, popups) — dark-themed to match the terminal ------- */

#map .maplibregl-ctrl-group {
	background: var(--panel);
	border: 1px solid var(--border);
}

#map .maplibregl-ctrl-group button + button {
	border-top: 1px solid var(--border);
}

#map .maplibregl-ctrl-group button span {
	filter: invert(1) hue-rotate(180deg);
}

#map .maplibregl-ctrl-attrib {
	background: rgba(11, 15, 20, 0.75);
}

#map .maplibregl-ctrl-attrib a {
	color: var(--muted);
}

.eq-popup .maplibregl-popup-content {
	background: var(--panel);
	color: var(--fg);
	border: 1px solid var(--border);
	border-radius: 6px;
	font-size: 0.78rem;
	padding: 0.5rem 0.65rem;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.eq-popup .maplibregl-popup-tip {
	border-top-color: var(--border);
	border-bottom-color: var(--border);
}

.eq-popup__meta {
	color: var(--muted);
}

/* --- Help / guide modal -------------------------------------------------------- */

.help-modal {
	position: fixed;
	inset: 0;
	z-index: 50;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(4, 8, 12, 0.55);
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
}

.help-modal[hidden] {
	display: none;
}

.help-modal__card {
	display: flex;
	flex-direction: column;
	width: min(620px, 92vw);
	max-height: 84vh;
	max-height: 84dvh;
	background: rgba(14, 20, 27, 0.96);
	border: 1px solid rgba(53, 193, 232, 0.35);
	border-radius: 12px;
	box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
	overflow: hidden;
}

.help-modal__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	padding: 0.75rem 1rem;
	border-bottom: 1px solid var(--border);
	background: linear-gradient(rgba(28, 38, 50, 0.9), rgba(14, 20, 27, 0.9));
}

.help-modal__header h2 {
	margin: 0;
	font-size: 0.95rem;
	letter-spacing: 0.02em;
}

.help-modal__body {
	padding: 0.9rem 1.1rem 1.1rem;
	overflow-y: auto;
	font-size: 0.84rem;
	line-height: 1.55;
}

.help-modal__body h3 {
	margin: 1.1rem 0 0.4rem;
	font-size: 0.75rem;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--accent);
}

.help-modal__body h3:first-child {
	margin-top: 0;
}

.help-modal__body p {
	margin: 0.4rem 0;
}

.help-modal__body code {
	background: rgba(53, 193, 232, 0.12);
	color: var(--accent);
	padding: 0.08rem 0.35rem;
	border-radius: 4px;
}

.help-modal__body table {
	width: 100%;
	border-collapse: collapse;
	margin: 0.3rem 0;
}

.help-modal__body td {
	padding: 0.32rem 0.6rem 0.32rem 0;
	border-bottom: 1px solid var(--border);
	vertical-align: top;
}

.help-modal__body td:first-child {
	white-space: nowrap;
}

.help-modal__body .muted {
	color: var(--muted);
}

/* --- Responsive: tablets & phones -------------------------------------------- */

/* Touch devices: enlarge the window buttons into comfortably tappable targets
   (the desktop 1.45rem circles are fine for a mouse but fiddly for a finger). */
@media (pointer: coarse) {
	.term-btn {
		width: 1.9rem;
		height: 1.9rem;
		font-size: 0.9rem;
	}

	.term-btn svg {
		width: 1rem;
		height: 1rem;
	}
}

/* Small screens: the floating window takes (almost) the whole viewport. dvh so
   it tracks the visible area as mobile browser chrome shows/hides. */
@media (max-width: 700px) {
	.term-window {
		width: calc(100vw - 16px);
		height: calc(100vh - 16px);
		height: calc(100dvh - 16px);
	}
}

/* Landscape phones / short viewports: use the full height rather than the
   500px cap, which would otherwise leave the window floating in a thin strip. */
@media (max-height: 480px) {
	.term-window {
		height: calc(100vh - 16px);
		height: calc(100dvh - 16px);
	}
}

/* Narrow titlebar: it runs out of room for the status label, title, and four
   controls at once — drop the label text (the coloured dot still shows the
   connection state) and tighten spacing so everything stays on one row. */
@media (max-width: 560px) {
	.term-titlebar {
		gap: 0.4rem;
		padding: 0.4rem 0.5rem;
	}

	.status__label {
		display: none;
	}

	.term-titlebar__controls {
		gap: 0.25rem;
	}

	.term-titlebar__title {
		font-size: 0.75rem;
	}
}
