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

:root {
  --primary-color: #2563eb;
  --secondary-color: #1e40af;
  --accent-color: #3b82f6;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --bg-color: #f8fafc;
  --surface-color: #ffffff;
  --border-color: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1),
    0 4px 6px -4px rgb(0 0 0 / 0.1);
  --border-radius: 8px;
  --transition: all 0.2s ease-in-out;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

body {
  font-family: var(--font-family);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: var(--text-primary);
  line-height: 1.6;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 3rem;
  color: white;
}

.header h1 {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
  font-weight: 300;
}

/* Chart Controls */
.chart-controls {
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 2rem;
}

.temperature-selector h3,
.prefecture-selector h3 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
  font-weight: 600;
}

/* Radio Button Styling */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.radio-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: var(--border-radius);
  transition: var(--transition);
  position: relative;
  font-size: 0.9rem;
}

.radio-label:hover {
  background: #f1f5f9;
}

.radio-label input[type="radio"] {
  display: none;
}

.radio-custom {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-color);
  border-radius: 50%;
  margin-right: 0.5rem;
  position: relative;
  transition: var(--transition);
}

.radio-label input[type="radio"]:checked + .radio-custom {
  border-color: var(--primary-color);
  background: var(--primary-color);
}

.radio-label input[type="radio"]:checked + .radio-custom::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background: white;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* Prefecture Grid */
.prefecture-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.4rem;
  max-height: 200px;
  overflow-y: auto;
  padding: 0.25rem;
}

.prefecture-btn {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  color: var(--text-primary);
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.prefecture-btn:hover {
  border-color: var(--primary-color);
  background: #eff6ff;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.prefecture-btn.clear {
  background: var(--danger-color);
  color: white;
  border-color: var(--danger-color);
}

.prefecture-btn.clear:hover {
  background: #dc2626;
  border-color: #dc2626;
}

/* Chart Section */
.chart-section {
  background: var(--surface-color);
  border-radius: var(--border-radius);
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-lg);
  min-height: 700px;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 500px;
  margin-bottom: 0.5rem;
}

.chart-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.chart-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

/* Loading Spinner */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 400px;
  color: var(--text-secondary);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading.hidden {
  display: none;
}

/* SVG Styling */
svg {
  width: 100%;
  height: auto;
  background: var(--surface-color);
  border-radius: var(--border-radius);
}

.axis {
  font-family: var(--font-family);
}

.axis text {
  fill: var(--text-secondary);
  font-size: 12px;
}

.axis path,
.axis line {
  fill: none;
  stroke: var(--border-color);
  shape-rendering: crispEdges;
}

.grid-line {
  stroke: var(--border-color);
  stroke-opacity: 0.3;
  stroke-dasharray: 2, 2;
}

/* Temperature Lines */
.temp-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.temp-line.mean {
  stroke: var(--success-color);
}

.temp-line.min {
  stroke: var(--primary-color);
}

.temp-line.max {
  stroke: var(--warning-color);
}

/* Period comparison lines */
.temp-line.period-line {
  stroke-width: 3;
}

/* First period - lighter colors (older data should be lighter) */
.temp-line.first-period.mean {
  stroke: #6ee7b7; /* lighter green */
}

.temp-line.first-period.min {
  stroke: #93c5fd; /* lighter blue */
}

.temp-line.first-period.max {
  stroke: #fbbf24; /* lighter orange */
}

/* Last period - darker colors (recent data should be darker) */
.temp-line.last-period.mean {
  stroke: #059669; /* darker green */
}

.temp-line.last-period.min {
  stroke: #1d4ed8; /* darker blue */
}

.temp-line.last-period.max {
  stroke: #d97706; /* darker orange */
}

/* Year lines during animation */
.temp-line.year-line {
  stroke-width: 1.5;
  opacity: 0.7;
}

/* Legend styles */
.legend-bg {
  rx: 4;
  ry: 4;
}

/* Message */
.message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 1rem 2rem;
  border-radius: var(--border-radius);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

.message.show {
  opacity: 1;
}

/* Footer */
.footer {
  text-align: center;
  color: white;
  opacity: 0.8;
  font-size: 0.9rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
  .chart-controls {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .header h1 {
    font-size: 2.5rem;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  .header h1 {
    font-size: 2rem;
  }

  .prefecture-grid {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 0.3rem;
  }

  .prefecture-btn {
    padding: 0.3rem;
    font-size: 0.7rem;
    min-height: 28px;
  }

  .chart-section {
    padding: 1.5rem;
  }

  .chart-container {
    height: 400px;
  }

  .chart-controls {
    gap: 1rem;
  }
}

@media (max-width: 480px) {
  .radio-group {
    flex-direction: column;
    gap: 0.5rem;
  }

  .radio-label {
    padding: 0.4rem;
    font-size: 0.8rem;
  }

  .prefecture-grid {
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    max-height: 150px;
  }

  .prefecture-btn {
    font-size: 0.65rem;
    min-height: 26px;
  }

  .chart-container {
    height: 350px;
  }
}
