:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #21262d;
  --kema: #7ee8a2;
  --kema-dim: #1a3d2b;
  --user: #58a6ff;
  --user-dim: #0d2848;
  --accent: #f78166;
  --text: #e6edf3;
  --muted: #8b949e;
  --radius: 16px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Kaku Gothic ProN', sans-serif;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
}

/* ===== Header ===== */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
}
.header-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
}
.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.header-nav::-webkit-scrollbar { display: none; }

.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--kema-dim);
  border: 2px solid var(--kema);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
}

.header-info h1 { font-size: 14px; font-weight: 700; color: var(--kema); }
.header-info p { font-size: 9px; color: var(--muted); }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s;
  margin-right: 4px;
}
.status-dot.online { background: var(--kema); }

.nav-btn {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; padding: 5px 8px; font-size: 11px;
  cursor: pointer; transition: all 0.2s;
}
.nav-btn:hover, .nav-btn.active {
  border-color: var(--kema); color: var(--kema);
}

/* ===== Tab panels ===== */
.tab-panel { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.tab-panel.active { display: flex; }

/* ===== Chat ===== */
#chat-messages, #talk-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.bubble-row {
  display: flex;
  gap: 8px;
  max-width: 90%;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bubble-row.kema { align-self: flex-start; }
.bubble-row.user { align-self: flex-end; flex-direction: row-reverse; }

.bubble-icon {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; margin-top: 2px; font-weight: 700;
}
.bubble-row.kema .bubble-icon {
  background: var(--kema-dim); border: 1.5px solid var(--kema); color: var(--kema);
}
.bubble-row.user .bubble-icon {
  background: var(--user-dim); border: 1.5px solid var(--user); color: var(--user);
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: 14px;
  word-break: break-word;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
}
.bubble-row.kema .bubble {
  background: var(--kema-dim);
  border: 1px solid var(--kema);
  border-top-left-radius: 4px;
}
.bubble-row.user .bubble {
  background: var(--user-dim);
  border: 1px solid var(--user);
  border-top-right-radius: 4px;
}

.bubble audio {
  display: block; margin-top: 6px; width: 100%; height: 28px;
  filter: invert(1) hue-rotate(90deg) brightness(0.8);
}

.typing .bubble {
  display: flex; align-items: center; gap: 4px; padding: 12px 16px;
}
.dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--kema);
  animation: bounce 1.2s ease infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%,80%,100% { transform: translateY(0); opacity: 0.5; }
  40%          { transform: translateY(-5px); opacity: 1; }
}

/* ===== Input Area ===== */
#input-area {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 10px;
  flex-shrink: 0;
}

.input-row {
  display: flex; gap: 6px; align-items: flex-end;
}

#text-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 10px 12px;
  resize: none;
  min-height: 38px;
  max-height: 80px;
  overflow-y: auto;
  outline: none;
  line-height: 1.4;
}
#text-input:focus { border-color: var(--kema); }
#text-input::placeholder { color: var(--muted); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0; transition: all 0.15s; font-weight: 700;
}

#send-btn { background: var(--kema); color: var(--bg); }
#send-btn:disabled { opacity: 0.4; }

.photo-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  font-size: 12px; font-weight: 700;
}
.photo-btn:hover, .photo-btn:active {
  border-color: var(--user); color: var(--user);
}

.talk-btn-row {
  display: flex; align-items: center; gap: 16px; justify-content: center;
}

/* ===== Talk Tab (Push-to-Talk) ===== */
#talk-area {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 12px 14px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#talk-status-text {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  min-height: 20px;
  transition: color 0.2s;
}
#talk-status-text.recording { color: var(--accent); font-weight: 700; }
#talk-status-text.processing { color: var(--user); }

#talk-visualizer {
  width: 160px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#audio-visualizer {
  width: 160px;
  height: 40px;
}

#talk-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#talk-btn:active, #talk-btn.recording {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  transform: scale(1.1);
  box-shadow: 0 0 30px rgba(247,129,102,0.4);
}

#talk-btn.processing {
  background: var(--user-dim);
  border-color: var(--user);
  color: var(--user);
  animation: pulse-proc 1.5s ease-in-out infinite;
}

@keyframes pulse-proc {
  0%,100% { box-shadow: 0 0 0 0 rgba(88,166,255,0.4); }
  50%      { box-shadow: 0 0 20px 5px rgba(88,166,255,0.2); }
}

#talk-btn-icon { font-size: 20px; font-weight: 700; }
#talk-btn-label { font-size: 10px; }

/* ===== Camera Tab ===== */
.camera-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  gap: 12px;
  overflow-y: auto;
}

#camera-img {
  width: 100%;
  max-width: 480px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #000;
}

.cam-btn-row { display: flex; gap: 8px; }

.cam-btn {
  background: var(--kema-dim); border: 1px solid var(--kema); color: var(--kema);
  border-radius: 10px; padding: 10px 20px; font-size: 14px;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.cam-btn:hover { background: var(--kema); color: var(--bg); }

/* ===== GPS Tab ===== */
.gps-container {
  flex: 1; padding: 16px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
}

.gps-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
}
.gps-card h3 { font-size: 13px; color: var(--kema); margin-bottom: 8px; }
.gps-card p { font-size: 14px; line-height: 1.6; color: var(--text); }
.gps-card .muted { color: var(--muted); font-size: 12px; }

#gps-toggle {
  background: var(--kema); color: var(--bg); border: none;
  border-radius: 10px; padding: 14px; font-size: 15px;
  cursor: pointer; font-family: inherit; font-weight: 700;
  width: 100%;
}
#gps-toggle.active { background: var(--accent); }

/* ===== Status Tab ===== */
.status-container {
  flex: 1; padding: 16px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}

.status-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px;
  display: flex; justify-content: space-between; align-items: center;
}
.status-item .label { font-size: 14px; }
.status-item .value { font-size: 13px; padding: 4px 10px; border-radius: 6px; }
.status-item .value.ok { background: var(--kema-dim); color: var(--kema); }
.status-item .value.ng { background: #3d1a1a; color: var(--accent); }

#bottom-anchor, #talk-bottom-anchor { height: 1px; }

/* Model badge - shows which Claude model was used */
.model-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  margin-top: 4px;
  margin-left: 2px;
  opacity: 0.65;
  background: rgba(255,255,255,0.1);
  color: inherit;
  vertical-align: middle;
  font-family: monospace;
  letter-spacing: 0.3px;
}
