*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --soil-900: #1a1a17;
  --soil-800: #2a2a24;
  --soil-700: #3d3d33;
  --soil-600: #525245;
  --soil-500: #6b6b5e;
  --soil-400: #8a8a7a;
  --soil-300: #a8a896;
  --soil-200: #c8c8b8;
  --soil-100: #e4e4d8;
  --soil-50:  #f4f4ec;
  --wheat:    #d4a843;
  --wheat-dim:#b8922e;
  --corn:     #5a8c3c;
  --corn-dim: #4a7430;
  --alert:    #c45d3e;
  --alert-dim:#a84e34;
  --l1-bg: #3e2a1a;
  --l1-border: #c45d3e;
  --l1-text: #f0c8a8;
  --l2-bg: #1a2a1e;
  --l2-border: #5a8c3c;
  --l2-text: #b8d8a8;
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--soil-100);
  background: var(--soil-900);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100%; max-width: 680px; margin: 0 auto; }

#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 12px) 16px 12px;
  border-bottom: 1px solid var(--soil-800); background: var(--soil-900); flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.logo-mark { width: 32px; height: 32px; border-radius: 6px; background: linear-gradient(135deg, var(--wheat) 0%, var(--corn) 100%); flex-shrink: 0; }
.header-text h1 { font-family: var(--font-display); font-size: 20px; font-weight: 400; color: var(--soil-50); letter-spacing: 0.01em; line-height: 1.1; }
.tagline { font-size: 11px; color: var(--soil-400); letter-spacing: 0.03em; text-transform: uppercase; }
#info-btn { background: none; border: none; color: var(--soil-400); cursor: pointer; padding: 8px; border-radius: var(--radius); transition: color 0.15s; }
#info-btn:hover { color: var(--soil-200); }

#chat-area { flex: 1; overflow-y: auto; padding: 16px; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }
#chat-area::-webkit-scrollbar { width: 4px; }
#chat-area::-webkit-scrollbar-track { background: transparent; }
#chat-area::-webkit-scrollbar-thumb { background: var(--soil-700); border-radius: 4px; }

#welcome { display: none; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px 16px 20px; min-height: 60vh; animation: fadeIn 0.4s ease; }
#welcome.welcome-visible { display: flex; }
.welcome-icon { color: var(--wheat); margin-bottom: 20px; opacity: 0.7; }
#welcome h2 { font-family: var(--font-display); font-size: 24px; font-weight: 400; color: var(--soil-100); margin-bottom: 8px; }
#welcome p { color: var(--soil-400); font-size: 14px; max-width: 360px; margin-bottom: 28px; }

.quick-prompts { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 360px; }
.quick-prompt { background: var(--soil-800); border: 1px solid var(--soil-700); border-radius: var(--radius); color: var(--soil-200); font-family: var(--font-body); font-size: 13px; padding: 10px 14px; cursor: pointer; text-align: left; transition: all 0.15s; }
.quick-prompt:hover { background: var(--soil-700); border-color: var(--soil-600); color: var(--soil-50); }

#messages { display: flex; flex-direction: column; gap: 16px; }
.msg { animation: slideUp 0.25s ease; }
.msg-user { align-self: flex-end; background: var(--soil-700); border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg); padding: 10px 14px; max-width: 85%; font-size: 14px; color: var(--soil-100); }
.msg-ai { align-self: flex-start; max-width: 100%; width: 100%; }

.layer-1-block { background: var(--l1-bg); border-left: 3px solid var(--l1-border); border-radius: 2px var(--radius) var(--radius) 2px; padding: 12px 14px; margin-bottom: 12px; position: relative; }
.layer-1-block::before { content: 'EXPERT VALIDATION'; display: block; font-family: var(--font-mono); font-size: 10px; font-weight: 500; color: var(--l1-border); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 6px; }
.layer-1-block p { color: var(--l1-text); font-size: 14px; line-height: 1.5; }
.layer-1-block .confidence { display: inline-block; font-family: var(--font-mono); font-size: 11px; color: var(--l1-border); margin-top: 6px; }

.layer-2-block { background: var(--l2-bg); border-left: 3px solid var(--l2-border); border-radius: 2px var(--radius) var(--radius) 2px; padding: 12px 14px; margin-bottom: 12px; position: relative; }
.layer-2-block::before { content: 'DECISION SPACE'; display: block; font-family: var(--font-mono); font-size: 10px; font-weight: 500; color: var(--l2-border); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 6px; }
.layer-2-block p, .layer-2-block li { color: var(--l2-text); font-size: 14px; line-height: 1.5; }

