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

:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #161616;
  --surface-3: #1c1c1c;
  --primary: #00bfff;
  --primary-glow: rgba(0, 191, 255, 0.15);
  --primary-border: rgba(0, 191, 255, 0.18);
  --primary-dim: rgba(0, 191, 255, 0.06);
  --text: #dddddd;
  --text-dim: #999999;
  --text-muted: #555555;
  --danger: #ff4757;
  --danger-dim: rgba(255, 71, 87, 0.08);
  --danger-border: rgba(255, 71, 87, 0.22);
  --border: rgba(255, 255, 255, 0.06);
  --topbar-h: 52px;
  --radius: 6px;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --font-ui: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14.5px;
  line-height: 1.55;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

a {
  color: inherit;
  text-decoration: none;
}

.shell {
  min-height: 100vh;
  background: var(--bg);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1;
  white-space: nowrap;
}

.brand-ry {
  color: var(--primary);
  text-shadow: 0 0 10px var(--primary-glow);
}

.brand-chat {
  color: var(--text-muted);
  font-weight: 300;
}

.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  z-index: 20;
}

.login-nav,
.app-topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 10, 0.96);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.login-nav {
  padding: 0 1.5rem;
}

.login-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.2rem 1.8rem;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
  transition: border-color 0.3s, box-shadow 0.3s;
  animation: fade-up 0.35s ease both;
}

.login-card:hover {
  border-color: var(--primary-border);
  box-shadow: 0 0 40px var(--primary-glow), 0 20px 60px rgba(0, 0, 0, 0.4);
}

.login-logo {
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: center;
  line-height: 1;
  margin-bottom: 0.35rem;
}

.logo-ry {
  color: var(--primary);
  font-size: 2.6rem;
  text-shadow: 0 0 24px rgba(0, 191, 255, 0.5), 0 0 50px rgba(0, 191, 255, 0.2);
}

.logo-chat {
  color: #444444;
  font-size: 2.6rem;
  font-weight: 300;
}

.login-sub {
  color: var(--text-muted);
  text-align: center;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  margin-bottom: 1.8rem;
}

.form-sep {
  height: 1px;
  background: var(--border);
  margin-bottom: 1.3rem;
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-label {
  display: block;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.status-line {
  min-height: 1.2rem;
  margin-top: 0.6rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.14s, border-color 0.14s, color 0.14s, box-shadow 0.14s, opacity 0.14s;
  white-space: nowrap;
  min-width: 0;
}

.btn-primary {
  background: var(--primary);
  color: #000000;
  box-shadow: 0 0 12px var(--primary-glow);
  padding: 0.55rem 0.95rem;
}

.login-card .btn-primary {
  width: 100%;
}

.btn-primary:hover:not(:disabled) {
  background: #1eccff;
  box-shadow: 0 0 20px rgba(0, 191, 255, 0.25);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 0.48rem 0.82rem;
}

.btn-ghost:hover {
  border-color: var(--primary-border);
  color: var(--text);
  background: var(--primary-dim);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger-border);
  padding: 0.48rem 0.82rem;
}

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

.btn-sm {
  min-height: 30px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: wait;
}

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-topbar {
  gap: 0.7rem;
  padding: 0 1.2rem;
  position: relative;
  z-index: 5;
}

.room-pill {
  color: var(--primary);
  border: 1px solid var(--primary-border);
  background: var(--primary-dim);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  padding: 0.14rem 0.55rem;
  text-transform: uppercase;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.74rem;
}

.user-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
  flex-shrink: 0;
}

#top-username {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.icon-button {
  min-width: 34px;
  min-height: 30px;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  transition: background 0.14s, border-color 0.14s, color 0.14s;
}

.icon-button:hover {
  color: var(--primary);
  border-color: var(--primary-border);
  background: var(--primary-dim);
}

.chat-screen {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.015), transparent 18%, transparent 82%, rgba(255, 255, 255, 0.015)),
    var(--bg);
}

.chat-panel {
  width: min(1040px, 100%);
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--bg);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.18);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
  padding: 0.95rem 1.1rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat-kicker {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.15rem;
}

.chat-header h1 {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
}

.message-count {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  white-space: nowrap;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.35rem 0 0.5rem;
  scroll-behavior: smooth;
}

.empty-state {
  height: calc(100% - 1rem);
  margin: 0.5rem 0.75rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.012);
}

.message {
  padding: 0.72rem 1.1rem 0.72rem calc(1.1rem - 2px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.035);
  border-left: 2px solid transparent;
  animation: fade-up 0.18s ease both;
}

.message:hover {
  background: rgba(255, 255, 255, 0.015);
  border-left-color: var(--primary-border);
}

