:root {
  --bg: #211b22;
  --panel: #2f2733;
  --panel-2: #3a2f3d;
  --ink: #efe7dd;
  --ink-dim: #b8aeb5;
  --amber: #f2a93b;
  --amber-dim: #c98a2c;
  --coral: #e8756b;
  --sage: #7c9082;
  --danger: #e8756b;
  --radius: 18px;
  --font-display: "Comfortaa", "Inter", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  background-image: radial-gradient(
      ellipse 60% 40% at 50% -10%,
      rgba(242, 169, 59, 0.12),
      transparent 60%
    ),
    radial-gradient(ellipse 50% 30% at 90% 100%, rgba(232, 117, 107, 0.08), transparent 60%);
  background-attachment: fixed;
}

/* Chat page: lock the document to the viewport so the header can never
   scroll out of view (iOS rubber-band / keyboard-open scroll drift). Only
   the .messages list scrolls internally. */
body.chat-page {
  position: fixed;
  inset: 0;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

a {
  color: var(--amber);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Login pages ---------- */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lamp-glow {
  position: relative;
}

.lamp-glow::before {
  content: "";
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  height: 220px;
  background: radial-gradient(circle, rgba(242, 169, 59, 0.35), transparent 70%);
  filter: blur(4px);
  pointer-events: none;
  z-index: 0;
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 40px 32px 32px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.auth-card h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-style: italic;
  font-size: 2.6rem;
  margin: 0 0 4px;
  color: var(--ink);
  letter-spacing: 0.5px;
}

.auth-card .tagline {
  margin: 0 0 28px;
  color: var(--ink-dim);
  font-size: 0.95rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form input[type="password"] {
  background: var(--bg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--ink);
  font-size: 1rem;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s ease;
}

.auth-form input[type="password"]:focus-visible {
  border-color: var(--amber);
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.auth-form button {
  background: var(--amber);
  color: #241a0a;
  border: none;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.auth-form button:hover {
  background: #ffbb52;
}

.auth-form button:active {
  transform: scale(0.98);
}

.auth-form button:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.auth-error {
  color: var(--danger);
  font-size: 0.88rem;
  margin: -4px 0 4px;
}

/* ---------- Chat page ---------- */

.chat-screen {
  height: 100vh;
  height: 100svh;
  /* When the on-screen keyboard opens, the visual viewport shrinks but
     100svh does not, so the header would stay pushed off-screen. --vv-height
     (set from JS via the visualViewport API) tracks the real visible
     height so the header + composer always stay on screen. */
  height: var(--vv-height, 100svh);
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

.avatar {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--coral), var(--amber));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  color: #241a0a;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar::after {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(242, 169, 59, 0.4), transparent 70%);
  z-index: -1;
}

.chat-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-header-text .name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
}

.chat-header-text .status {
  font-size: 0.8rem;
  color: var(--sage);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sage);
  box-shadow: 0 0 6px var(--sage);
}

.logout-link {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--ink-dim);
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px 10px;
}

.logout-link:hover {
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.2);
}

.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.45;
  font-size: 0.98rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: rise 0.22s ease;
}

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

.bubble.persona {
  align-self: flex-start;
  background: linear-gradient(160deg, rgba(232, 117, 107, 0.22), rgba(232, 117, 107, 0.1));
  border: 1px solid rgba(232, 117, 107, 0.25);
  border-bottom-left-radius: 4px;
}

.bubble.guest {
  align-self: flex-end;
  background: transparent;
  border: 1px solid rgba(239, 231, 221, 0.25);
  color: var(--ink);
  border-bottom-right-radius: 4px;
}

.typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 14px 16px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  opacity: 0.5;
  animation: pulse 1.1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: scale(0.85);
  }
  30% {
    opacity: 1;
    transform: scale(1.1);
  }
}

.composer {
  display: flex;
  gap: 10px;
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  resize: none;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.98rem;
  max-height: 140px;
  outline: none;
}

.composer textarea:focus-visible {
  border-color: var(--amber);
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.composer button {
  background: var(--amber);
  color: #241a0a;
  border: none;
  border-radius: 14px;
  width: 48px;
  flex-shrink: 0;
  cursor: pointer;
  font-size: 1.2rem;
  transition: background 0.15s ease, transform 0.1s ease;
}

.composer button:hover:not(:disabled) {
  background: #ffbb52;
}

.composer button:active:not(:disabled) {
  transform: scale(0.96);
}

.composer button:disabled {
  opacity: 0.5;
  cursor: default;
}

.composer button:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.chat-notice {
  align-self: center;
  font-size: 0.82rem;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 8px 14px;
}

/* ---------- Admin page ---------- */

.admin-screen {
  min-height: 100vh;
  padding: 32px 20px;
  display: flex;
  justify-content: center;
}

.admin-card {
  width: 100%;
  max-width: 640px;
}

.admin-card h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6rem;
  margin: 0 0 4px;
}

.admin-card .tagline {
  color: var(--ink-dim);
  margin: 0 0 24px;
  font-size: 0.9rem;
}

.admin-card h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  margin: 32px 0 4px;
}

.admin-card .phrases-textarea {
  min-height: 140px;
}

.admin-card textarea {
  width: 100%;
  min-height: 320px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 16px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}

.admin-card textarea:focus-visible {
  border-color: var(--amber);
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.admin-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}

.admin-actions button {
  background: var(--amber);
  color: #241a0a;
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-body);
}

.admin-actions button:hover {
  background: #ffbb52;
}

.admin-status {
  font-size: 0.85rem;
  color: var(--sage);
}

.admin-footer {
  margin-top: 28px;
  font-size: 0.8rem;
}

.admin-footer a {
  color: var(--ink-dim);
}
