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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
}

header {
  text-align: center;
  padding: 2rem 1rem 1rem;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 1px solid #334155;
}

header h1 {
  font-size: 2rem;
  color: #f59e0b;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: #94a3b8;
  font-size: 1rem;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  position: relative;
}

/* Steps */
.step {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  margin-bottom: 1.5rem;
  overflow: hidden;
  transition: opacity 0.3s;
}

.step.hidden {
  display: none;
}

.step-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: #1a2332;
  border-bottom: 1px solid #334155;
}

.step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f59e0b;
  color: #0f172a;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.step-header h2 {
  font-size: 1.15rem;
  color: #f1f5f9;
}

.step-content {
  padding: 0.75rem 1.25rem 1.25rem;
}

/* Print-only elements */
.print-only { display: none; }

/* Step helper text */
.step-hint {
  color: #64748b;
  font-size: 0.825rem;
  margin-top: 0;
  margin-bottom: 0.75rem;
}

/* Address Input */
.input-group {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.input-group input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid #475569;
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 1rem;
}

.input-group input:focus {
  outline: none;
  border-color: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

button {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  background: #f59e0b;
  color: #0f172a;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

button:hover {
  background: #d97706;
}

button:disabled {
  background: #475569;
  color: #94a3b8;
  cursor: not-allowed;
}

#start-over-btn {
  background: #334155;
  color: #e2e8f0;
}

#start-over-btn:hover {
  background: #475569;
}

#location-btn {
  background: transparent;
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.4);
  font-size: 1.1rem;
  padding: 0 0.65rem;
  flex-shrink: 0;
  min-width: 44px;
}

#location-btn:hover:not(:disabled) {
  background: rgba(245, 158, 11, 0.08);
}

#location-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: transparent;
}

#map-container {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #334155;
}

#map {
  width: 100%;
  height: 400px;
  background: #1a2332;
}

.error {
  color: #ef4444;
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(239, 68, 68, 0.1);
  border-radius: 6px;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.notice {
  color: #fbbf24;
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: rgba(251, 191, 36, 0.08);
  border-radius: 6px;
  border: 1px solid rgba(251, 191, 36, 0.3);
  font-size: 0.9rem;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* Roof segments */
#roof-segments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.segment-card {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 1rem;
}

.segment-card.south-facing {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.05);
}

.segment-card h4 {
  color: #94a3b8;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.segment-card .value {
  font-size: 1.1rem;
  color: #f1f5f9;
  font-weight: 600;
}

.segment-card .detail {
  font-size: 0.85rem;
  color: #64748b;
  margin-top: 0.25rem;
}

.segment-card .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 0.5rem;
}

.badge.excellent { background: #166534; color: #4ade80; }
.badge.good { background: #854d0e; color: #fbbf24; }
.badge.fair { background: #7c2d12; color: #fb923c; }
.badge.poor { background: #7f1d1d; color: #f87171; }

/* Sun path */
#sun-path-container {
  margin-top: 1rem;
}

#sun-path-container h3 {
  margin-bottom: 0.75rem;
  color: #f1f5f9;
}

#sun-path-canvas {
  width: 100%;
  max-width: 600px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
}

.chart-caption {
  color: #64748b;
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

/* Configuration grid */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.config-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.config-item label {
  font-size: 0.85rem;
  color: #94a3b8;
  font-weight: 500;
}

.config-item input,
.config-item select {
  padding: 0.6rem 0.75rem;
  border: 1px solid #475569;
  border-radius: 6px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 0.95rem;
}

.config-item input:focus,
.config-item select:focus {
  outline: none;
  border-color: #f59e0b;
}

.config-item .hint {
  font-size: 0.75rem;
  color: #64748b;
}

#calculate-btn {
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
}

/* Results */
.results-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.result-card {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 1.25rem;
  text-align: center;
}

.result-card.highlight {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.05);
}

.result-card h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #94a3b8;
  margin-bottom: 0.5rem;
}

.result-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: #f1f5f9;
}

.result-card.highlight .result-value {
  color: #f59e0b;
}

.result-unit {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 0.25rem;
}

/* Monthly chart */
#monthly-chart-container {
  margin-bottom: 2rem;
}

#monthly-chart-container h3 {
  margin-bottom: 0.75rem;
  color: #f1f5f9;
}

#monthly-chart {
  width: 100%;
  max-width: 700px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
}

/* Table */
#detailed-results h3 {
  margin-bottom: 0.75rem;
  color: #f1f5f9;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  background: #0f172a;
  padding: 0.75rem;
  text-align: left;
  color: #94a3b8;
  font-weight: 600;
  border-bottom: 2px solid #334155;
}

