:root {
  --bg: #313338;
  --bg-elevated: #2b2d31;
  --surface: #2b2d31;
  --surface2: #383a40;
  --line: #3f4147;
  --line-soft: #3f4147;
  --text: #f2f3f5;
  --muted: #949ba4;
  --accent: #5865f2;
  --accent-2: #7289da;
  --accent-dim: rgba(88, 101, 242, 0.15);
  --danger: #da373c;
  --warn: #f0b232;
  --ok: #23a559;
  --radius: 8px;
  --radius-sm: 4px;
  --font: "gg sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  --header-h: 48px;
  --sidebar-w: 240px;
  --shadow: 0 8px 16px rgba(0,0,0,0.24);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.65; transform: scale(0.9); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: none; }
}
@keyframes barFill {
  from { width: 0; }
}

.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: rgba(18, 21, 26, 0.92);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  animation: pulseDot 2.2s var(--ease) infinite;
}

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

.chip {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 5px 9px;
  border-radius: 999px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 0.18s var(--ease), border-color 0.18s, background 0.18s, transform 0.12s;
  text-decoration: none;
}
.icon-btn:hover {
  color: var(--text);
  border-color: #3a4458;
  background: var(--surface2);
  text-decoration: none;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 18px; height: 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.12s, opacity 0.15s, box-shadow 0.2s;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #2bbfaf);
  color: #04110f;
  box-shadow: 0 4px 16px rgba(61, 214, 198, 0.2);
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: #3a4458;
  text-decoration: none;
}

.btn-danger { background: var(--danger); color: #fff; }

.input, .textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.input:focus, .textarea:focus {
  border-color: rgba(61, 214, 198, 0.45);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.input::placeholder, .textarea::placeholder { color: #5c6578; }

.label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 7px;
  letter-spacing: 0.03em;
}
.field { margin-bottom: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px;
  animation: fadeUp 0.35s var(--ease);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(18px);
  background: var(--danger);
  color: #fff;
  font-size: 13px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  z-index: 300;
  max-width: 90%;
  text-align: center;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.ok { background: var(--ok); color: #04140c; }

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 10, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  animation: fadeIn 0.2s ease;
  backdrop-filter: blur(6px);
}
.modal-bg.open { display: flex; }

.modal {
  width: min(420px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  animation: scaleIn 0.28s var(--ease);
  box-shadow: var(--shadow);
}
.modal h2 { font-size: 18px; margin-bottom: 6px; }
.modal .lead { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

.pwd-wrap { position: relative; }
.pwd-wrap .input { padding-right: 44px; }
.pwd-eye {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  border-radius: 4px;
}
.pwd-eye:hover { color: var(--text); background: var(--surface2); }
.pwd-eye svg { width: 18px; height: 18px; }

.strength {
  margin-top: 8px;
}
.strength-bar {
  height: 5px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}
.strength-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  transition: width 0.35s var(--ease), background 0.35s;
}
.strength-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}
.page h1 { font-size: 22px; margin-bottom: 6px; }
.page .sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 22px 0 10px;
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.auth-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
}
.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 28px 24px;
  animation: fadeUp 0.4s var(--ease);
  box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 20px; margin-bottom: 6px; }
.auth-card .lead { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.auth-card .foot {
  margin-top: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.progress {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
}
.progress span {
  flex: 1;
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.progress span.on {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-top {
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
}
.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  animation: fadeUp 0.3s var(--ease);
}
.conv-item:hover { background: var(--surface); }
.conv-item.active {
  background: var(--surface2);
  border-color: var(--line);
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2a3a4a, #1a2a3a);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}
.conv-meta { min-width: 0; flex: 1; }
.conv-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}
.chat-head {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(18, 21, 26, 0.6);
}
.chat-head h2 { font-size: 15px; }
.chat-head .sub { font-size: 12px; color: var(--muted); }

#feed {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#feed::-webkit-scrollbar { width: 6px; }
#feed::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

.bubble {
  max-width: min(520px, 85%);
  padding: 10px 13px;
  border-radius: 12px;
  border: 1px solid var(--line-soft);
  background: var(--surface);
  animation: fadeUp 0.25s var(--ease);
  word-break: break-word;
}
.bubble.own {
  align-self: flex-end;
  background: linear-gradient(160deg, #14352f, #0f2a26);
  border-color: #1f4a42;
}
.bubble.other { align-self: flex-start; }
.bubble-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  text-align: right;
}
.bubble-body { font-size: 14px; line-height: 1.5; white-space: pre-wrap; }

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 40px 16px;
  animation: fadeIn 0.4s ease;
}

.composer {
  border-top: 1px solid var(--line-soft);
  background: var(--bg-elevated);
  padding: 12px 14px 14px;
  position: relative;
}
.composer-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  position: relative;
}
#msg {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 48px 12px 14px;
  resize: none;
}
#emoji-toggle {
  display: none;
  position: absolute;
  right: 56px;
  bottom: 6px;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  border-radius: 6px;
}
#emoji-toggle:hover { color: var(--text); background: var(--surface2); }
@media (hover: hover) and (pointer: fine) {
  #emoji-toggle { display: block; }
  #msg { padding-right: 88px; }
}
#go {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #2bbfaf);
  color: #04110f;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: transform 0.12s, filter 0.15s;
}
#go:hover:not(:disabled) { filter: brightness(1.06); }
#go:active:not(:disabled) { transform: scale(0.95); }
#go:disabled { opacity: 0.4; }
#go svg { width: 18px; height: 18px; }

