/* Mycelia comms — minimal mobile-first chat */

:root {
  --bg: #161412;
  --bg-elevated: #1e1c19;
  --border: #2a2724;
  --text: #e8e4dd;
  --text-dim: #8a857c;
  --accent: #c4a878;
  --user-bubble: #2a2724;
  --assistant-bubble: transparent;
  --error: #d97757;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

.view {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* --- Login --- */
#login-view {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-box {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.login-box h1 {
  font-size: 32px;
  font-weight: 300;
  letter-spacing: 0.02em;
  color: var(--accent);
  margin-bottom: 4px;
}

.login-box .sub {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 32px;
  letter-spacing: 0.05em;
}

#login-form input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  margin-bottom: 12px;
}

#login-form input:focus {
  outline: none;
  border-color: var(--accent);
}

#login-form button {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 0.02em;
}

#login-form button:active {
  opacity: 0.8;
}

.error {
  color: var(--error);
  font-size: 13px;
  margin-top: 8px;
  min-height: 16px;
}

/* --- Chat --- */
#chat-view header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 0) 12px 0 12px;
  padding-bottom: 8px;
  padding-top: calc(env(safe-area-inset-top, 0) + 8px);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

header .title {
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.02em;
}

header button {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  border-radius: 6px;
}

header button:active {
  background: var(--bg-elevated);
}

.spend {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

main#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  -webkit-overflow-scrolling: touch;
}

.message {
  margin-bottom: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.55;
}

.message.user {
  background: var(--user-bubble);
  padding: 10px 14px;
  border-radius: 12px;
  margin-left: 32px;
  align-self: flex-end;
}

.message.assistant {
  padding: 4px 0;
  color: var(--text);
}

.message.assistant strong { color: var(--accent); font-weight: 600; }
.message.assistant code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 14px;
  font-family: 'SF Mono', 'Menlo', monospace;
}
.message.assistant pre {
  background: var(--bg-elevated);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
}

.message.pending {
  color: var(--text-dim);
  font-style: italic;
}

.message-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* --- Input area --- */
#chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0) + 12px);
  border-top: 1px solid var(--border);
  background: var(--bg);
}

#message-input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  padding: 10px 16px;
  resize: none;
  max-height: 200px;
  line-height: 1.4;
}

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

#send-btn {
  width: 40px;
  height: 40px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

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

#mic-btn {
  width: 40px;
  height: 40px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

#mic-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

#mic-btn.listening {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  animation: mic-pulse 1.2s ease-in-out infinite;
}

#mic-btn.unsupported {
  display: none;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(196, 168, 120, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(196, 168, 120, 0); }
}
