/* ============================================
   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.85);
  --board-bg: #0A0E14;
  --wall-color: rgba(203, 213, 225, 0.75);
  --start-color: #22C55E;
  --start-glow: rgba(34, 197, 94, 0.3);
  --end-color: #F59E0B;
  --end-glow: rgba(245, 158, 11, 0.3);
  --ball-color: #60A5FA;
  --ball-highlight: #BFDBFE;
  --ball-shadow: #1E40AF;
  --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.9);
    --board-bg: #F0F2F5;
    --wall-color: rgba(51, 65, 85, 0.75);
    --start-color: #16A34A;
    --start-glow: rgba(22, 163, 74, 0.25);
    --end-color: #D97706;
    --end-glow: rgba(217, 119, 6, 0.25);
    --ball-color: #3B82F6;
    --ball-highlight: #93C5FD;
    --ball-shadow: #1E3A8A;
  }
}

/* ============================================
   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);
}

/* ============================================
   App Layout
   ============================================ */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  position: relative;
  max-width: 480px;
  margin: 0 auto;
}

#game-content {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-height: 844px;
}

.hidden {
  display: none !important;
}

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

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

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

.game-title {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: 10px;
  background: linear-gradient(135deg, #22C55E, #3B82F6, #F59E0B);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.game-desc {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 28px;
}

.primary-btn {
  display: inline-block;
  padding: 14px 40px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.primary-btn:active {
  background: #2563EB;
  transform: scale(0.95);
}

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

/* Victory */
.victory-title {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 6px;
  background: linear-gradient(135deg, #F59E0B, #EF4444, #F59E0B);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 24px;
  animation: victoryPulse 1s ease infinite alternate;
}

@keyframes victoryPulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

.final-time {
  margin-bottom: 16px;
}

.time-label {
  font-size: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.time-value {
  font-size: 36px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.new-record {
  font-size: 18px;
  font-weight: 700;
  color: #F59E0B;
  animation: recordBounce 0.6s ease infinite alternate;
  margin-bottom: 12px;
}

@keyframes recordBounce {
  from { transform: scale(1); }
  to { transform: scale(1.12); }
}

/* ============================================
   Game Header
   ============================================ */
#game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  flex-shrink: 0;
}

#timer-area {
  display: flex;
  align-items: center;
  gap: 6px;
}

.timer-value {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.header-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--btn-bg);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.header-btn:active {
  background: var(--btn-active);
  transform: scale(0.95);
}

/* ============================================
   Maze Board
   ============================================ */
#maze-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  min-height: 0;
}

#maze-canvas {
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--board-bg);
  max-width: 100%;
  max-height: 100%;
}

/* ============================================
   Control Hint
   ============================================ */
.control-hint {
  flex-shrink: 0;
  text-align: center;
  padding: 10px 16px 16px;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 42px;
  animation: hintFade 0.5s ease;
}

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

/* ============================================
   Responsive
   ============================================ */
@media (max-height: 600px) {
  #game-header { padding: 4px 12px; }
  .timer-value { font-size: 22px; }
  .control-hint { padding: 4px 12px 8px; font-size: 11px; }
}

@media (min-height: 800px) {
  .timer-value { font-size: 32px; }
}
