:root {
	/* Discord-like dark palette */
	--bg-deep: #1e1f22;
	--bg-base: #313338;
	--bg-elevated: #2b2d31;
	--bg-further: #35373c;
	--bg-modifier: #404249;
	--bg-hover: #3b3d44;
	--accent: #5865f2;
	--accent-hover: #4752c4;
	--green: #23a55a;
	--green-hover: #1a8347;
	--red: #ed4245;
	--red-hover: #c43133;
	--orange: #f0843d;
	--orange-hover: #d96b23;
	--purple: #9147ff;
	--purple-hover: #7d3cde;
	--text-normal: #dbdee1;
	--text-muted: #949ba4;
	--text-faint: #80848e;
	--text-link: #00a8fc;
	--border: #26282c;
	--radius: 8px;
	--radius-sm: 6px;
}

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

html, body {
	height: 100%;
}

body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	background: var(--bg-base);
	color: var(--text-normal);
	min-height: 100vh;
	display: flex;
	justify-content: center;
	align-items: center;
}

#app {
	width: 100%;
	max-width: 1200px;
	height: 100vh;
	max-height: 100vh;
	padding: 16px;
	display: flex;
}

/* Shared button base ---------------------------------------------------- */
button {
	font-family: inherit;
	border: none;
	border-radius: var(--radius-sm);
	background: var(--bg-further);
	color: var(--text-normal);
	font-size: 0.95rem;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
}

button:hover {
	background: var(--bg-modifier);
}

button:active {
	transform: scale(0.97);
}

/* =======================================================================
   Join screen
   ======================================================================= */
#join-screen {
	margin: auto;
	text-align: left;
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	border-radius: 14px;
	padding: 32px;
	width: 100%;
	max-width: 420px;
	box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

#join-screen h1 {
	margin-bottom: 22px;
	font-size: 1.4rem;
	font-weight: 700;
	text-align: center;
	color: #fff;
	letter-spacing: 0.2px;
}

.form-group {
	margin-bottom: 16px;
}

.form-group label {
	display: block;
	margin-bottom: 6px;
	font-size: 0.85rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.4px;
	color: var(--text-muted);
}

.form-group input {
	width: 100%;
	padding: 11px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--bg-deep);
	color: var(--text-normal);
	font-size: 1rem;
	outline: none;
	transition: border-color 0.15s ease;
}

.form-group input:focus {
	border-color: var(--accent);
}

.form-group input::placeholder {
	color: var(--text-faint);
}

/* Primary join button */
#join-btn {
	width: 100%;
	margin: 4px 0 0;
	padding: 12px;
	background: var(--accent);
	color: #fff;
	font-weight: 600;
	font-size: 1rem;
	border-radius: var(--radius-sm);
}

#join-btn:hover {
	background: var(--accent-hover);
}

/* Active rooms list (polled from /api/rooms), styled like a channels list */
#rooms-section {
	margin-top: 26px;
	padding-top: 18px;
	border-top: 1px solid var(--border);
}

#rooms-header {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 8px;
	margin-bottom: 10px;
}

#rooms-header h2 {
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--text-faint);
	font-weight: 700;
}

#rooms-status {
	font-size: 0.75rem;
	color: var(--red);
	min-height: 1.2em;
}

#rooms-list {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 4px;
	max-height: 240px;
	overflow-y: auto;
}

.room-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 9px 12px;
	background: transparent;
	border-radius: var(--radius-sm);
	cursor: pointer;
	transition: background 0.15s ease;
}

.room-item:hover {
	background: var(--bg-modifier);
}

.room-name {
	font-size: 0.95rem;
	color: var(--text-normal);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	display: flex;
	align-items: center;
	gap: 6px;
}

.room-name::before {
	content: "#";
	color: var(--text-faint);
	font-weight: 700;
}

.room-count {
	font-size: 0.78rem;
	color: var(--text-muted);
	white-space: nowrap;
}

.rooms-empty {
	padding: 10px 12px;
	color: var(--text-faint);
	font-size: 0.85rem;
	font-style: italic;
}

/* =======================================================================
   Chat screen (Discord-style layout)
   ======================================================================= */
#chat-screen {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

/* Top bar: status on the left, user chip on the right */
#chat-topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 8px 12px;
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

#status {
	font-size: 0.85rem;
	color: var(--text-muted);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.user-chip {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-shrink: 0;
	padding: 4px 10px 4px 4px;
	background: var(--bg-further);
	border-radius: 999px;
}

