:root {
  --bg: #0a0a1a;
  --bg-card: #141428;
  --bg-card-light: #1e1e3a;
  --green: #00ff88;
  --green-dim: #00cc6a;
  --blue: #00d4ff;
  --purple: #b44dff;
  --pink: #ff4da6;
  --orange: #ff8c00;
  --red: #ff3355;
  --white: #eef;
  --gray: #666;
  --text-dim: #8888aa;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--white);
}

/* SCREENS */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 10;
}

/* HOME SCREEN */
#screen-home {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.home-content {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 20px;
  gap: 14px;
}

.logo {
  text-align: center;
}

.logo-icon {
  font-size: 48px;
  animation: pulse-glow 2s ease-in-out infinite;
}

.logo-title {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 1.1;
  color: var(--white);
}

.logo-title span {
  background: linear-gradient(135deg, var(--green), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 40px;
}

/* LEVEL CARD */
.level-card {
  width: 100%;
  max-width: 340px;
  background: var(--bg-card);
  border-radius: 16px;
  padding: 12px 16px;
  border: 1px solid #2a2a4a;
}

.level-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.level-badge {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: white;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 1px;
}

.level-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--white);
}

.xp-bar-container {
  width: 100%;
  height: 8px;
  background: #2a2a4a;
  border-radius: 4px;
  overflow: hidden;
}

.xp-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--blue));
  border-radius: 4px;
  transition: width 0.6s ease;
}

.xp-text {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  text-align: right;
}

/* STATS GRID */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 340px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  border: 1px solid #2a2a4a;
}

.stat-value {
  font-size: 24px;
  font-weight: 900;
  color: var(--green);
}

.stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* BUTTONS */
.btn-start {
  position: relative;
  width: 100%;
  max-width: 340px;
  padding: 16px 32px;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--bg);
  background: linear-gradient(135deg, var(--green), var(--blue));
  border: none;
  border-radius: 16px;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

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

.btn-start-glow {
  position: absolute;
  inset: -2px;
  background: linear-gradient(135deg, var(--green), var(--blue));
  border-radius: 18px;
  filter: blur(12px);
  opacity: 0.4;
  z-index: -1;
}

.btn-secondary {
  width: 100%;
  max-width: 340px;
  padding: 12px 32px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-dim);
  background: var(--bg-card);
  border: 1px solid #2a2a4a;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.btn-secondary:active {
  transform: scale(0.96);
}

/* COUNTDOWN SCREEN */
.countdown-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.countdown-hint {
  font-size: 18px;
  color: var(--text-dim);
  text-align: center;
  animation: fade-in-up 0.5s ease;
}

.countdown-number {
  font-size: 140px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--green), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: countdown-pop 1s ease infinite;
}

.countdown-subtext {
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  padding: 0 40px;
}

/* WORKOUT SCREEN */
#screen-workout {
  background: var(--bg);
  touch-action: none;
}

.workout-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  position: relative;
  z-index: 20;
}

.workout-timer {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.btn-stop {
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 800;
  color: var(--red);
  background: rgba(255, 51, 85, 0.15);
  border: 1px solid rgba(255, 51, 85, 0.3);
  border-radius: 10px;
  cursor: pointer;
  letter-spacing: 1px;
  z-index: 100;
}

.workout-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 5;
}

.combo-display {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.combo-text {
  font-size: 24px;
  font-weight: 900;
  color: var(--orange);
  letter-spacing: 2px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.combo-text.active {
  opacity: 1;
  animation: combo-bounce 0.3s ease;
}

.counter-container {
  position: relative;
}

.counter {
  font-size: 160px;
  font-weight: 900;
  line-height: 1;
  color: var(--green);
  text-shadow: 0 0 40px rgba(0, 255, 136, 0.4), 0 0 80px rgba(0, 255, 136, 0.2);
  transition: transform 0.1s ease;
  font-variant-numeric: tabular-nums;
}

.counter.bump {
  animation: counter-bump 0.25s ease;
}

.session-xp {
  font-size: 20px;
  font-weight: 700;
  color: var(--blue);
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.workout-touch-hint {
  text-align: center;
  padding: 20px;
  font-size: 16px;
  color: var(--text-dim);
  letter-spacing: 1px;
  animation: pulse-glow 2s ease-in-out infinite;
  position: relative;
  z-index: 5;
}

/* SCREEN FLASH */
.screen-flash {
  position: fixed;
  inset: 0;
  background: var(--green);
  opacity: 0;
  pointer-events: none;
  z-index: 15;
  transition: opacity 0.05s ease;
}

.screen-flash.flash {
  opacity: 0.3;
}

/* PARTICLES */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  overflow: hidden;
}

.particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  animation: particle-fly 0.8s ease-out forwards;
}

/* REST POPUP */
.rest-popup {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 26, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.rest-popup.active {
  opacity: 1;
  pointer-events: auto;
}

.rest-popup-content {
  text-align: center;
}

.rest-popup-content p {
  font-size: 36px;
  margin-bottom: 24px;
}

.rest-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-rest-continue {
  padding: 14px 32px;
  font-size: 18px;
  font-weight: 800;
  color: var(--bg);
  background: var(--green);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  letter-spacing: 1px;
}

.btn-rest-stop {
  padding: 14px 32px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--bg-card);
  border: 1px solid #2a2a4a;
  border-radius: 12px;
  cursor: pointer;
}

/* RESULTS SCREEN */
.results-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  gap: 16px;
  overflow-y: auto;
}

