:root {
	--main-background: #313338;
	--main-color: #dbdee1;
	--sidebar-background: #2b2d31;
	--expander-background: #3a3c43;
	--expander-background-hover: #454750;
	--expander-border: #1e1f22;

	--button-color: #eff7ef;
	--button-background: #5865f2;
	--button-background-hover: #4752c4;
	--button-border: #2b2d31;

	--danger-button-color: #eff7ef;
	--danger-button-background: #da373c;
	--danger-button-background-hover: #b52d31;
	--danger-button-border: #2b2d31;

	--green: #3ba55d;
	--gray: #949ba4;
	--red: #ed4245;
}

html {
	scrollbar-color: #8e8e8e transparent;
}

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

body {
	display: grid;
	grid-template-rows: auto 1fr max-content;
	grid-template-columns: max-content 1fr max-content;
	font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
	background: var(--main-background);
	color: var(--main-color);
}

noscript {
	display: block;
	margin: 0 auto;
	max-width: 600px;
	grid-column-start: 2;
}

button {
	background: var(--button-background);
	transition: background 0.25s linear;
	color: var(--button-color);
	padding: 0.35rem 0.65rem;
	border-style: solid;
	border-color: var(--button-border);
	border-width: 1px;
	font-size: 0.85rem;
	cursor: pointer;
	border-radius: 6px;
}

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

button.danger {
	background: var(--danger-button-background);
	color: var(--danger-button-color);
	border-color: var(--danger-button-border);
}

button.danger:hover {
	background: var(--danger-button-background-hover);
}

#buffer, #connect {
	color: var(--main-color);
	background: var(--main-background);
	width: 100%;
	height: 100%;
	overflow-x: hidden;
	overflow-y: auto;
}

#buffer-list, #member-list {
	color: var(--main-color);
	background: var(--main-background);
	width: 100%;
	height: 100%;

	background-color: var(--sidebar-background);
	grid-column: 1;
	grid-row: 1 / 4;

	display: flex;
	flex-direction: row;
}

.expander {
	display: none;
	cursor: pointer;
	padding: 0;
	margin: 0;
	background: var(--expander-background);
	transition: background 0.2s linear;
	border: none;
	width: 10px;
}

.expander:hover {
	background: var(--expander-background-hover);
}

.expander span {
	display: block;
	width: 100%;
	height: 2px;
	margin-bottom: 2px;
	border-style: solid;
	border-width: 1px 0;
	border-color: var(--expander-border);
}

#buffer-list ul {
	list-style-type: none;
	margin: 0;
	padding: 8px 6px;
	flex: 1 0 auto;
	overflow-x: hidden;
	overflow-y: auto;
	scrollbar-width: thin;
}

#buffer-list li a {
	display: inline-block;
	width: 100%;
	padding: 6px 10px;
	box-sizing: border-box;
	border-radius: 6px;
	color: var(--gray);
}

#buffer-list li a:hover {
	background: rgba(255, 255, 255, 0.06);
	color: var(--main-color);
	text-decoration: none;
}

#buffer-list li.active a {
	color: white;
	background-color: #404249;
	font-weight: 600;
}

#buffer-list li.error a {
	color: #ff7b7b;
}

#buffer-list li.unread-message a {
	color: #f0b232;
}

#buffer-list li.unread-highlight a {
	color: #6ea8fe;
}

#buffer-list li:not(.type-server) a {
	padding-left: 20px;
}

#member-list-header {
	color: var(--main-color);
	background-color: #2b2d31;
	box-sizing: border-box;
	padding: 8px 10px;
	border-bottom: 1px solid #1e1f22;
	font-weight: 600;
}

#buffer-header {
	color: var(--main-color);
	background-color: #313338;
	box-sizing: border-box;
	border-bottom: 1px solid #1e1f22;

	grid-row: 1;
	grid-column: 2;

	display: grid;
	grid-template-rows: 1fr auto;
	grid-template-columns: 1fr auto;
}

#buffer-header .title {
	display: none;
	padding: 8px 12px;
	font-weight: bold;
	grid-row: 1;
	grid-column: 1;
}

#buffer-header .description {
	padding: 8px 12px;
	grid-row: 2;
	grid-column: 1;
	max-height: 20vh;
	overflow-y: auto;
	word-break: break-word;
	color: var(--gray);
}

#buffer-header .actions {
	grid-row: 1 / 3;
	grid-column: 2;
}

