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

:root {
  --bg:      #0d0d0f;
  --surface: #1a1a1f;
  --border:  #2a2a32;
  --accent:  #00d4ff;
  --warn:    #ff6b35;
  --text:    #e8e8ec;
  --muted:   #6b6b78;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 1.1rem;
  line-height: 1.4;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

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

#app-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent);
}

#header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#install-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}

#install-btn:active {
  background: rgba(0, 212, 255, 0.12);
}

#install-btn.hidden {
  display: none;
}

#session-timer {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 600;
}

.state-active #session-timer {
  color: var(--accent);
}

/* ── Location panel ── */
#location-panel {
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#gps-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.3s;
}

.status-dot.gps-ok       { background: #4ade80; }
.status-dot.gps-error    { background: var(--warn); }
.status-dot.gps-waiting  { background: #facc15; animation: blink 1.2s ease-in-out infinite; }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

#location-text {
  font-size: 1.15rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#speed-heading {
  font-size: 0.9rem;
  color: var(--muted);
  padding-left: 20px;
}

/* ── Lookahead panel ── */
#lookahead-panel {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

#lookahead-label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent);
  white-space: nowrap;
  text-transform: uppercase;
}

#lookahead-text {
  font-size: 1rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main action ── */
#main-action {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px 20px;
}

#start-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  width: 85vw;
  max-width: 480px;
  min-height: 130px;
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  background: var(--accent);
  color: #000;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  user-select: none;
}

#start-btn:active {
  transform: scale(0.96);
}

#start-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.state-active #start-btn {
  background: var(--warn);
  color: #fff;
}

.state-error #start-btn {
  background: var(--warn);
  color: #fff;
}

@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(0, 212, 255, 0.6); }
  60%  { box-shadow: 0 0 0 22px rgba(0, 212, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 212, 255, 0); }
}

.state-active #start-btn.ai-speaking {
  animation: pulse-ring 1.3s ease-out infinite;
}

#ai-status {
  font-size: 1rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.4em;
}

.state-active #ai-status {
  color: var(--text);
}

/* ── Transcript ── */
#transcript-panel {
  max-height: 30vh;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding: 0;
  -webkit-overflow-scrolling: touch;
}

#transcript-inner {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.transcript-line {
  font-size: 0.88rem;
  line-height: 1.45;
  padding: 6px 10px;
  border-radius: 10px;
  max-width: 90%;
}

.transcript-line.user {
  background: var(--surface);
  align-self: flex-end;
  color: var(--text);
}

.transcript-line.ai {
  background: rgba(0, 212, 255, 0.08);
  border: 1px solid rgba(0, 212, 255, 0.2);
  align-self: flex-start;
  color: var(--text);
}

.transcript-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.transcript-line.ai .transcript-label { color: var(--accent); }

/* ── Error bar ── */
#error-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--warn);
  color: #fff;
  padding: 14px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  z-index: 100;
  transition: opacity 0.3s;
}

#error-bar.hidden {
  display: none;
}

/* ── Connecting animation ── */
@keyframes connecting-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.state-connecting #start-btn,
.state-reconnecting #start-btn {
  animation: connecting-pulse 1s ease-in-out infinite;
}
