:root {
	color-scheme: dark;
	--ink: #ebe7e0;
	--muted: #9b968e;
	/* Accent: obsidian. Primary buttons are polished black (see button.primary); rings, sliders, your name and links are
	   silver, since black would vanish on the dark UI. */
	--accent-hi: #e6e9ee;
	--accent: #b9c0c9;
	--red-hi: #f27873;
	--red: #d9443f;
	--red-lo: #982420;
	--ok: #5fbf6a;
	--warn: #e0a84a;
	--err: #ec5a55;
	/* Static grain, rasterized once: --noise over the background shader, the fainter --ui-grain on UI surfaces. */
	--noise: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 .09'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
	--ui-grain: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 .035'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
	--surface: linear-gradient(180deg, #3a3c41 0%, #2a2c30 52%, #212226 100%);
	--raised: inset 0 1px 0 rgb(255 255 255 / 0.14), inset 0 -2px 0 rgb(0 0 0 / 0.3), 0 1px 1px rgb(0 0 0 / 0.55),
		0 6px 14px -6px rgb(0 0 0 / 0.75);
	--pressed: inset 0 2px 5px rgb(0 0 0 / 0.6), inset 0 -1px 0 rgb(255 255 255 / 0.05), 0 1px 0 rgb(255 255 255 / 0.05);
	font: 14px/1.4 "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	height: 100%;
	overflow: hidden;
	color: var(--ink);
}

/* On html only: a body background would paint over the negative-z shader and grain layers. */
html {
	background: radial-gradient(ellipse at 30% 20%, #1d1e21, #0b0c0e 70%);
}

[hidden] {
	display: none !important;
}

#bg {
	position: fixed;
	inset: 0;
	z-index: -2;
	width: 100%;
	height: 100%;
}

/* Granite grain over the shader; static, so free. */
body::before {
	content: "";
	position: fixed;
	inset: 0;
	z-index: -1;
	background: var(--noise);
	pointer-events: none;
}

/* ---------- Tactile controls ---------- */

button,
input,
select {
	font: inherit;
	color: inherit;
}

button,
select {
	padding: 8px 15px;
	border: 1px solid rgb(0 0 0 / 0.7);
	border-radius: 11px;
	background: var(--ui-grain), var(--surface);
	box-shadow: var(--raised);
	color: var(--ink);
	font-weight: 600;
	letter-spacing: 0.01em;
	text-shadow: 0 1px 0 rgb(0 0 0 / 0.6);
	cursor: pointer;
	transition:
		transform 0.08s ease,
		box-shadow 0.08s ease,
		filter 0.15s ease;
}

button:hover,
select:hover {
	filter: brightness(1.13);
}

button:active,
button[aria-pressed="true"],
button[aria-expanded="true"] {
	transform: translateY(1px);
	box-shadow: var(--pressed);
	filter: brightness(0.93);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

button.primary {
	border-color: #000;
	background: var(--ui-grain), linear-gradient(180deg, #2c2e33, #111215 55%, #050506);
	color: #f2f2f0;
	text-shadow: 0 -1px 0 rgb(0 0 0 / 0.7);
}

button.danger {
	border-color: #4d0f0d;
	background: var(--ui-grain), linear-gradient(180deg, var(--red-hi), var(--red) 55%, var(--red-lo));
	color: #fff;
	text-shadow: 0 1px 0 rgb(0 0 0 / 0.45);
}

button.big {
	padding: 12px 20px;
	font-size: 16px;
	border-radius: 14px;
}

button.small {
	padding: 4px 11px;
	border-radius: 9px;
	font-size: 12px;
}

button.icon {
	display: grid;
	place-items: center;
	padding: 7px;
}

button.icon svg,
.bar button svg {
	width: 18px;
	height: 18px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
	filter: drop-shadow(0 1px 0 rgb(0 0 0 / 0.6));
}

input[type="range"] {
	--level: 50%;
	height: 28px;
	margin: 0;
	padding: 0;
	background: none;
	cursor: pointer;
	appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
	height: 7px;
	border-radius: 4px;
	background: linear-gradient(to right, var(--accent) var(--level), rgb(0 0 0 / 0.45) var(--level));
	box-shadow:
		inset 0 1px 2px rgb(0 0 0 / 0.6),
		0 1px 0 rgb(255 255 255 / 0.06);
}

input[type="range"]::-webkit-slider-thumb {
	width: 18px;
	height: 18px;
	margin-top: -6px;
	border: 1px solid rgb(0 0 0 / 0.6);
	border-radius: 50%;
	background: radial-gradient(circle at 35% 30%, #fff, #c9c4bc);
	box-shadow: 0 2px 4px rgb(0 0 0 / 0.6);
	appearance: none;
}

input[type="range"]::-moz-range-track {
	height: 7px;
	border-radius: 4px;
	background: rgb(0 0 0 / 0.45);
}

input[type="range"]::-moz-range-progress {
	height: 7px;
	border-radius: 4px;
	background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
	width: 18px;
	height: 18px;
	border: 1px solid rgb(0 0 0 / 0.6);
	border-radius: 50%;
	background: radial-gradient(circle at 35% 30%, #fff, #c9c4bc);
}

.panel {
	border: 1px solid rgb(0 0 0 / 0.65);
	border-radius: 18px;
	background: var(--ui-grain), linear-gradient(180deg, rgb(46 48 52 / 0.94), rgb(25 26 29 / 0.96));
	box-shadow:
		inset 0 1px 0 rgb(255 255 255 / 0.08),
		0 14px 34px -12px rgb(0 0 0 / 0.75);
}

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

.error {
	margin: 0;
	color: var(--err);
}

/* ---------- Home ---------- */

.center {
	display: grid;
	place-items: center;
	height: 100%;
}

.card {
	display: grid;
	gap: 14px;
	width: min(380px, 90vw);
	padding: 28px;
}

.card h1 {
	margin: 0;
	font-size: 22px;
	letter-spacing: -0.01em;
}

.card p {
	margin: 0;
}

/* ---------- Room layout ---------- */

/* Top bar, canvas (with every window, chat included), sound notice and dock, top to bottom. */
#room {
	position: fixed;
	inset: 0;
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	grid-template-rows: auto minmax(0, 1fr) auto auto;
}

#room > .bar {
	grid-area: 1 / 1 / 2 / -1;
}

#room > .sound-hint {
	grid-area: 3 / 1 / 4 / -1;
}

#room > .dock {
	grid-area: 4 / 1 / 5 / -1;
}

.bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin: 10px 10px 0;
	padding: 7px 8px 7px 16px;
}

