:root {
  --bg: #12131a;
  --bg-soft: #191b24;
  --bg-hard: #0d0e14;
  --line: #262a37;
  --text: #d7dbe6;
  --muted: #7c8398;
  --accent: #7aa2f7;
  --danger: #f7768e;
  --ok: #9ece6a;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

/* The hidden attribute must beat every display rule in this sheet
   (.screen, .drop-hint etc. are flex and would otherwise cancel it). */
[hidden] {
  display: none !important;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

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

/* ------------------------------------------------------------- sign-in */

#login {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
}

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

.card p {
  margin: 0 0 12px;
  font-size: 12px;
}

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

input[type='text'],
input[type='password'] {
  background: var(--bg-hard);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  padding: 9px 11px;
  width: 100%;
}

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

button {
  cursor: pointer;
  font: inherit;
}

.card button[type='submit'] {
  margin-top: 14px;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
  color: var(--bg-hard);
  font-weight: 700;
  padding: 10px;
}

.card button[type='submit']:disabled {
  opacity: 0.5;
  cursor: progress;
}

.error,
.notice {
  margin: 10px 0 0 !important;
  font-size: 12px;
}

.error {
  color: var(--danger);
}

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

/* ---------------------------------------------------------------- chat */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-hard);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  min-height: 44px;
}

.head-left,
.head-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.head-left strong {
  color: var(--accent);
}

.topic {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.idle {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.idle.warn {
  color: var(--danger);
}

.me {
  font-size: 12px;
}

.text-button {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 4px;
  text-decoration: underline;
}

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

.icon-button {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
}

#toggle-users {
  display: none;
}

main {
  display: flex;
  flex: 1;
  min-height: 0;
}

.stream {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

/* Window bar: the channel plus one tab per private conversation. */
.tabs {
  display: flex;
  gap: 4px;
  align-items: stretch;
  background: var(--bg-hard);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  padding: 5px 6px 0;
  scrollbar-width: none;
}

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

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.tab.active {
  background: var(--bg);
  border-color: var(--line);
  color: var(--text);
  margin-bottom: -1px;
  padding-bottom: 7px;
}

.tab.private.active {
  border-color: rgba(187, 154, 247, 0.5);
}

.tab .badge {
  background: var(--accent);
  border-radius: 9px;
  color: var(--bg-hard);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  min-width: 16px;
  padding: 3px 5px;
  text-align: center;
}

.tab.private .badge {
  background: #bb9af7;
}

.tab-close {
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}

.tab-close:hover {
  color: var(--danger);
}

.views {
  display: flex;
  flex: 1;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-wrap: anywhere;
  padding: 10px 12px 16px;
  scrollbar-width: thin;
}

#users {
  width: 168px;
  flex-shrink: 0;
  background: var(--bg-hard);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 10px;
}

#users h2 {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.1em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

#users div {
  padding: 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.line {
  display: flex;
  gap: 8px;
  padding: 1px 0;
}

.line .ts {
  color: #4c5163;
  flex-shrink: 0;
  font-size: 12px;
  padding-top: 1px;
}

.line .body {
  min-width: 0;
  flex: 1;
}

.nick {
  font-weight: 700;
}

.nick.clickable {
  cursor: pointer;
  border-radius: 3px;
}

.nick.clickable:hover,
.nick.clickable:focus-visible {
  outline: none;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* The menu that opens when a nick is clicked. */
.nick-menu {
  position: fixed;
  z-index: 60;
  min-width: 190px;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  padding: 4px;
}

.nick-menu-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 6px 8px 7px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nick-menu button {
  background: none;
  border: 0;
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 7px 8px;
  text-align: left;
}

.nick-menu button:hover,
.nick-menu button:focus-visible {
  background: rgba(122, 162, 247, 0.16);
  color: var(--accent);
  outline: none;
}

.nick-menu button.danger:hover,
.nick-menu button.danger:focus-visible {
  background: rgba(247, 118, 142, 0.16);
  color: var(--danger);
}

.line.system .body {
  color: var(--muted);
  font-style: italic;
}

.line.action .body {
  color: #bb9af7;
  font-style: italic;
}

.line.notice .body {
  color: var(--danger);
}

/* Inside a private window everything on screen is private, so marking each
   line is pointless — the tab and the →/← arrow already say it. */

.line.mention {
  background: rgba(122, 162, 247, 0.09);
  border-left: 2px solid var(--accent);
  margin-left: -12px;
  padding-left: 10px;
}

a {
  color: var(--accent);
}

/* -------------------------------------------------------- attachments */

.media {
  margin: 4px 0;
  max-width: 420px;
}

.media img,
.media video {
  display: block;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 100%;
  max-height: 320px;
  cursor: zoom-in;
}

.media video {
  cursor: default;
}

.media audio {
  width: 100%;
  max-width: 320px;
}

.media .meta {
  color: var(--muted);
  font-size: 11px;
  padding-top: 2px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 11px;
  text-decoration: none;
}

.file-chip:hover {
  border-color: var(--accent);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 7, 10, 0.94);
  cursor: zoom-out;
  padding: 20px;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* --------------------------------------------------------------- input */

footer {
  background: var(--bg-hard);
  border-top: 1px solid var(--line);
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  position: relative;
}

#composer {
  display: flex;
  gap: 8px;
}

#input {
  flex: 1;
}

