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

:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --text: #2c2c2c;
  --text-soft: #6b6b6b;
  --accent: #4a7c59;
  --accent-light: #e8f0ea;
  --border: #e5e5e3;
  --input-bg: #ffffff;
  --bubble-user: #f0f0ee;
  --bubble-ai: #ffffff;
  --radius: 20px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

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

/* ---- Gate ---- */

.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.gate-card h1 {
  font-size: 48px;
  margin-bottom: 32px;
  line-height: 1;
}

.gate-input {
  width: 100%;
  padding: 14px 18px;
  font-size: 17px;
  font-family: var(--font);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--text);
  text-align: center;
  letter-spacing: 0.15em;
  outline: none;
  transition: border-color 0.2s;
}

.gate-input:focus {
  border-color: var(--accent);
}

.gate-input::placeholder {
  letter-spacing: normal;
  color: var(--text-soft);
  opacity: 0.6;
}

.gate-error {
  margin-top: 12px;
  font-size: 14px;
  color: #b54;
  min-height: 20px;
}

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

.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-header-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.chat-header-status {
  font-size: 12px;
  color: var(--text-soft);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 15px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message-user {
  align-self: flex-end;
  background: var(--bubble-user);
  border-bottom-right-radius: 6px;
}

.message-ai {
  align-self: flex-start;
  background: var(--bubble-ai);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.message-ai p { margin-bottom: 0.6em; }
.message-ai p:last-child { margin-bottom: 0; }
.message-ai code {
  background: var(--accent-light);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 13px;
}
.message-ai pre {
  background: #f4f4f2;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.5;
}
.message-ai pre code {
  background: none;
  padding: 0;
}
.message-ai ul, .message-ai ol {
  margin: 4px 0 8px 20px;
}
.message-ai h1, .message-ai h2, .message-ai h3 {
  margin: 12px 0 4px;
  font-size: 15px;
  font-weight: 600;
}

.message-status {
  align-self: flex-start;
  font-size: 13px;
  color: var(--text-soft);
  font-style: italic;
  padding: 4px 0;
}

/* Typing indicator */
.typing {
  display: inline-flex;
  gap: 4px;
  padding: 8px 16px;
  align-self: flex-start;
}

.typing span {
  width: 6px;
  height: 6px;
  background: var(--text-soft);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

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

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.input-area {
  padding: 12px 20px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-row textarea {
  flex: 1;
  padding: 12px 16px;
  font-size: 16px;
  font-family: var(--font);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  background: var(--input-bg);
  color: var(--text);
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.2s;
}

.input-row textarea:focus {
  border-color: var(--accent);
}

.input-row textarea::placeholder {
  color: var(--text-soft);
  opacity: 0.5;
}

.send-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

/* Hidden */
.hidden { display: none !important; }

/* Mobile */
@media (max-width: 720px) {
  .chat { max-width: 100%; }
  .messages { padding: 12px; }
  .input-area { padding: 8px 12px 16px; }
  .message { max-width: 90%; }
}

/* Safe area for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .input-area {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}
