:root {
  --bg: #0c1117;
  --surface: #161d27;
  --surface2: #1e2a36;
  --accent: #00e676;
  --accent2: #00bcd4;
  --warn: #ffab40;
  --text: #dce4e8;
  --text2: #6b8299;
  --radius: 16px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  opacity: 0;
  animation: fadeIn .5s ease forwards;
}

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

/* ---- HEADER ---- */
.header {
  padding: 20px 24px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.rider-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}
.streak {
  font-size: 12px;
  color: var(--warn);
  font-weight: 600;
}
.level-pill {
  background: var(--surface2);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

/* ---- NEARBY INDICATOR ---- */
.nearby-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 24px;
  font-size: 13px;
  color: var(--text2);
}
.pulse-dot {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .3; transform: scale(.6); }
}
.nearby-strip .count { color: var(--accent); font-weight: 600; }

/* ---- CONTENT ---- */
.content {
  flex: 1;
  padding: 0 24px 40px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---- DAILY PROGRESS RING ---- */
.progress-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 24px;
}
.ring-wrap {
  position: relative;
  width: 140px; height: 140px;
}
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--surface2); stroke-width: 8; }
.ring-fg {
  fill: none;
  stroke: url(#ringGrad);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset .8s ease;
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-center .mins { font-size: 32px; font-weight: 800; }
.ring-center .label { font-size: 11px; color: var(--text2); margin-top: 2px; }
.progress-sub {
  display: flex;
  gap: 28px;
  margin-top: 16px;
}
.progress-sub .item { text-align: center; }
.progress-sub .num { font-size: 20px; font-weight: 700; }
.progress-sub .lbl { font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; }
.progress-sub .num.green { color: var(--accent); }
.progress-sub .num.orange { color: var(--warn); }

/* ---- BREATHING EXERCISE ---- */
.breath-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 16px;
}
.breath-title { font-size: 17px; font-weight: 700; }
.breath-sub { font-size: 12px; color: var(--text2); margin-top: 4px; }

/* Pattern selector */
.pattern-selector {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}
.pattern-btn {
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: 20px;
  padding: 6px 14px;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.pattern-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(0,230,118,.08);
}
.pattern-btn:active { transform: scale(.95); }

.breath-ring-wrap {
  position: relative;
  width: 200px; height: 200px;
  margin: 24px auto;
}
.breath-bg-circle {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0,230,118,.06) 0%, transparent 70%);
}
.breath-circle {
  width: 100%; height: 100%;
  border-radius: 50%;
  border: 3px solid var(--surface2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 4s ease-in-out, border-color .6s, box-shadow .6s;
  position: relative;
  z-index: 1;
}
.breath-circle .phase-text {
  font-size: 18px;
  font-weight: 600;
  transition: color .4s;
}
.breath-circle .phase-count {
  font-size: 40px;
  font-weight: 800;
  margin-top: 4px;
  opacity: 0;
  transition: opacity .3s;
}
.breath-circle .phase-count.visible { opacity: 1; }

.breath-circle.inhale {
  transform: scale(1.25);
  border-color: var(--accent);
  box-shadow: 0 0 40px rgba(0,230,118,.15), inset 0 0 40px rgba(0,230,118,.05);
}
.breath-circle.exhale {
  transform: scale(.75);
  border-color: var(--accent2);
  box-shadow: 0 0 40px rgba(0,188,212,.15), inset 0 0 40px rgba(0,188,212,.05);
}
.breath-circle.hold {
  transform: scale(1.25);
  border-color: var(--warn);
  box-shadow: 0 0 40px rgba(255,171,64,.12), inset 0 0 40px rgba(255,171,64,.04);
}
.breath-circle.ready {
  transform: scale(1);
  border-color: var(--surface2);
}
.breath-circle.done {
  transform: scale(1);
  border-color: var(--accent);
  box-shadow: 0 0 50px rgba(0,230,118,.2);
}

.zen-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 30px;
  padding: 14px 44px;
  color: var(--bg);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s, opacity .15s;
  margin-top: 8px;
  -webkit-tap-highlight-color: transparent;
}
.zen-btn:active { transform: scale(.95); }
.zen-btn.stop {
  background: var(--surface2);
  color: var(--text2);
}

.cycle-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}
.cycle-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--surface2);
  transition: background .3s;
}
.cycle-dot.done { background: var(--accent); }
.cycle-dot.active { background: var(--warn); }

/* ---- EXERCISE LIST ---- */
.section-title {
  font-size: 12px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 20px 0 12px;
}

.exercise {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: transform .12s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.exercise:active { transform: scale(.97); background: var(--surface2); }
.exercise .icon { font-size: 26px; width: 36px; text-align: center; flex-shrink: 0; }
.exercise .info { flex: 1; }
.exercise .name { font-weight: 600; font-size: 15px; }
.exercise .desc { font-size: 12px; color: var(--text2); margin-top: 2px; }
.exercise .xp-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(0,230,118,.1);
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

/* ---- XP TOAST ---- */
.xp-toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--accent);
  color: var(--bg);
  padding: 10px 28px;
  border-radius: 30px;
  font-weight: 700;
  font-size: 17px;
  opacity: 0;
  transition: all .4s cubic-bezier(.17,.67,.35,1.2);
  pointer-events: none;
  z-index: 100;
}
.xp-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- OVERLAY ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12,17,23,.95);
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  max-width: 430px;
  margin: 0 auto;
}
.overlay.active { display: flex; }
.overlay .close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--surface2);
  border: none;
  color: var(--text2);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.overlay .close-btn:active { transform: scale(.9); }
