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

:root {
  --font-sans: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Scientific color psychology themes */
  /* 1. Venting / High Arousal (Red-Orange) */
  --color-vent-bg: #0e0503;
  --color-vent-bg-alt: #1a0a06;
  --color-vent-primary: #ff4d24;
  --color-vent-secondary: #ff843d;
  --color-vent-glow: rgba(255, 77, 36, 0.35);
  
  /* 2. Transition / Medium Arousal (Indigo-Violet) */
  --color-trans-bg: #060512;
  --color-trans-bg-alt: #0c0b24;
  --color-trans-primary: #7952eb;
  --color-trans-secondary: #a37df8;
  --color-trans-glow: rgba(121, 82, 235, 0.35);
  
  /* 3. Calming / Low Arousal (Teal-Emerald Green) */
  --color-calm-bg: #020b0b;
  --color-calm-bg-alt: #051616;
  --color-calm-primary: #14b8a6;
  --color-calm-secondary: #10b981;
  --color-calm-glow: rgba(20, 184, 166, 0.25);

  /* Active variables (Dynamically updated via [data-theme]) */
  --theme-bg: var(--color-vent-bg);
  --theme-bg-alt: var(--color-vent-bg-alt);
  --theme-primary: var(--color-vent-primary);
  --theme-secondary: var(--color-vent-secondary);
  --theme-glow: var(--color-vent-glow);
  
  /* Glassmorphism system */
  --glass-bg: rgba(255, 255, 255, 0.03);
  --glass-bg-hover: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-border-focus: rgba(255, 255, 255, 0.15);
  --glass-shadow: rgba(0, 0, 0, 0.6);
  
  --text-primary: #f8fafc;
  --text-muted: #94a3b8;
  --text-dark: #0f172a;
  
  --transition-slow: all 1.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-medium: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Theme states */
[data-theme="vent"] {
  --theme-bg: var(--color-vent-bg);
  --theme-bg-alt: var(--color-vent-bg-alt);
  --theme-primary: var(--color-vent-primary);
  --theme-secondary: var(--color-vent-secondary);
  --theme-glow: var(--color-vent-glow);
}

[data-theme="trans"] {
  --theme-bg: var(--color-trans-bg);
  --theme-bg-alt: var(--color-trans-bg-alt);
  --theme-primary: var(--color-trans-primary);
  --theme-secondary: var(--color-trans-secondary);
  --theme-glow: var(--color-trans-glow);
}

[data-theme="calm"] {
  --theme-bg: var(--color-calm-bg);
  --theme-bg-alt: var(--color-calm-bg-alt);
  --theme-primary: var(--color-calm-primary);
  --theme-secondary: var(--color-calm-secondary);
  --theme-glow: var(--color-calm-glow);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--theme-bg);
  background-image: radial-gradient(circle at 50% 50%, var(--theme-bg-alt) 0%, var(--theme-bg) 100%);
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  transition: background-color 1.5s ease, background-image 1.5s ease;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Glass panel components */
.glass-panel {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 16px;
  box-shadow: 0 8px 32px var(--glass-shadow);
  transition: var(--transition-medium);
}

/* Background canvas overlays */
.canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  transition: opacity 1s ease;
}

/* App Header & Progression HUD */
.app-header {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  pointer-events: none;
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #ffffff 0%, var(--theme-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  pointer-events: auto;
  cursor: pointer;
  transition: var(--transition-slow);
}

.hud-container {
  display: flex;
  gap: 15px;
  pointer-events: auto;
}

.hud-pill {
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 50px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--glass-border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.hud-pill span.value {
  color: var(--theme-secondary);
  font-size: 1rem;
  font-weight: 800;
  transition: color 1s ease;
}

/* State Screens Container */
.screen-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden; /* Prevent child pointer-events leakage */
  transition: opacity 0.8s ease, transform 0.8s ease, visibility 0.8s ease;
  transform: scale(0.97);
}

.screen-layer.active {
  opacity: 1;
  transform: scale(1);
  visibility: visible; /* Restore visibility */
}

/* Floating Check-In Card (Option A: Floating & Non-intrusive) */
.checkin-card {
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 320px;
  padding: 20px;
  z-index: 15;
  pointer-events: auto;
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.5s ease;
}

.checkin-card.minimized {
  transform: translateY(120%) scale(0.8);
  opacity: 0;
  pointer-events: none;
}

.checkin-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.checkin-card p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 15px;
}

.slider-container {
  margin-bottom: 15px;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 5px;
}

.styled-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.1);
  outline: none;
}

.styled-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--theme-primary);
  cursor: pointer;
  box-shadow: 0 0 10px var(--theme-primary);
  transition: background-color 1s ease, box-shadow 1s ease;
}

.trigger-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 15px;
}

.trigger-btn {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--glass-border);
  padding: 8px;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  text-align: center;
}

.trigger-btn:hover {
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-focus);
}

.trigger-btn.active {
  background: var(--theme-primary);
  border-color: var(--theme-primary);
  box-shadow: 0 0 8px var(--theme-glow);
  color: var(--text-dark);
  font-weight: 600;
}

.submit-btn {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: none;
  background: var(--text-primary);
  color: var(--text-dark);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.submit-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Rage Click Arena UI Elements */
.arena-controls {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  z-index: 10;
  pointer-events: auto;
}

.cooldown-prompt {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 300px;
  line-height: 1.4;
  opacity: 0.8;
  animation: floatSlow 3s ease-in-out infinite;
}

.cooldown-btn {
  background: rgba(0, 0, 0, 0.4);
  border: 1.5px solid var(--theme-primary);
  color: var(--theme-primary);
  padding: 12px 30px;
  border-radius: 30px;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: var(--transition-medium);
  box-shadow: 0 0 15px rgba(0,0,0,0.3);
  position: relative;
  overflow: hidden;
}

.cooldown-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
  transition: 0.5s;
}

