:root {
  color-scheme: light dark;
  --bg: #eef4f2;
  --surface: #ffffff;
  --ink: #142124;
  --muted: #607276;
  --line: #cbd9d7;
  --primary: #0f6b73;
  --primary-deep: #123a42;
  --control-ink: #1a5d66;
  --accent: #d9753b;
  --button: #f6faf9;
  --button-pressed: #dce9e7;
  --shadow: 0 18px 40px rgba(18, 58, 66, 0.16);
  --stepper-button: clamp(38px, 10vw, 44px);
  font-family: Inter, Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  align-items: center;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  justify-content: center;
  padding: 0;
}

button,
output {
  font: inherit;
}

button {
  border: 0;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  gap: clamp(8px, 1.5dvh, 14px);
  grid-template-rows: auto minmax(0, 1fr);
  height: 100svh;
  height: 100dvh;
  min-height: 0;
  max-width: 460px;
  overflow: hidden;
  padding: clamp(12px, 2dvh, 18px);
  width: 100%;
}

.summary {
  display: grid;
  gap: clamp(8px, 1.5dvh, 14px);
  min-height: 0;
}

.brand-row {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  min-height: clamp(34px, 4.7dvh, 42px);
}

.brand-lockup {
  align-items: center;
  display: flex;
  gap: 10px;
  min-width: 0;
}

.app-icon {
  height: clamp(32px, 4.3dvh, 38px);
  width: clamp(32px, 4.3dvh, 38px);
}

h1 {
  font-size: 1.35rem;
  line-height: 1;
  margin: 0;
}

.icon-button {
  align-items: center;
  aspect-ratio: 1;
  background: var(--button);
  border: 1px solid var(--line);
  color: var(--control-ink);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 1rem;
  font-weight: 850;
  height: clamp(34px, 4.7dvh, 42px);
  justify-content: center;
  line-height: 1;
}

.icon-button:active,
.portfolio-button:active,
.support-button:active {
  background: var(--button-pressed);
  transform: translateY(1px);
}

.bill-panel {
  background: var(--primary-deep);
  color: #ffffff;
  display: grid;
  gap: 4px;
  padding: clamp(12px, 2dvh, 18px);
}

.label {
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.bill-panel .label {
  color: #b9d2d4;
}

.bill {
  font-size: clamp(2.5rem, 13vw, 4.3rem);
  font-weight: 850;
  line-height: 1;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.control {
  border: 1px solid var(--line);
  display: grid;
  gap: clamp(6px, 1dvh, 10px);
  padding: clamp(8px, 1.4dvh, 12px);
}

/* Same columns as the stepper so the toggle sits over the value, not over + or −. */
.control-head {
  align-items: center;
  display: grid;
  grid-template-columns: var(--stepper-button) 1fr var(--stepper-button);
}

.unit-toggle {
  display: flex;
  justify-self: center;
  /* Keeps the bigger tap targets from making the Tip control taller than Split. */
  margin-block: -7px;
}

.unit-toggle button {
  background: var(--button);
  border: 1px solid var(--line);
  color: var(--control-ink);
  font-size: 0.85rem;
  font-weight: 850;
  height: 28px;
  width: 28px;
}

.unit-toggle button + button {
  border-left: 0;
}

.unit-toggle button[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.stepper {
  align-items: center;
  display: grid;
  grid-template-columns: var(--stepper-button) 1fr var(--stepper-button);
  min-height: clamp(40px, 5.4dvh, 48px);
}

.stepper button {
  -webkit-touch-callout: none;
  aspect-ratio: 1;
  background: var(--button);
  border: 1px solid var(--line);
  color: var(--control-ink);
  font-size: 1.5rem;
  font-weight: 800;
}

.stepper button:active,
.keypad button:active {
  background: var(--button-pressed);
  transform: translateY(1px);
}

.stepper output {
  font-size: 1.45rem;
  font-weight: 850;
  text-align: center;
}

.totals {
  border-top: 1px solid var(--line);
  display: grid;
  gap: clamp(6px, 1dvh, 10px);
  padding-top: clamp(8px, 1.4dvh, 12px);
}

.totals > div {
  align-items: baseline;
  display: flex;
  justify-content: space-between;
  min-height: clamp(28px, 3.9dvh, 34px);
}

.totals output {
  font-size: 1.42rem;
  font-weight: 850;
}

.keypad {
  display: grid;
  gap: clamp(8px, 1.2dvh, 10px);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  min-height: 0;
}

.keypad button {
  background: var(--button);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: clamp(1.75rem, 8vw, 2.45rem);
  font-weight: 850;
  min-height: 0;
}

.keypad .utility {
  color: var(--primary);
  font-size: clamp(1rem, 4vw, 1.2rem);
  text-transform: uppercase;
}

.keypad #reset {
  color: var(--accent);
}

.about-dialog {
  background: transparent;
  border: 0;
  color: inherit;
  margin: auto auto 0;
  max-width: 460px;
  padding: 0;
  width: 100%;
}

.about-dialog::backdrop {
  background: rgba(7, 17, 19, 0.58);
}

.about-sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  padding: 18px;
  position: relative;
}

.about-close {
  height: 38px;
  justify-self: end;
  position: absolute;
  right: 18px;
  top: 18px;
}

.about-heading {
  align-items: start;
  display: grid;
  gap: 12px;
  grid-template-columns: 44px minmax(0, 1fr);
  padding-right: 48px;
}

.about-icon {
  height: 44px;
  width: 44px;
}

.about-heading h2 {
  font-size: 1.2rem;
  line-height: 1.1;
  margin: 0 0 6px;
}

.about-heading p,
.about-meta {
  color: var(--muted);
  margin: 0;
}

.about-heading p {
  line-height: 1.45;
}

.about-meta {
  text-align: center;
  font-weight: 700;
}

.about-links {
  display: grid;
  gap: 10px;
}

.portfolio-button,
.support-button {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  min-height: 48px;
  padding: 0 16px;
  text-decoration: none !important;
}

.portfolio-button {
  background: var(--primary-deep);
  border: 1px solid var(--primary-deep);
  color: #ffffff !important;
  gap: 10px;
  font-weight: 800;
}

.portfolio-favicon {
  height: 1em;
  width: 1em;
}

.support-button {
  background: var(--primary-deep);
  border: 1px solid var(--primary-deep);
  color: #ffffff !important;
  font-weight: 800;
}

@media (max-width: 360px) {
  body {
    padding: 0;
  }

  .app {
    gap: 10px;
    padding: 12px;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .keypad {
    gap: 8px;
    grid-template-rows: repeat(4, minmax(62px, 1fr));
  }

  .about-sheet {
    gap: 14px;
    padding: 16px;
  }

  .about-close {
    right: 16px;
    top: 16px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #071113;
    --surface: #102023;
    --ink: #eef7f6;
    --muted: #9fb5b8;
    --line: #294246;
    --button: #152b2f;
    --button-pressed: #203f44;
    --control-ink: #2a7f89;
    --shadow: none;
  }
}
