/* ============================================
   COSMIC CHAIN - コズミック・チェイン
   ============================================ */

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

body {
  background: #000;
  overflow: hidden;
  font-family: 'Zen Maru Gothic', sans-serif;
  color: #fff;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}

#game-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ---- Canvas ---- */
#bg-canvas, #game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#bg-canvas {
  z-index: 0;
}

#game-canvas {
  z-index: 1;
  cursor: crosshair;
}

/* ---- Title Screen ---- */
#title-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10, 5, 40, 0.85) 0%, rgba(0, 0, 0, 0.95) 100%);
  animation: titleFadeIn 1s ease-out;
}

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

#title-content {
  text-align: center;
  position: relative;
  z-index: 2;
}

#title-orb {
  width: 120px;
  height: 120px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #a78bfa 30%, #7c3aed 60%, #4c1d95 100%);
  box-shadow:
    0 0 40px rgba(167, 139, 250, 0.6),
    0 0 80px rgba(124, 58, 237, 0.4),
    0 0 120px rgba(76, 29, 149, 0.3),
    inset 0 0 30px rgba(255, 255, 255, 0.3);
  animation: titleOrbPulse 3s ease-in-out infinite, titleOrbFloat 4s ease-in-out infinite;
}

@keyframes titleOrbPulse {
  0%, 100% { box-shadow: 0 0 40px rgba(167, 139, 250, 0.6), 0 0 80px rgba(124, 58, 237, 0.4), 0 0 120px rgba(76, 29, 149, 0.3), inset 0 0 30px rgba(255, 255, 255, 0.3); }
  50% { box-shadow: 0 0 60px rgba(167, 139, 250, 0.8), 0 0 100px rgba(124, 58, 237, 0.6), 0 0 160px rgba(76, 29, 149, 0.4), inset 0 0 40px rgba(255, 255, 255, 0.4); }
}

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

.title-en {
  display: block;
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(32px, 8vw, 56px);
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #a78bfa, #60a5fa, #34d399, #fbbf24, #f472b6);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 4s ease-in-out infinite;
  text-shadow: none;
  filter: drop-shadow(0 0 20px rgba(167, 139, 250, 0.5));
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.title-ja {
  display: block;
  font-size: clamp(14px, 3.5vw, 22px);
  color: #c4b5fd;
  margin-top: 8px;
  letter-spacing: 3px;
}

#title-desc {
  margin-top: 24px;
  font-size: clamp(12px, 2.8vw, 16px);
  color: #a5b4fc;
  line-height: 1.8;
  opacity: 0;
  animation: fadeUp 1s 0.5s ease-out forwards;
}

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

#start-btn {
  margin-top: 40px;
  padding: 16px 60px;
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(16px, 4vw, 22px);
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #7c3aed, #6366f1);
  border: 2px solid rgba(167, 139, 250, 0.5);
  border-radius: 50px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  opacity: 0;
  animation: fadeUp 1s 0.8s ease-out forwards;
  letter-spacing: 3px;
}

#start-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(124, 58, 237, 0.6), 0 0 60px rgba(99, 102, 241, 0.3);
  border-color: rgba(167, 139, 250, 0.8);
}

#start-btn:active {
  transform: scale(0.98);
}

.btn-glow {
  position: absolute;
  inset: -2px;
  border-radius: 50px;
  background: linear-gradient(45deg, transparent, rgba(167, 139, 250, 0.4), transparent);
  animation: btnGlowSweep 2s ease-in-out infinite;
}

@keyframes btnGlowSweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

#best-score-display {
  margin-top: 20px;
  font-family: 'Orbitron', sans-serif;
  font-size: 14px;
  color: #fbbf24;
  letter-spacing: 2px;
  opacity: 0;
  animation: fadeUp 1s 1s ease-out forwards;
}

