:root {
  --bg: #ffffff;
  --surface: #f5f5f5;
  --text: #1a1a1a;
  --text-secondary: #666666;
  --accent: #004634;
  --accent-light: #e8f5e9;
  --border: #e0e0e0;
  --guy-bg: #f0f4f0;
  --user-bg: #004634;
  --user-text: #ffffff;
  --input-bg: #ffffff;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.dark {
  --bg: #1a1a1a;
  --surface: #2a2a2a;
  --text: #e0e0e0;
  --text-secondary: #999999;
  --accent: #4CAF50;
  --accent-light: #1b3a1b;
  --border: #333333;
  --guy-bg: #2a2a2a;
  --user-bg: #2e5a3e;
  --user-text: #ffffff;
  --input-bg: #333333;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
}

header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

.tagline {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

#theme-toggle {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#theme-toggle:hover {
  background: var(--surface);
}

#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  -webkit-overflow-scrolling: touch;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease-in;
}

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

.message.guy {
  align-self: flex-start;
  background: var(--guy-bg);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

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

.message.system {
  align-self: center;
  background: var(--accent-light);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  max-width: 90%;
  border-radius: 12px;
}

.message pre {
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
}

.message code {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 13px;
}

.message strong {
  font-weight: 600;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
  background: var(--guy-bg);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

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

#input-area {
  padding: 8px 20px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#question-counter {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px 0;
  min-height: 20px;
}

#chat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#user-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 16px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  resize: none;
  max-height: 120px;
  outline: none;
  transition: border-color 0.2s;
}

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

#user-input::placeholder {
  color: var(--text-secondary);
}

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

#send-btn:hover {
  opacity: 0.85;
}

#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Paywall overlay */
.paywall-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.paywall-card {
  background: var(--bg);
  border-radius: 16px;
  padding: 32px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}

.paywall-card h2 {
  font-size: 20px;
  margin-bottom: 12px;
  color: var(--text);
}

.paywall-card p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.paywall-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 14px 28px;
  border-radius: 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  width: 100%;
}

.paywall-btn:hover {
  opacity: 0.9;
}

/* Mobile adjustments */
@media (max-width: 600px) {
  header {
    padding: 12px 16px 8px;
  }
  
  #chat-container {
    padding: 12px 16px;
  }
  
  #input-area {
    padding: 8px 16px 16px;
  }
  
  .message {
    max-width: 90%;
    font-size: 15px;
  }

  #user-input {
    font-size: 16px; /* prevents iOS zoom */
  }
}

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