.message-meta {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  margin-bottom: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.message-name {
  color: var(--primary);
  font-weight: 700;
}

.message-time {
  color: var(--text-muted);
}

.message-body {
  color: var(--text);
  font-size: 0.94rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-body.message-media {
  display: grid;
  justify-items: start;
  gap: 0.35rem;
  white-space: normal;
}

.message-gif {
  display: block;
  max-width: min(420px, 100%);
  max-height: 340px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  object-fit: contain;
}

.gif-source,
.gif-attribution {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.64rem;
}

.gif-source:hover,
.gif-attribution:hover {
  color: var(--primary);
}

.inline-code {
  padding: 0.05rem 0.32rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-3);
  color: #f0f0f0;
  font-family: var(--font-mono);
  font-size: 0.84em;
}

.code-block {
  margin: 0.45rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0d0d0d;
  overflow: hidden;
  white-space: normal;
}

.code-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.28rem 0.4rem 0.28rem 0.7rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.66rem;
}

.code-lang {
  color: var(--text-dim);
  text-transform: lowercase;
}

.code-lines {
  flex: 1;
}

.code-copy {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  padding: 0.12rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.66rem;
}

.code-copy:hover {
  border-color: var(--primary-border);
  color: var(--primary);
}

.code-block pre {
  margin: 0;
  padding: 0.65rem 0.8rem;
  overflow-x: auto;
  tab-size: 4;
}

.code-block code {
  color: #e6e6e6;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre;
  overflow-wrap: normal;
}

.message-body.is-collapsed {
  max-height: 22rem;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 75%, transparent);
  mask-image: linear-gradient(to bottom, #000 75%, transparent);
}

.message-expand {
  margin-top: 0.35rem;
  border: none;
  background: none;
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

.message-expand:hover {
  text-decoration: underline;
}

.copy-scratch {
  position: fixed;
  top: 0;
  left: -9999px;
  opacity: 0;
}

.message.failed .message-name,
.message.failed .message-body {
  color: #e3b341;
}

.composer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.75rem 0.85rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
}

.composer textarea {
  display: block;
  min-height: 38px;
  max-height: 280px;
  resize: none;
  overflow-y: hidden;
  line-height: 1.45;
  white-space: pre-wrap;
  tab-size: 4;
}

.composer textarea.is-scrolling {
  overflow-y: auto;
}

.composer-actions {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
}

.composer-tool.composer-code {
  font-family: var(--font-mono);
}

.composer-hint {
  grid-column: 1 / -1;
  margin-top: -0.35rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.64rem;
}

.composer-tool {
  min-width: 38px;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 700;
}

.media-picker {
  grid-column: 1 / -1;
  max-height: min(420px, 48vh);
  overflow-y: auto;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.38);
  padding: 0.75rem;
}

.picker-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.67rem;
}

.picker-heading strong {
  color: var(--text);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

.emoji-option {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 1.35rem;
}

.emoji-option:hover,
.emoji-option:focus-visible {
  border-color: var(--primary-border);
  background: var(--primary-dim);
}

.gif-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

.picker-status {
  min-height: 1rem;
  margin: 0.55rem 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.gif-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.55rem;
}

.gif-option {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text-dim);
  text-align: left;
  transition: border-color 0.14s, transform 0.14s;
}

.gif-option:hover,
.gif-option:focus-visible {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.gif-option img {
  display: block;
  width: 100%;
  height: 130px;
  background: var(--bg);
  object-fit: cover;
}

.gif-option span {
  display: block;
  overflow: hidden;
  padding: 0.38rem 0.48rem;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gif-attribution {
  display: inline-block;
  margin-top: 0.65rem;
}

.char-count {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  min-width: 56px;
  text-align: right;
}

.confirm-dialog {
  width: min(420px, calc(100vw - 2rem));
  border: 1px solid var(--primary-border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.25rem;
  margin: auto;
}

.confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.confirm-dialog h2 {
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 1rem;
  margin-bottom: 0.6rem;
}

.confirm-dialog p {
  color: var(--text-dim);
  font-size: 0.86rem;
  line-height: 1.55;
  margin-bottom: 1rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(340px, calc(100vw - 2rem));
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  font-size: 0.84rem;
  padding: 0.65rem 0.8rem;
  z-index: 50;
}

[hidden] {
  display: none !important;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

@media (max-width: 760px) {
  .login-nav,
  .app-topbar {
    padding: 0 0.75rem;
  }

  .room-pill,
  .message-count,
  .char-count,
  .composer-hint {
    display: none;
  }

  #top-username {
    max-width: 96px;
  }

  .top-actions {
    gap: 0.28rem;
  }

  #clear-chat {
    max-width: 112px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-panel {
    border-left: none;
    border-right: none;
  }

  .chat-header,
  .message {
    padding-left: 0.8rem;
    padding-right: 0.8rem;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    justify-content: flex-end;
  }

  .media-picker {
    max-height: 42vh;
  }

  .gif-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gif-option img {
    height: 110px;
  }
}

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