:root {
  --bg-base: #f8fafc;
  --bg-surface: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --accent: #1e3a8a;
  --accent-hover: #1e40af;
  --accent2: #16a34a;
  --accent-soft: #eff6ff;
  --border-color: #e2e8f0;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font-heading: 'Lora', 'Cambria', 'Georgia', serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
}

main {
  width: 100%;
  max-width: 480px;
  text-align: center;
}

.top-bar {
  width: 100%;
  max-width: 480px;
  padding-bottom: 0.5rem;
}

.back-home-link {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
}

.back-home-link:hover {
  color: var(--accent);
}

.site-footer {
  width: 100%;
  max-width: 480px;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.875rem;
}

.site-footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent);
}

h1 {
  font-family: var(--font-heading);
  font-size: 1.75rem;
}

#duration {
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
}

button {
  font-size: 1.1rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  margin: 0.5rem;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#error {
  color: #b91c1c;
}

#phase {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

#gauge {
  width: 100%;
  max-width: 220px;
  margin: 0.5rem auto 0;
  display: block;
}

#gauge-needle {
  transition: transform 0.3s ease-out;
}

.gauge-label {
  font-size: 11px;
  fill: var(--text-secondary);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

#gauge-unit {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#live-reading {
  font-size: 2rem;
  font-weight: 700;
  min-height: 2.5rem;
}

#chart {
  width: 100%;
  max-width: 320px;
  height: 110px;
  display: block;
  margin: 0 auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

#chart-legend {
  display: flex;
  justify-content: center;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 0.25rem;
  vertical-align: middle;
}

.swatch.download {
  background: var(--accent);
}

.swatch.upload {
  background: var(--accent2);
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-top: 1rem;
}

#results dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
  text-align: left;
}

#results dt {
  font-weight: 600;
  color: var(--text-secondary);
}

#results dd {
  margin: 0;
}

#quality {
  margin: 1rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  font-weight: 600;
  color: var(--accent);
}

#history {
  margin-top: 1rem;
  text-align: left;
}

#history h2 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
}

#history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#history-list li {
  background: var(--accent-soft);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
