:root {
  --bg: #182427;
  --panel: #1f2e31;
  --panel-raised: #263a3e;
  --border: #33474b;

  --text: #f3ece4;
  --text-muted: #8fa3a0;

  --add: #e8a33d;
  --add-press: #cf8c2c;
  --subtract: #5c8a99;
  --subtract-press: #4a717e;
  --danger: #b85c5c;
  --danger-press: #9c4a4a;

  --radius: 14px;
  --gap: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ---------- Display ---------- */

.display {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.display__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.display__label {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.display__reset {
  font-size: 13px;
  color: var(--danger);
  padding: 6px 8px;
  margin: -6px -8px;
  border-radius: 8px;
}

.display__reset:active {
  background: rgba(184, 92, 92, 0.15);
}

.display__total {
  margin-top: 6px;
  font-size: clamp(32px, 9vw, 44px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1.15;
  word-break: break-word;
}

.display__total.is-negative {
  color: var(--danger);
}

/* ---------- Entry chips ---------- */

.entry {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}

.entry__chip {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: background 0.12s, border-color 0.12s;
}

.entry__chip.is-active {
  background: var(--panel-raised);
  border-color: var(--add);
}

.entry__value {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.entry__chip.is-active .entry__value {
  color: var(--add);
}

.entry__label {
  font-size: 11px;
  color: var(--text-muted);
}

/* ---------- Keypad ---------- */

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  margin-top: 4px;
}

.key {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 24px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  padding: 18px 0;
  min-height: 56px;
}

.key:active {
  background: var(--panel-raised);
}

.key--muted {
  color: var(--text-muted);
  font-size: 18px;
}

/* ---------- Apply row ---------- */

.apply {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-top: 2px;
}

.apply__btn {
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 600;
  padding: 16px 0;
  min-height: 56px;
}

.apply__btn--add {
  background: var(--add);
  color: #1a1300;
}

.apply__btn--add:active {
  background: var(--add-press);
}

.apply__btn--subtract {
  background: var(--subtract);
  color: #041014;
}

.apply__btn--subtract:active {
  background: var(--subtract-press);
}

/* ---------- Small screens / safety ---------- */

@media (max-width: 340px) {
  .display__total {
    font-size: 30px;
  }
  .key {
    font-size: 20px;
    padding: 14px 0;
  }
}