/* Buttons keep their size and one-line labels; the status text is what gets cut short (…) when space runs out. */
.actions {
	display: flex;
	flex-shrink: 0;
	gap: 8px;
	white-space: nowrap;
}

.status {
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.status::before {
	content: "";
	display: inline-block;
	width: 9px;
	height: 9px;
	margin-right: 9px;
	border-radius: 50%;
	background: var(--muted);
	box-shadow: inset 0 1px 1px rgb(255 255 255 / 0.4);
}

.status[data-tone="ok"]::before {
	background: var(--ok);
	box-shadow: 0 0 8px rgb(95 191 106 / 0.7);
}

.status[data-tone="warn"]::before {
	background: var(--warn);
}

.status[data-tone="err"]::before {
	background: var(--err);
}

.canvas {
	grid-area: 2 / 1;
	position: relative;
	min-width: 0;
	min-height: 0;
}

.empty-hint {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	margin: 0;
	padding: 14px 22px;
	color: var(--muted);
	text-align: center;
	box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.06); /* flat on the canvas: no drop shadow, just the panel's top edge */
}

.dock {
	display: flex;
	gap: 6px;
	justify-self: center;
	max-width: calc(100% - 20px);
	margin: 0 10px 10px;
	padding: 6px;
	overflow-x: auto;
	scrollbar-width: none; /* still scrolls by swipe/wheel, without a visible bar */
	user-select: none;
	-webkit-user-select: none;
}

.dock::-webkit-scrollbar {
	display: none;
}

.chip {
	display: flex;
	align-items: center;
	gap: 9px;
	padding: 5px 12px 5px 5px;
	border-radius: 13px;
	white-space: nowrap;
}

.chip.on-canvas {
	background: rgb(255 255 255 / 0.05);
	box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.05);
	cursor: pointer;
}

.chip.on-canvas:hover {
	background: rgb(255 255 255 / 0.09);
}

.chip-text {
	display: flex;
	flex-direction: column;
	line-height: 1.2;
}

.chip .conn {
	color: var(--muted);
	font-size: 11px;
}

.chip .conn:empty {
	display: none;
}

/* Your own name: click to rename. */
.chip .name.editable {
	cursor: text;
	border-radius: 4px;
	text-decoration: underline dotted rgb(255 255 255 / 0);
	text-underline-offset: 3px;
	transition: text-decoration-color 0.15s ease;
}