tbody td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #1e293b;
}

tbody tr:hover {
  background: rgba(245, 158, 11, 0.03);
}

/* Loading */
#loading {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #334155;
  border-top-color: #f59e0b;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

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

#loading p {
  color: #94a3b8;
  font-size: 1rem;
}

/* Guide & FAQ content sections */
#guide h3, #faq h3 {
  color: #f59e0b;
  font-size: 1rem;
  margin: 1.5rem 0 0.5rem;
}

#guide h3:first-child {
  margin-top: 0;
}

#guide p {
  font-size: 0.9rem;
  line-height: 1.75;
  color: #94a3b8;
  margin-bottom: 0.5rem;
}

/* ============================================================
   Site Navigation
   ============================================================ */

.site-nav {
  background: #1a2332;
  border-bottom: 1px solid #334155;
  padding: 0 1rem;
  display: flex;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.site-nav::-webkit-scrollbar { display: none; }

.site-nav a {
  color: #94a3b8;
  text-decoration: none;
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.site-nav a:hover,
.site-nav a.active {
  color: #f59e0b;
  border-bottom-color: #f59e0b;
}

/* ============================================================
   Article Pages
   ============================================================ */

.article-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2.5rem 1rem 4rem;
}

.article-container h1 {
  font-size: 1.7rem;
  color: #f1f5f9;
  margin-bottom: 0.6rem;
  line-height: 1.3;
}

.article-meta {
  color: #64748b;
  font-size: 0.82rem;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #334155;
}

.article-container h2 {
  color: #f59e0b;
  font-size: 1.15rem;
  margin: 2rem 0 0.6rem;
}

.article-container h3 {
  color: #e2e8f0;
  font-size: 1rem;
  margin: 1.25rem 0 0.4rem;
}

.article-container p {
  color: #94a3b8;
  line-height: 1.8;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.article-container ul,
.article-container ol {
  color: #94a3b8;
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.article-container li {
  line-height: 1.75;
  margin-bottom: 0.3rem;
  font-size: 0.95rem;
}

.article-container strong {
  color: #e2e8f0;
}

.article-container a {
  color: #f59e0b;
}

.article-cta {
  background: rgba(245, 158, 11, 0.07);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 10px;
  padding: 1.75rem 1.5rem;
  margin-top: 3rem;
  text-align: center;
}

.article-cta p {
  color: #e2e8f0 !important;
  font-size: 1rem !important;
  margin-bottom: 1.1rem;
}

.article-cta a.cta-btn {
  display: inline-block;
  background: #f59e0b;
  color: #0f172a;
  text-decoration: none;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1rem;
  transition: background 0.2s;
}

.article-cta a.cta-btn:hover {
  background: #d97706;
}

.data-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.25rem 0;
}

.article-container .data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.article-container .data-table th {
  background: #0f172a;
  padding: 0.65rem 0.75rem;
  text-align: left;
  color: #94a3b8;
  font-weight: 600;
  border-bottom: 2px solid #334155;
  white-space: nowrap;
}

.article-container .data-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #1e293b;
  color: #94a3b8;
}

.article-container .data-table tr:hover td {
  background: rgba(245, 158, 11, 0.03);
}

.article-container .data-table .hi {
  color: #f59e0b;
  font-weight: 600;
}

.article-container .data-table .good {
  color: #4ade80;
}

.article-container .data-table .mid {
  color: #fbbf24;
}

.article-container .data-table .low {
  color: #f87171;
}

.callout {
  background: #1e293b;
  border-left: 3px solid #f59e0b;
  padding: 0.9rem 1rem;
  border-radius: 0 6px 6px 0;
  margin: 1.25rem 0;
}

.callout p {
  margin-bottom: 0 !important;
}

/* Footer */
footer {
  text-align: center;
  padding: 2rem 1rem;
  color: #64748b;
  font-size: 0.85rem;
  border-top: 1px solid #1e293b;
}

footer a {
  color: #f59e0b;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ============================================================
   Responsive — mobile-first breakpoints
   ============================================================ */

/* Make table scrollable on small screens */
#detailed-results {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Ensure canvases never overflow */
canvas {
  max-width: 100%;
  height: auto;
}

/* Touch-friendly minimum tap targets */
button,
.config-item input,
.config-item select,
.input-group input {
  min-height: 44px;
}

/* ---- Large desktop (1280px+) ---- */
@media (min-width: 1280px) {
  main {
    max-width: 1100px;
  }

  .config-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .results-summary {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* ---- Standard desktop (1024px–1279px) ---- */
@media (min-width: 1024px) and (max-width: 1279px) {
  .results-summary {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ---- Tablet landscape (768px–1023px) ---- */
@media (max-width: 1023px) {
  .results-summary {
    grid-template-columns: repeat(3, 1fr);
  }

  .config-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ---- Tablet portrait (600px–767px) ---- */
@media (max-width: 767px) {
  header {
    padding: 1.25rem 1rem 0.75rem;
  }

  header h1 {
    font-size: 1.6rem;
  }

  main {
    padding: 1rem 0.75rem;
  }

  .step-content {
    padding: 1rem;
  }

  .config-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .results-summary {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  #map {
    height: 320px;
  }

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

/* ---- Mobile (< 600px) ---- */
@media (max-width: 599px) {
  header h1 {
    font-size: 1.35rem;
  }

  .subtitle {
    font-size: 0.875rem;
  }

  main {
    padding: 0.75rem 0.25rem;
  }

  .step {
    border-radius: 8px;
    margin-bottom: 1rem;
  }

  .step-content {
    padding: 0.625rem;
  }

  .input-group {
    flex-direction: row;
    gap: 0.3rem;
  }

  #location-btn {
    padding: 0 0.45rem;
    min-width: 38px;
  }

  #analyze-btn {
    padding: 0.75rem 0.5rem;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  #map {
    height: 260px;
  }

  .config-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem;
  }

  .config-item label {
    font-size: 0.8rem;
  }

  .results-summary {
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem;
  }

  .result-card {
    padding: 0.875rem 0.625rem;
  }

  .result-value {
    font-size: 1.35rem;
  }

  .result-card h3 {
    font-size: 0.7rem;
  }

  #roof-segments {
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem;
  }

  table {
    font-size: 0.8rem;
  }

  thead th,
  tbody td {
    padding: 0.5rem;
  }

  .chart-caption {
    font-size: 0.7rem;
  }

  footer {
    padding: 1.25rem 0.75rem;
    font-size: 0.8rem;
  }
}

/* ---- Very small mobile (< 400px) ---- */
@media (max-width: 399px) {
  header h1 {
    font-size: 1.2rem;
  }

  .config-grid {
    grid-template-columns: 1fr;
  }

  .results-summary {
    grid-template-columns: 1fr 1fr;
  }

  #roof-segments {
    grid-template-columns: 1fr;
  }

  #map {
    height: 220px;
  }

  .result-value {
    font-size: 1.2rem;
  }
}

/* ---- Print / Export PDF ---- */
#print-btn {
  margin-left: auto;
  background: transparent;
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.4);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.3rem 0.7rem;
  white-space: nowrap;
}

