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

:root {
  --bg: #1a2332;
  --bg-surface: #243447;
  --bg-elevated: #2d4156;
  --text: #e8edf2;
  --text-muted: #8fa3b8;
  --accent: #4ecdc4;
  --accent-warm: #f7b731;
  --danger: #eb4d4b;
  --success: #6ab04c;
  --purple: #a29bfe;
  --radius: 12px;
}

html, body {
  height: 100%;
  height: 100dvh; /* dynamic viewport height — handles iOS address bar */
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
}

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

.header-logo {
  height: 36px;
  width: auto;
  object-fit: contain;
}

.header-left h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.caddy-badge {
  font-size: 11px;
  padding: 3px 8px;
  background: var(--accent);
  color: var(--bg);
  border-radius: 20px;
  font-weight: 600;
}

.xp-badge {
  font-size: 11px;
  padding: 3px 8px;
  background: var(--accent-warm);
  color: var(--bg);
  border-radius: 20px;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.icon-btn:hover {
  background: var(--bg-elevated);
}

/* Status bar */
#status-bar {
  display: flex;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--bg-elevated);
  font-size: 12px;
  color: var(--text-muted);
}

#streak-info {
  color: var(--accent-warm);
}

/* Conversation */
#conversation {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  padding: 12px 16px;
  border-radius: var(--radius);
  max-width: 90%;
  line-height: 1.5;
  font-size: 14px;
}

.message strong {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.message.user {
  background: var(--bg-elevated);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.message.user strong {
  color: var(--accent);
}

.message.assistant {
  background: var(--bg-surface);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border-left: 3px solid var(--accent);
}
.message.assistant strong {
  color: var(--accent);
}

.message.system {
  background: var(--bg-surface);
  align-self: center;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--bg-elevated);
  max-width: 100%;
}
.message.system strong {
  color: var(--accent);
}

.message.pattern-alert {
  border-left: 3px solid var(--accent-warm);
}
.message.pattern-alert strong {
  color: var(--accent-warm);
}

.message.judge-judy {
  border-left: 3px solid var(--purple);
}
.message.judge-judy strong {
  color: var(--purple);
}

.message.milestone {
  border-left: 3px solid var(--success);
  background: rgba(106, 176, 76, 0.1);
}
.message.milestone strong {
  color: var(--success);
}

.xp-tag {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  background: var(--accent-warm);
  color: var(--bg);
  border-radius: 10px;
  font-weight: 600;
  margin-left: 8px;
}

/* Wake word indicator */
#wake-indicator {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 100;
}
#wake-indicator.hidden { display: none; }

#wake-indicator span {
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
}

.pulse-ring {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.3;
  animation: pulse 1.5s ease-out infinite;
}

@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.5; }
  100% { transform: scale(1.8); opacity: 0; }
}

/* Controls */
#controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-surface);
  border-top: 1px solid var(--bg-elevated);
}

/* GPS indicator */
.gps-good { color: var(--success); font-size: 10px; font-weight: 600; }
.gps-rough { color: var(--accent-warm); font-size: 10px; font-weight: 600; }
.gps-off { color: var(--danger); font-size: 10px; }

#activation-mode {
  font-size: 11px;
  color: var(--text-muted);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.toggle-label input {
  accent-color: var(--accent);
}

.mic-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: var(--bg);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.mic-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

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

.mic-btn.processing {
  background: var(--accent-warm);
  border-color: var(--accent-warm);
  color: var(--bg);
  animation: none;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(78, 205, 196, 0.4); }
  50% { box-shadow: 0 0 0 15px rgba(78, 205, 196, 0); }
}

#shot-count {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 12px;
  color: var(--text-muted);
}

#hole-display {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

/* Panels */
.panel {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
}
.panel.hidden { display: none; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--bg-elevated);
}

.panel-header h2 {
  font-size: 18px;
}

.panel-header .icon-btn {
  font-size: 28px;
}

#history-content, #summary-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.round-card {
  background: var(--bg-surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
.round-card:hover {
  background: var(--bg-elevated);
}

.round-card h3 {
  font-size: 15px;
  margin-bottom: 4px;
}

.round-card .round-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.round-card .round-stats {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 12px;
}

.round-card .stat-item {
  display: flex;
  flex-direction: column;
}
.round-card .stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

/* Summary markdown */
#summary-content h2 {
  color: var(--accent);
  font-size: 16px;
  margin-top: 20px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--bg-elevated);
}