.chip .name.editable:hover {
	text-decoration-color: rgb(255 255 255 / 0.45);
}

.chip .rename {
	width: 15ch;
	margin: -2px 0;
	padding: 1px 6px;
	border: 1px solid rgb(0 0 0 / 0.6);
	border-radius: 6px;
	background: rgb(0 0 0 / 0.3);
	box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.35);
	color: inherit;
	font: inherit;
	user-select: text;
	-webkit-user-select: text;
}

.chip .rename:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 1px;
}

.chip .rename.invalid {
	outline-color: var(--red);
	border-color: var(--red-lo);
}

.avatar {
	display: grid;
	place-items: center;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: radial-gradient(circle at 35% 30%, hsl(var(--hue, 25) 45% 62%), hsl(var(--hue, 25) 38% 34%));
	box-shadow:
		inset 0 1px 1px rgb(255 255 255 / 0.4),
		inset 0 -2px 3px rgb(0 0 0 / 0.35),
		0 2px 5px rgb(0 0 0 / 0.55);
	color: #fff;
	font-weight: 700;
	text-shadow: 0 1px 1px rgb(0 0 0 / 0.5);
	transition: box-shadow 0.12s ease;
}

/* Speaking: a green ring around the avatar. */
.chip.speaking .avatar {
	box-shadow:
		0 0 0 2px #0d0f12,
		0 0 0 4px var(--ok),
		0 0 12px 2px rgb(95 191 106 / 0.55);
}

.voice-state {
	display: grid;
	place-items: center;
	color: var(--err);
}

