:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-strong: #059669;
  --accent-soft: rgba(16, 185, 129, 0.18);
  --line: #f59e0b;
  --line-2: #38bdf8;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --text: #0f172a;
    --muted: #64748b;
    --shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inputs, .results, .breakdown, .display-options, .chart-section, .inflation-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px 12px;
  box-shadow: var(--shadow);
}

.inputs { display: flex; flex-direction: column; gap: 8px; }
.inflation-section { display: flex; flex-direction: column; }

.field { display: flex; flex-direction: column; gap: 2px; }
.field-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.field label { font-size: 0.92rem; color: var(--muted); font-weight: 500; }

.value-wrap {
  display: inline-flex; align-items: center;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 2px 8px;
  gap: 2px;
  transition: border-color 0.15s;
}
.value-wrap:focus-within { border-color: var(--accent); }
.value-wrap .suffix { color: var(--muted); font-size: 0.95rem; }

.value-wrap input[type="number"] {
  width: 110px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  text-align: right;
  padding: 4px 4px;
  -moz-appearance: textfield;
}
.value-wrap input[type="number"]::-webkit-outer-spin-button,
.value-wrap input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.value-wrap input.invalid { color: var(--danger); }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px;
  background: transparent; cursor: pointer;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; background: var(--surface-2); border-radius: 999px; }
input[type="range"]::-moz-range-track { height: 6px; background: var(--surface-2); border-radius: 999px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface);
  margin-top: -8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

.field-select { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field-select label { flex: 0 0 auto; }
.field-select select {
  appearance: none; -webkit-appearance: none;
  background: var(--surface-2); color: var(--text);
  border: 1px solid transparent; border-radius: 10px;
  padding: 6px 28px 6px 10px; font-size: 0.95rem; font-weight: 600;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath d='M5 8l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
.field-select select:focus { outline: none; border-color: var(--accent); }

.display-options { display: flex; flex-direction: column; gap: 6px; }
.switch {
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; user-select: none;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  position: relative; flex: 0 0 auto;
  width: 40px; height: 22px;
  background: var(--surface-2);
  border-radius: 999px;
  transition: background 0.18s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--text); opacity: 0.55;
  transition: transform 0.18s, background 0.18s, opacity 0.18s;
}
.switch input:checked + .switch-track { background: var(--accent-soft); }
.switch input:checked + .switch-track::after {
  transform: translateX(18px);
  background: var(--accent); opacity: 1;
}
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.switch-label { font-size: 0.95rem; }
.switch-label small { color: var(--muted); font-size: 0.8rem; margin-left: 4px; }

.results { display: flex; flex-direction: column; gap: 8px; }
.result {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface-2); border-radius: 12px; padding: 10px 14px;
}
.result-label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.result-value { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }
.result-final {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
}
.result-final .result-label { color: rgba(255,255,255,0.85); }
.result-final .result-value { font-size: 1.6rem; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.chart-section { display: flex; flex-direction: column; gap: 6px; }
.chart-wrap { width: 100%; }
canvas#chart { width: 100%; display: block; }
.legend {
  display: flex; flex-wrap: wrap; gap: 12px 16px;
  font-size: 0.85rem; color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.section-title { margin: 0 0 6px; font-size: 0.95rem; color: var(--muted); font-weight: 600; }
.table-wrap {
  max-height: 320px; overflow: auto;
  border-radius: 10px; background: var(--surface-2);
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td {
  text-align: right; padding: 6px 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}
th:first-child, td:first-child { text-align: left; }
thead th {
  position: sticky; top: 0; background: var(--surface-2);
  color: var(--muted); font-weight: 600;
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
}
tbody tr:last-child td { border-bottom: none; }

.app-footer { text-align: center; color: var(--muted); }

[hidden] { display: none !important; }

@media (max-width: 380px) {
  .result-grid { grid-template-columns: 1fr; }
  .value-wrap input[type="number"] { width: 90px; }
}
