@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Inter:wght@400;500;600&display=swap');

:root {
  --ink: #0a0e12;
  --panel: #10161c;
  --panel-border: rgba(77, 232, 224, 0.14);
  --grid-line: rgba(77, 232, 224, 0.06);
  --text: #e8f4f3;
  --text-muted: #7d9294;
  --cyan: #4de8e0;
  --cyan-dim: rgba(77, 232, 224, 0.35);
  --alert: #ff5c4d;
  --alert-dim: rgba(255, 92, 77, 0.35);
  --radius: 14px;
  --mono: 'Space Mono', ui-monospace, monospace;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* Blueprint grid backdrop — faint, structural, never competes with content */
body {
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 28px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) 0;
}

/* ---------- Header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--panel-border);
}

.wordmark {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.35em;
  color: var(--cyan);
}

.status-row { display: flex; align-items: center; gap: 8px; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
  transition: background 0.2s, box-shadow 0.2s;
}
.status-dot.alert { background: var(--alert); box-shadow: 0 0 10px var(--alert); }

.icon-btn {
  background: none; border: none; color: var(--text-muted);
  font-family: var(--mono); font-size: 18px; cursor: pointer; padding: 4px 8px;
}
.icon-btn:hover { color: var(--cyan); }

/* ---------- Chat ---------- */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  max-width: 82%;
  padding: 12px 14px;
  border-radius: var(--radius);
  line-height: 1.45;
  font-size: 15px;
  animation: rise 0.25s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.user {
  align-self: flex-end;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
}

.msg.kurt {
  align-self: flex-start;
  background: transparent;
  border-left: 2px solid var(--cyan-dim);
  padding-left: 14px;
  color: var(--text);
}

.msg.system {
  align-self: center;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.05em;
}

.msg.alert {
  align-self: center;
  color: var(--alert);
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.05em;
  border: 1px solid var(--alert-dim);
  border-radius: var(--radius);
  padding: 10px 16px;
}

/* ---------- Core indicator (Kurt's state) ---------- */
.core-wrap { display: flex; justify-content: center; padding: 6px 0 2px; }

.core {
  width: 46px; height: 46px; border-radius: 50%;
  position: relative;
  background: radial-gradient(circle at 40% 35%, rgba(77,232,224,0.9), rgba(77,232,224,0.05) 70%);
  box-shadow: 0 0 18px var(--cyan-dim);
  animation: idle-pulse 3.2s ease-in-out infinite;
}
.core::after {
  content: ''; position: absolute; inset: -8px; border-radius: 50%;
  border: 1px solid var(--cyan-dim);
  animation: ring 3.2s ease-in-out infinite;
}
@keyframes idle-pulse { 0%,100% { transform: scale(0.94); opacity: 0.85; } 50% { transform: scale(1.04); opacity: 1; } }
@keyframes ring { 0%,100% { transform: scale(1); opacity: 0.5; } 50% { transform: scale(1.15); opacity: 0; } }

.core.listening { animation: listen-pulse 0.9s ease-in-out infinite; box-shadow: 0 0 26px var(--cyan); }
@keyframes listen-pulse { 0%,100% { transform: scale(0.96); } 50% { transform: scale(1.12); } }

.core.speaking { animation: speak-pulse 0.55s ease-in-out infinite; }
@keyframes speak-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08) rotate(3deg); } }

.core.alert { background: radial-gradient(circle at 40% 35%, rgba(255,92,77,0.95), rgba(255,92,77,0.05) 70%); box-shadow: 0 0 24px var(--alert); animation: alert-flash 0.4s ease-in-out 3; }
@keyframes alert-flash { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); } }

/* ---------- Input bar ---------- */
#input-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--panel-border);
  background: var(--ink);
}

#text-input {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 11px 16px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  outline: none;
}
#text-input:focus { border-color: var(--cyan-dim); }

.round-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--cyan);
  font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.round-btn.mic.active { background: var(--cyan); color: var(--ink); box-shadow: 0 0 14px var(--cyan); }
.round-btn:active { transform: scale(0.95); }

/* ---------- Settings modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 10;
}
.modal-backdrop.hidden { display: none; }

.modal {
  width: 100%; max-width: 640px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  max-height: 82vh; overflow-y: auto;
}

.modal h2 {
  font-family: var(--mono); font-size: 13px; letter-spacing: 0.2em;
  color: var(--cyan); text-transform: uppercase; margin: 0 0 16px;
}

.field { margin-bottom: 18px; }
.field label {
  display: block; font-size: 12px; color: var(--text-muted);
  font-family: var(--mono); letter-spacing: 0.04em; margin-bottom: 6px;
}
.field input[type="text"], .field select {
  width: 100%; background: var(--ink); border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 10px 12px; color: var(--text); font-size: 14px;
}

.radio-row { display: flex; gap: 10px; }
.radio-row label {
  flex: 1; text-align: center; padding: 10px; border-radius: 8px;
  border: 1px solid var(--panel-border); font-size: 14px; cursor: pointer;
  font-family: var(--sans); color: var(--text-muted);
}
.radio-row input { display: none; }
.radio-row input:checked + span { color: var(--ink); }
.radio-row label:has(input:checked) { background: var(--cyan); border-color: var(--cyan); color: var(--ink); }

.btn {
  width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--cyan-dim);
  background: transparent; color: var(--cyan); font-family: var(--mono); font-size: 13px;
  letter-spacing: 0.06em; cursor: pointer;
}
.btn:active { background: var(--cyan-dim); }
.btn.close { border-color: var(--panel-border); color: var(--text-muted); margin-top: 4px; }

.hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; line-height: 1.4; }