.ai-text { color: var(--soil-200); font-size: 14px; line-height: 1.6; padding: 0 2px; }
.ai-text p { margin-bottom: 10px; }
.ai-text p:last-child { margin-bottom: 0; }
.ai-text strong { color: var(--soil-50); font-weight: 600; }
.ai-text ul, .ai-text ol { padding-left: 18px; margin-bottom: 10px; }
.ai-text li { margin-bottom: 4px; }
.ai-text code { font-family: var(--font-mono); font-size: 13px; background: var(--soil-800); padding: 1px 5px; border-radius: 3px; }

.speak-btn { position: absolute; top: 10px; right: 10px; background: none; border: none; color: var(--l1-border); cursor: pointer; padding: 4px; opacity: 0.6; transition: opacity 0.15s; }
.speak-btn:hover { opacity: 1; }
.speak-btn.speaking { opacity: 1; animation: pulse 1s infinite; }

.msg-loading { align-self: flex-start; padding: 12px 0; }
.loading-dots { display: flex; gap: 4px; }
.loading-dots span { width: 6px; height: 6px; background: var(--soil-500); border-radius: 50%; animation: dotPulse 1.2s infinite; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

#input-area { flex-shrink: 0; padding: 8px 16px calc(var(--sab) + 8px); border-top: 1px solid var(--soil-800); background: var(--soil-900); }
#voice-indicator { display: flex; align-items: center; gap: 8px; padding: 6px 0 10px; font-size: 13px; color: var(--wheat); }
#voice-indicator.hidden { display: none; }
.pulse-ring { width: 10px; height: 10px; background: var(--wheat); border-radius: 50%; animation: pulse 1.2s infinite; }

.input-row { display: flex; align-items: flex-end; gap: 8px; background: var(--soil-800); border: 1px solid var(--soil-700); border-radius: var(--radius-lg); padding: 6px 6px 6px 4px; transition: border-color 0.15s; }
.input-row:focus-within { border-color: var(--soil-500); }

#mic-btn, #send-btn { flex-shrink: 0; width: 38px; height: 38px; border-radius: var(--radius); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s; }
#mic-btn { background: transparent; color: var(--soil-400); }
#mic-btn:hover { color: var(--soil-200); background: var(--soil-700); }
#mic-btn.recording { color: var(--wheat); background: rgba(212, 168, 67, 0.15); }
#send-btn { background: var(--wheat); color: var(--soil-900); }
#send-btn:disabled { background: var(--soil-700); color: var(--soil-600); cursor: default; }
#send-btn:not(:disabled):hover { background: var(--wheat-dim); }

#query-input { flex: 1; background: none; border: none; color: var(--soil-100); font-family: var(--font-body); font-size: 15px; line-height: 1.4; padding: 8px 4px; resize: none; max-height: 120px; outline: none; }
#query-input::placeholder { color: var(--soil-500); }

.input-meta { display: flex; justify-content: space-between; padding: 4px 4px 0; font-size: 11px; color: var(--soil-600); }
#char-count { font-family: var(--font-mono); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-end; justify-content: center; z-index: 100; animation: fadeIn 0.2s ease; }
.modal.hidden { display: none; }
.modal-content { background: var(--soil-800); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 24px 20px calc(var(--sab) + 24px); max-width: 680px; width: 100%; max-height: 70vh; overflow-y: auto; position: relative; }
.modal-content h2 { font-family: var(--font-display); font-size: 20px; font-weight: 400; color: var(--soil-50); margin-bottom: 12px; }
.modal-content h3 { font-size: 13px; font-weight: 600; color: var(--soil-300); text-transform: uppercase; letter-spacing: 0.05em; margin: 16px 0 6px; }
.modal-content p { color: var(--soil-300); font-size: 14px; margin-bottom: 8px; line-height: 1.5; }
.modal-disclaimer { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--soil-700); font-size: 12px; color: var(--soil-500); }
.layer-badge { display: inline-block; font-family: var(--font-mono); font-size: 9px; font-weight: 500; padding: 2px 6px; border-radius: 3px; letter-spacing: 0.05em; vertical-align: middle; }
.layer-badge.l1 { background: var(--l1-bg); color: var(--l1-border); border: 1px solid var(--l1-border); }
.layer-badge.l2 { background: var(--l2-bg); color: var(--l2-border); border: 1px solid var(--l2-border); }
#close-modal { position: absolute; top: 16px; right: 16px; background: none; border: none; color: var(--soil-400); font-size: 18px; cursor: pointer; padding: 4px 8px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes dotPulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }

@media (min-width: 680px) {
  #app { border-left: 1px solid var(--soil-800); border-right: 1px solid var(--soil-800); }
  .modal-content { border-radius: var(--radius-lg); margin-bottom: 40px; }
  .modal { align-items: center; }
}