.user-avatar {
	width: 32px;
	height: 32px;
	flex-shrink: 0;
	border-radius: 50%;
	background: var(--accent);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.9rem;
	font-weight: 700;
}

.user-name {
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--text-normal);
	max-width: 140px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.user-dot {
	width: 10px;
	height: 10px;
	flex-shrink: 0;
	border-radius: 50%;
	background: var(--green);
	border: 2px solid var(--bg-elevated);
}

/* Video grid (fills the middle, scrolls when many participants) */
#video-grid {
	flex: 1 1 auto;
	min-height: 0;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
	gap: 12px;
	overflow-y: auto;
	align-content: start;
	padding: 2px;
}

.video-cell {
	position: relative;
	background: var(--bg-deep);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	overflow: hidden;
	aspect-ratio: 16/9;
}

.video-cell video {
	width: 100%;
	height: 100%;
	object-fit: cover;
	background: var(--bg-deep);
}

.video-label {
	position: absolute;
	bottom: 8px;
	left: 8px;
	background: rgba(0, 0, 0, 0.6);
	padding: 3px 10px;
	border-radius: 6px;
	font-size: 0.8rem;
	color: #fff;
}

/* Bottom control bar */
#controls {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 28px;
	padding: 12px 16px;
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	flex-wrap: wrap;
}

.control-group {
	display: flex;
	align-items: center;
	gap: 10px;
}

/* Round/pill media buttons. Default holds an icon; when JS writes text
   (screen-share / deaf states) the same element gracefully widens. */
.ctrl-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 48px;
	height: 48px;
	padding: 0 14px;
	border-radius: 14px;
	background: var(--bg-further);
	font-size: 1.05rem;
}

.ctrl-btn:hover {
	background: var(--bg-modifier);
}

.ctrl-btn .ctrl-icon {
	font-size: 1.25rem;
	line-height: 1;
}

/* "Active" = feature on (mic/cam/deaf sound on). */
.ctrl-btn.active {
	background: var(--green);
	color: #fff;
}

.ctrl-btn.active:hover {
	background: var(--green-hover);
}

/* Distinct accents for the action buttons, shown on demand. */
#leave-btn {
	background: var(--red);
	color: #fff;
}

#leave-btn:hover {
	background: var(--red-hover);
}

#reconnect-btn {
	background: var(--orange);
	color: #fff;
}

#reconnect-btn:hover {
	background: var(--orange-hover);
}

#resume-screen-btn {
	background: var(--purple);
	color: #fff;
}

#resume-screen-btn:hover {
	background: var(--purple-hover);
}

/* Expand button on a screen-share cell */
.screen-expand-btn {
	position: absolute;
	top: 8px;
	right: 8px;
	background: rgba(0, 0, 0, 0.6);
	color: #fff;
	border: none;
	border-radius: 6px;
	padding: 5px 9px;
	font-size: 0.95rem;
	cursor: pointer;
	z-index: 2;
}

.screen-expand-btn:hover {
	background: rgba(0, 0, 0, 0.85);
}

/* Mic-off badge: overlaid on a peer's video cell when their microphone is off,
   positioned in the top-left corner (mirrors .screen-expand-btn in top-right).
   Only rendered visible by JS when the peer's mic is muted. */
.mic-badge {
	position: absolute;
	top: 8px;
	left: 8px;
	background: rgba(0, 0, 0, 0.6);
	color: #fff;
	border-radius: 6px;
	padding: 5px 9px;
	font-size: 0.95rem;
	line-height: 1;
	z-index: 2;
}

/* =======================================================================
   Screen overlay: full-page view of a shared screen
   ======================================================================= */
#screen-overlay {
	position: fixed;
	inset: 0;
	background: #000;
	z-index: 100;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}

#overlay-video {
	width: 100%;
	height: 100%;
	object-fit: contain;
}

#overlay-controls {
	position: absolute;
	bottom: 16px;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	gap: 8px;
	z-index: 101;
}

#overlay-controls button {
	padding: 10px 16px;
	background: var(--bg-further);
	color: var(--text-normal);
}

/* Keep overlay controls visible inside native fullscreen */
#screen-overlay:fullscreen {
	background: #000;
}

/* Responsive: stack the top-bar chip under the status on narrow screens */
@media (max-width: 560px) {
	#chat-topbar {
		flex-direction: column;
		align-items: stretch;
		gap: 6px;
	}

	.user-chip {
		justify-content: center;
	}

	#controls {
		gap: 12px;
	}
}
