/* ============================================
   CSS Variables & Theme
   ============================================ */
:root {
  --bg-primary: #0D1117;
  --bg-secondary: #161B22;
  --bg-tertiary: #21262D;
  --text-primary: #F0F6FC;
  --text-secondary: #8B949E;
  --text-muted: #484F58;
  --accent: #3B82F6;
  --accent-glow: rgba(59, 130, 246, 0.3);
  --border: #30363D;
  --btn-bg: #21262D;
  --btn-active: #30363D;
  --overlay-bg: rgba(0, 0, 0, 0.88);
  --board-bg: #0A0E14;
  --board-grid: rgba(48, 54, 61, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F6F8FA;
    --bg-tertiary: #E9ECF0;
    --text-primary: #1B1E28;
    --text-secondary: #57606A;
    --text-muted: #8C959F;
    --accent: #3182F6;
    --accent-glow: rgba(49, 130, 246, 0.2);
    --border: #D0D7DE;
    --btn-bg: #E9ECF0;
    --btn-active: #D0D7DE;
    --overlay-bg: rgba(255, 255, 255, 0.92);
    --board-bg: #F0F2F5;
    --board-grid: rgba(208, 215, 222, 0.45);
  }
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

/* ============================================
   App Layout
   ============================================ */
#app {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-secondary);
  overflow: hidden;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.hidden {
  display: none !important;
}

/* ============================================
   Overlay Screens (Start, GameOver)
   ============================================ */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fadeIn 0.3s ease;
}

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

.overlay-content {
  text-align: center;
  padding: 40px 32px;
}

.game-title {
  font-size: 48px;
  font-weight: 800;
  letter-spacing: 8px;
  background: linear-gradient(135deg, #3B82F6, #8B5CF6, #EC4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  margin-top: 16px;
}

.subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  margin-top: 24px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 1; }
}

.start-info {
  margin-top: 12px;
  font-size: 14px;
  color: var(--text-muted);
}

.gameover-title {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 4px;
  color: #EF4444;
  margin-bottom: 24px;
}

.final-score {
  margin-bottom: 20px;
}

.score-label {
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.score-value {
  font-size: 42px;
  font-weight: 800;
  color: var(--accent);
}

.final-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 16px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.stat-value {
  font-size: 26px;
  font-weight: 700;
}

/* ============================================
   Game Header
   ============================================ */
#game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 6px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.header-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 64px;
}

.center-stat {
  flex: 1;
  align-items: center;
}

.hstat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.hstat-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.hstat-value.accent {
  color: var(--accent);
}

/* ============================================
   Timer Bar
   ============================================ */
#timer-bar-wrap {
  width: 100%;
  height: 5px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}

#timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #3B82F6, #8B5CF6);
  border-radius: 3px;
  transition: width 0.25s linear, background 0.5s ease;
}

#timer-bar.low {
  background: linear-gradient(90deg, #EF4444, #F97316);
}

#timer-display {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
}

#timer-display.low {
  color: #EF4444;
  animation: timerPulse 0.5s ease-in-out infinite alternate;
}

@keyframes timerPulse {
  from { transform: scale(1); }
  to   { transform: scale(1.1); }
}

/* ============================================
   Board
   ============================================ */
#board-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--board-bg);
  overflow: hidden;
  padding: 8px;
}

#board-canvas {
  display: block;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--board-bg);
  touch-action: none;
  max-width: 100%;
  max-height: 100%;
}

/* ============================================
   Match3 Icon (CSS art gem)
   ============================================ */
.icon-match3 {
  display: block;
  position: relative;
  width: 36px;
  height: 36px;
  animation: pulse-scale 2s ease-in-out infinite;
}
/* diamond shape via clip-path */
.icon-match3::before {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  background: radial-gradient(circle at 38% 35%, #7DD3FC, #3B82F6, #1D4ED8);
  box-shadow: 0 0 14px rgba(59,130,246,0.7), inset -3px -3px 6px rgba(0,0,0,0.3);
  clip-path: polygon(50% 0%, 100% 38%, 80% 100%, 20% 100%, 0% 38%);
  top: 2px;
  left: 5px;
}
/* small sparkle */
.icon-match3::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  background: radial-gradient(circle at 40% 40%, #F472B6, #EC4899);
  clip-path: polygon(50% 0%, 100% 38%, 80% 100%, 20% 100%, 0% 38%);
  box-shadow: 0 0 8px rgba(236,72,153,0.8);
  bottom: 2px;
  right: 2px;
}