.cooldown-btn:hover {
  background: var(--theme-primary);
  color: var(--text-dark);
  box-shadow: 0 0 25px var(--theme-glow);
  transform: translateY(-2px) scale(1.03);
}

.cooldown-btn:hover::before {
  left: 100%;
}

/* Breathing Screen UI */
.breathing-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 10;
}

.breath-circle-outer {
  width: 250px;
  height: 250px;
  border-radius: 50%;
  border: 1px solid rgba(20, 184, 166, 0.1);
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 40px;
  position: relative;
  transition: transform 4s ease-in-out;
}

.breath-circle-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px dashed var(--theme-primary);
  opacity: 0.3;
  width: 100%;
  height: 100%;
  animation: rotateClockwise 25s linear infinite;
  transition: border-color 1s ease;
  pointer-events: none; /* Ignore pointer events */
}

.breath-circle-pulse {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, var(--theme-glow) 0%, transparent 70%);
  width: 120%;
  height: 120%;
  opacity: 0.15;
  transition: transform 0.4s ease;
  pointer-events: none; /* Ignore pointer events */
}

.breath-circle-inner {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: var(--glass-bg);
  border: 1.5px solid var(--theme-primary);
  box-shadow: 0 0 30px var(--theme-glow);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  user-select: none;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  transition: transform 4s cubic-bezier(0.4, 0, 0.2, 1), background-color 1s ease, border-color 1s ease, box-shadow 1s ease;
  z-index: 2;
  pointer-events: auto; /* Capture clicks directly */
}

.breath-circle-inner:active, .breath-circle-inner.pressed {
  background: rgba(20, 184, 166, 0.15);
}

.breath-instruction {
  font-size: 1.7rem;
  font-weight: 600;
  margin-bottom: 12px;
  min-height: 2.5rem;
  transition: var(--transition-medium);
}

.breath-sub-instruction {
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 340px;
  line-height: 1.5;
  min-height: 3rem;
}

.breath-progress-dots {
  display: flex;
  gap: 8px;
  margin-top: 30px;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  transition: var(--transition-medium);
}

.progress-dot.active {
  background: var(--theme-primary);
  box-shadow: 0 0 8px var(--theme-primary);
}

/* Zen Garden overlay */
.zen-overlay {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 10;
  pointer-events: none;
}

.zen-overlay * {
  pointer-events: auto;
}

.zen-tip {
  font-size: 0.95rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--glass-border);
  padding: 8px 20px;
  border-radius: 30px;
  backdrop-filter: blur(8px);
}

.zen-progress-bar {
  width: 250px;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}

.zen-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--theme-primary), var(--theme-secondary));
  transition: width 0.3s ease;
  box-shadow: 0 0 8px var(--theme-glow);
}

/* Visual Analytics Dashboard Layout */
.dashboard-container {
  width: 90%;
  max-width: 900px;
  height: 85vh;
  margin-top: 40px;
  padding: 30px;
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 25px;
  overflow-y: auto;
  pointer-events: auto;
}

.dashboard-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.dashboard-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.dashboard-title {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 5px;
  background: linear-gradient(135deg, #fff 0%, var(--theme-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.chart-panel {
  padding: 20px;
  height: 300px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.chart-panel h4 {
  font-size: 0.95rem;
  margin-bottom: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-wrapper {
  flex: 1;
  position: relative;
  width: 100%;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
}

.stat-card {
  padding: 15px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.stat-card span.label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
}

.stat-card span.value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--theme-secondary);
}

.history-panel {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  max-height: 400px;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding-right: 5px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.85rem;
}

.history-item:last-child {
  border-bottom: none;
}

.history-date {
  color: var(--text-primary);
  font-weight: 500;
}

.history-details {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
}

.history-reduction {
  color: var(--color-calm-primary);
  font-weight: 600;
}

.dashboard-actions {
  display: flex;
  gap: 15px;
  margin-top: 10px;
}

.dashboard-btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: none;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-fast);
}

.dashboard-btn.primary {
  background: var(--theme-primary);
  color: var(--text-dark);
  box-shadow: 0 4px 15px var(--theme-glow);
}

.dashboard-btn.secondary {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}

.dashboard-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--theme-glow);
}

.dashboard-btn.secondary:hover {
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-focus);
}

/* Animations */
@keyframes rotateClockwise {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes floatSlow {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* Screen shaking dynamic class */
.shake-screen {
  animation: shake 0.15s cubic-bezier(.36,.07,.19,.97) both;
  transform: translate3d(0, 0, 0);
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 1px, 0); }
  20%, 80% { transform: translate3d(2px, -1px, 0); }
  30%, 50%, 70% { transform: translate3d(-3px, 2px, 0); }
  40%, 60% { transform: translate3d(3px, -2px, 0); }
}

/* Custom scrollbars */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.25);
}

/* Responsiveness overrides */
@media (max-width: 768px) {
  .dashboard-container {
    grid-template-columns: 1fr;
    height: auto;
    max-height: 85vh;
    padding: 15px;
    margin-top: 60px;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .stat-card {
    padding: 10px;
  }
  
  .checkin-card {
    left: 20px;
    right: 20px;
    width: auto;
    bottom: 20px;
  }
  
  .breath-circle-outer {
    width: 200px;
    height: 200px;
  }
  
  .breath-circle-inner {
    width: 130px;
    height: 130px;
    font-size: 0.95rem;
  }
}