#summary-content p {
  margin-bottom: 12px;
  line-height: 1.6;
  font-size: 14px;
}

#summary-content ul, #summary-content ol {
  margin-bottom: 12px;
  padding-left: 20px;
}

#summary-content li {
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.5;
}

#summary-content strong {
  color: var(--accent);
}

/* Settings panel */
#settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.settings-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--bg-elevated);
}
.settings-section:last-child { border-bottom: none; }

.settings-section h3 {
  font-size: 14px;
  color: var(--accent);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.settings-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
}

.settings-select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--bg-elevated);
  border-radius: 8px;
  font-size: 14px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.settings-select:focus {
  outline: none;
  border-color: var(--accent);
}

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

.button-guide {
  background: var(--bg-surface);
  border-radius: var(--radius);
  padding: 12px;
}

.guide-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--bg-elevated);
}
.guide-item:last-child { border-bottom: none; }

.guide-key {
  font-weight: 600;
  color: var(--accent);
  font-size: 12px;
  padding: 3px 8px;
  background: var(--bg-elevated);
  border-radius: 6px;
}

/* Activation status indicator in controls */
#activation-status {
  font-size: 11px;
  color: var(--text-muted);
}

.status-indicator {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
  background: var(--bg-elevated);
}
.status-indicator.active {
  color: var(--accent);
}

/* Legal links in settings */
.legal-links {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}
.legal-links a {
  color: var(--text-muted);
  font-size: 13px;
  text-decoration: none;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-radius: 8px;
  transition: color 0.2s;
}
.legal-links a:hover {
  color: var(--accent);
}

/* Onboarding Tutorial */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}
.onboarding-overlay.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.onboarding-card {
  background: var(--bg-surface);
  border-radius: 16px;
  max-width: 400px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px 24px 20px;
  position: relative;
}

.onboarding-progress {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bg-elevated);
  transition: all 0.3s;
}
.progress-dot.active {
  background: var(--accent);
  width: 24px;
  border-radius: 4px;
}

.onboarding-step {
  display: none;
  text-align: center;
  animation: slideIn 0.3s ease;
}
.onboarding-step.active { display: block; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.onboarding-hero {
  max-height: 160px;
  width: auto;
  margin: 0 auto 16px;
  display: block;
  border-radius: 12px;
}
.onboarding-hero.onboarding-bag {
  max-height: 180px;
}

.onboarding-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.onboarding-step h2 {
  font-size: 20px;
  margin-bottom: 10px;
  color: var(--text);
}

.onboarding-step p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 8px;
}

.onboarding-subtitle {
  font-style: italic;
  color: var(--accent) !important;
  font-weight: 600;
  margin-top: 4px;
}

.onboarding-examples {
  text-align: left;
  margin: 16px 0;
}
.onboarding-examples .example {
  background: var(--bg-elevated);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text);
  border-left: 3px solid var(--accent);
}

.onboarding-guide {
  margin: 16px 0;
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 12px;
}
.onboarding-guide .guide-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--bg-surface);
}
.onboarding-guide .guide-row:last-child { border-bottom: none; }
.onboarding-guide .key {
  font-weight: 600;
  color: var(--accent);
  font-size: 12px;
  padding: 3px 8px;
  background: var(--bg-surface);
  border-radius: 6px;
}

.onboarding-hint {
  font-size: 12px !important;
  color: var(--text-muted) !important;
  margin-top: 8px;
}

.onboarding-features {
  text-align: left;
  margin: 16px 0;
}
.onboarding-features .feature {
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--bg-elevated);
}
.onboarding-features .feature:last-child { border-bottom: none; }
.onboarding-features .feature strong { color: var(--accent); }

.onboarding-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--bg-elevated);
}

.onboarding-btn-skip {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 10px 16px;
}

.onboarding-btn-next {
  background: var(--accent);
  color: var(--bg);
  border: none;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 28px;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.2s;
}
.onboarding-btn-next:hover { opacity: 0.9; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 4px; }