.voice-state svg,
.voice-controls svg {
	width: 16px;
	height: 16px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.voice-state .deaf,
.voice-state.deafened .mic-off {
	display: none;
}

.voice-state.deafened .deaf {
	display: block;
}

.voice-controls {
	display: flex;
	gap: 5px;
	margin-left: 2px;
}

.voice-controls button.icon {
	padding: 6px;
	border-radius: 9px;
}

.voice-controls .slash {
	display: none;
}

/* Off (muted mic / deafened): pressed in, red slashed icon. On: raised like any button. */
.voice-controls button.off {
	color: var(--err);
	box-shadow: var(--pressed);
}

.voice-controls button.off .slash {
	display: inline;
}

.sound-hint {
	justify-self: center;
	margin-bottom: 6px;
	border-radius: 999px;
	font-size: 13px;
}

.popover {
	position: fixed;
	z-index: 100001;
	display: grid;
	gap: 8px;
	width: 220px;
	padding: 12px 14px;
}

.popover-title {
	font-weight: 600;
}

.popover label {
	display: grid;
	gap: 6px;
}

.popover label > span {
	display: flex;
	justify-content: space-between;
	color: var(--muted);
	font-size: 12px;
}

.live {
	padding: 1px 6px;
	border-radius: 5px;
	background: linear-gradient(#f2645f, #c3302b);
	box-shadow:
		inset 0 1px 0 rgb(255 255 255 / 0.3),
		0 0 10px rgb(236 90 85 / 0.45);
	color: #fff;
	font-size: 10px;
	font-weight: 800;
	letter-spacing: 0.07em;
}

@keyframes pulse {
	50% {
		transform: scale(1.04);
	}
}

.win.pulse .win-body {
	animation: pulse 0.35s ease;
}

/* ---------- Stream windows ---------- */

.win {
	position: absolute;
	top: 0;
	left: 0;
	transform-origin: center;
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
	will-change: transform;
	container-type: size; /* its size is always set explicitly; the grips scale with it (cqw/cqh) */
}

.win-body {
	position: absolute;
	inset: 0;
	container-type: inline-size;
	overflow: hidden;
	border-radius: 18px;
	background: #000;
	box-shadow:
		0 0 0 1px rgb(255 255 255 / 0.08),
		0 24px 50px -18px rgb(0 0 0 / 0.85),
		0 8px 18px -8px rgb(0 0 0 / 0.6);
	transition: box-shadow 0.2s ease;
}

/* Held: lifted a little (slightly larger, softer shadow) with a faint rim; just enough to read as picked up. */
.win.dragging .win-body {
	box-shadow:
		0 0 0 1px rgb(230 233 238 / 0.22),
		0 28px 58px -20px rgb(0 0 0 / 0.85),
		0 10px 22px -10px rgb(0 0 0 / 0.6);
}

/* The window always has its stream's aspect ratio, so cover fills it with no bars and no visible crop. */
.win video {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	cursor: grab;
}

.win.dragging video {
	cursor: grabbing;
}

.win:not(.active):not(.dragging) video {
	cursor: none;
}

.win:fullscreen {
	width: 100% !important;
	height: 100% !important;
	transform: none !important;
}

.win:fullscreen .win-body {
	border-radius: 0;
}

.win:fullscreen video {
	object-fit: contain;
	cursor: default;
}

.win:fullscreen .handle,
.win:fullscreen .fill {
	display: none;
}

.win-label {
	position: absolute;
	bottom: 10px;
	left: 10px;
	display: flex;
	align-items: center;
	gap: 7px;
	max-width: calc(100% - 20px);
	padding: 4px 10px;
	border-radius: 9px;
	background: rgb(16 17 19 / 0.72);
	box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.07);
	font-size: 13px;
	white-space: nowrap;
	transition: opacity 0.2s;
}

.win-label .name {
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Above the resize handles (z-index 2), whose generous hit areas reach into the window corners. */
.controls {
	position: absolute;
	top: 10px;
	right: 10px;
	z-index: 3;
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 5px;
	border-radius: 14px;
	background: rgb(16 17 19 / 0.72);
	box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.07);
	opacity: 0;
	transition: opacity 0.15s;
}

/* Overlays on a stream show only while the mouse moves over it. */
.win.active .controls {
	opacity: 1;
}

.win:not(.active) .win-label {
	opacity: 0;
}

.fill .shrink,
.win[data-mode="full"] .fill .grow {
	display: none;
}

.win[data-mode="full"] .fill .shrink {
	display: inline;
}

.volume-group {
	display: flex;
	align-items: center;
	gap: 6px;
}

.controls .volume {
	width: 120px;
	margin-right: 4px;
}

/* Small windows: the speaker button alone, no slider. */
@container (max-width: 460px) {
	.controls .volume {
		display: none;
	}
}

.mute .speaker {
	fill: currentColor;
	stroke: none;
}

.mute:not([data-level="muted"]) .cross,
.mute[data-level="muted"] .wave1,
.mute[data-level="muted"] .wave2,
.mute[data-level="low"] .wave2 {
	display: none;
}

.stats {
	position: absolute;
	top: 10px;
	left: 10px;
	margin: 0;
	padding: 6px 9px;
	border-radius: 9px;
	background: rgb(16 17 19 / 0.78);
	font: 12px/1.5 ui-monospace, monospace;
	pointer-events: none;
}

.stats:empty {
	display: none;
}

.unmute {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	border-radius: 999px;
}

/* Resize handles: generous hit areas that reach outside the window; a grip shows while hovering. */
.handle {
	position: absolute;
	z-index: 2;
}

.handle[data-edge="n"],
.handle[data-edge="s"] {
	right: 34px;
	left: 34px;
	height: 26px;
	cursor: ns-resize;
}

.handle[data-edge="n"] {
	top: -13px;
}

.handle[data-edge="s"] {
	bottom: -13px;
}

.handle[data-edge="e"],
.handle[data-edge="w"] {
	top: 34px;
	bottom: 34px;
	width: 26px;
	cursor: ew-resize;
}

.handle[data-edge="e"] {
	right: -13px;
}

.handle[data-edge="w"] {
	left: -13px;
}

.handle[data-edge="nw"],
.handle[data-edge="ne"],
.handle[data-edge="sw"],
.handle[data-edge="se"] {
	width: 48px;
	height: 48px;
}

.handle[data-edge="nw"] {
	top: -16px;
	left: -16px;
	cursor: nwse-resize;
}

.handle[data-edge="ne"] {
	top: -16px;
	right: -16px;
	cursor: nesw-resize;
}

.handle[data-edge="sw"] {
	bottom: -16px;
	left: -16px;
	cursor: nesw-resize;
}

.handle[data-edge="se"] {
	right: -16px;
	bottom: -16px;
	cursor: nwse-resize;
}

/* Grips: faint and neutral while the window is hovered, bright only under the cursor. Every grip is centered on the
   window's edge line; corner grips are arcs that follow the rounded corner. */
.handle::after {
	content: "";
	position: absolute;
	opacity: 0;
	transition: opacity 0.15s;
	filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.8));
	pointer-events: none; /* decoration only: the handle box alone is the hit area */
}

.handle[data-edge="n"]::after,
.handle[data-edge="s"]::after,
.handle[data-edge="e"]::after,
.handle[data-edge="w"]::after {
	top: 50%;
	left: 50%;
	border-radius: 99px;
	background: rgb(255 255 255 / 0.85);
	transform: translate(-50%, -50%);
}

