/* ============================================
   BrianGPT — Matching briantemple.com style
   ============================================ */

/* --- Reset & Base --- */

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

:root {
  --bg: #ffffff;
  --text: #1d1d1f;
  --secondary: #6e6e73;
  --accent: #cf4f27;
  --link: #0071e3;
  --user-msg-bg: #f5f5f7;
  --border: rgba(134, 134, 139, 0.2);
  --max-width: 680px;
  --header-height: 56px;
  --input-area-height: 120px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --text: #f5f5f7;
    --secondary: #86868b;
    --link: #2997ff;
    --user-msg-bg: #1c1c1e;
    --border: rgba(134, 134, 139, 0.25);
  }
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Utility --- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Header --- */

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-height);
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
}

.header-logo {
  width: 28px;
  height: 28px;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

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

.chat {
  min-height: 100%;
  padding-top: calc(var(--header-height) + 32px);
  padding-bottom: var(--input-area-height);
}

.chat-messages {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px 32px;
}

/* --- Date Separator --- */

.date-separator {
  text-align: center;
  padding: 24px 0 20px;
}

.date-separator span {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--secondary);
}

/* --- Message Pair --- */

.message-pair {
  margin-bottom: 40px;
}

/* --- User Message (Question) --- */

.message-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-bottom: 16px;
}

.message-user .message-bubble {
  background: var(--user-msg-bg);
  border-radius: 12px;
  padding: 12px 16px;
  max-width: 85%;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
}

/* --- Assistant Message (Answer) --- */

.message-assistant {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.message-assistant .message-body {
  font-size: 16px;
  line-height: 1.6;
  color: var(--secondary);
}

.message-assistant .message-body p {
  margin-bottom: 14px;
}

.message-assistant .message-body p:last-child {
  margin-bottom: 0;
}

/* --- Markdown Content --- */

.message-body a {
  color: var(--link);
  text-decoration: none;
}

.message-body a:hover {
  text-decoration: underline;
}

.message-body strong {
  color: var(--text);
  font-weight: 600;
}

.message-body code {
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: var(--user-msg-bg);
  padding: 2px 6px;
  border-radius: 4px;
}

.message-body ul,
.message-body ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-body li {
  margin-bottom: 4px;
}

.message-body h2,
.message-body h3,
.message-body h4 {
  color: var(--text);
  text-transform: none;
  letter-spacing: normal;
  margin: 16px 0 8px;
}

.message-body h2 { font-size: 18px; }
.message-body h3 { font-size: 16px; }
.message-body h4 { font-size: 15px; }

/* --- Pending Message --- */

.message-pending .message-body {
  color: var(--secondary);
}

.thinking-dots::after {
  content: '...';
  animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* --- Input Area --- */

.input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background-color: var(--bg);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.input-area.visible {
  opacity: 1;
  pointer-events: auto;
}

.input-form {
  max-width: var(--max-width);
  margin: 0 auto;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 6px 6px 6px 16px;
  transition: border-color 0.2s ease;
}

.input-row:focus-within {
  border-color: var(--secondary);
}

.message-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  resize: none;
  max-height: 120px;
  padding: 6px 0;
}

.message-input::placeholder {
  color: var(--secondary);
}

.send-button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--user-msg-bg);
  color: var(--secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.send-button:hover {
  background: var(--accent);
  color: #ffffff;
}

.send-button:active {
  transform: scale(0.94);
}

.input-status {
  font-size: 12px;
  color: var(--secondary);
  text-align: center;
  margin-top: 8px;
  line-height: 1.4;
  min-height: 17px;
}

/* --- Intro Animation --- */

.fade-in {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.fade-in.visible {
  opacity: 1;
}

.streaming-cursor::after {
  content: '▍';
  animation: cursor-blink 0.6s steps(2) infinite;
  color: var(--secondary);
}

@keyframes cursor-blink {
  0% { opacity: 1; }
  50% { opacity: 0; }
}

/* --- Responsive --- */

@media (max-width: 600px) {
  :root {
    --max-width: 100%;
  }

  .chat-messages {
    padding: 0 16px 24px;
  }

  .message-user .message-bubble {
    max-width: 92%;
  }

  .input-area {
    padding: 10px 16px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
}

/* --- Reduced Motion --- */

@media (prefers-reduced-motion: reduce) {
  .thinking-dots::after {
    animation: none;
    content: '...';
  }

  .fade-in {
    transition: none;
  }

  .streaming-cursor::after {
    animation: none;
  }
}
