:root {
  --paper: #fdfbf3;
  --paper-edge: #f2ede0;
  --ink: #2e2a26;
  --ink-soft: #6b6459;
  --line: #d9d2c0;
  --accent: #e0563f;
  --accent-soft: #f7cdb8;
  --highlighter: #ffe89e;
  --marker-blue: #3a6ea5;
  --marker-green: #4f7942;
  --shadow: rgba(60, 50, 30, 0.18);
  --radius: 14px;
}

* { box-sizing: border-box; }

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

body {
  font-family: 'Nunito', sans-serif;
  background: var(--paper-edge);
  background-image:
    linear-gradient(var(--paper-edge) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-edge) 1px, transparent 1px);
  color: var(--ink);
  overflow: hidden;
}

.hidden { display: none !important; }

.screen {
  width: 100vw;
  height: 100vh;
}

/* ---------- Auth screen ---------- */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, #fff9ec 0%, transparent 45%),
    radial-gradient(circle at 80% 80%, #fff2e0 0%, transparent 45%),
    var(--paper-edge);
  position: relative;
}

.paper {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px var(--shadow), 0 2px 0 rgba(0,0,0,0.03);
  position: relative;
}

.auth-card {
  width: 380px;
  padding: 48px 40px 40px;
  text-align: center;
}

.spiral {
  position: absolute;
  top: 14px;
  left: 0;
  right: 0;
  height: 14px;
  background-image: radial-gradient(circle, var(--ink-soft) 2.5px, transparent 2.6px);
  background-size: 24px 14px;
  background-repeat: repeat-x;
  background-position: 20px center;
  opacity: 0.35;
}

.brand {
  font-family: 'Caveat', cursive;
  font-size: 3rem;
  font-weight: 700;
  margin: 8px 0 4px;
  color: var(--ink);
  transform: rotate(-1.5deg);
}
.brand.small { font-size: 2rem; margin: 0; }
.brand-dot { color: var(--accent); }

.tagline {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin: 0 0 28px;
  line-height: 1.4;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  background: var(--paper-edge);
  padding: 4px;
  border-radius: 999px;
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 999px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.2s ease;
}
.tab-btn.active {
  background: var(--paper);
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: left;
}

.auth-form label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-form input {
  font-family: 'Space Mono', monospace;
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: #fffefb;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease;
}
.auth-form input:focus {
  border-color: var(--accent);
}

.btn-primary {
  margin-top: 6px;
  background: var(--accent);
  color: #fff8f0;
  border: none;
  padding: 13px 18px;
  border-radius: 8px;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 0 #b7402c;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #b7402c;
}

.form-error {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  min-height: 1.2em;
  margin: 0;
}

/* ---------- Chat screen ---------- */
#chat-screen {
  display: flex;
}

.sidebar {
  width: 250px;
  background: #f5efe0;
  border-right: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 2px dashed var(--line);
}

.channel-section {
  flex: 1;
  padding: 20px 12px;
  overflow-y: auto;
}

.channel-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  padding: 0 10px;
  margin-bottom: 8px;
}

.channel-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.channel-item {
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 0.95rem;
  transition: background 0.12s ease;
}
.channel-item:hover { background: rgba(0,0,0,0.04); }
.channel-item.active {
  background: var(--highlighter);
  color: var(--ink);
}

.btn-ghost {
  border: none;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 9px 12px;
  text-align: left;
  border-radius: 8px;
  width: 100%;
}
.btn-ghost:hover { background: rgba(224, 86, 63, 0.08); }
.btn-ghost.small { font-size: 0.78rem; color: var(--ink-soft); }

.sidebar-footer {
  padding: 16px 20px 0;
  border-top: 2px dashed var(--line);
}

.me {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.me-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--marker-blue);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
}

.me-name {
  font-weight: 800;
  font-size: 0.95rem;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 34px,
    var(--line) 35px
  );
}

.chat-header {
  padding: 20px 32px;
  border-bottom: 2px solid var(--line);
  background: var(--paper);
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.chat-header h2 {
  margin: 0;
  font-family: 'Caveat', cursive;
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink);
}

.typing-indicator {
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-style: italic;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  display: flex;
  gap: 12px;
  max-width: 640px;
  animation: pop-in 0.18s ease;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
}

.msg-body { flex: 1; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-author {
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--ink);
}

.msg-time {
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.decipher-btn {
  font-family: 'Space Mono', monospace;
  font-size: 0.68rem;
  font-weight: 700;
  border: 1.5px dashed var(--marker-blue);
  background: transparent;
  color: var(--marker-blue);
  padding: 2px 8px;
  border-radius: 999px;
  cursor: pointer;
  margin-left: auto;
  transition: background 0.12s ease, color 0.12s ease;
}
.decipher-btn:hover {
  background: var(--marker-blue);
  color: #fff;
}
.decipher-btn.active {
  background: var(--highlighter);
  border-color: var(--highlighter);
  color: var(--ink);
}

.msg-content {
  font-size: 0.96rem;
  line-height: 1.45;
  color: var(--ink);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.system .msg-content {
  color: var(--ink-soft);
  font-style: italic;
  font-size: 0.85rem;
}

.message-form {
  display: flex;
  gap: 12px;
  padding: 18px 32px 24px;
  border-top: 2px solid var(--line);
  background: var(--paper);
}

.message-form input {
  flex: 1;
  font-family: 'Nunito', sans-serif;
  font-size: 0.98rem;
  padding: 13px 16px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: #fffefb;
  outline: none;
}
.message-form input:focus { border-color: var(--accent); }

.btn-send {
  background: var(--accent);
  color: #fff8f0;
  border: none;
  padding: 0 26px;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 #b7402c;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn-send:active { transform: translateY(4px); box-shadow: 0 0 0 #b7402c; }

/* Scrollbars */
.messages::-webkit-scrollbar, .channel-section::-webkit-scrollbar {
  width: 8px;
}
.messages::-webkit-scrollbar-thumb, .channel-section::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}

@media (max-width: 720px) {
  .sidebar { width: 84px; }
  .sidebar-header, .channel-label, .btn-ghost.small, .me-name { display: none; }
  .channel-item { text-align: center; font-size: 0.7rem; }
}