#panel {
  display: none;
  position: absolute;
  bottom: 68px;
  right: 12px;
  width: min(380px, calc(100vw - 24px));
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 12px;
  z-index: 30;
  box-shadow: var(--shadow);
  overflow: hidden;
}
#panel.open { display: block; animation: scaleIn 0.2s var(--ease); }
.panel-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
}
.panel-tabs button {
  flex: 1 1 12%;
  min-width: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 9px 4px;
  font-size: 15px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.panel-tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.panel-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 2px;
  padding: 10px;
  max-height: 240px;
  overflow-y: auto;
}
.panel-grid span {
  display: grid;
  place-items: center;
  height: 34px;
  font-size: 18px;
  cursor: pointer;
  border-radius: 6px;
  user-select: none;
  transition: background 0.12s, transform 0.1s;
}
.panel-grid span:hover {
  background: var(--surface2);
  transform: scale(1.12);
}

.lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 3px 8px;
  border-radius: 999px;
}

@media (max-width: 800px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar {
    position: absolute;
    inset: var(--header-h) 0 0 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.28s var(--ease);
  }
  .sidebar.open { transform: none; }
}

[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface2: #eef0f4;
  --line: #d8dce6;
  --line-soft: #e4e7ee;
  --text: #1a1d24;
  --muted: #6b7285;
  --accent: #0d9f90;
  --accent-2: #4b6fff;
  --accent-dim: rgba(13, 159, 144, 0.12);
  --own: #d9f5f1;
  --danger: #e11d48;
  --ok: #059669;
  --shadow: 0 16px 40px rgba(20, 24, 40, 0.12);
}

[data-theme="dim"] {
  --bg: #1a1d22;
  --bg-elevated: #22262e;
  --surface: #282d37;
  --surface2: #323844;
  --line: #3d4452;
  --line-soft: #343a46;
  --text: #e6e8ee;
  --muted: #9aa3b5;
  --accent: #45c4b6;
  --accent-2: #7b93ff;
  --accent-dim: rgba(69, 196, 182, 0.14);
  --own: #1c3d37;
  --danger: #ff6b81;
  --ok: #4ade80;
  --shadow: 0 16px 40px rgba(0,0,0,0.35);
}

.code-inputs {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 16px 0 8px;
}
.code-inputs input {
  width: 42px;
  height: 48px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  font-family: var(--mono);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  outline: none;
}
.code-inputs input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.profile-preview {
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
  background: var(--surface);
}
.profile-banner {
  height: 100px;
  background: linear-gradient(135deg, #1a2a3a, #0d1a22);
  background-size: cover;
  background-position: center;
  position: relative;
}
.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid var(--surface);
  background: var(--surface2);
  background-size: cover;
  background-position: center;
  position: absolute;
  left: 16px;
  bottom: -28px;
  object-fit: cover;
}
.profile-body {
  padding: 36px 16px 16px;
}
.profile-body h3 { font-size: 16px; margin-bottom: 2px; }
.profile-body .uname { color: var(--muted); font-size: 13px; }
.profile-body .pr { color: var(--muted); font-size: 12px; margin-top: 4px; }
.profile-body .bio { font-size: 13px; margin-top: 10px; line-height: 1.45; color: var(--text); }

.theme-picks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.theme-pick {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  transition: border-color 0.15s, color 0.15s;
}
.theme-pick.active {
  border-color: var(--accent);
  color: var(--accent);
}
.theme-pick span {
  display: block;
  height: 18px;
  border-radius: 4px;
  margin-bottom: 8px;
}