.overlay .step-text {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
  max-width: 280px;
}
.overlay .step-sub {
  font-size: 14px;
  color: var(--text2);
  margin-top: 12px;
  text-align: center;
}
.overlay .step-progress {
  margin-top: 30px;
  font-size: 13px;
  color: var(--text2);
}
.body-figure {
  font-size: 80px;
  margin-bottom: 24px;
  transition: opacity .5s;
}

/* Countdown timer bar */
.overlay-timer-bar {
  width: 200px;
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  margin-top: 20px;
  overflow: hidden;
}
.overlay-timer-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width linear;
  width: 100%;
}

/* ---- INSTALL BANNER ---- */
.install-banner {
  display: none;
  align-items: center;
  gap: 12px;
  margin: 0 24px 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(0,230,118,.1), rgba(0,188,212,.1));
  border: 1px solid rgba(0,230,118,.2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform .12s;
  -webkit-tap-highlight-color: transparent;
}
.install-banner.visible { display: flex; }
.install-banner:active { transform: scale(.97); }
.install-banner .install-icon { font-size: 24px; }
.install-banner .install-text { flex: 1; }
.install-banner .install-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}
.install-banner .install-sub {
  font-size: 11px;
  color: var(--text2);
  margin-top: 2px;
}
.install-banner .install-dismiss {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

/* ---- LEVEL UP CELEBRATION ---- */
.levelup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12,17,23,.9);
  z-index: 300;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 430px;
  margin: 0 auto;
}
.levelup-overlay.active { display: flex; }
.levelup-icon {
  font-size: 64px;
  animation: levelBounce .6s ease;
}
.levelup-text {
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-top: 16px;
}
.levelup-sub {
  font-size: 14px;
  color: var(--text2);
  margin-top: 8px;
}
@keyframes levelBounce {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

/* ---- GOAL REACHED ---- */
.goal-banner {
  display: none;
  text-align: center;
  padding: 12px;
  margin: -8px 0 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(0,230,118,.08), rgba(0,188,212,.08));
  border: 1px solid rgba(0,230,118,.15);
  animation: goalPulse 2s ease infinite;
}
.goal-banner.visible { display: block; }
.goal-banner .goal-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}
@keyframes goalPulse {
  0%, 100% { border-color: rgba(0,230,118,.15); }
  50% { border-color: rgba(0,230,118,.35); }
}

/* ---- XP PROGRESS BAR ---- */
.xp-bar-wrap {
  width: 100%;
  height: 3px;
  background: var(--surface2);
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}
.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width .6s ease;
}

/* ---- OVERLAY FADE TRANSITIONS ---- */
.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: opacity .3s ease;
}
.overlay-content.fading { opacity: 0; }

/* ---- PARTICLES ---- */
.particle {
  position: fixed;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 350;
  animation: particleFly 1s ease-out forwards;
}
@keyframes particleFly {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}

/* ---- TOUCH FEEDBACK ---- */
.exercise, .zen-btn, .pattern-btn, .overlay .close-btn {
  -webkit-tap-highlight-color: transparent;
}

/* ---- CONNECTION CHAT PANEL ---- */
.connection-panel {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: none;
  flex-direction: column;
  max-width: 430px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.connection-panel.active { display: flex; }

.connection-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--surface2);
  position: relative;
}
.connection-header .close-btn {
  position: absolute;
  top: 12px;
  right: 16px;
  background: var(--surface2);
  border: none;
  color: var(--text2);
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}
.connection-header-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.connection-header-info .pulse-dot { width: 8px; height: 8px; }
.connection-location {
  font-size: 12px;
  color: var(--text2);
  margin-top: 4px;
  padding-left: 16px;
}

/* Chat messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: msgSlide .3s ease;
}
.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-msg .avatar {
  font-size: 20px;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
  align-self: flex-end;
}
.chat-msg .msg-body { display: flex; flex-direction: column; gap: 2px; }
.chat-msg .name {
  font-size: 10px;
  color: var(--text2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.chat-msg.user .name { text-align: right; }
.chat-msg .bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
}
.chat-msg.rider .bubble {
  background: var(--surface);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-msg.user .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: var(--bg);
  border-bottom-right-radius: 4px;
}
.chat-msg .time {
  font-size: 10px;
  color: var(--text2);
  margin-top: 2px;
}
.chat-msg.user .time { text-align: right; }

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

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 4px;
  font-size: 12px;
  color: var(--text2);
  animation: msgSlide .3s ease;
}
.typing-dots {
  display: flex;
  gap: 3px;
}
.typing-dots span {
  width: 5px; height: 5px;
  background: var(--text2);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* System messages */
.system-msg {
  text-align: center;
  font-size: 12px;
  color: var(--text2);
  padding: 8px 0;
  animation: msgSlide .3s ease;
}

/* Quick replies */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  min-height: 0;
}
.quick-reply-btn {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 20px;
  padding: 8px 16px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.quick-reply-btn:active {
  transform: scale(.95);
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* Chat input */
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 16px 12px;
  border-top: 1px solid var(--surface2);
}
.chat-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 24px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.chat-input::placeholder { color: var(--text2); }
.chat-input:focus { border-color: var(--accent); }
.chat-send-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 50%;
  width: 40px; height: 40px;
  color: var(--bg);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .12s;
}
.chat-send-btn:active { transform: scale(.9); }