/* Edge grips take the free stretch between the corner arcs (which reach ~26px in from each corner), minus a margin,
   at most 56px; on a very small window they shrink away instead of running into the corners. */
.handle[data-edge="n"]::after,
.handle[data-edge="s"]::after {
	width: clamp(0px, 100cqw - 76px, 56px);
	height: 5px;
}

.handle[data-edge="e"]::after,
.handle[data-edge="w"]::after {
	width: 5px;
	height: clamp(0px, 100cqh - 76px, 56px);
}

/* The window corner sits 16px into each corner handle; the 4px arc straddles the 18px-radius edge. */
.handle[data-edge="nw"]::after,
.handle[data-edge="ne"]::after,
.handle[data-edge="sw"]::after,
.handle[data-edge="se"]::after {
	width: 28px;
	height: 28px;
	border: 0 solid rgb(255 255 255 / 0.85);
}

.handle[data-edge="nw"]::after {
	top: 14px;
	left: 14px;
	border-width: 4px 0 0 4px;
	border-top-left-radius: 20px;
}

.handle[data-edge="ne"]::after {
	top: 14px;
	right: 14px;
	border-width: 4px 4px 0 0;
	border-top-right-radius: 20px;
}

.handle[data-edge="sw"]::after {
	bottom: 14px;
	left: 14px;
	border-width: 0 0 4px 4px;
	border-bottom-left-radius: 20px;
}

.handle[data-edge="se"]::after {
	right: 14px;
	bottom: 14px;
	border-width: 0 4px 4px 0;
	border-bottom-right-radius: 20px;
}

.win.active .handle::after,
.chat.active .handle::after,
.chat.dragging .handle::after {
	opacity: 0.55;
}

.handle:hover::after {
	opacity: 1;
}

.fullscreen .exit,
.win:fullscreen .fullscreen .enter {
	display: none;
}

.win:fullscreen .fullscreen .exit {
	display: inline;
}

.snap-preview {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 99999;
	border: 2px solid rgb(230 233 238 / 0.7);
	border-radius: 18px;
	background: rgb(185 192 201 / 0.1);
	box-shadow: inset 0 0 40px rgb(185 192 201 / 0.18);
	pointer-events: none;
	transition:
		transform 0.16s ease,
		width 0.16s ease,
		height 0.16s ease;
}

/* ---------- Settings ---------- */

.settings {
	position: absolute;
	top: 10px;
	right: 10px;
	z-index: 100000;
	width: 300px;
	max-height: calc(100% - 20px);
	padding: 14px 18px;
	overflow-y: auto;
}

/* Toolbar: text labels on wide screens, icons on phones. */
.bar button svg {
	display: none;
}

button.done {
	box-shadow:
		var(--raised),
		0 0 0 2px var(--ok);
}

@media (max-width: 640px) {
	.bar {
		gap: 8px;
		margin: 8px 8px 0;
		padding: 6px 6px 6px 12px;
		font-size: 13px;
	}

	.actions {
		gap: 6px;
	}

	.bar button {
		display: grid;
		place-items: center;
		padding: 8px;
	}

	.bar button svg {
		display: block;
		width: 20px;
		height: 20px;
	}

	.bar button .label {
		display: none;
	}

	.settings {
		left: 10px;
		width: auto;
	}

	.empty-hint {
		width: calc(100% - 40px);
	}
}

.settings h2 {
	margin: 0 0 4px;
	font-size: 15px;
}

.settings h2.section {
	margin-top: 24px;
}

.settings p {
	margin: 0;
}

.settings label {
	display: grid;
	gap: 5px;
	margin: 14px 0;
}

.settings label > span {
	display: flex;
	justify-content: space-between;
}

.settings select {
	width: 100%;
	padding: 7px 10px;
	font-weight: 500;
}

.settings select option {
	background: #222327;
}

/* ---------- Chat ---------- */

#chatToggle {
	position: relative;
}