.send-button {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0 14px;
}

.send-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.upload {
  color: var(--muted);
  font-size: 12px;
  padding: 6px 2px 0;
}

.upload.error {
  color: var(--danger);
}

#composer.private-mode #input {
  border-color: #bb9af7;
  background: rgba(187, 154, 247, 0.06);
}

.user-row {
  border-radius: 4px;
  cursor: pointer;
  margin: 0 -4px;
  padding: 2px 4px !important;
}

.user-row:hover,
.user-row:focus-visible {
  background: rgba(122, 162, 247, 0.14);
  outline: none;
}

.user-row.active {
  background: rgba(187, 154, 247, 0.18);
}

/* Emoji picker, anchored above the composer. */
.emoji-panel {
  position: absolute;
  bottom: calc(100% - 4px);
  left: 8px;
  right: 8px;
  max-width: 360px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.emoji-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-hard);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  padding: 4px;
  scrollbar-width: none;
}

.emoji-tabs::-webkit-scrollbar {
  display: none;
}

.emoji-tab {
  background: none;
  border: 0;
  border-radius: 5px;
  font-size: 15px;
  line-height: 1;
  padding: 5px 7px;
}

.emoji-tab:hover {
  background: rgba(255, 255, 255, 0.06);
}

.emoji-tab.active {
  background: rgba(122, 162, 247, 0.2);
}

.emoji-body {
  max-height: 240px;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
}

.emoji-heading {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
  padding-bottom: 6px;
  text-transform: uppercase;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 2px;
}

.emoji-grid.wide {
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
}

.emoji-item {
  background: none;
  border: 0;
  border-radius: 5px;
  font-size: 20px;
  line-height: 1;
  padding: 5px 0;
}

.emoji-grid.wide .emoji-item {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  padding: 6px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.emoji-item:hover,
.emoji-item:focus-visible {
  background: rgba(122, 162, 247, 0.2);
  outline: none;
}

#emoji-button.active {
  border-color: var(--accent);
  color: var(--accent);
}

.drop-hint {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(122, 162, 247, 0.12);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
}

/* ------------------------------------------------------------- mobile */

@media (max-width: 640px) {
  #toggle-users {
    display: block;
  }

  .topic {
    display: none;
  }

  .tab {
    font-size: 12px;
    padding: 5px 8px;
  }

  #users {
    position: absolute;
    top: 45px;
    right: 0;
    bottom: 0;
    z-index: 20;
    border-left: 1px solid var(--line);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.5);
  }

  .send-button {
    padding: 0 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
