:root {
  color-scheme: dark;
  --bg: #090a0f;
  --panel: rgba(19, 20, 27, 0.92);
  --panel-strong: rgba(24, 25, 34, 0.98);
  --surface: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f3f0e8;
  --muted: #a9a39a;
  --accent: #4f8cff;
  --accent-hover: #78a8ff;
  --accent-soft: #9cc6ff;
  --danger: #ef7777;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font-ui: "Avenir Next", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-title: Georgia, "Times New Roman", "Songti SC", serif;
}

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

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

body {
  font-family: var(--font-ui);
  background:
    linear-gradient(120deg, rgba(79, 140, 255, 0.16), transparent 32%),
    linear-gradient(240deg, rgba(156, 198, 255, 0.12), transparent 34%),
    linear-gradient(180deg, #10131a 0%, #090a0f 52%, #0c111a 100%);
  color: var(--text);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 100% 12px;
  mask-image: linear-gradient(to bottom, black, transparent 82%);
  pointer-events: none;
}

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

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

button,
input,
textarea {
  font: inherit;
}

.hidden {
  display: none !important;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 34px;
}

.app-page .shell {
  width: 100%;
  min-height: 100vh;
  padding: 0;
}

.shell--center {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.panel,
.gate-panel,
.chat-layout {
  background: linear-gradient(180deg, rgba(19, 24, 42, 0.95), rgba(11, 14, 26, 0.88));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.gate-panel,
.admin-login {
  width: min(420px, 100%);
  padding: 28px;
}

.eyebrow {
  margin: 0 0 12px;
  font-size: 0.83rem;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--accent);
}

h1,
h2 {
  margin: 0;
  font-family: var(--font-title);
  letter-spacing: 0;
}

h1 {
  font-size: 2.15rem;
  line-height: 1.12;
}

h2 {
  font-size: 1.3rem;
}

.lead {
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.75;
}

.stack-form {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

.field {
  display: grid;
  gap: 10px;
}

.field span {
  color: var(--muted);
  font-size: 0.95rem;
}

input,
textarea {
  width: 100%;
  padding: 13px 14px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease;
}

input::placeholder,
textarea::placeholder {
  color: rgba(167, 172, 209, 0.74);
}

input:focus,
textarea:focus {
  border-color: rgba(79, 140, 255, 0.72);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.16);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease,
    background 180ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
}

.button--primary {
  color: #ffffff;
  font-weight: 700;
  background: var(--accent);
  box-shadow: 0 14px 28px rgba(79, 140, 255, 0.22);
}

.button--primary:hover {
  background: var(--accent-hover);
}

.button--icon {
  width: 48px;
  min-width: 48px;
  padding: 0;
  font-size: 1.2rem;
}

.button--ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
}

.button--danger {
  color: #fff5f7;
  background: linear-gradient(135deg, #ff5b72, #ff94a3);
  box-shadow: 0 16px 34px rgba(255, 91, 114, 0.28);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: #ffafbc;
}

.inline-meta {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
  color: var(--muted);
  font-size: 0.95rem;
}

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

.chat-layout {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-width: 0;
  border-radius: 0;
  overflow: hidden;
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.user-pill {
  max-width: 180px;
  padding: 11px 13px;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.045);
}

.status-badge {
  min-width: 68px;
  padding: 10px 12px;
  color: var(--muted);
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.045);
}

.status-badge[data-state="connected"] {
  color: #b9d2ff;
  border-color: rgba(79, 140, 255, 0.35);
  background: rgba(79, 140, 255, 0.12);
}

.status-badge[data-state="disconnected"] {
  color: #ffb4b4;
  border-color: rgba(239, 119, 119, 0.32);
  background: rgba(239, 119, 119, 0.12);
}

.chat-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 20px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
}

.message-list,
.admin-message-list {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.message-list {
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.message-card,
.admin-message-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.015)),
    var(--panel-strong);
  padding: 14px 16px;
}

.message-meta,
.admin-message-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.message-author {
  font-weight: 700;
  color: var(--accent);
}

.message-time {
  color: var(--muted);
  font-size: 0.92rem;
}

.message-text {
  margin: 12px 0 0;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.empty-state {
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
}

.composer {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.field--composer span {
  margin-bottom: 2px;
}

.composer-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-top: 14px;
}

.admin-dashboard {
  display: grid;
  gap: 20px;
}

.admin-header,
.admin-log {
  padding: 22px;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.stat-card {
  padding: 22px;
}

.stat-card strong {
  display: block;
  margin-top: 12px;
  font-size: 1.6rem;
}

.admin-message-card {
  display: grid;
  gap: 12px;
}

.admin-message-text {
  white-space: pre-wrap;
  line-height: 1.65;
  word-break: break-word;
}

.admin-message-actions {
  display: flex;
  justify-content: flex-end;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 0.88rem;
}

.rise-in {
  animation: rise-in 560ms ease both;
}

.rise-in--delay {
  animation-delay: 120ms;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 920px) {
  .chat-topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    padding: 18px 0 28px;
  }

  .gate-panel,
  .admin-login,
  .chat-panel,
  .admin-header,
  .admin-log,
  .stat-card {
    padding: 20px;
  }

  .inline-meta,
  .chat-header,
  .composer-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-layout {
    min-height: 100vh;
  }

  .chat-topbar {
    padding: 18px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .user-pill {
    max-width: 100%;
    flex: 1 1 140px;
  }

  .admin-stats {
    grid-template-columns: 1fr;
  }
}
