:root {
  --bg: #0a0a0a;
  --bg-2: #141414;
  --bg-3: #1c1c1c;
  --fg: #eee;
  --fg-dim: #888;
  --accent: #2a7;
  --accent-dim: #1a5;
  --user: #5cf;
  --morse: #2a7;
  --reflection: #b88;
  --error: #e64;
  --border: #222;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 800px;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 17px;
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #555;
  transition: background .2s;
}
.dot.connected { background: var(--accent); }
.dot.thinking  { background: #fa3; animation: pulse 1s infinite; }
.dot.error     { background: var(--error); }
@keyframes pulse { 50% { opacity: .4; } }

.actions { display: flex; gap: 6px; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 22px;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  text-decoration: none;  /* for <a class="icon-btn"> variants */
}
.icon-btn:hover { background: var(--bg-2); }
.icon-btn.active { background: var(--accent-dim); color: white; }
.icon-btn.recording { background: #c33; color: white; animation: pulse .8s infinite; }

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.user {
  align-self: flex-end;
  background: var(--user);
  color: #001;
  border-bottom-right-radius: 4px;
}
.msg.morse {
  align-self: flex-start;
  background: var(--bg-2);
  color: var(--fg);
  border-bottom-left-radius: 4px;
}
.msg.morse.interrupted {
  opacity: 0.55;
  font-style: italic;
}
.msg.reflection {
  align-self: center;
  background: transparent;
  color: var(--reflection);
  font-size: 13px;
  font-style: italic;
  max-width: 100%;
  text-align: center;
  padding: 6px 12px;
}
.msg.proactive {
  align-self: stretch;
  background: linear-gradient(180deg, #1d2a1d 0%, #142014 100%);
  color: #d8eecf;
  border: 1px solid #2a5;
  border-radius: 12px;
  max-width: 100%;
  padding: 12px 14px;
}
.msg.proactive .proactive-head {
  font-weight: 600;
  font-size: 14px;
  color: #aef0a0;
  margin-bottom: 6px;
}
.msg.proactive .proactive-body {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.5;
}
.msg.proactive a {
  color: #6fdc6f;
  text-decoration: underline;
  word-break: break-all;
}
.msg.error {
  align-self: center;
  background: transparent;
  color: var(--error);
  font-size: 13px;
}

/* Autonomous skill proposal — Morse decided to learn something on his
   own and is asking for the go-ahead. Card with title/why/plan/buttons. */
.msg.skill-proposal {
  background: var(--bg-2);
  border-left: 3px solid var(--accent);
  padding: 12px 14px;
  font-size: 14px;
  max-width: 100%;
}
.skill-head {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--accent);
}
.skill-why {
  font-size: 12px;
  color: var(--fg-dim);
  margin-bottom: 8px;
}
.skill-desc {
  margin-bottom: 8px;
  line-height: 1.5;
}
.skill-plan {
  margin: 6px 0 10px 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--fg-dim);
}
.skill-plan li {
  margin: 2px 0;
}
.skill-actions {
  display: flex;
  gap: 8px;
}
.skill-actions button {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 5px 14px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.skill-actions .skill-yes {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: white;
}
.skill-actions button:hover { opacity: 0.85; }

/* Earbud help offer — quiet inline suggestion when Morse overheard
   a help-eligible moment. Operator can accept (turn fires) or dismiss. */
.msg.help-offer {
  background: var(--bg-2);
  border-left: 2px solid var(--accent);
  padding: 10px 14px;
  font-size: 14px;
}
.help-offer-text {
  margin-bottom: 6px;
  color: var(--fg);
}
.help-offer-actions {
  display: flex;
  gap: 8px;
}
.help-offer-actions button {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 4px 12px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.help-offer-actions .help-offer-yes {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: white;
}
.help-offer-actions button:hover { opacity: 0.85; }

/* Thinking trail — visible cognitive trace above the morse reply.
   Collapsed by default, tap to expand. Muted styling so it doesn't
   dominate; the morse reply itself stays the visual anchor. */
.thinking-trail {
  align-self: stretch;
  margin: 4px 0;
  padding: 0;
  background: transparent;
  border-left: 2px solid var(--accent-dim);
  padding-left: 10px;
  max-width: 90%;
}
.thinking-trail summary {
  font-size: 12px;
  color: var(--fg-dim);
  cursor: pointer;
  list-style: none;
  padding: 4px 0;
  user-select: none;
}
.thinking-trail summary::-webkit-details-marker { display: none; }
.thinking-trail summary:hover { color: var(--accent); }
.thinking-trail[open] summary { color: var(--accent); }
.thinking-body {
  font-size: 13px;
  color: var(--fg);
  padding: 4px 0 8px 0;
  line-height: 1.5;
}
.thinking-note {
  margin: 2px 0;
  color: var(--fg-dim);
}
.msg .meta {
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 4px;
}
.thinking-indicator {
  align-self: flex-start;
  color: var(--fg-dim);
  font-style: italic;
  font-size: 13px;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
#input {
  flex: 1;
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 16px;
  resize: none;
  font-family: inherit;
  max-height: 120px;
  line-height: 1.4;
}
#input:focus {
  outline: none;
  border-color: var(--accent-dim);
}
.send {
  background: var(--accent);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  font-size: 22px;
  cursor: pointer;
  font-weight: bold;
}
.send:disabled { opacity: .4; cursor: default; }