#buffer-header .status-here {
	color: var(--green);
}

#buffer-header .status-gone {
	color: #faa61a;
}

#buffer-header .status-offline {
	color: var(--red);
}

.actions {
	display: flex;
	flex-direction: row;
	justify-content: center;
}

.actions button {
	border-width: 0 0 0 1px;
	border-radius: 0;
}

#buffer {
	grid-row: 2;
	grid-column: 2;
}

#buffer:focus {
	outline: none;
}

#member-list {
	grid-row: 1 / 4;
	grid-column: 3;
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: row;
}

#member-list > section {
	display: flex;
	flex-direction: column;
	background: var(--sidebar-background);
}

#member-list-header {
	border-left: 1px solid #1e1f22;
}

#member-list ul {
	list-style-type: none;
	margin: 0;
	padding: 8px 6px;
	flex-grow: 1;
	overflow-x: hidden;
	overflow-y: auto;
	scrollbar-width: thin;
}

#member-list li a {
	display: inline-block;
	width: 100%;
	padding: 4px 10px;
	box-sizing: border-box;
	color: var(--gray);
	border-radius: 6px;
}

#member-list li a:hover {
	background: rgba(255, 255, 255, 0.06);
	color: var(--main-color);
	text-decoration: none;
}

#member-list li a.away {
	color: var(--gray);
	opacity: 0.8;
}

.membership.owner {
	color: #ff6b6b;
}
.membership.admin {
	color: #6ea8fe;
}
.membership.op {
	color: var(--green);
}
.membership.halfop {
	color: #faa61a;
}
.membership.voice {
	color: #f0b232;
}

#composer {
	color: var(--main-color);
	background: #313338;
	grid-row: 3;
	grid-column: 2 / 3;
	border-top: 1px solid #1e1f22;
	padding: 10px 12px;
}

#composer input {
	display: block;
	height: 42px;
	width: 100%;
	box-sizing: border-box;
	padding: 10px 14px;
	border-radius: 8px;
	background: #383a40;
	color: var(--main-color);
	border: none;
	outline: none;
	font-family: inherit;
	font-size: 1rem;
}

#composer input::placeholder {
	color: var(--gray);
}

#composer input, #composer input:focus {
	border: none;
	outline: none;
}

#composer.read-only {
	display: none;
}

#connect {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
}

#connect form {
	margin: 0 auto;
	max-width: 350px;
	padding: 10px;
	box-sizing: border-box;
}

form input[type="text"],
form input[type="username"],
form input[type="password"],
form input[type="url"],
form input[type="email"],
form input[type="search"] {
	box-sizing: border-box;
	width: 100%;
	font-family: inherit;
	font-size: inherit;
	color: var(--main-color);
	background: #383a40;
	border: 1px solid #4a4d55;
	padding: 0.35rem 0.5rem;
	border-radius: 6px;
}

form input[type="text"]:focus,
form input[type="username"]:focus,
form input[type="password"]:focus,
form input[type="url"]:focus,
form input[type="email"]:focus,
form input[type="search"]:focus {
	outline: 0;
	border-color: #5865f2;
}

a {
	color: #00a8fc;
}

#buffer-list li a,
a.timestamp,
a.nick {
	color: var(--gray);
	text-decoration: none;
}

#buffer-list li a:hover, #buffer-list li a:active,
a.timestamp:hover, a.timestamp:active,
a.nick:hover, a.nick:active {
	text-decoration: underline;
}

details summary[role="button"] {
	user-select: none;
	cursor: pointer;
}

#buffer {
	box-sizing: border-box;
	color: var(--gray);
	word-wrap: break-word;
}

#buffer .logline-list {
	padding: 10px;
}

#buffer .logline {
	white-space: pre-wrap;
	border-radius: 6px;
}

#buffer .logline:hover {
	background: rgba(255, 255, 255, 0.03);
}

#buffer .comicchat-line {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	overflow: visible;
	background: transparent;
}

#buffer .comicchat-avatar-slot {
	flex: 0 0 72px;
	width: 72px;
	min-width: 72px;
	background: transparent;
	display: flex;
	align-items: flex-start;
	justify-content: center;
}

#buffer .comicchat-line-body {
	flex: 1 1 auto;
	min-width: 0;
	background: transparent;
}

