:root {
  --view: #141618;
  --main: #202326;
  --sidebar: #292c30;
  --pri: #292c30;
  --alt: #1d1f22;
  --text: #fcfcfc;
  --outline: #505155;
  --accent: #78b3a9;
  --accent-full: #86ddcf;
  --accent-active: #49504f;

  --error: #da4453;
  --error-bg: #da445350;

  --sidebar-width: 192px;
}

@media (prefers-color-scheme: light) {
  :root {
    --view: #ffffff;
    --main: #eff0f1;
    --sidebar: #dddfe1;
    --pri: #fcfcfc;
    --alt: #f7f7f7;
    --text: #232629;
    --outline: #aaacb3;
    --accent: #78b3a9;
    --accent-full: #86ddcf;
    --accent-active: #d2e6e3;

    --error: #da4453;
    --error-bg: #da445350;
  }

  .roturLogo {
    filter: invert();
  }
}

* {
  scrollbar-color: var(--outline) var(--main);
}

body {
  margin: 0;
  background: var(--main);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Oxygen,
    Ubuntu,
    Cantarell,
    "Open Sans",
    "Helvetica Neue",
    sans-serif;
  user-select: none;
  font-size: 10pt;
  font-weight: normal;
}

p {
  font-size: 10pt;
}

.titlebar {
  z-index: 1001;
}

#serverBar {
  position: absolute;
  left: 0;
  width: 72px;
  height: 100vh;
  background: #111;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 8px;
  gap: 12px;
  box-sizing: border-box;
  border-right: 1px solid var(--outline);
  z-index: 7;
}

#serverIcons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  align-items: center;
}

.server-icon {
  width: 70%;
  aspect-ratio: 1/1;
  height: auto;
  background: var(--pri);
  border-radius: 6px;
  align-items: center;
  transition:
    background 0.15s,
    border-radius 0.05s;
  border: 1px solid transparent;
  overflow: hidden;
}

.server-icon.active {
  border-color: var(--accent);
}

.server-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#addServerBtn {
  width: 70%; /* match .server-icon */
  aspect-ratio: 1 / 1; /* keep square */
  background: var(--pri);
  border-radius: 6px;
  font-size: 30px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    border-color 0.05s;
  padding: 0;
  line-height: 1;
  box-sizing: border-box;
  overflow: hidden;
}

#addServerBtn:hover {
  border-color: var(--accent-full);
}

#addServerBtn:active {
  background: var(--accent-active);
}

#sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--view);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  outline: 1px solid var(--outline);
  position: absolute;
  left: 72px;
}

#userPanel {
  display: flex;
  align-items: center;
  padding: 8px;
  background: var(--alt);
  border-top: 1px solid var(--outline);
  gap: 8px;
}

#userPanel img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  outline: 1px solid var(--outline);
}

#userPanel .userMeta {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 4px;
}

#userPanel .userMeta span {
  font-size: 10pt;
  font-weight: 600;
}

#userPanel .userActions {
  display: flex;
  gap: 4px;
}

#userPanel button {
  padding: 2px 6px;
  font-size: 9pt;
  border-radius: 4px;
}

a {
  color: var(--accent);
  text-decoration: none;
  margin: 8px;
}

#sidebar a {
  all: unset;
  margin: 4px;
  margin-inline: 8px;
  color: var(--text);
  text-decoration: none;
  cursor: default;
}
.channel-link {
  display: inline-block;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  max-width: calc(var(--sidebar-width) - 24px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.channel-link:hover {
  background: var(--alt);
}
.channel-link.active {
  background: var(--accent-active);
  color: var(--accent-full);
}

#sidebar hr {
  width: calc(var(--sidebar-width) - 24px);
  margin: 2px;
  margin-inline: 4px;
  border: none;
  height: 1px;
  background: var(--outline);
}

#authPrompt {
  background: var(--main);
  width: 100vw;
  height: 100vh;
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

input {
  all: unset;
  background: var(--view);
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  border: solid 1px var(--outline);
  border-radius: 4px;
  padding: 6px;
  margin: 4px;
  transition: border cubic-bezier(0.19, 1, 0.22, 1) 0.1s;
}

input:hover {
  border: solid 1px var(--accent);
}

input:focus {
  border: solid 1px var(--accent);
}

textarea {
  all: unset;
  background: var(--view);
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  border: solid 1px var(--outline);
  border-radius: 4px;
  padding: 6px;
  margin: 4px;
  transition: border cubic-bezier(0.19, 1, 0.22, 1) 0.1s;
}

textarea:hover {
  border: solid 1px var(--accent);
}

textarea:focus {
  border: solid 1px var(--accent);
}

::-moz-selection {
  /* Code for Firefox */
  color: var(--main);
  background: var(--accent-full);
}

::selection {
  color: var(--main);
  background: var(--accent-full);
}

button {
  all: unset;
  background: var(--pri);
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  border: solid 1px var(--outline);
  border-radius: 4px;
  padding: 6px 20px;
  margin: 4px;
  transition: cubic-bezier(0.19, 1, 0.22, 1) 0.1s;
}

button:hover {
  border: solid 1px var(--accent);
}

button:active {
  border: solid 1px var(--accent);
  background: var(--accent-active);
}

#errorBox {
  position: absolute;
  left: 0;
  top: 0;
  width: 100vw;
  display: none;
  background: var(--error-bg);
  outline: solid 1px var(--error);
  transition: cubic-bezier(0.19, 1, 0.22, 1) 0.1s;
}

#errorBox p {
  margin: 12px;
  font-size: 10pt;
}

#errorBox i {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 16px;
  margin: 8px;
  border-radius: 4px;
  padding: 4px;
  transition: cubic-bezier(0.19, 1, 0.22, 1) 0.1s;
}

