:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d1d1b;
  --muted: #7a776f;
  --line: #e4e1d8;
  --accent: #1f7a5a;
  --accent-ink: #ffffff;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141513;
    --card: #1e1f1c;
    --ink: #f1efe8;
    --muted: #9b988f;
    --line: #34352f;
    --accent: #3fbf8c;
    --accent-ink: #0d1a14;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .06);
}
h1 { margin: 0 0 20px; font-size: 1.25rem; letter-spacing: -.01em; }
.label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 8px;
  padding: 0;
}
.field { display: block; margin-bottom: 20px; }
.money {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
  transition: border-color .15s;
}
.money:focus-within { border-color: var(--accent); }
.currency { color: var(--muted); font-size: 1.5rem; margin-right: 6px; }
input {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  outline: none;
  min-width: 0;
}
#bill { flex: 1; font-size: 1.75rem; font-weight: 600; padding: 12px 0; font-variant-numeric: tabular-nums; }
.hint { display: block; min-height: 1.2em; font-size: .8rem; color: #c0392b; margin-top: 4px; }
fieldset { border: 0; margin: 0 0 20px; padding: 0; min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile {
  font: inherit;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  min-height: 52px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.tile:hover { border-color: var(--accent); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.custom { padding: 0 8px; cursor: text; }
.custom input { width: 100%; text-align: center; font-weight: 600; font-size: 1rem; }
.custom input::placeholder { color: var(--muted); font-weight: 500; font-size: .9rem; }
.custom .pct { display: none; }
.custom[aria-checked="true"] .pct { display: inline; }
.custom[aria-checked="true"] input::placeholder { color: inherit; opacity: .6; }
.results {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 4px 16px;
  margin-bottom: 16px;
}
.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 0;
  font-variant-numeric: tabular-nums;
}
.row + .row { border-top: 1px solid var(--line); }
.row small { color: var(--muted); }
.row strong { font-size: 1.25rem; }
.total strong { font-size: 1.75rem; color: var(--accent); }
.reset {
  width: 100%;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 0;
  padding: 10px;
  border-radius: var(--radius);
  cursor: pointer;
}
.reset:hover { color: var(--ink); }
@media (max-width: 340px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
