:root {
  --bg-0: #140f0d;
  --bg-1: #1c1714;
  --bg-2: #241f1c;
  --bg-3: #2e2824;
  --line: #3c342e;
  --text: #f3eadf;
  --muted: #a89880;
  --accent: #e8a54b;
  --danger: #e07060;
  --sidebar: 252px;
  --radius: 8px;
  --font: "Courier New", Courier, ui-monospace, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html, body, button, input, textarea {
  font-family: var(--font);
  letter-spacing: 0.02em;
}
body {
  background: var(--bg-0);
  color: var(--text);
  overflow: hidden;
}
body::after {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.22) 0px,
    rgba(0, 0, 0, 0.22) 1px,
    transparent 1px,
    transparent 3px
  );
}
button, input, textarea { font: inherit; color: inherit; }
.hidden,
[hidden] {
  display: none !important;
}
.view { height: 100%; }

/* ---------- auth ---------- */
#view-auth {
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-0);
}
.auth-card {
  width: min(400px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px 28px;
  text-align: center;
}
.auth-logo {
  width: 72px; height: 72px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  border-radius: 12px;
}
.auth-card h1 {
  margin: 12px 0 0;
  font-size: 1.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.auth-tag { color: var(--muted); margin: 6px 0 20px; }
.auth-form { display: grid; gap: 12px; text-align: left; }
.auth-form label {
  display: grid; gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
}
.auth-form input, .composer textarea, .gif-head input, .dialog input {
  background: var(--bg-0);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  outline: none;
}
.auth-form input:focus, .composer textarea:focus, .gif-head input:focus {
  border-color: var(--accent);
}
.auth-form button, .send-btn, .dialog menu button, #btn-invite {
  background: var(--accent);
  color: #1a1208;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}
.auth-form button:hover, .send-btn:hover { filter: brightness(1.06); }
.hint { color: var(--muted); font-size: 0.8rem; margin: 0; }
.error { color: var(--danger); min-height: 1.2em; }

/* ---------- discord-style shell ---------- */
#view-chat { display: flex; }

.sidebar {
  width: var(--sidebar);
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding-top: var(--safe-t);
}
.server-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
.server-head img, .user-bar img {
  width: 36px; height: 36px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  border-radius: 8px;
  flex-shrink: 0;
}
.server-head strong, .user-bar strong { display: block; }
.server-head span, .user-bar span { color: var(--muted); font-size: 0.75rem; }

.nav-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 12px;
}
.nav-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 4px;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.nav-label button {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 4px;
}
.nav-label button:hover { color: var(--text); }
.nav-list { display: flex; flex-direction: column; padding: 0 8px; }
.nav-list button {
  background: none;
  border: 0;
  text-align: left;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted);
}
.nav-list button:hover { background: var(--bg-3); color: var(--text); }
.nav-list button.active {
  background: var(--bg-3);
  color: var(--text);
}

.user-bar {
  display: grid;
  grid-template-columns: 36px 1fr;
  grid-template-areas:
    "avatar meta"
    "actions actions";
  gap: 8px 10px;
  align-items: center;
  padding: 8px;
  margin: 4px;
  margin-bottom: calc(4px + var(--safe-b));
  background: var(--bg-0);
  border-radius: var(--radius);
}
.user-bar img { grid-area: avatar; }
.user-meta {
  grid-area: meta;
  min-width: 0;
}
.user-meta strong, .user-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-actions {
  grid-area: actions;
  display: flex;
  gap: 6px;
}
.user-actions button {
  flex: 1;
  background: var(--bg-3);
  border: 0;
  border-radius: 6px;
  padding: 6px 4px;
  cursor: pointer;
  font-size: 0.68rem;
  text-transform: uppercase;
}
#btn-invite { background: var(--accent); color: #1a1208; font-weight: 700; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + var(--safe-t)) 16px 8px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
.topbar h2 { font-size: 1rem; margin: 0; flex: 1; }
.icon-btn {
  display: none;
  background: none; border: 0; color: var(--text);
  font-size: 1.3rem; cursor: pointer;
}
.presence { color: var(--muted); font-size: 0.8rem; }

.log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
}
.day-rule {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 0.75rem;
  margin: 16px 0 10px;
}
.day-rule::before, .day-rule::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.msg { display: flex; gap: 12px; padding: 4px 8px; border-radius: var(--radius); }
.msg:hover { background: rgba(0, 0, 0, 0.15); }
.msg.grouped { padding-top: 0; }
.msg.grouped .avatar, .msg.grouped .meta { display: none; }
.avatar {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: #5a3d1f;
  color: var(--accent);
  display: grid; place-items: center;
  font-weight: 700; flex-shrink: 0;
}
.meta { font-size: 0.8rem; margin-bottom: 2px; }
.meta .who { font-weight: 700; margin-right: 8px; }
.meta .when { color: var(--muted); }
.body { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.gif {
  display: block;
  max-width: min(360px, 100%);
  border-radius: var(--radius);
  margin-top: 6px;
}

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 16px calc(12px + var(--safe-b));
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  min-height: 44px;
  line-height: 1.4;
  background: var(--bg-3);
}
.gif-btn {
  background: var(--bg-3);
  border: 0;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-weight: 800;
  color: var(--accent);
  cursor: pointer;
}
.send-btn { min-width: 72px; }

.gif-panel {
  margin: 0 16px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  max-height: 260px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.gif-head { display: flex; gap: 8px; align-items: center; }
.gif-head input { flex: 1; }
.gif-credit { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; }
.gif-head button, #btn-close-invite {
  background: var(--bg-3);
  border: 0;
  border-radius: var(--radius);
  padding: 8px 12px;
  cursor: pointer;
}
.gif-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
  overflow-y: auto;
}
.gif-grid button {
  padding: 0; border: 0; background: #000;
  border-radius: 6px; overflow: hidden; cursor: pointer; aspect-ratio: 1.3;
}
.gif-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }

.dialog {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 12px;
  padding: 20px;
  width: min(480px, 92vw);
}
.dialog h3 { margin: 0; color: var(--accent); }
.dialog input { width: 100%; margin: 12px 0; }
.dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; }
.scrim {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 15;
}

@media (max-width: 720px) {
  .icon-btn { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; }
}