#buffer .comicchat-avatar {
	display: block;
	width: 72px;
	height: 96px;
	object-fit: contain;
	background: transparent !important;
	border: none;
	box-shadow: none;
}

#buffer .comicchat-line-body {
	flex: 1 1 auto;
	min-width: 0;
}

#buffer .comicchat-meta {
	display: flex;
	align-items: baseline;
	gap: 8px;
	margin-bottom: 2px;
}

#buffer .comicchat-content {
	color: var(--main-color);
	line-height: 1.4;
}

#buffer .comicchat-meta .nick {
	font-weight: 700;
	font-size: 1rem;
}

#buffer .comicchat-meta .timestamp {
	color: var(--gray);
	font-size: 0.85rem;
	font-weight: 500;
}

#buffer .talk,
#buffer .motd {
	color: var(--main-color);
}

#buffer .error {
	color: #ff7b7b;
}

#buffer .me-tell {
	color: #f0b232;
}

#buffer .highlight .nick {
	color: #ffffff;
	background-color: rgba(88, 101, 242, 0.35);
	padding: 0 4px;
	border-radius: 4px;
}

#buffer .nick {
	font-weight: 600;
}

#buffer .nick-1 {
	color: #ff7b72;
}
#buffer .nick-2 {
	color: #f28c28;
}
#buffer .nick-3 {
	color: #f0b232;
}
#buffer .nick-4 {
	color: #d7ba7d;
}
#buffer .nick-5 {
	color: #7ee787;
}
#buffer .nick-6 {
	color: #56d364;
}
#buffer .nick-7 {
	color: #3fb950;
}
#buffer .nick-8 {
	color: #39c5cf;
}
#buffer .nick-9 {
	color: #58a6ff;
}
#buffer .nick-10 {
	color: #79c0ff;
}
#buffer .nick-11 {
	color: #a5d6ff;
}
#buffer .nick-12 {
	color: #b392f0;
}
#buffer .nick-13 {
	color: #d2a8ff;
}
#buffer .nick-14 {
	color: #f778ba;
}
#buffer .nick-15 {
	color: #ff7eb6;
}
#buffer .nick-16 {
	color: #ff5c8a;
}

#buffer .separator {
	display: flex;
	align-items: center;
	text-align: center;
	text-transform: lowercase;
	font-variant: small-caps;
	color: var(--gray);
}

#buffer .separator::before,
#buffer .separator::after {
	content: "";
	flex: 1;
	border-bottom: 1px solid transparent;
}

#buffer .date-separator {
	color: var(--gray);
}

#buffer .date-separator::before,
#buffer .date-separator::after {
	border-color: #3f4147;
}

#buffer .unread-separator {
	color: #f23f43;
}

#buffer .unread-separator::before,
#buffer .unread-separator::after {
	border-color: #f23f43;
}

#error-msg {
	color: white;
	background-color: #da373c;
	position: fixed;
	bottom: 2rem;
	right: 0;
	padding: 0.5rem;
	margin: 0.5rem;
	border-radius: 6px;
}

#error-msg button, .dialog button.dialog-close {
	border: none;
	background: transparent;
	color: inherit;
	font-size: inherit;
	padding: 0;
}

.error-text {
	color: #ff7b7b;
}

.dialog {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.65);
	overflow: auto;
}

.dialog .dialog-body {
	background-color: #2b2d31;
	color: var(--main-color);
	margin: 20px auto;
	max-width: 500px;
	padding: 15px;
	border: 1px solid #1e1f22;
	border-radius: 8px;
}

.dialog .dialog-header {
	display: flex;
	flex-direction: row;
	align-items: center;
	margin-bottom: 1em;
}

.dialog .dialog-header h2 {
	flex-grow: 1;
	margin: 0;
}

.dialog .dialog-header button.dialog-close {
	font-size: 1.5em;
	padding: 0 5px;
}

.dialog h2 {
	margin-top: 0;
}

.dialog form button:not([type="button"]) {
	float: right;
}

.dialog form {
	overflow: auto;
}

.dialog .protocol-handler {
	display: flex;
	flex-direction: row;
}

.dialog .protocol-handler .left {
	flex-grow: 1;
}

kbd {
	background-color: #1e1f22;
	border: 1px solid #4a4d55;
	box-shadow: inset 0 -1px 0 #4a4d55;
	display: inline-block;
	font-size: 80%;
	margin: 3px;
	min-width: 1em;
	text-align: center;
	white-space: nowrap;
	padding: 2px 4px;
	font-family: monospace;
	border-radius: 3px;
	color: var(--main-color);
}

