:root {
  --paper: #f5efe1;
  --paper-edge: #ece4cf;
  --ink: #1a1814;
  --ink-soft: #4a4438;
  --ink-fade: #7a7263;
  --oxblood: #6e1d1f;
  --rule: #c9bea2;
  --bureau-line: #8a7a5a;
  --bubble-them: #efe6cf;
  --bubble-you: #1a1814;
  --bubble-you-text: #f5efe1;
  --shadow: 0 1px 0 rgba(26,24,20,0.06), 0 2px 8px rgba(26,24,20,0.04);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'EB Garamond', Georgia, 'Times New Roman', serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.masthead {
  flex: 0 0 auto;
  padding: calc(0.5rem + var(--safe-top)) 1rem 0.5rem;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.masthead-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.seal {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1.5px solid var(--bureau-line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--bureau-line);
}

.masthead-text { min-width: 0; }

.masthead-line-1 {
  font-family: 'EB Garamond', serif;
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  color: var(--ink);
  line-height: 1.15;
}

.masthead-line-2 {
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 400;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-fade);
  margin-top: 0.15rem;
}

.conversation {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 0.875rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.bubble {
  max-width: 88%;
  padding: 0.625rem 0.875rem;
  border-radius: 14px;
  font-size: 1rem;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  box-shadow: var(--shadow);
}

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

.bubble.you {
  align-self: flex-end;
  background: var(--bubble-you);
  color: var(--bubble-you-text);
  border-bottom-right-radius: 4px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.95rem;
  font-weight: 400;
}

.bubble.system {
  align-self: center;
  background: transparent;
  color: var(--ink-fade);
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.78rem;
  font-style: italic;
  padding: 0.125rem 0.5rem;
  box-shadow: none;
  max-width: 100%;
  text-align: center;
}

.bubble.them.streaming::after {
  content: '\2009\258C';
  display: inline;
  color: var(--bureau-line);
  animation: blink 1s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.bubble .image-thumb {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.bubble .tool-trace {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.75rem;
  font-style: italic;
  color: var(--ink-fade);
  margin-top: 0.25rem;
}

.map-attachment {
  align-self: stretch;
  margin: 0.25rem 0.5rem;
  height: 240px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow);
  background: var(--paper-edge);
}

.map-attachment .mapboxgl-canvas { border-radius: 11px; }

.map-attachment-caption {
  align-self: stretch;
  margin: 0 0.75rem 0.25rem;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.72rem;
  color: var(--ink-fade);
  text-align: center;
}

.bct-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--oxblood);
  border: 2px solid var(--paper);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  cursor: pointer;
}

.bct-marker.you {
  background: var(--bureau-line);
  width: 12px;
  height: 12px;
}

.mapboxgl-popup-content {
  font-family: 'EB Garamond', serif;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  color: var(--ink);
}

#composer-area {
  flex: 0 0 auto;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  padding: 0.5rem 0.75rem calc(0.5rem + var(--safe-bottom));
}

.attachment-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  margin-bottom: 0.375rem;
  background: var(--bubble-them);
  border-radius: 10px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.attachment-preview.hidden { display: none; }

.attachment-preview img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
}

.attachment-preview button {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--ink-fade);
  font-size: 1.2rem;
  padding: 0 0.25rem;
  cursor: pointer;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.attach-button {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-fade);
  background: var(--paper-edge);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.attach-button:active { background: var(--rule); color: var(--ink); }

#message-input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--rule);
  border-radius: 18px;
  padding: 0.5rem 0.875rem;
  font-family: 'EB Garamond', serif;
  font-size: 1rem;
  line-height: 1.4;
  background: var(--paper);
  color: var(--ink);
  max-height: 30vh;
}

#message-input:focus {
  outline: none;
  border-color: var(--bureau-line);
}

#send-button {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--oxblood);
  color: var(--paper);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

#send-button:disabled {
  opacity: 0.45;
  cursor: default;
}

#send-button:not(:disabled):active { transform: scale(0.95); }
