/* iOS-flavoured theme: system colors, grouped cards, light + dark */
:root {
  color-scheme: light dark;
  --bg: #f2f2f7;            /* systemGroupedBackground */
  --card: #ffffff;          /* secondarySystemGroupedBackground */
  --field: #f2f2f7;
  --text: #000000;
  --muted: rgba(60, 60, 67, 0.6);   /* secondaryLabel */
  --separator: rgba(60, 60, 67, 0.18);
  --grid: rgba(60, 60, 67, 0.12);
  --fill: rgba(120, 120, 128, 0.16);
  --accent: #007aff;        /* systemBlue */
  --up: #ff3b30;            /* systemRed */
  --down: #34c759;          /* systemGreen */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --field: #2c2c2e;
    --text: #ffffff;
    --muted: rgba(235, 235, 245, 0.6);
    --separator: rgba(235, 235, 245, 0.16);
    --grid: rgba(235, 235, 245, 0.12);
    --fill: rgba(120, 120, 128, 0.32);
    --accent: #0a84ff;
    --up: #ff453a;
    --down: #30d158;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 16px)
           calc(env(safe-area-inset-bottom) + 28px) calc(env(safe-area-inset-left) + 16px);
}

main {
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* iOS Large Title */
h1 {
  font-size: 34px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 4px 4px 0;
}

h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 12px;
}

.muted {
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin: 0 0 8px;
}

/* 16px+ font keeps iOS Safari from zooming on focus; 48px stays above the 44px tap floor */
input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--field);
  border: 0;
  border-radius: 12px;
  -webkit-appearance: none;
  appearance: none;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input + label { margin-top: 16px; }

button {
  min-height: 48px;
  padding: 12px 18px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

button:active {
  transform: scale(0.98);
  opacity: 0.88;
}

button.secondary {
  color: var(--accent);
  background: var(--fill);
  font-weight: 500;
}

#entry-form button[type="submit"] {
  display: block;
  width: 100%;
  margin-top: 20px;
}

.row {
  display: flex;
  gap: 12px;
}

.row > button { flex: 1; }

/* Summary: one hero number, two secondary stats side by side */
.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
}

.summary dt:nth-of-type(1) {
  grid-area: 1 / 1 / 2 / -1;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.summary dd:nth-of-type(1) {
  grid-area: 2 / 1 / 3 / -1;
  margin: 2px 0 0;
  font-size: 44px;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.summary dt:nth-of-type(2),
.summary dt:nth-of-type(3) {
  border-top: 1px solid var(--separator);
  margin-top: 20px;
  padding-top: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.summary dt:nth-of-type(2) { grid-area: 3 / 1 / 4 / 3; }
.summary dt:nth-of-type(3) { grid-area: 3 / 3 / 4 / 5; padding-left: 12px; }

.summary dd:nth-of-type(2),
.summary dd:nth-of-type(3) {
  margin: 4px 0 0;
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.summary dd:nth-of-type(2) { grid-area: 4 / 1 / 5 / 3; }
.summary dd:nth-of-type(3) { grid-area: 4 / 3 / 5 / 5; padding-left: 12px; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  color: var(--accent);
}

.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-weight: 500; }
.chart .line { fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart .area { stroke: none; fill: url(#chart-fill); }
.chart .fill-top { stop-color: var(--accent); stop-opacity: 0.22; }
.chart .fill-bottom { stop-color: var(--accent); stop-opacity: 0; }
.chart .dot { fill: currentColor; stroke: var(--card); stroke-width: 2; }

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

.list li + li { border-top: 1px solid var(--separator); }

.list .date {
  flex: 1;
  font-size: 16px;
  color: var(--text);
}

.list .kg {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* Visually small, but still a 44px hit area */
.list .delete {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border-radius: 999px;
}

.list .delete:active {
  background: var(--fill);
  color: var(--up);
  opacity: 1;
}

.empty {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

@media (min-width: 480px) {
  body { padding-top: 24px; }
}
