:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --user-bubble: #2563eb;
  --user-text: #ffffff;
  --assistant-bubble: #f1f2f4;
  --assistant-text: #1a1a1a;
  --error-text: #b42318;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --text: #e8e9ec;
    --muted: #9aa1ac;
    --border: #2a2e37;
    --assistant-bubble: #232732;
    --assistant-text: #e8e9ec;
    --error-text: #ff8a80;
  }
}

* { box-sizing: border-box; }

/* #gate and #chat both set `display: flex` via an ID selector, which has
   higher specificity than the browser's default `[hidden] { display: none }`
   (an attribute selector) — so toggling the `hidden` property in app.js was
   flipping the attribute correctly but had no visual effect at any width.
   This restores it, explicitly, for exactly the two elements that need it. */
#gate[hidden],
#chat[hidden] {
  display: none;
}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
}

#chat {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.06);
}

@media (min-width: 560px) {
  #chat {
    height: min(720px, 90vh);
    margin: 24px;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
  }
}

#chat-header {
  padding: 16px 20px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.95rem;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  color: var(--assistant-text);
  border-bottom-left-radius: 4px;
}

.msg.typing {
  color: var(--muted);
  font-style: italic;
}

.msg.error {
  align-self: flex-start;
  background: transparent;
  color: var(--error-text);
  font-size: 0.85rem;
}

#chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

#chat-input:focus {
  border-color: var(--user-bubble);
}

#chat-send {
  padding: 10px 18px;
  border-radius: 999px;
  border: none;
  background: var(--user-bubble);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}

#chat-send:disabled {
  opacity: 0.6;
  cursor: default;
}

#gate {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.06);
}

@media (min-width: 560px) {
  #gate {
    height: min(720px, 90vh);
    margin: 24px;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
  }
}

#gate-card {
  width: 100%;
  padding: 32px;
  text-align: center;
}

#gate-card h1 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 20px;
}

#gate-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#gate-input {
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  text-align: center;
}

#gate-input:focus {
  border-color: var(--user-bubble);
}

#gate-submit {
  padding: 12px 18px;
  border-radius: 999px;
  border: none;
  background: var(--user-bubble);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}

#gate-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

#gate-error {
  margin: 14px 0 0;
  color: var(--error-text);
  font-size: 0.85rem;
}