/* ---- HUD ---- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 16px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.7) 0%, transparent 100%);
  pointer-events: none;
}

#hud-left, #hud-right {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(10px, 2.5vw, 14px);
  line-height: 1.8;
}

#hud-left {
  text-align: left;
}

#hud-right {
  text-align: right;
}

#level-display {
  color: #a78bfa;
  font-weight: 700;
  letter-spacing: 2px;
}

#level-num {
  color: #c4b5fd;
  font-size: 1.2em;
}

#orbs-remaining {
  color: #94a3b8;
  font-size: 0.85em;
}

#hud-center {
  text-align: center;
}

#score-display {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#score-label {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(8px, 2vw, 11px);
  color: #64748b;
  letter-spacing: 3px;
}

#score-value {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(20px, 5vw, 32px);
  font-weight: 900;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.5));
}

#chain-display {
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  animation: chainPop 0.3s ease-out;
}

@keyframes chainPop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

#chain-count {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 900;
  color: #f472b6;
  text-shadow: 0 0 20px rgba(244, 114, 182, 0.8);
}

#chain-label {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(12px, 3vw, 18px);
  font-weight: 700;
  color: #f9a8d4;
  letter-spacing: 3px;
}

#clicks-left {
  color: #34d399;
  font-weight: 700;
  letter-spacing: 1px;
}

#clicks-value {
  color: #6ee7b7;
  font-size: 1.3em;
}

#target-display {
  color: #94a3b8;
  font-size: 0.85em;
  letter-spacing: 1px;
}

/* ---- Level Intro ---- */
#level-intro {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

#level-intro-content {
  text-align: center;
  animation: levelIntroAnim 2s ease-out forwards;
}

@keyframes levelIntroAnim {
  0% { opacity: 0; transform: scale(0.5); }
  20% { opacity: 1; transform: scale(1.1); }
  40% { transform: scale(1); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.5); }
}

#level-intro-sub {
  display: block;
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(14px, 3.5vw, 20px);
  letter-spacing: 8px;
  color: #a78bfa;
}

#level-intro-num {
  display: block;
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(64px, 16vw, 120px);
  font-weight: 900;
  background: linear-gradient(135deg, #a78bfa, #60a5fa, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 30px rgba(167, 139, 250, 0.6));
  line-height: 1.1;
}

#level-intro-name {
  display: block;
  font-size: clamp(14px, 3.5vw, 20px);
  color: #c4b5fd;
  margin-top: 8px;
  letter-spacing: 4px;
}

/* ---- Combo Popup ---- */
#combo-popup {
  position: absolute;
  z-index: 7;
  pointer-events: none;
  animation: comboAnim 1.2s ease-out forwards;
}

@keyframes comboAnim {
  0% { opacity: 0; transform: scale(0.3) rotate(-5deg); }
  15% { opacity: 1; transform: scale(1.2) rotate(2deg); }
  30% { transform: scale(1) rotate(0deg); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.3) translateY(-40px); }
}

#combo-text {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(32px, 8vw, 60px);
  font-weight: 900;
  -webkit-text-stroke: 2px rgba(255, 255, 255, 0.3);
  text-shadow:
    0 0 20px currentColor,
    0 0 40px currentColor,
    0 0 60px currentColor;
}

/* ---- Level Clear ---- */
#level-clear {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10, 5, 40, 0.9) 0%, rgba(0, 0, 0, 0.95) 100%);
  animation: screenFadeIn 0.5s ease-out;
}

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

#clear-content, #gameover-content {
  text-align: center;
  padding: 30px;
}

#clear-title {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 900;
  background: linear-gradient(135deg, #fbbf24, #f59e0b, #fbbf24);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 2s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(251, 191, 36, 0.5));
  margin-bottom: 30px;
}

#clear-stats, #gameover-stats {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.clear-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 260px;
}

.clear-stat-label {
  font-size: clamp(12px, 3vw, 16px);
  color: #94a3b8;
}

.clear-stat-value {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(18px, 4.5vw, 28px);
  font-weight: 900;
  color: #e2e8f0;
}

#clear-bonus {
  color: #34d399 !important;
}

