:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --surface: #fffaf0;
  --ink: #12252a;
  --muted: #5d6b6f;
  --line: #d7cdb9;
  --brand: #0d5c63;
  --brand-dark: #083f45;
  --accent: #d17b38;
  --good: #236f4d;
  --shadow: 0 18px 48px rgba(19, 35, 39, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(13, 92, 99, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(209, 123, 56, 0.18), transparent 32%),
    var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
}

.calculator {
  width: min(100%, 440px);
  background: var(--surface);
  border: 1px solid rgba(13, 92, 99, 0.12);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow,
h1,
h2,
p {
  margin: 0;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  font-size: 2rem;
  line-height: 1.05;
}

h2 {
  font-size: 1rem;
}

.icon-button {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border: 0;
  border-radius: 50%;
  background: #e7f0ec;
  color: var(--brand);
  display: grid;
  place-items: center;
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.field-grid {
  display: grid;
  gap: 12px;
}

.money-field,
.custom-tip,
.splitter {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.input-wrap {
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  padding: 0 16px;
  color: var(--muted);
}

.input-wrap:focus-within,
.custom-tip input:focus,
.stepper:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(13, 92, 99, 0.13);
}

.input-wrap input,
.custom-tip input,
.stepper input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.6rem;
  font-weight: 800;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

input[type="number"] {
  appearance: textfield;
}

.control-group {
  margin-top: 20px;
}

.section-heading,
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.custom-tip {
  width: 112px;
}

.custom-tip span {
  text-align: right;
}

.custom-tip input {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  padding: 0 10px;
  font-size: 1rem;
  text-align: right;
}

.tip-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.tip-button {
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--brand-dark);
  font-size: 1rem;
  font-weight: 850;
}

.tip-button.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.settings-row {
  margin-top: 20px;
  align-items: end;
}

.toggle {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
}

.toggle input {
  position: absolute;
  opacity: 0;
}

.toggle-track {
  width: 54px;
  height: 30px;
  border-radius: 999px;
  background: #d8dddb;
  padding: 3px;
  transition: background 160ms ease;
}

.toggle-track::after {
  content: "";
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
  transition: transform 160ms ease;
}

.toggle input:checked + .toggle-track {
  background: var(--good);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(24px);
}

.stepper {
  height: 48px;
  width: 152px;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
}

.stepper button {
  border: 0;
  background: #e7f0ec;
  color: var(--brand-dark);
  font-size: 1.3rem;
  font-weight: 900;
}

.stepper input {
  text-align: center;
  font-size: 1.1rem;
}

.results {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.primary-result {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
}

.primary-result span,
.result-grid span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.primary-result strong {
  color: var(--brand-dark);
  font-size: 2.7rem;
  line-height: 1;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.result-grid div {
  min-height: 82px;
  display: grid;
  align-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  padding: 12px;
}

.result-grid strong {
  font-size: 1.25rem;
}

@media (min-width: 620px) {
  .field-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 360px) {
  .calculator {
    padding: 16px;
  }

  .settings-row,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .custom-tip,
  .stepper {
    width: 100%;
  }

  .custom-tip span {
    text-align: left;
  }
}