ul.switcher-list {
	list-style-type: none;
	margin: 0;
	padding: 0;
	margin-top: 10px;
}

ul.switcher-list li a {
	display: inline-block;
	width: 100%;
	padding: 5px 10px;
	margin: 4px 0;
	box-sizing: border-box;
	text-decoration: none;
	color: inherit;
	border-radius: 6px;
}

ul.switcher-list li a.selected {
	background-color: rgba(255, 255, 255, 0.08);
}

ul.switcher-list .server {
	float: right;
	opacity: 0.8;
}

@media (max-width: 640px) {
	.expander {
		display: block;
	}

	#buffer-list ul, #member-list > section {
		width: 0px;
	}

	#buffer-list.expand, #member-list.expand {
		z-index: 999;
		grid-column-start: 1;
		grid-column-end: 4;
	}

	#buffer-list.expand ul {
		width: auto;
	}

	#member-list.expand > section {
		width: 100%;
	}

	#member-list-header {
		border-left: none;
	}

	#buffer-header {
		grid-template-columns: 1fr min-content;
	}

	#buffer-header .title {
		display: block;
	}
}

@media (pointer: none), (pointer: coarse) {
	#buffer-list li a, #member-list li a {
		padding: 7px 10px;
	}
}

/* --- chat spacing / polish tweaks --- */

#buffer .logline-list {
	padding: 14px 16px 22px;
}

#buffer .logline.talk,
#buffer .logline.comicchat-line {
	margin: 0 0 8px 0;
	padding: 12px 14px;
	border-radius: 10px;
}

#buffer .logline.talk:hover,
#buffer .logline.comicchat-line:hover {
	background: rgba(255, 255, 255, 0.04);
}

/* Center avatar rows vertically */
#buffer .comicchat-line {
	align-items: center;
	gap: 14px;
}

/* Slightly larger avatar area */
#buffer .comicchat-avatar-slot {
	flex: 0 0 72px;
	width: 72px;
	min-width: 72px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: transparent;
}

#buffer .comicchat-avatar {
	display: block;
	width: 72px;
	height: 96px;
	object-fit: contain;
	background: transparent !important;
	border: none;
	box-shadow: none;
}

/* Keep body vertically centered beside avatar */
#buffer .comicchat-line-body {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding-top: 0;
}

/* Better spacing between name/time and message */
#buffer .comicchat-meta {
	display: flex;
	align-items: baseline;
	gap: 8px;
	margin-bottom: 4px;
}

#buffer .comicchat-content {
	line-height: 1.45;
}

/* Make plain text rows breathe more too */
#buffer .logline.talk:not(.comicchat-line) {
	padding-top: 14px;
	padding-bottom: 14px;
}

/* Softer highlight row, instead of making the nick look weird */
#buffer .logline.highlight {
	background: rgba(88, 101, 242, 0.14);
}

#buffer .logline.highlight:hover {
	background: rgba(88, 101, 242, 0.20);
}

#buffer .highlight .nick {
	background: transparent;
	padding: 0;
	border-radius: 0;
}

/* --- keep server / MOTD / status lines simple --- */

#buffer .logline:not(.comicchat-line) .comicchat-avatar-slot {
	display: none;
}

#buffer .logline:not(.comicchat-line) .comicchat-line-body {
	display: block;
	padding-top: 0;
}

#buffer .logline:not(.comicchat-line) {
	margin: 0 0 2px 0;
	padding: 2px 12px;
	border-radius: 0;
	background: transparent;
}

#buffer .logline:not(.comicchat-line) .timestamp {
	display: inline;
	margin-right: 10px;
	font-size: 0.95rem;
	font-weight: 600;
	color: var(--gray);
}

#buffer .logline:not(.comicchat-line):hover {
	background: transparent;
}

/* Fallback avatar badge for users without Comic Chat art */
#buffer .comicchat-avatar-fallback {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 72px;
	height: 72px;
	border-radius: 999px;
	box-sizing: border-box;
	background: rgba(255, 255, 255, 0.10);
	border: 1px solid rgba(255, 255, 255, 0.08);
	font-size: 2.5rem;
	font-weight: 900;
	line-height: 1;
	text-transform: uppercase;
	user-select: none;
}