.results-title {
  font-size: 28px;
  font-weight: 900;
  animation: fade-in-up 0.5s ease;
}

.results-main-stat {
  text-align: center;
  animation: fade-in-up 0.5s ease 0.1s both;
}

.results-count {
  font-size: 100px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--green), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

.results-count-label {
  font-size: 18px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 3px;
}

.results-stats {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fade-in-up 0.5s ease 0.2s both;
}

.results-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  padding: 12px 16px;
  border-radius: 10px;
}

.results-stat-label {
  color: var(--text-dim);
  font-size: 14px;
}

.results-stat-value {
  font-weight: 800;
  font-size: 16px;
}

.results-xp {
  color: var(--blue) !important;
}

.level-up-display {
  background: linear-gradient(135deg, rgba(180, 77, 255, 0.2), rgba(255, 77, 166, 0.2));
  border: 1px solid rgba(180, 77, 255, 0.4);
  border-radius: 16px;
  padding: 16px 24px;
  text-align: center;
  width: 100%;
  max-width: 340px;
  animation: level-up-glow 1s ease infinite alternate;
}

.level-up-text {
  font-size: 24px;
  font-weight: 900;
  color: var(--purple);
}

.level-up-new {
  font-size: 18px;
  font-weight: 700;
  color: var(--white);
  margin-top: 4px;
}

.new-record {
  font-size: 20px;
  font-weight: 900;
  color: var(--orange);
  animation: record-pulse 0.6s ease infinite alternate;
}

.new-achievements {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.new-achievement-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 255, 136, 0.1);
  border: 1px solid rgba(0, 255, 136, 0.3);
  border-radius: 12px;
  padding: 12px 16px;
  animation: fade-in-up 0.5s ease both;
}

.new-achievement-icon {
  font-size: 28px;
}

.new-achievement-info {
  flex: 1;
}

.new-achievement-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--green);
}

.new-achievement-desc {
  font-size: 12px;
  color: var(--text-dim);
}

.results-buttons {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fade-in-up 0.5s ease 0.4s both;
}

/* ACHIEVEMENTS SCREEN */
.achievements-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
}

.achievements-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.achievements-header h2 {
  font-size: 24px;
  font-weight: 900;
}

.btn-back {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--white);
  background: var(--bg-card);
  border: 1px solid #2a2a4a;
  border-radius: 10px;
  cursor: pointer;
}

.achievements-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.achievement-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  border: 1px solid #2a2a4a;
  transition: all 0.3s ease;
}

.achievement-card.unlocked {
  border-color: rgba(0, 255, 136, 0.3);
  background: rgba(0, 255, 136, 0.05);
}

.achievement-card.locked {
  opacity: 0.4;
}

.achievement-card .ach-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.achievement-card.locked .ach-icon {
  filter: grayscale(1);
}

.achievement-card .ach-title {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 4px;
}

.achievement-card .ach-desc {
  font-size: 11px;
  color: var(--text-dim);
}

/* ANIMATIONS */
@keyframes pulse-glow {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.05); }
}

@keyframes countdown-pop {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes counter-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes combo-bounce {
  0% { transform: scale(0.5); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes particle-fly {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}

@keyframes level-up-glow {
  from { box-shadow: 0 0 20px rgba(180, 77, 255, 0.2); }
  to { box-shadow: 0 0 40px rgba(180, 77, 255, 0.5); }
}

@keyframes record-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
  .workout-top {
    padding-top: calc(16px + env(safe-area-inset-top));
  }
  .home-content {
    padding-top: calc(24px + env(safe-area-inset-top));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
}
