:root {
  --bg: #1f2121;
  --surface: #262828;
  --surface-2: #2c2f2f;
  --surface-3: #343737;
  --text: #f5f5f5;
  --muted: rgba(245,245,245,.60);
  --muted-2: rgba(245,245,245,.40);
  --border: rgba(167,169,169,.24);
  --teal: #32b8c6;
  --teal-2: #258d99;
  --teal-soft: rgba(50,184,198,.10);
  --gold: #ffd700;
  --gold-soft: rgba(255,215,0,.09);
  --shadow: 0 16px 44px rgba(0,0,0,.22);
}

* { box-sizing: border-box; }
html {
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% -12%, rgba(50,184,198,.10), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  font-weight: 400;
  font-synthesis: none;
  overscroll-behavior-y: none;
  -webkit-touch-callout: none;
}
button, select { font: inherit; }

.vat-shell {
  width: min(620px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(20px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    calc(30px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.app-header {
  padding: 6px 2px 14px;
}
.brand-main {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-home-link {
  flex: 0 0 auto;
  color: inherit;
  text-decoration: none;
  border-radius: 50%;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid rgba(50,184,198,.55);
  box-shadow: 0 0 20px rgba(50,184,198,.18);
  color: var(--teal);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -.03em;
}
.brand-copy { min-width: 0; }
.eyebrow {
  color: var(--teal);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: .13em;
}
h1, p { margin-top: 0; }
h1 {
  margin: 0 0 3px;
  font-size: 25px;
  line-height: 1.1;
  letter-spacing: -.025em;
  font-weight: 800;
}
.brand-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 148px;
  gap: 10px;
  margin-bottom: 12px;
}
.mode-switch {
  min-height: 50px;
  padding: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.mode-button {
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.mode-button.is-active {
  background: #141515;
  color: var(--text);
  box-shadow: 0 5px 15px rgba(0,0,0,.28);
}

.vat-rate {
  min-height: 50px;
  padding: 7px 10px 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 16px;
  border: 1px solid rgba(255,215,0,.20);
  background: var(--gold-soft);
}
.vat-rate > span {
  color: var(--muted);
  font-size: 9px;
  line-height: 1;
  font-weight: 850;
  letter-spacing: .12em;
}
.vat-rate select {
  min-width: 76px;
  height: 34px;
  padding: 0 24px 0 8px;
  border: 0;
  border-radius: 9px;
  background-color: rgba(0,0,0,.18);
  color: var(--gold);
  font-size: 14px;
  font-weight: 800;
  outline: none;
}

.display-card {
  padding: 16px 18px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.025), rgba(255,255,255,.008)),
    var(--surface);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.expression {
  min-height: 18px;
  margin-bottom: 4px;
  color: var(--muted-2);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.amount-block {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}
.amount-label {
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.amount {
  min-width: 0;
  font-size: clamp(42px, 11.6vw, 64px);
  line-height: .98;
  letter-spacing: -.055em;
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.display-divider {
  height: 1px;
  margin: 12px 0 10px;
  background: rgba(167,169,169,.18);
}
.amount--result {
  color: rgba(245,245,245,.78);
  font-size: clamp(34px, 9.4vw, 52px);
}
.amount-block--result .amount-label { padding-bottom: 6px; }
.vat-detail {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(167,169,169,.12);
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}
.vat-detail strong {
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
}
.vat-pill {
  margin-left: auto;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 10px;
  font-weight: 850;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.key {
  min-height: 66px;
  border: 1px solid rgba(255,255,255,.025);
  border-radius: 14px;
  background: #2a2c2c;
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0,0,0,.10);
  font-size: 28px;
  line-height: 1;
  font-weight: 450;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
.key:active {
  transform: scale(.985);
  background: #343737;
}
.key--utility {
  color: rgba(245,245,245,.80);
  background: #303232;
  font-size: 18px;
  font-weight: 700;
}
.key--operator {
  color: var(--teal);
  background: var(--teal-soft);
  border-color: rgba(50,184,198,.14);
  font-weight: 700;
}
.key--equals {
  color: #102326;
  background: var(--teal);
  border-color: rgba(50,184,198,.50);
  font-weight: 850;
}
.key--zero {
  grid-column: span 2;
}

button, a, select {
  min-height: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

@media (max-width: 430px) {
  .vat-shell {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .app-header { padding-bottom: 14px; }
  .control-row {
    grid-template-columns: 1fr 126px;
    gap: 8px;
  }
  .mode-button { font-size: 13px; }
  .vat-rate { padding-left: 9px; padding-right: 8px; }
  .vat-rate > span { display: none; }
  .vat-rate select {
    width: 100%;
    min-width: 0;
    font-size: 13px;
  }
  .display-card {
    padding: 14px 15px 12px;
    border-radius: 18px;
  }
  .key {
    min-height: 62px;
    border-radius: 13px;
    font-size: 26px;
  }
  .key--utility { font-size: 17px; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .vat-shell {
    width: min(900px, 100%);
    padding-top: max(18px, calc(env(safe-area-inset-top) + 8px));
    display: grid;
    grid-template-columns: minmax(280px, .9fr) minmax(360px, 1.1fr);
    grid-template-areas:
      "header keypad"
      "controls keypad"
      "display keypad";
    gap: 10px 14px;
    align-content: start;
  }
  .app-header { grid-area: header; padding-bottom: 0; }
  .control-row { grid-area: controls; margin: 0; }
  .display-card { grid-area: display; margin: 0; }
  .keypad { grid-area: keypad; }
  .key { min-height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .key { transition: none; }
}