.badge {
	position: absolute;
	top: -7px;
	right: -7px;
	min-width: 19px;
	height: 19px;
	padding: 0 5px;
	border-radius: 10px;
	background: linear-gradient(#f2645f, #c3302b);
	box-shadow: 0 0 0 2px #1d1e21;
	color: #fff;
	font-size: 11px;
	font-weight: 800;
	line-height: 19px;
	text-align: center;
	text-shadow: none;
}

/* The chat window: a raised granite frame (header and composer sit on it) with the messages in a recessed well. */
.chat {
	position: absolute;
	top: 0;
	left: 0;
	container-type: size; /* for its grips, as on stream windows */
	display: flex;
	flex-direction: column;
	padding: 0 8px 12px;
	border: 1px solid rgb(0 0 0 / 0.75);
	border-radius: 18px;
	/* Lit from above like the other panels, but gently: a tall window should not get a bright band at the top. */
	background: var(--ui-grain), linear-gradient(180deg, #333539 0%, #2a2c30 45%, #222428 100%);
	box-shadow:
		inset 0 1px 0 rgb(255 255 255 / 0.16),
		inset 0 -2px 0 rgb(0 0 0 / 0.35),
		inset 1px 0 0 rgb(255 255 255 / 0.04),
		inset -1px 0 0 rgb(255 255 255 / 0.04),
		0 24px 50px -18px rgb(0 0 0 / 0.85),
		0 8px 18px -8px rgb(0 0 0 / 0.6);
	transition: box-shadow 0.2s ease;
}

.chat.dragging {
	box-shadow:
		inset 0 1px 0 rgb(255 255 255 / 0.16),
		inset 0 -2px 0 rgb(0 0 0 / 0.35),
		0 0 0 1px rgb(230 233 238 / 0.22),
		0 28px 58px -20px rgb(0 0 0 / 0.85),
		0 10px 22px -10px rgb(0 0 0 / 0.6);
}

/* The drag handle. */
.chat-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 8px 0 8px 8px;
	cursor: grab;
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
}

.chat.dragging .chat-head {
	cursor: grabbing;
}

.chat-head h2 {
	margin: 0;
	font-size: 15px;
	text-shadow: 0 1px 0 rgb(0 0 0 / 0.6);
}

.chat .handle {
	touch-action: none;
}

/* The header is the chat's only drag area: its corners reach just 16px inside (still 16px outside), so they do not
   cover the ends of the header, the title included. */
.chat .handle[data-edge="nw"],
.chat .handle[data-edge="ne"],
.chat .handle[data-edge="sw"],
.chat .handle[data-edge="se"] {
	width: 32px;
	height: 32px;
}

/* Above the resize handles, whose hit areas reach inside the frame: inside the well, clicks and scrolling win. */
.chat-list,
.chat-compose,
.chat-head button {
	position: relative;
	z-index: 3;
}

.chat-list {
	flex: 1;
	min-height: 0;
	padding: 6px 6px 10px;
	overflow-y: auto;
	border-radius: 13px;
	background: rgb(8 9 11 / 0.55);
	box-shadow:
		inset 0 2px 6px rgb(0 0 0 / 0.65),
		inset 0 0 0 1px rgb(0 0 0 / 0.55),
		0 1px 0 rgb(255 255 255 / 0.07);
	scrollbar-width: thin;
	scrollbar-color: transparent transparent; /* shown while scrolling (see showScrollbarWhileScrolling) */
	transition: scrollbar-color 0.4s ease;
}

.chat-list.scrolling,
.chat-compose textarea.scrolling {
	scrollbar-color: rgb(255 255 255 / 0.22) transparent;
	transition-duration: 0.1s;
}

#loadPrevious {
	display: block;
	margin: 4px auto 10px;
}

.chat-empty {
	margin: 32px 0;
	font-size: 13px;
	text-align: center;
}

.msg {
	display: grid;
	grid-template-columns: 32px minmax(0, 1fr);
	column-gap: 10px;
	padding: 8px 6px 2px;
	border-radius: 10px;
}

.msg.cont {
	padding-top: 2px;
}

.msg.cont .avatar,
.msg.cont .msg-head {
	display: none;
}

.msg-body {
	grid-column: 2;
	min-width: 0;
}

.msg .avatar {
	font-size: 14px;
}

.msg-head {
	display: flex;
	align-items: baseline;
	gap: 8px;
	margin-bottom: 1px;
}