#errorBox i:hover {
  outline: solid 1px var(--accent);
}

#errorBox i:active {
  outline: solid 1px var(--accent);
  background: var(--accent-active);
}

#main {
  display: flex;
  flex-direction: column;
  position: fixed;
  bottom: 4px;
  margin-left: calc(var(--sidebar-width) + 72px);
  width: calc(100vw - var(--sidebar-width) - 72px - 240px);
  max-height: calc(100% - 48px);
  height: auto;
  overflow-y: auto;
  scrollbar-color: var(--outline) var(--main);
  margin-bottom: 48px;
}

#main .message {
  margin: 4px;
  margin-inline: 8px;
  display: flex;
  z-index: 2;
}

#main .message p {
  margin: 0;
}

.message img {
  max-width: 100%;
  max-height: 300px;
  height: auto;
  display: block;
  margin-top: 8px;
  border-radius: 6px;
  object-fit: contain;
}
.message .avatar {
  border-radius: 50%;
  width: 32px;
  height: 32px;
  margin-inline-end: 4px;
}

.message span {
  margin-inline: 4px;
  display: block;
  user-select: text;
}

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

#chatInput {
  position: fixed;
  bottom: 1px;
  margin: 0;
  margin-left: calc(var(--sidebar-width) + 72px);
  width: calc(100vw - var(--sidebar-width) - 72px - 240px - 15px);
  overflow-y: scroll;
  scrollbar-color: var(--outline) var(--main);
  border-radius: 0;
}

#replyBanner {
  position: fixed;
  bottom: 48px;
  margin-left: calc(var(--sidebar-width) + 72px);
  width: calc(100vw - var(--sidebar-width) - 72px - 240px - 15px);
  background: var(--alt);
  border: 1px solid var(--outline);
  border-bottom: none;
  padding: 4px 8px;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  z-index: 5;
}
#replyBanner.hidden {
  display: none;
}
#replyBanner.hidden {
  display: none;
}
#editBanner {
  position: fixed;
  bottom: 48px;
  margin-left: calc(var(--sidebar-width) + 72px);
  width: calc(100vw - var(--sidebar-width) - 72px - 240px - 15px);
  background: var(--alt);
  border: 1px solid var(--outline);
  border-bottom: none;
  padding: 4px 8px;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  z-index: 5;
}
#editBanner.hidden {
  display: none;
}
.edited-tag {
  font-size: 10px;
  opacity: 0.6;
  margin-left: 6px;
}
.reply-excerpt {
  font-size: 11px;
  opacity: 0.8;
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-left: 2px solid var(--accent);
  margin: 2px 0 4px;
  border-radius: 2px;
  display: flex;
  gap: 4px;
}
.reply-excerpt .reply-user {
  font-weight: 600;
}
.ctx-menu {
  background: var(--pri);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  border: 1px solid #222;
  padding: 4px;
  display: flex;
  flex-direction: column;
  min-width: 140px;
  border-radius: 6px;
}
.ctx-menu button {
  background: none;
  color: var(--text);
  border: none;
  text-align: left;
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 4px;
}
.ctx-menu button:hover {
  background: rgba(255, 255, 255, 0.1);
}
#replyBanner button {
  padding: 2px 6px;
  font-size: 10px;
}

#serverHeader {
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-weight: 600;
  background: var(--pri);
  border-bottom: 1px solid var(--outline);
}

.channel-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 72px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.channel-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #16181a;
  font-size: 11px;
  letter-spacing: 0.2px;
  border: 1px solid #1f2326;
  transition:
    background 0.12s,
    border-color 0.12s;
}
.channel-link:hover {
  background: #1e2225;
  border-color: #292f33;
}
.channel-link.active {
  background: var(--accent-active);
  border-color: var(--accent);
}
.channel-link.active:hover {
  background: var(--accent-active);
}
.channel-link::before {
  content: "#";
  opacity: 0.7;
}

.channel-link.active::before {
  opacity: 1;
}

/* Unread badge */
.channel-link .badge {
  margin-left: 10px;
  background: var(--accent);
  color: #000;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 12px;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
}

/* Message hover highlight */
#main .message {
  position: relative;
  border-radius: 4px;
  padding: 4px
}
#main .message:hover {
  background: var(--pri);
  outline: solid 1px var(--outline);
}

/* Members panel */
#membersPanel {
  position: fixed;
  right: 0;
  width: 240px;
  height: 100vh;
  background: var(--view);
  border-left: 1px solid var(--outline);
  display: flex;
  flex-direction: column;
  z-index: 6;
}

#membersScroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 72px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.member-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  opacity: 0.7;
  padding: 4px 6px;
}

.member-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 12px;
  cursor: default;
  transition: background 0.12s;
}
.member-entry:hover {
  background: var(--alt);
}
.member-entry.offline {
  opacity: 0.4;
}

.member-entry img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.role-pill {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--alt);
  border: 1px solid var(--outline);
  margin-left: auto;
  opacity: 0.8;
}

/* Server switch modal */
#serverSwitchModal.hidden {
  display: none;
}
#serverSwitchModal {
  position: fixed;
  inset: 0;
  background: rgba(
    0,
    0,
    0,
    0.7
  ); /* dim only, no blur for better perf w/o GPU */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}
.ssm-window {
  width: 420px;
  background: var(--main);
  border: 1px solid var(--outline);
  border-radius: 12px;
  padding: 20px 24px 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ssm-window h3 {
  margin: 0 0 4px 0;
  font-size: 16px;
}
.ssm-window p {
  margin: 0;
  opacity: 0.8;
}
.ssm-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.ssm-error {
  color: var(--error);
  font-size: 10pt;
  margin-top: 8px;
}
.ssm-window input {
  width: 100%;
  box-sizing: border-box;
}