#print-btn:hover {
  background: rgba(245, 158, 11, 0.08);
}

@media print {
  /* Light background for readability */
  body { background: #fff; color: #0f172a; }

  /* Hide chrome, loading, and action buttons */
  header, footer, #loading { display: none !important; }
  #print-btn, #start-over-btn, #analyze-btn, #location-btn, #calculate-btn { display: none !important; }
  #faq { display: none !important; }
  #guide { display: none !important; }

  /* Show all steps that have content */
  .step.hidden { display: block !important; }
  /* Show print-only elements */
  .print-only { display: block !important; color: #0f172a; font-size: 0.95rem; font-weight: 500; margin-bottom: 0.5rem; }

  /* Hide address input UI — address shown via print-only element */
  #map-container, .input-group, #address-error, #address-notice, .step-hint { display: none !important; }

  .step {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 1rem;
    break-inside: avoid;
  }

  .step-header { background: #f8fafc; border-bottom: 1px solid #e2e8f0; }
  .step-number { background: #f59e0b; color: #0f172a; }
  .step-header h2 { color: #0f172a; }

  .result-card, .segment-card {
    background: #f8fafc;
    border-color: #e2e8f0;
    break-inside: avoid;
  }

  .result-card.highlight, .segment-card.south-facing { border-color: #f59e0b; }
  .result-value, .segment-card .value { color: #0f172a; }
  .result-card.highlight .result-value { color: #d97706; }
  .result-unit, .segment-card .detail, .segment-card h4 { color: #64748b; }

  .config-item label { color: #475569; }
  .config-item input, .config-item select {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #0f172a;
  }

  table { font-size: 0.8rem; }
  thead th { background: #f1f5f9; color: #475569; }
  tbody td { border-bottom-color: #e2e8f0; color: #0f172a; }

  #sun-path-container h3, #monthly-chart-container h3, #detailed-results h3 { color: #0f172a; }
  .chart-caption { color: #64748b; }

  canvas { max-width: 100%; }
}
