/* SPDX-License-Identifier: MIT */
/*
 * 9tab: text is the interface. Flat pale yellow text surfaces and pale
 * blue tag bars after rio and acme, one strong rule colour, square
 * corners, no gradients or shadows. The dark variant keeps the same
 * structure at night: warm dark paper, deep teal tags, the rule lifted.
 */

:root {
	--paper: #ffffea;
	--ink: #1a1a14;
	--dim: #5f5f45;
	--tag: #eaffff;
	--tag-ink: #10262b;
	--rule: #57579e;
	--sel: #eeee9e;
	--note: #2d6b6b;
	--warn-bg: #fff1d6;
	--warn: #7a3d00;
	--bad: #a3001b;
	--good: #1f6b2a;
	--focus: #1a1a14;
	--ui: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
	--mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", "Noto Sans Mono", monospace;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--paper: #1b1a12;
		--ink: #ebe7c6;
		--dim: #a5a283;
		--tag: #13272b;
		--tag-ink: #d3f1f1;
		--rule: #9090dc;
		--sel: #4d4a1e;
		--note: #79c4c4;
		--warn-bg: #3a2a0c;
		--warn: #f2c27a;
		--bad: #ff8a8a;
		--good: #8fd69a;
		--focus: #f4f0d0;
		color-scheme: dark;
	}
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
	margin: 0;
	background: var(--paper);
	color: var(--ink);
	font: 15px/1.45 var(--ui);
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

::selection { background: var(--sel); color: var(--ink); }

a { color: var(--rule); text-underline-offset: 2px; }

h1 { font-size: 1.5rem; line-height: 1.2; margin: 0 0 .75rem; font-weight: 650; }

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

[hidden] { display: none !important; }

.sr {
	position: absolute; width: 1px; height: 1px; overflow: hidden;
	clip-path: inset(50%); white-space: nowrap;
}

button {
	font: inherit;
	color: var(--tag-ink);
	background: var(--tag);
	border: 1px solid var(--rule);
	border-radius: 0;
	padding: .35rem .7rem;
	min-height: 2.25rem;
	cursor: pointer;
}
button:hover { background: var(--sel); color: var(--ink); }
button:active { background: var(--rule); color: var(--paper); }
button:disabled { opacity: .5; cursor: default; }
button.primary {
	background: var(--rule);
	color: var(--paper);
	font-weight: 600;
	padding: .55rem 1.1rem;
}
button.primary:hover { background: var(--ink); color: var(--paper); }
button.wide { width: 100%; }

input[type="text"] {
	font: 15px/1.3 var(--mono);
	color: var(--ink);
	background: var(--paper);
	border: 1px solid var(--rule);
	border-radius: 0;
	padding: .45rem .5rem;
	min-width: 0;
}

/* ---- tag bars ---- */

.tag {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: .25rem 1rem;
	background: var(--tag);
	color: var(--tag-ink);
	border-bottom: 1px solid var(--rule);
	padding: .4rem max(.75rem, env(safe-area-inset-right)) .4rem max(.75rem, env(safe-area-inset-left));
}
.brand { font: 600 1rem/1.4 var(--mono); letter-spacing: .02em; }
.who b { font-family: var(--mono); }
.gridid { font-family: var(--mono); color: var(--dim); margin-left: auto; }

/* ---- front door and messages ---- */

.door .body {
	max-width: 38rem;
	padding: 1.75rem max(1rem, env(safe-area-inset-left)) 2rem;
}
.door .body p { margin: 0 0 1rem; }
.actions { margin: 1.5rem 0 1.25rem; }
.fine { color: var(--dim); font-size: .875rem; }
.checking { color: var(--dim); }
.savedgrids h2 { font-size: 1rem; margin: 1.5rem 0 .5rem; }
.saved { list-style: none; margin: 0 0 1.25rem; padding: 0; }
.saved li { padding: .55rem 0 .6rem; border-top: 1px solid var(--sel); }
.saved .l1 { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .6rem; }
.saved .l1 b { font-family: var(--mono); }
.saved .gridid { margin-left: 0; }
.saved .l2 { color: var(--dim); font-size: .8rem; margin: .15rem 0 .4rem; }
.saved .row { display: flex; gap: .5rem; }
.warn {
	background: var(--warn-bg);
	color: var(--warn);
	border-left: 3px solid var(--warn);
	padding: .4rem .6rem;
	margin: 0 0 1rem;
}

.support h1 { font-size: 1.25rem; }
.checks { list-style: none; padding: 0; margin: 0 0 1rem; font-size: .9rem; }
.checks li { padding: .3rem 0; border-bottom: 1px solid var(--sel); }
.checks .mark {
	display: inline-block; width: 2.2rem;
	font: 600 .8rem/1 var(--mono); text-transform: uppercase;
}
.checks .ok .mark { color: var(--good); }
.checks .no .mark { color: var(--bad); }
.checks .why { color: var(--dim); }

