:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111;
  color: #f5f5f3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(48px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.calculator {
  width: min(100%, 400px);
  margin: 0 auto;
}

h1 {
  margin: 0 0 48px;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

h2, label {
  display: block;
  margin: 0;
  color: #aaa;
  font-size: 0.9rem;
  font-weight: 500;
}

.amount-field, .percent-field {
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid #666;
}

.amount-field {
  margin-top: 8px;
  font-size: clamp(2.5rem, 12vw, 3.25rem);
  font-weight: 400;
}

.amount-field:focus-within, .percent-field:focus-within { border-color: #fff; }

input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-variant-numeric: tabular-nums;
}

input::placeholder { color: #666; opacity: 1; }
.amount-field input { height: 78px; }

.percentage { margin-top: 42px; }
h2 { margin-bottom: 14px; }
.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
button { font: inherit; cursor: pointer; }

.presets button {
  min-height: 52px;
  border: 1px solid #666;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  font-size: 1rem;
  font-weight: 500;
}

.presets button[aria-pressed="true"] { border-color: #f5f5f3; background: #f5f5f3; color: #111; }
.presets button:focus-visible, .reset:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.custom-field { margin-top: 22px; }
.custom-field[hidden] { display: none; }
.percent-field { width: 132px; margin-top: 6px; padding-right: 4px; font-size: 1.5rem; }
.percent-field input { height: 48px; }

.results { margin-top: 42px; border-top: 1px solid #444; }
.result-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0;
}

.result-row span { color: #aaa; }
.result-row output {
  min-width: 0;
  font-size: 1.5rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: right;
  overflow-wrap: anywhere;
}

.result-row.total { border-top: 1px solid #444; }
.result-row.total span { color: #f5f5f3; }
.result-row.total output { font-size: clamp(2.2rem, 10vw, 2.85rem); font-weight: 600; letter-spacing: -0.03em; }

.reset {
  display: block;
  margin: 28px auto 0;
  padding: 12px 16px;
  border: 0;
  background: transparent;
  color: #aaa;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (min-width: 700px) {
  body { padding-top: 11vh; }
}
