*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0f1923;
  --bg-secondary: #1a2634;
  --bg-tertiary: #243447;
  --text-primary: #e8edf2;
  --text-secondary: #8899aa;
  --accent: #e85d26;
  --accent-dim: #cc3700;
  --border: #2a3a4a;
  --chart-bg: #1a2634;
}

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

#app {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 1fr auto;
  height: 100vh;
  gap: 0;
}

/* Sidebar */
.sidebar {
  grid-row: 1 / 3;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.sidebar h1 span {
  color: var(--accent);
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* Time Controls */
.time-controls {
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 16px;
}

.time-display {
  text-align: center;
  margin-bottom: 16px;
}

.time-display .hour {
  font-size: 48px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1;
}

.time-display .label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.slider-container {
  margin-bottom: 16px;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-primary);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-primary);
  cursor: pointer;
  transition: transform 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

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

.play-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.play-controls button {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.play-controls button:hover {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

.play-controls button.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

/* View Toggle */
.view-toggle {
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 16px;
}

.toggle-buttons {
  display: flex;
  gap: 4px;
  background: var(--bg-primary);
  border-radius: 8px;
  padding: 3px;
}

.toggle-buttons button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.toggle-buttons button.active {
  background: var(--accent);
  color: var(--bg-primary);
}

/* Legend */
.legend {
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 16px;
}

.legend-gradient {
  height: 12px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
}

/* Ward Info */
.ward-info {
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 16px;
}

.ward-info .ward-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.ward-info .ward-name-jp {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.ward-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat {
  background: var(--bg-primary);
  border-radius: 8px;
  padding: 10px;
}

.stat .stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.stat .stat-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.ward-info.empty {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

/* Map */
#map {
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  height: 100%;
}

/* Chart Panel */
.chart-panel {
  grid-column: 2;
  grid-row: 2;
  background: var(--chart-bg);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  height: 200px;
  display: flex;
  flex-direction: column;
}

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

.chart-panel .chart-title {
  font-size: 13px;
  font-weight: 600;
}

.chart-panel .chart-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
}

#chart-container {
  flex: 1;
  width: 100%;
  min-height: 0;
}

#chart-container svg {
  width: 100%;
  height: 100%;
}

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  font-size: 13px;
}

/* Tooltip */
.map-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  z-index: 1000;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  max-width: 220px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.map-tooltip.visible {
  opacity: 1;
}

.map-tooltip .tooltip-name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 2px;
}

.map-tooltip .tooltip-jp {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 8px;
}

.map-tooltip .tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 4px;
}

.map-tooltip .tooltip-label {
  color: var(--text-secondary);
}

.map-tooltip .tooltip-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.4s ease;
}

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

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

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

/* Responsive */
@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  .sidebar {
    grid-row: 1;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
    gap: 12px;
    overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar > * {
    flex: 1;
    min-width: 200px;
  }

  #map {
    grid-column: 1;
    grid-row: 2;
    min-height: 400px;
  }

  .chart-panel {
    grid-column: 1;
    grid-row: 3;
  }
}