/* ---- the node view ---- */

.nodeview { display: flex; flex-direction: column; min-height: 100%; }

.notice {
	display: flex; gap: .75rem; align-items: center; justify-content: space-between;
	background: var(--warn-bg); color: var(--warn);
	border-bottom: 1px solid var(--rule);
	padding: .35rem .75rem; font-size: .9rem;
}
.notice button { min-height: 1.9rem; padding: .15rem .6rem; }

.node { display: flex; flex-direction: column; }

.cpane { display: flex; flex-direction: column; min-width: 0; }

.console { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.console .out {
	flex: none;
	height: 62vh;
	height: 62dvh;
	min-height: 16rem;
	overflow: auto;
	overscroll-behavior: contain;
	padding: .5rem .75rem;
	background: var(--paper);
	cursor: text;
}
.console .text {
	margin: 0;
	font: 14px/1.38 var(--mono);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	tab-size: 8;
}
.console .note { color: var(--note); font-style: italic; }

.cin {
	display: flex; flex-wrap: wrap; gap: .4rem;
	padding: .4rem .5rem;
	border-top: 1px solid var(--rule);
	background: var(--tag);
}
.cin .line { flex: 1 1 12rem; }
.cin .keys { display: flex; gap: .4rem; }
.cin .keys button { font-family: var(--mono); min-width: 2.75rem; padding: .35rem .5rem; }

.status {
	display: flex; flex-wrap: wrap; gap: .15rem 1rem;
	padding: .3rem .75rem;
	border-top: 1px solid var(--rule);
	border-bottom: 1px solid var(--rule);
	font: 12.5px/1.5 var(--mono);
	color: var(--dim);
	background: var(--paper);
}
.kstate { color: var(--ink); font-weight: 600; }
.kstate[data-state="running"]::before { content: "\25cf  "; color: var(--good); }
.kstate[data-state="panicked"], .kstate[data-state="trapped"], .kstate[data-state="failed"] { color: var(--bad); }
.kstate[data-state="halted"], .kstate[data-state="stopped"] { color: var(--warn); }

/* a terminal's screen: rio in a canvas, Plan 9 pixels a whole number of device pixels */
.screenbar {
	display: flex; flex-wrap: wrap; gap: .4rem;
	padding: .3rem .5rem;
	background: var(--tag);
	border-bottom: 1px solid var(--rule);
}
.screenbar button { min-height: 1.9rem; padding: .1rem .6rem; font: 13px/1.3 var(--mono); }
.screenbar .logtoggle[aria-pressed="true"] { background: var(--rule); color: var(--paper); }
@media (pointer: fine) { .screenbar .kbd { display: none; } }
.screenbox {
	position: relative;
	display: flex; align-items: center; justify-content: center;
	height: calc(100vh - 6.6rem);
	height: calc(100dvh - 6.6rem);
	min-height: 12rem;
	overflow: hidden;
	background: #777777;	/* rio's background, around a screen smaller than its box */
}
.screenbox:fullscreen { height: 100%; background: #000; }
canvas.screen {
	display: block;
	flex: none;
	image-rendering: pixelated;
	image-rendering: crisp-edges;
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
	cursor: default;
}
canvas.screen:focus-visible { outline: none; }
textarea.kbdtext {
	position: absolute; left: 0; bottom: 0;
	width: 1px; height: 1px;
	padding: 0; border: 0; margin: 0;
	opacity: 0; resize: none; overflow: hidden;
	font-size: 16px;	/* no zoom-on-focus */
	caret-color: transparent;
}
/* the node's snarf: a toggle in the bar, a text box under it */
.screenbar .cliptoggle { margin-left: auto; }
.screenbar .cliptoggle.open { background: var(--rule); color: var(--paper); }
.screenbar .cliptoggle.waiting { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); font-weight: 600; }
.clippanel {
	padding: .5rem .75rem .6rem;
	background: var(--paper);
	border-bottom: 1px solid var(--rule);
}
/* on a screen it lies over the canvas's top, which keeps its place and size */
.screenbox .clippanel {
	position: absolute; top: 0; left: 0; right: 0; z-index: 2;
	max-height: 100%; overflow: auto;
	box-shadow: 0 .3rem .8rem rgb(0 0 0 / .35);
}
.clippanel .fine { margin: 0 0 .4rem; }
.cliptext {
	display: block; width: 100%;
	font: 14px/1.35 var(--mono);
	color: var(--ink); background: var(--paper);
	border: 1px solid var(--rule); border-radius: 0;
	padding: .4rem .5rem;
	resize: vertical;
	min-height: 5rem; max-height: 40vh;
}
.cliprow { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; margin-top: .4rem; }
.cliprow button { min-height: 1.9rem; padding: .1rem .6rem; font: 13px/1.3 var(--mono); }
.clipstatus { color: var(--dim); font-size: .85rem; }
.console.log .cin { display: none; }
.console.log .out { height: calc(100dvh - 6.6rem); }

/* panels: a tag bar (the summary) over a text surface */
.side { display: flex; flex-direction: column; min-width: 0; }
.panel { border-bottom: 1px solid var(--rule); }
.panel > summary {
	display: flex; align-items: baseline; gap: .75rem;
	list-style: none;
	background: var(--tag); color: var(--tag-ink);
	padding: .4rem .75rem;
	cursor: pointer;
	user-select: none;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before { content: "\25b8"; font-family: var(--mono); width: .8em; }
.panel[open] > summary::before { content: "\25be"; }
.panel[open] > summary { border-bottom: 1px solid var(--rule); }
.ptitle { font: 600 .95rem/1.4 var(--mono); }
.pnote { color: var(--dim); font-size: .85rem; margin-left: auto; }
.pbody { padding: .75rem; }

.roles { border: 0; padding: 0; margin: 0 0 .75rem; display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; }
.roles legend { padding: 0; margin-bottom: .25rem; color: var(--dim); font-size: .875rem; width: 100%; }
.roles label { display: inline-flex; align-items: center; gap: .3rem; min-height: 2rem; cursor: pointer; }
.roles input { accent-color: var(--rule); width: 1.05rem; height: 1.05rem; margin: 0; }

.qr {
	width: min(100%, 15rem);
	aspect-ratio: 1;
	background: #fff;	/* scanners want dark on light whatever the theme */
	border: 1px solid var(--rule);
	margin: 0 0 .75rem;
}
.qr svg { display: block; width: 100%; height: 100%; }

.urlrow { display: flex; gap: .4rem; margin-bottom: .25rem; }
.urlrow .url { flex: 1; font-size: 12.5px; }
.copied { display: block; min-height: 1.3em; font-size: .85rem; color: var(--good); margin-bottom: .4rem; }
.join .fine { margin: .75rem 0 0; }

.transport { margin: 0 0 .6rem; font: 12.5px/1.4 var(--mono); color: var(--dim); }
.net[data-state="open"]::before { content: "\25cf  "; color: var(--good); }
.net[data-state="connecting"]::before { content: "\25cb  "; color: var(--warn); }
.net[data-state="closed"]::before { content: "\25cb  "; color: var(--bad); }

.peers { list-style: none; margin: 0; padding: 0; }
.peers li { padding: .45rem 0 .5rem; border-top: 1px solid var(--sel); }
.peers li:first-child { border-top: 0; padding-top: 0; }
.peers .l1 { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .6rem; }
.peers .l1 b { font-family: var(--mono); }
.peers .role { color: var(--dim); font-size: .875rem; }
.peers .ip { font: 12.5px var(--mono); }
.peers .mark {
	margin-left: auto;
	font: 600 11px/1.6 var(--mono); text-transform: uppercase; letter-spacing: .04em;
	color: var(--paper); background: var(--rule); padding: 0 .35rem;
}
.peers .l2 { color: var(--dim); font-size: .8rem; }
.peers li.me { border-left: 3px solid var(--rule); margin-left: -.75rem; padding-left: calc(.75rem - 3px); }

/* a grid that was just started puts its join panel first on a phone */
.node.fresh .side { display: contents; }
.node.fresh .join { order: -1; border-top: 0; }
.node.fresh .grid { order: 1; }

@media (pointer: coarse) {
	button { min-height: 2.75rem; }
	input[type="text"], .cin .line, .cliptext { font-size: 16px; }	/* no zoom-on-focus */
	.cliprow button { min-height: 2.75rem; }
	.console .text { font-size: 13px; }
}

/* wide: console on the left, panels on the right, both full height */
@media (min-width: 56rem) {
	.nodeview { height: 100%; }
	.node, .node.fresh {
		flex: 1;
		min-height: 0;
		display: grid;
		grid-template-columns: minmax(0, 1fr) minmax(19rem, 24rem);
	}
	.node.fresh .side { display: flex; }
	.cpane { min-height: 0; border-right: 1px solid var(--rule); }
	.console .out { flex: 1; height: auto; min-height: 0; }
	.console.log .out { height: auto; }
	.status { border-bottom: 0; }
	.side { overflow: auto; }
}

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
	.qr { forced-color-adjust: none; }
}