#clear-rank {
  font-size: clamp(48px, 12vw, 80px);
  margin: 20px 0;
  filter: drop-shadow(0 0 20px rgba(251, 191, 36, 0.5));
  animation: rankBounce 0.6s ease-out;
}

@keyframes rankBounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.3); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

#next-level-btn, #retry-btn, #home-btn {
  margin: 8px;
  padding: 14px 40px;
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(13px, 3.2vw, 17px);
  font-weight: 700;
  color: #fff;
  border: 2px solid rgba(167, 139, 250, 0.5);
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 2px;
}

#next-level-btn {
  background: linear-gradient(135deg, #7c3aed, #6366f1);
}

#retry-btn {
  background: linear-gradient(135deg, #7c3aed, #6366f1);
}

#home-btn {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.2);
  color: #94a3b8;
}

#next-level-btn:hover, #retry-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(124, 58, 237, 0.6);
}

#home-btn:hover {
  border-color: rgba(255, 255, 255, 0.4);
  color: #e2e8f0;
}

/* ---- Game Over ---- */
#game-over {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(40, 5, 10, 0.9) 0%, rgba(0, 0, 0, 0.95) 100%);
  animation: screenFadeIn 0.5s ease-out;
}

#gameover-title {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 900;
  background: linear-gradient(135deg, #f87171, #ef4444, #f87171);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 2s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(248, 113, 113, 0.5));
  margin-bottom: 30px;
}

#new-record {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(18px, 4.5vw, 28px);
  font-weight: 900;
  color: #fbbf24;
  text-shadow: 0 0 20px rgba(251, 191, 36, 0.8);
  margin-bottom: 20px;
  animation: recordPulse 0.8s ease-in-out infinite alternate;
}

@keyframes recordPulse {
  from { transform: scale(1); opacity: 0.8; }
  to { transform: scale(1.1); opacity: 1; }
}

/* ---- Shared ---- */
.hidden {
  display: none !important;
}

.back-to-top-link {
  position: fixed;
  bottom: 12px;
  left: 12px;
  z-index: 100;
  color: rgba(255, 255, 255, 0.3);
  text-decoration: none;
  font-size: 12px;
  transition: color 0.3s;
}

.back-to-top-link:hover {
  color: rgba(255, 255, 255, 0.7);
}

/* ---- Screen Shake ---- */
.shake-light {
  animation: shakeLight 0.2s ease-out;
}

.shake-medium {
  animation: shakeMedium 0.3s ease-out;
}

.shake-heavy {
  animation: shakeHeavy 0.5s ease-out;
}

@keyframes shakeLight {
  0%, 100% { transform: translate(0); }
  25% { transform: translate(-2px, 1px); }
  50% { transform: translate(2px, -1px); }
  75% { transform: translate(-1px, 2px); }
}

@keyframes shakeMedium {
  0%, 100% { transform: translate(0); }
  10% { transform: translate(-4px, 3px); }
  30% { transform: translate(4px, -3px); }
  50% { transform: translate(-3px, 4px); }
  70% { transform: translate(3px, -2px); }
  90% { transform: translate(-2px, 1px); }
}

@keyframes shakeHeavy {
  0%, 100% { transform: translate(0); }
  5% { transform: translate(-8px, 6px); }
  15% { transform: translate(8px, -4px); }
  25% { transform: translate(-6px, 8px); }
  35% { transform: translate(6px, -6px); }
  45% { transform: translate(-4px, 4px); }
  55% { transform: translate(4px, -3px); }
  65% { transform: translate(-3px, 3px); }
  75% { transform: translate(2px, -2px); }
  85% { transform: translate(-1px, 1px); }
}

/* Flash overlay */
.flash-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  animation: flashFade 0.4s ease-out forwards;
}

@keyframes flashFade {
  from { opacity: 0.6; }
  to { opacity: 0; }
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
  #hud {
    padding: 8px 10px;
  }

  .clear-stat {
    min-width: 220px;
    padding: 10px 16px;
  }

  #next-level-btn, #retry-btn, #home-btn {
    padding: 12px 30px;
  }
}