.msg-name {
	overflow: hidden;
	font-size: 13px;
	font-weight: 700;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.msg.own .msg-name {
	color: var(--accent-hi);
}

.msg-head time {
	flex: none;
	color: var(--muted);
	font-size: 11px;
}

.msg-text {
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	line-height: 1.45;
}

.msg-text a {
	color: var(--accent-hi);
}

/* Attachments: image previews and file chips. Plain surfaces, not raised buttons. */
.attach {
	position: relative;
	margin-top: 6px;
	padding: 0;
	border: 0;
	background: none;
	box-shadow: none;
	font-weight: 400;
	text-align: left;
	text-shadow: none;
}

.attach:active {
	transform: none;
	box-shadow: none;
	filter: none;
}

.attach-image {
	display: block;
	max-width: 100%;
	border-radius: 16px;
}

.attach-clip {
	position: absolute;
	inset: 0;
	overflow: hidden;
	border-radius: 16px;
	background: #111;
	box-shadow: 0 0 0 1px rgb(255 255 255 / 0.08);
}

.attach-clip img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.attach-clip .preview {
	filter: blur(14px) saturate(1.2);
	transform: scale(1.2); /* hides the blur's soft edge */
}

.attach-clip .full {
	opacity: 0;
	transition: opacity 0.25s ease;
}

.attach-image.loaded .full {
	opacity: 1;
}

.attach-cta {
	position: absolute;
	top: 50%;
	left: 50%;
	display: flex;
	align-items: center;
	gap: 7px;
	padding: 8px 12px 8px 10px;
	border-radius: 14px;
	background: rgb(16 17 19 / 0.7);
	box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.1);
	font-size: 12px;
	white-space: nowrap;
	transform: translate(-50%, -50%);
}

.attach-cta svg {
	width: 18px;
	height: 18px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.attach-image[data-state="done"] .attach-cta {
	display: none;
}

.attach-image[data-state="done"] {
	cursor: zoom-in;
}

.attach-file {
	display: flex;
	align-items: center;
	gap: 12px;
	width: min(100%, 280px);
	padding: 8px 12px 8px 8px;
	border-radius: 16px;
	background: rgb(255 255 255 / 0.04);
	box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.05);
}

.attach-file:hover {
	background: rgb(255 255 255 / 0.07);
}

/* Squircle-ish file badge, colored by kind of file. */
.file-icon {
	--hue: 220;
	--sat: 12%;
	position: relative;
	flex: none;
	display: grid;
	place-items: center;
	width: 46px;
	height: 46px;
	border-radius: 32%;
	background: linear-gradient(160deg, hsl(var(--hue) var(--sat) 58%), hsl(var(--hue) var(--sat) 32%));
	box-shadow:
		inset 0 1px 0 rgb(255 255 255 / 0.35),
		inset 0 -2px 3px rgb(0 0 0 / 0.3),
		0 3px 8px rgb(0 0 0 / 0.45);
	color: #fff;
	text-shadow: 0 1px 1px rgb(0 0 0 / 0.45);
}

.file-icon .ext {
	font-size: 11px;
	font-weight: 800;
	letter-spacing: 0.04em;
}

.file-icon[data-cat="image"] { --hue: 280; --sat: 45%; }
.file-icon[data-cat="video"] { --hue: 330; --sat: 50%; }
.file-icon[data-cat="audio"] { --hue: 185; --sat: 50%; }
.file-icon[data-cat="pdf"] { --hue: 3; --sat: 60%; }
.file-icon[data-cat="archive"] { --hue: 40; --sat: 55%; }
.file-icon[data-cat="sheet"] { --hue: 140; --sat: 45%; }
.file-icon[data-cat="slides"] { --hue: 22; --sat: 65%; }
.file-icon[data-cat="doc"] { --hue: 214; --sat: 55%; }
.file-icon[data-cat="code"] { --hue: 255; --sat: 40%; }
.file-icon[data-cat="text"] { --hue: 205; --sat: 20%; }

/* Downloaded: a small check on the badge. */
.attach-file[data-state="done"] .file-icon::after {
	content: "✓";
	position: absolute;
	right: -4px;
	bottom: -4px;
	display: grid;
	place-items: center;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: var(--ok);
	box-shadow: 0 0 0 2px #232428;
	font-size: 11px;
	font-weight: 800;
}

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

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

.file-size {
	color: var(--muted);
	font-size: 12px;
}

[data-state="unavailable"] .file-size,
[data-state="unavailable"] .attach-cta {
	color: var(--warn);
}

/* Download progress: a stroke that runs around the badge or the image. */
.ring {
	position: absolute;
	inset: -5px;
	width: calc(100% + 10px);
	height: calc(100% + 10px);
	overflow: visible;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s;
}

.ring rect {
	x: 1.5px;
	y: 1.5px;
	width: calc(100% - 3px);
	height: calc(100% - 3px);
	rx: 20px;
	fill: none;
	stroke: var(--accent-hi);
	stroke-width: 3;
	stroke-linecap: round;
	stroke-dasharray: 100;
	stroke-dashoffset: calc(100 - var(--progress, 0));
	transition: stroke-dashoffset 0.15s linear;
	filter: drop-shadow(0 0 3px rgb(230 233 238 / 0.6));
}

