/* === RESET & BASE === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: #0a0a1a;
  color: #e0e0f0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: radial-gradient(ellipse at 50% 40%, #12123a 0%, #0a0a1a 70%);
}

#app {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  max-height: 700px;
  position: relative;
  overflow: hidden;
}

/* === SCREENS === */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.screen.active {
  display: flex;
}

/* === MENU === */
.title {
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  font-weight: 900;
  text-align: center;
  letter-spacing: 0.08em;
  line-height: 1.1;
  color: #00f0ff;
  text-shadow: 0 0 30px rgba(0, 240, 255, 0.3);
  margin-bottom: 8px;
}

.subtitle {
  font-size: clamp(0.85rem, 3vw, 1rem);
  color: #667;
  margin-bottom: 36px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

#mode-select {
  display: flex;
  gap: 12px;
  margin-bottom: 32px;
}

.mode-btn {
  width: 72px;
  height: 72px;
  border: 2px solid #223;
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  color: #aab;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mode-btn:hover, .mode-btn:focus {
  border-color: #00f0ff;
  color: #00f0ff;
  background: rgba(0, 240, 255, 0.06);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.15);
  transform: translateY(-2px);
}
.mode-btn:active {
  transform: translateY(0);
}

.hint {
  font-size: 0.8rem;
  color: #445;
  letter-spacing: 0.1em;
}

/* === GAME SCREEN === */
#timer-section {
  width: 100%;
  text-align: center;
  margin-bottom: 20px;
}

#timer-bar-wrap {
  width: 100%;
  height: 6px;
  background: #1a1a2e;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}

#timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #00f0ff, #00c8ff);
  border-radius: 3px;
  transition: width 0.1s linear, background 0.3s ease;
}
#timer-bar.warning {
  background: linear-gradient(90deg, #ff4444, #ff8844);
}

#timer-text {
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #dde;
  letter-spacing: 0.04em;
}

/* === PRESS AREA (contains canvas overlay) === */
#press-area {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px solid #1a1a30;
  border-radius: 20px;
  background: rgba(255,255,255,0.015);
  cursor: pointer;
  position: relative;
  overflow: visible;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.06s;
  min-height: 280px;
}
#press-area.pulse {
  border-color: #00f0ff;
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.2), inset 0 0 40px rgba(0, 240, 255, 0.03);
  transform: scale(0.985);
}

/* Canvas sits behind the text elements */
#game-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  border-radius: 18px;
}

/* Text elements float above canvas */
#combo-display {
  position: relative;
  z-index: 2;
  font-size: 0.85rem;
  font-weight: 700;
  color: #ff00aa;
  opacity: 0;
  transition: opacity 0.2s, color 0.3s;
  letter-spacing: 0.05em;
}
#combo-display.visible {
  opacity: 1;
}
#combo-display.fire {
  color: #ffd700;
  text-shadow: 0 0 12px rgba(255, 215, 0, 0.5);
}

#press-count {
  position: relative;
  z-index: 2;
  font-size: clamp(4rem, 14vw, 7rem);
  font-weight: 900;
  line-height: 1;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 40px rgba(0, 240, 255, 0.15);
}

#cps-display {
  position: relative;
  z-index: 2;
  font-size: clamp(1rem, 4vw, 1.4rem);
  color: #668;
  margin-top: 8px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* === PRESS AREA FLASH === */
#press-area.flash {
  animation: screenFlash 0.08s ease-out;
}
@keyframes screenFlash {
  0% { background: rgba(0, 240, 255, 0.06); }
  100% { background: rgba(255,255,255,0.015); }
}

/* === MILESTONE FLASH === */
@keyframes milestoneFlash {
  0% { box-shadow: 0 0 80px rgba(255, 215, 0, 0.4), inset 0 0 40px rgba(255, 215, 0, 0.1); }
  100% { box-shadow: none; }
}
#press-area.milestone {
  animation: milestoneFlash 0.3s ease-out;
  border-color: #ffd700 !important;
}

/* === RESULT SCREEN === */
#result-card {
  width: 100%;
  max-width: 340px;
  background: rgba(255,255,255,0.03);
  border: 1px solid #1a1a30;
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  margin-bottom: 24px;
}

.rank-badge {
  display: inline-block;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  padding: 6px 20px;
  border-radius: 8px;
  margin-bottom: 24px;
}
.rank-badge.beginner {
  background: rgba(100, 100, 120, 0.2);
  color: #778;
  border: 1px solid #334;
}
.rank-badge.fast {
  background: rgba(0, 200, 255, 0.1);
  color: #00c8ff;
  border: 1px solid rgba(0, 200, 255, 0.3);
}
.rank-badge.rapid {
  background: rgba(0, 240, 136, 0.1);
  color: #00f088;
  border: 1px solid rgba(0, 240, 136, 0.3);
}
.rank-badge.machine {
  background: rgba(255, 100, 0, 0.1);
  color: #ff6400;
  border: 1px solid rgba(255, 100, 0, 0.3);
}
.rank-badge.legendary {
  background: rgba(255, 215, 0, 0.12);
  color: #ffd700;
  border: 1px solid rgba(255, 215, 0, 0.35);
  text-shadow: 0 0 16px rgba(255, 215, 0, 0.3);
}

#result-presses, #result-cps, #result-best, #result-combo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
#result-combo {
  border-bottom: none;
}

.result-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #556;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#result-press-count, #result-cps-val, #result-best-val, #result-combo-val {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #dde;
}

.new-best {
  font-size: 0.7rem;
  font-weight: 700;
  color: #ffd700;
  background: rgba(255, 215, 0, 0.12);
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 8px;
  letter-spacing: 0.08em;
}

#result-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 340px;
}

.action-btn {
  flex: 1;
  padding: 16px;
  border: 2px solid #00f0ff;
  border-radius: 12px;
  background: rgba(0, 240, 255, 0.08);
  color: #00f0ff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.1em;
  transition: all 0.15s ease;
}
.action-btn:hover, .action-btn:focus {
  background: rgba(0, 240, 255, 0.15);
  box-shadow: 0 0 24px rgba(0, 240, 255, 0.15);
  transform: translateY(-1px);
}
.action-btn.secondary {
  border-color: #334;
  background: rgba(255,255,255,0.02);
  color: #667;
}
.action-btn.secondary:hover, .action-btn.secondary:focus {
  border-color: #556;
  color: #99a;
  background: rgba(255,255,255,0.04);
  box-shadow: none;
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* === SMALL SCREENS === */
@media (max-height: 550px) {
  #press-area {
    min-height: 200px;
  }
  .title {
    font-size: 2rem;
    margin-bottom: 4px;
  }
  .subtitle {
    margin-bottom: 20px;
  }
}
