/* Fortune Echoes - 財運迴響 */
/* Color Palette */
:root {
  --bg-dark: #020617;
  --bg-panel: rgba(2, 6, 23, 0.92);
  --gold-power: #ff6b35;
  --gold-lotto: #fbbf24;
  --gold-daily: #d97706;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --border-color: rgba(251, 191, 36, 0.2);
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans TC', sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
}

/* Map */
#map {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Dark mode via CSS filter on tile pane */
#map.dark-mode .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9);
}

/* SVG Ripple Layer */
#ripple-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* Control Panel */
#panel {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 280px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

@supports not (backdrop-filter: blur(12px)) {
  #panel {
    background: rgba(2, 6, 23, 0.98);
  }
}

.title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gold-lotto);
  margin-bottom: 2px;
  letter-spacing: 0.05em;
}

.subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* Stats */
#stats {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gold-lotto);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Legend / Filter */
#legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: opacity 0.2s;
}

.legend-item:hover {
  color: var(--text-primary);
}

.legend-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--gold-lotto);
  cursor: pointer;
}

.legend-item:has(input:not(:checked)) {
  opacity: 0.4;
}

/* View Mode Toggle */
#view-mode {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.mode-btn {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn:hover {
  border-color: var(--gold-lotto);
  color: var(--text-primary);
}

.mode-btn.active {
  background: var(--gold-lotto);
  border-color: var(--gold-lotto);
  color: var(--bg-dark);
  font-weight: 600;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
}

.legend-dot.power {
  background: var(--gold-power);
  color: var(--gold-power);
  width: 16px;
  height: 16px;
}

.legend-dot.lotto {
  background: var(--gold-lotto);
  color: var(--gold-lotto);
  width: 14px;
  height: 14px;
}

.legend-dot.daily {
  background: var(--gold-daily);
  color: var(--gold-daily);
}

/* Timeline */
#timeline {
  margin-bottom: 16px;
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

#current-month {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gold-lotto);
  font-variant-numeric: tabular-nums;
}

#play-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--gold-lotto);
  color: var(--bg-dark);
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
}

#play-btn:hover {
  transform: scale(1.1);
  background: var(--gold-power);
}

#play-btn.playing {
  background: var(--gold-power);
}

#timeline-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(251, 191, 36, 0.2);
  border-radius: 3px;
  cursor: pointer;
}

#timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--gold-lotto);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--gold-lotto);
  cursor: grab;
}

#timeline-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--gold-lotto);
  border-radius: 50%;
  border: none;
  box-shadow: 0 0 10px var(--gold-lotto);
  cursor: grab;
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Monthly Stats */
#monthly-stats {
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.monthly-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.monthly-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.monthly-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gold-lotto);
  font-variant-numeric: tabular-nums;
}

/* Theme Toggle Button */
#theme-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: var(--bg-panel);
  color: var(--text-primary);
  font-size: 1.25rem;
  cursor: pointer;
  z-index: 100;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.2s, background 0.2s;
}

#theme-btn:hover {
  transform: scale(1.1);
  background: rgba(251, 191, 36, 0.2);
}

/* Attribution */
#attribution {
  position: absolute;
  bottom: 10px;
  right: 10px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--bg-panel);
  padding: 4px 10px;
  border-radius: 4px;
  z-index: 100;
}

#attribution a {
  color: var(--gold-lotto);
  text-decoration: none;
}

#attribution a:hover {
  text-decoration: underline;
}

/* Tooltip */
#tooltip {
  position: absolute;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.875rem;
  z-index: 200;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  max-width: 240px;
}

#tooltip.hidden {
  display: none;
}

#tooltip .tt-district {
  font-weight: 600;
  color: var(--gold-lotto);
  margin-bottom: 4px;
}

#tooltip .tt-info {
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Leaflet overrides */
.leaflet-control-attribution {
  display: none !important;
}

.leaflet-control-zoom {
  border: none !important;
  margin-bottom: 40px !important;
}

.leaflet-control-zoom a {
  background: var(--bg-panel) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
}

.leaflet-control-zoom a:hover {
  background: rgba(251, 191, 36, 0.2) !important;
}

.leaflet-bottom.leaflet-right {
  bottom: 30px;
}

/* Responsive */
@media (max-width: 600px) {
  #panel {
    width: calc(100% - 40px);
    top: auto;
    bottom: 20px;
    left: 20px;
    padding: 16px;
  }

  .title {
    font-size: 1.25rem;
  }

  #stats {
    gap: 12px;
  }

  .stat-value {
    font-size: 1.5rem;
  }
}

/* Ripple Animation Keyframes (for CSS fallback) */
@keyframes ripple-expand {
  0% {
    transform: scale(0);
    opacity: 0.8;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}

/* Energy Orb Glow */
.energy-orb {
  animation: orb-pulse 2s ease-in-out infinite;
}

@keyframes orb-pulse {
  0%, 100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}

/* [H04] Accessibility Focus Styles */
.energy-orb-core:focus {
  outline: 2px solid var(--gold-lotto);
  outline-offset: 4px;
}

.mode-btn:focus,
#play-btn:focus,
#theme-btn:focus {
  outline: 2px solid var(--gold-lotto);
  outline-offset: 2px;
}

#timeline-slider:focus {
  outline: 2px solid var(--gold-lotto);
  outline-offset: 2px;
}

.legend-item input[type="checkbox"]:focus {
  outline: 2px solid var(--gold-lotto);
  outline-offset: 2px;
}

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--gold-lotto);
  color: var(--bg-dark);
  padding: 8px 16px;
  z-index: 1000;
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 0;
}

/* [M08] Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.3s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(251, 191, 36, 0.2);
  border-top-color: var(--gold-lotto);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* [H01] Error Message */
.error-message {
  text-align: center;
  color: var(--gold-power);
  padding: 20px;
}

.error-message h2 {
  font-size: 3rem;
  margin-bottom: 16px;
}

.error-message p {
  font-size: 1rem;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.error-message button {
  margin-top: 16px;
  padding: 10px 24px;
  background: var(--gold-lotto);
  border: none;
  border-radius: 6px;
  color: var(--bg-dark);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.error-message button:hover {
  background: var(--gold-power);
}