.file-icon .ring rect {
	rx: 19px;
}

[data-state="loading"] .ring {
	opacity: 1;
}

.chat-notice {
	margin: 0 14px 4px;
	color: var(--muted);
	font-size: 12px;
}

.chat-compose {
	display: flex;
	align-items: flex-end;
	gap: 6px;
	padding: 10px 0 0;
}

.chat-compose textarea {
	flex: 1;
	min-width: 0;
	max-height: 140px;
	padding: 8px 12px;
	overflow-y: hidden; /* until it reaches max-height (set from chat.js) */
	border: 1px solid rgb(0 0 0 / 0.65);
	border-radius: 12px;
	background: rgb(0 0 0 / 0.35);
	box-shadow:
		inset 0 2px 4px rgb(0 0 0 / 0.5),
		0 1px 0 rgb(255 255 255 / 0.05);
	color: inherit;
	font: inherit;
	line-height: 1.4;
	resize: none;
	scrollbar-width: thin;
	scrollbar-color: transparent transparent;
	transition: scrollbar-color 0.4s ease;
}

/* Same height and corners as the one-line message box beside them. */
.chat-compose button.icon {
	width: 38px;
	height: 38px;
	border-radius: 12px;
}

.chat-compose textarea:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 1px;
}

.chat-drop {
	position: absolute;
	inset: 8px;
	z-index: 4; /* above the message list and composer (3) */
	display: grid;
	place-items: center;
	border: 2px dashed var(--accent);
	border-radius: 16px;
	background: rgb(14 15 17 / 0.88);
	font-weight: 700;
	pointer-events: none;
}

/* Dropped files wait here for Send or Cancel, covering the chat. */
.chat-confirm {
	position: absolute;
	inset: 0;
	z-index: 4;
	display: grid;
	place-items: center;
	padding: 14px;
	border-radius: 18px;
	background: rgb(10 11 13 / 0.72);
}

.chat-confirm-card {
	display: flex;
	flex-direction: column;
	gap: 12px;
	width: min(100%, 340px);
	max-height: 100%;
	padding: 16px;
	border: 1px solid rgb(0 0 0 / 0.75);
	border-radius: 16px;
	background: var(--ui-grain), var(--surface);
	box-shadow:
		inset 0 1px 0 rgb(255 255 255 / 0.14),
		0 18px 40px -14px rgb(0 0 0 / 0.85);
}

.chat-confirm-card h3 {
	margin: 0;
	font-size: 15px;
}

.chat-confirm-list {
	display: flex;
	flex-direction: column;
	gap: 8px;
	min-height: 0;
	margin: 0;
	padding: 0;
	overflow-y: auto;
	list-style: none;
	scrollbar-width: thin;
	scrollbar-color: rgb(255 255 255 / 0.15) transparent;
}

.chat-confirm-list li {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
}

.chat-confirm-list .thumb {
	flex: none;
	width: 44px;
	height: 44px;
	border-radius: 10px;
	object-fit: cover;
	box-shadow: 0 0 0 1px rgb(0 0 0 / 0.6);
}

.chat-confirm-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.lightbox {
	position: fixed;
	inset: 0;
	z-index: 200000;
	display: grid;
	place-items: center;
	background: rgb(0 0 0 / 0.82);
	cursor: zoom-out;
}

.lightbox img {
	max-width: 94vw;
	max-height: 94vh;
	border-radius: 10px;
	box-shadow: 0 20px 60px rgb(0 0 0 / 0.8);
}

/* After the chat rules above, so it wins on phones (where the chat opens full screen). */
@media (max-width: 640px) {
	.chat-compose textarea {
		font-size: 16px; /* smaller makes iPhone Safari zoom the page on focus */
	}
}

/* Phones and tablets: cheaper, not flat. CSS filters go, since each one makes the browser render that element on its
   own: the drop shadows on grips, the transfer-ring glow, brightness on hover and press (pressing still sinks the
   button). Shadows, edge highlights, grain and the icons' small drop shadow stay: static, painted once. The
   background is a single still frame (bg.js). Last in the file, so it beats the rules above. */
@media (pointer: coarse) {
	.handle::after,
	.ring rect,
	button:hover,
	select:hover,
	button:active,
	button[aria-pressed="true"],
	button[aria-expanded="true"] {
		filter: none;
	}

	/* The speaking ring, without its soft glow. */
	.chip.speaking .avatar {
		box-shadow:
			0 0 0 2px #0d0f12,
			0 0 0 4px var(--ok);
	}
}
