:root {
  --paper: #d4d0c8;
  --panel: #ffffff;
  --panel-alt: #efefef;
  --ink: #000000;
  --muted: #555555;
  --line: #808080;
  --line-soft: #c0c0c0;
  --navy: #000080;
  --accent: #0000ee;
  --danger: #cc0000;
  --bevel-light: #ffffff;
  --bevel-dark: #a0a0a0;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Verdana, Geneva, Tahoma, Arial, sans-serif;
  font-size: 12px;
  line-height: 1.45;
}

a { color: var(--accent); }
a:visited { color: #660099; }
a:hover { color: #cc0000; }

hr {
  border: 0;
  border-top: 1px solid var(--line-soft);
  margin: 8px 0;
}

tt, code { font-family: "Courier New", monospace; font-size: 11.5px; background: #ffffcc; padding: 0 2px; }

input, textarea, select, button {
  font-family: Verdana, Geneva, Tahoma, Arial, sans-serif;
  font-size: 12px;
  color: var(--ink);
}

input[type="text"], input[type="password"], textarea {
  padding: 4px 6px;
  border: 1px solid #808080;
  background: #ffffff;
  border-radius: 0;
  box-shadow: inset 1px 1px 0 #404040, inset -1px -1px 0 #ffffff;
}

input:focus, textarea:focus {
  outline: 1px dotted #000000;
  outline-offset: -1px;
}

textarea { resize: vertical; width: 100%; }

.btn {
  background: #d4d0c8;
  border: 1px solid #808080;
  box-shadow: inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark);
  padding: 3px 9px;
  cursor: pointer;
  font-size: 11px;
  color: var(--ink);
  white-space: nowrap;
}
.btn:hover { background: #e8e8e8; }
.btn:active { box-shadow: inset -1px -1px 0 var(--bevel-light), inset 1px 1px 0 var(--bevel-dark); }
.btn.primary { font-weight: bold; color: #ffffff; background: #000080; border-color: #000040; }
.btn.primary:hover { background: #0000a0; }
.btn.danger { color: var(--danger); }
.btn.tiny { font-size: 11px; padding: 2px 7px; }
.btn.micro { font-size: 10px; padding: 0 4px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

.linkbtn {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.linkbtn:hover { color: #cc0000; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: #000080;
  background: linear-gradient(#000080, #1084d0);
  color: #ffffff;
  border-bottom: 2px solid #808080;
}

.brand {
  font-family: Tahoma, Verdana, sans-serif;
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 1px;
  line-height: 1.1;
}

.tagline {
  font-size: 9px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #e0e0ff;
  margin-top: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-me {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #ffffff;
  font-size: 11px;
  line-height: 1.25;
}
.header-me .me-text strong { font-size: 11.5px; }
.header-me .me-text small { color: #c8ccff; font-size: 10px; }
.header-right .linkbtn { color: #c8ccff; }
.header-right .linkbtn:hover { color: #ffffff; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border: 1px solid #000000;
  color: #ffffff;
  font-family: "Courier New", monospace;
  font-size: 12px;
  font-weight: bold;
  overflow: hidden;
  vertical-align: middle;
}
.avatar-img { object-fit: cover; background: #c0c0c0; }
.avatar.small { width: 26px; height: 26px; font-size: 13px; }
.avatar.tiny { width: 16px; height: 16px; font-size: 9px; border-width: 1px; }
.avatar.big { width: 56px; height: 56px; font-size: 22px; }

.auth-wrap {
  display: flex;
  justify-content: center;
  padding: 30px 12px 44px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 3px 3px 0 #808080;
}

.auth-head {
  background: #000080;
  background: linear-gradient(#000080, #1084d0);
  color: #ffffff;
  padding: 7px 13px;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1.2px;
}

.auth-body { padding: 14px 16px 16px; }

.auth-tabs { font-size: 12px; }
.tab-sep { color: #808080; margin: 0 4px; }

.auth-tab {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}
.auth-tab.active { color: var(--ink); font-weight: bold; text-decoration: none; cursor: default; }

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
}
.field-row label {
  flex: 0 0 92px;
  width: 92px;
  text-align: right;
  font-size: 11.5px;
  color: #3a3a3a;
}
.field-row input { flex: 1 1 auto; min-width: 0; }

.form-actions { margin: 10px 0 6px; }

.hint { font-size: 10.5px; color: var(--muted); }
.hint.right { text-align: right; }
.auth-foot { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line-soft); }

.auth-error {
  margin: 8px 0;
  padding: 5px 7px;
  border: 1px solid #cc0000;
  background: #ffe4e4;
  color: #990000;
  font-size: 11.5px;
}
.auth-error.ok {
  border-color: #009900;
  background: #e2ffe2;
  color: #006600;
}

#app-window {
  max-width: 1480px;
  margin: 12px auto 0;
  padding: 0 12px;
}

.app-grid {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 290px;
  gap: 10px;
  height: calc(100vh - 158px);
  min-height: 470px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark);
}
.rail-title {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 8px 10px 4px;
  font-size: 9.5px;
  font-weight: bold;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: var(--navy);
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-alt);
}

.title-count { color: #808080; font-weight: normal; font-size: 10px; letter-spacing: 0; }

.sidebar { overflow-y: auto; padding-bottom: 10px; }
.sidebar .side-list,
.sidebar .side-actions,
.sidebar .find-form,
.sidebar #friend-requests,
.sidebar #friend-results { padding: 0 10px; }
.sidebar hr { margin: 8px 10px; }

.side-list { margin: 4px 0; }

.side-item {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  background: none;
  border: 0;
  padding: 2px 0;
  margin: 1px 0;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  text-align: left;
  line-height: 1.4;
}
.side-item:hover { color: #cc0000; }
.side-item.active { color: var(--ink); font-weight: bold; text-decoration: none; }
.side-item .room-mark { color: #808080; width: 9px; flex: 0 0 9px; }
.side-item .label { margin: 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .count { color: #808080; font-size: 10px; margin-left: auto; }
.badge { color: #cc0000; font-weight: bold; font-size: 11px; margin-left: auto; }
.badge::before { content: "("; }
.badge::after { content: ")"; }

.side-actions { display: flex; flex-direction: column; gap: 2px; font-size: 11px; margin: 2px 0 6px; }

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  background: #808080;
  border: 1px solid #404040;
}
.dot.on { background: #00aa00; border-color: #006600; }

.muted { color: var(--muted); }
.tiny-pad { padding: 2px 0; font-size: 11px; }

.requests {
  border: 1px dashed #808080;
  background: #ffffcc;
  padding: 5px 6px;
  margin: 5px 0;
  font-size: 11px;
}
.requests .muted { text-transform: uppercase; font-size: 9px; letter-spacing: .8px; }
.request { display: flex; align-items: center; gap: 4px; margin: 3px 0; flex-wrap: wrap; }
.request .label { font-weight: bold; }
.request-actions { display: inline-flex; gap: 3px; }
.outgoing { color: #808080; font-size: 10px; padding: 2px 10px; }

.find-form { margin-top: 6px; }
.find-form label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--navy); }
.find-row { display: flex; gap: 4px; margin-top: 3px; }
.find-row input { flex: 1 1 auto; min-width: 0; }

.chat { overflow: hidden; }

#channel-header {
  padding: 9px 12px 8px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-alt);
}
#channel-name {
  font-family: Verdana, Geneva, Tahoma, Arial, sans-serif;
  font-size: 16px;
  font-weight: bold;
  color: var(--navy);
  line-height: 1.2;
}
#channel-topic { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
#channel-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  font-size: 11px;
}
#channel-actions:empty { display: none; }

.invite-code {
  font-family: "Courier New", monospace;
  font-size: 11px;
  background: #ffffcc;
  border: 1px dashed #808080;
  padding: 1px 5px;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px;
  background: #ffffff;
  font-family: "Courier New", Courier, monospace;
  font-size: 12.5px;
  line-height: 1.45;
}

.msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px dotted #e0e0e0;
}
.msg:last-child { border-bottom: 0; }
.msg.mine { background: #f6f9ff; }
.msg-avatar { width: 26px; height: 26px; flex: 0 0 26px; font-size: 13px; }
.msg-main { flex: 1 1 auto; min-width: 0; }
.msg-line { word-break: break-word; }
.msg .ts { color: #808080; }
.msg .nick { font-weight: bold; }
.msg .body { white-space: pre-wrap; }
.msg.mine .nick { text-decoration: underline; }
.empty { color: #808080; font-style: italic; padding: 12px 0; }

.embed-gate {
  margin-top: 6px;
  max-width: 520px;
  border: 1px dashed #808080;
  background: #ffffcc;
  padding: 8px 10px;
  font-family: Verdana, sans-serif;
  font-size: 11.5px;
}
.embed-warn { color: #555555; margin-bottom: 6px; }
.embed-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.embed-actions a { font-size: 11px; }
.embed { margin-top: 6px; }
.embed-img {
  display: block;
  max-width: 100%;
  max-height: 380px;
  border: 1px solid var(--line);
  background: #ffffff;
}
.embed-broken { color: var(--danger); font-size: 11px; }

#composer {
  border-top: 1px solid var(--line-soft);
  background: var(--panel-alt);
  padding: 8px;
}
.composer-row { display: flex; gap: 6px; align-items: stretch; }
#message-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #808080;
  background: #ffffff;
  border-radius: 0;
  font-size: 12.5px;
}

.rightbar { overflow-y: auto; padding-bottom: 10px; }

.my-card, .profile-card {
  margin: 8px 10px;
  background: #ffffff;
  border: 1px solid var(--line);
}
.profile-banner {
  height: 74px;
  background-color: #d4d0c8;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  border-bottom: 1px solid var(--line);
}
.profile-head { display: flex; align-items: flex-start; gap: 8px; padding: 8px; }
.profile-head .avatar.big {
  margin-top: -34px;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px var(--line);
}
.profile-head-text { min-width: 0; padding-top: 2px; }
.profile-name { font-weight: bold; font-size: 12.5px; word-break: break-word; }
.profile-sub { color: var(--muted); font-size: 10.5px; }
.profile-bio { padding: 0 8px 8px; font-size: 11px; color: #3a3a3a; line-height: 1.4; word-break: break-word; white-space: pre-wrap; }
.presence { font-size: 10px; margin-top: 1px; }
.presence.on { color: #007700; }
.presence.off { color: #808080; }
.my-card .btn { margin: 0 8px 8px; width: calc(100% - 16px); }

.member-list { padding: 4px 10px 0; }
.member {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
  font-size: 11.5px;
  line-height: 1.5;
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
}
.member:hover { background: #e8e8e8; }
.member .label { font-weight: bold; overflow: hidden; text-overflow: ellipsis; }

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  padding: 4px 6px;
  border: 1px solid #808080;
  box-shadow: inset 1px 1px 0 #a0a0a0, inset -1px -1px 0 #ffffff;
  background: #d4d0c8;
  font-size: 10.5px;
  color: #333333;
}
.status-left { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.status-sep { color: #808080; }
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #808080;
  border: 1px solid #333333;
}
.status-dot.connected { background: #00aa00; }
.status-dot.offline { background: #cc0000; }

.site-footer {
  max-width: 1480px;
  margin: 20px auto 26px;
  padding: 0 12px;
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 12px;
  overflow-y: auto;
  background: rgba(0, 0, 0, .5);
}
.modal-box {
  width: 100%;
  max-width: 620px;
  margin: auto;
  background: var(--panel);
  border: 1px solid #000000;
  box-shadow: 4px 4px 0 #808080;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: #000080;
  background: linear-gradient(#000080, #1084d0);
  color: #ffffff;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1.2px;
}
.modal-head .linkbtn { color: #c8ccff; }
.modal-head .linkbtn:hover { color: #ffffff; }
.modal-body { padding: 14px; }
.modal-foot {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line-soft);
  background: var(--panel-alt);
}

.banner-preview {
  aspect-ratio: 2300 / 1080;
  background-color: #d4d0c8;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

.editor-top { display: flex; align-items: center; gap: 12px; }
.avatar-preview .avatar.big { width: 64px; height: 64px; font-size: 26px; }
.editor-top-fields { flex: 1 1 auto; min-width: 0; }

.field-block { margin: 12px 0; }
.field-block > label {
  display: block;
  margin-bottom: 4px;
  font-size: 9.5px;
  font-weight: bold;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--navy);
}

.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #808080;
  cursor: pointer;
}
.swatch.active { box-shadow: 0 0 0 2px var(--navy); }

.banner-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 6px 0;
}
.banner-tile {
  aspect-ratio: 2300 / 1080;
  padding: 0;
  border: 2px solid var(--line);
  background-color: #e0e0e0;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  cursor: pointer;
  font-size: 10px;
  color: var(--muted);
}
.banner-tile.active { border-color: var(--navy); box-shadow: 0 0 0 2px var(--accent); }

.rank {
  font-size: 10px;
  font-weight: bold;
  letter-spacing: .4px;
  margin-left: 4px;
  white-space: nowrap;
  font-family: Verdana, sans-serif;
}
.rank-owner { color: #c00000; }
.rank-co-owner { color: #8a2be2; }
.rank-admin { color: #0b5cad; }
.rank-mod { color: #0a7d32; }

.reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  margin-bottom: 6px;
  border: 1px solid #808080;
  background: #ffffcc;
  font-size: 11px;
  color: #333333;
}
.reply-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-quote {
  margin: 2px 0 3px;
  padding: 2px 6px;
  border-left: 3px solid #808080;
  background: #f0f0f0;
  color: #444444;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.ban-notice {
  padding: 5px 8px;
  margin-bottom: 6px;
  border: 1px solid #cc0000;
  background: #ffe8e8;
  color: #990000;
  font-size: 11px;
  font-weight: bold;
}
.ban-mark {
  color: #cc0000;
  font-size: 10px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.msg-tools {
  display: flex;
  gap: 6px;
  margin-top: 2px;
  opacity: 0;
}
.msg:hover .msg-tools { opacity: 1; }
@media (hover: none) {
  .msg-tools { opacity: 1; }
}
.msg-tool {
  padding: 0;
  border: 0;
  background: none;
  color: #6f7fb0;
  font-family: Verdana, sans-serif;
  font-size: 10px;
  cursor: pointer;
  text-decoration: underline;
}
.msg-tool:hover { color: var(--navy); }
.msg-tool.danger { color: #b00020; }
.msg-tool.danger:hover { color: #ff0000; }

.msg.system { background: #fff4f4; }
.msg .system-body { color: #cc0000; font-weight: bold; }

.modal-box.wide { max-width: 760px; }
.admin-section { margin-bottom: 16px; }
.admin-section:last-child { margin-bottom: 0; }
.admin-title {
  padding: 3px 0;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 1.2px;
  color: var(--navy);
}
.admin-list {
  max-height: 210px;
  overflow-y: auto;
  border: 1px solid var(--line-soft);
  background: #ffffff;
}
.admin-user, .admin-room {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-bottom: 1px dotted #e0e0e0;
  font-size: 12px;
}
.admin-user:last-child, .admin-room:last-child { border-bottom: 0; }
.admin-name { font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-user .admin-name { flex: 0 0 auto; }
.admin-user .rank-select { margin-left: auto; }
.admin-room .muted { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-room .btn { margin-left: auto; flex: 0 0 auto; }
.admin-row { display: flex; gap: 6px; align-items: stretch; margin: 6px 0; }
.admin-row input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #808080;
  background: #ffffff;
  border-radius: 0;
  font-size: 12.5px;
}
.rank-select {
  padding: 2px 4px;
  border: 1px solid #808080;
  background: #ffffff;
  border-radius: 0;
  font-size: 11px;
}
.rank-select:disabled { background: #e0e0e0; color: #808080; }
.admin-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.admin-cmds { font-size: 11.5px; line-height: 1.7; color: #404040; }
.admin-cmds tt {
  font-family: "Courier New", monospace;
  background: #ffffcc;
  border: 1px solid #c0c0c0;
  padding: 0 4px;
}
.tiny-pad { padding: 6px 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 2000;
  max-width: min(92vw, 460px);
  padding: 8px 14px;
  background: #14161a;
  color: #ffffff;
  border: 1px solid #000000;
  box-shadow: 3px 3px 0 #404040;
  font-size: 12px;
  text-align: center;
}

.mobile-bar { display: none; padding: 0 12px 6px; }

@media (max-width: 1040px) {
  .app-grid { grid-template-columns: 230px minmax(0, 1fr); }
  .rightbar { display: none; }
}

@media (max-width: 760px) {
  body { font-size: 13px; }
  .site-header { padding: 8px 12px; }
  .brand { font-size: 18px; letter-spacing: 2px; }
  .tagline { display: none; }

  #app-window { margin-top: 8px; padding: 0 8px; }

  .app-grid {
    display: block;
    height: auto;
    min-height: 0;
  }
  .sidebar { display: none; max-height: 46vh; }
  .app-grid.sidebar-open .sidebar { display: flex; margin-bottom: 8px; }
  .chat { height: calc(100vh - 190px); min-height: 380px; }
  .mobile-bar { display: block; }
  .messages { font-size: 12px; }
  .msg-avatar { width: 22px; height: 22px; flex: 0 0 22px; font-size: 11px; }
  .modal { padding: 10px 6px; }
  .banner-grid { grid-template-columns: repeat(2, 1fr); }
  .field-row { flex-direction: column; align-items: stretch; gap: 2px; }
  .field-row label { flex: 0 0 auto; width: auto; text-align: left; }
}
