*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0d0d0f;
  --purple: #7c3aed;
  --purple-deep: #6d28d9;
  --purple-glow: rgba(124, 58, 237, 0.35);
  --pink: #d946ef;
  --pink-gradient: linear-gradient(90deg, #a855f7 0%, #d946ef 50%, #f0abfc 100%);
  --gray-keys: #2a2a2e;
  --gray-fn-bg: #4a4a50;
  --gray-fn-text: #1a1a1a;
  --text: #fafafa;
  --muted: #a3a3a3;
  --success: #22c55e;
  --gold: #facc15;
  --glass-bg: rgba(20, 20, 24, 0.78);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-border-strong: rgba(255, 255, 255, 0.15);
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: Inter, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow-x: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── App Container ───────────────────────────────────────────────── */

.app {
  width: 100%;
  max-width: 420px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ─── Calculator ──────────────────────────────────────────────────── */

.calculator {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: 0.75rem 1.25rem 1.25rem;
  padding-top: env(safe-area-inset-top, 0.75rem);
  padding-bottom: env(safe-area-inset-bottom, 1.25rem);
}

.calculator__header {
  margin-bottom: 0.5rem;
  text-align: center;
}

.calculator__title {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

/* ─── Display ─────────────────────────────────────────────────────── */

.calculator__display {
  flex: 1;
  min-height: 100px;
  padding: 0.75rem 0 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 0.4rem;
}

.calculator__expression {
  width: 100%;
  text-align: right;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  min-height: 1.25rem;
  word-break: break-all;
}

.calculator__prompt {
  width: 100%;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--purple);
  padding: 0.5rem 0;
}

.calculator__prompt--hidden {
  display: none;
}

.calculator__main-readout {
  width: 100%;
  text-align: right;
}

.calculator__value {
  font-size: 3.5rem;
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.02em;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calculator__value--blur {
  filter: blur(14px);
  user-select: none;
  text-shadow: 0 0 28px rgba(255, 255, 255, 0.3);
}

/* ─── Keys ────────────────────────────────────────────────────────── */

.calculator__keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding-bottom: 0.5rem;
}

.key {
  appearance: none;
  border: none;
  margin: 0;
  font-family: inherit;
  font-size: 1.35rem;
  font-weight: 500;
  aspect-ratio: 1;
  border-radius: 18px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.key:active {
  transform: scale(0.92);
}

.key:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

.key--num {
  background: var(--gray-keys);
  color: var(--text);
}

.key--num:hover {
  background: #363639;
}

.key--fn {
  background: var(--gray-fn-bg);
  color: var(--gray-fn-text);
  font-weight: 600;
}

.key--fn:hover {
  background: #5a5a60;
}

.key--op {
  background: linear-gradient(145deg, #8b5cf6 0%, #7c3aed 50%, #6d28d9 100%);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 18px var(--purple-glow);
}

.key--op:hover {
  box-shadow: 0 6px 24px rgba(124, 58, 237, 0.5);
}

.key--zero {
  grid-column: span 2;
  aspect-ratio: auto;
  height: auto;
  min-height: 60px;
}

/* ─── Overlay & Modal ─────────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(1rem + env(safe-area-inset-top, 0px))
    calc(1.25rem + env(safe-area-inset-right, 0px))
    calc(1rem + env(safe-area-inset-bottom, 0px))
    calc(1.25rem + env(safe-area-inset-left, 0px));
  animation: fadeIn 0.2s ease;
}

.overlay--hidden {
  display: none;
}

.overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.glass {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: min(380px, 100%);
  min-width: 0;
  overflow: hidden;
  border-radius: 22px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.55),
    0 0 80px rgba(124, 58, 237, 0.08);
  animation: slideUp 0.25s ease;
}

/* ─── Modal Panels ────────────────────────────────────────────────── */

.modal__panel {
  padding: 2rem 1.75rem 1.75rem;
  min-width: 0;
}

.modal__panel--hidden {
  display: none;
}

.modal__panel--center {
  text-align: center;
}

/* Lock icon */
.modal__icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 1.25rem;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__icon--lock {
  background: linear-gradient(145deg, rgba(124, 58, 237, 0.4), rgba(109, 40, 217, 0.25));
  color: #e879f9;
  border: 1px solid rgba(232, 121, 249, 0.3);
}

.modal__icon--success {
  background: linear-gradient(180deg, var(--success) 0%, #16a34a 100%);
  box-shadow: 0 8px 28px rgba(34, 197, 94, 0.4);
}

.modal__title {
  margin: 0 0 0.4rem;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
}

.modal__title--gold {
  color: var(--text);
  text-align: center;
}

.modal__heading {
  margin: 0 0 0.3rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  text-align: center;
  text-wrap: balance;
}

.modal__gateway {
  margin: 0 0 1.5rem;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--muted);
  text-transform: uppercase;
  text-align: center;
}

.modal__lead {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
}

.modal__body {
  margin: 0 0 1.5rem;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
}

.modal__body--tight {
  margin-bottom: 1.75rem;
}

.modal__subtitle {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
  font-weight: 700;
  color: #e5e5e5;
  text-align: center;
}

.modal__panel--locked .modal__body {
  max-width: 260px;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 1.5rem;
  font-size: 0.8125rem;
  font-weight: 400;
  line-height: 1.5;
  color: #a3a3a3;
}

/* ─── Checkout Form ───────────────────────────────────────────────── */

.checkout-form__section-label {
  margin: 0 0 0.5rem;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.checkout-form__section-label:not(:first-child) {
  margin-top: 1.25rem;
}

.checkout-form {
  width: 100%;
  min-width: 0;
}

.checkout-form__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.checkout-form__row > .field {
  min-width: 0;
}

.field {
  display: block;
  width: 100%;
  min-width: 0;
  margin-bottom: 8px;
}

.field:last-of-type {
  margin-bottom: 0;
}

.field__control {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  background: rgba(34, 34, 38, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 12px;
  padding: 0 14px;
  min-height: 48px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: border-color 0.15s ease;
}

.field__control--select {
  position: relative;
  padding-right: 28px;
}

.field__icon {
  flex-shrink: 0;
  color: var(--muted);
}

.field input,
.field select {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  padding: 12px 0;
}

.field select {
  appearance: none;
  cursor: pointer;
  padding-right: 8px;
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.field__caret {
  position: absolute;
  right: 12px;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.field input::placeholder {
  color: #666;
}

.field input:focus,
.field select:focus {
  outline: none;
}

.field:focus-within .field__control {
  border-color: rgba(124, 58, 237, 0.5);
}

/* ─── Buttons ─────────────────────────────────────────────────────── */

.btn {
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

.btn--primary {
  display: block;
  width: 100%;
  padding: 16px 16px;
  color: #fff;
  background: var(--pink-gradient);
  box-shadow: 0 8px 32px rgba(217, 70, 239, 0.35);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.btn--primary:hover {
  box-shadow: 0 10px 40px rgba(217, 70, 239, 0.5);
}

.btn--block {
  margin-top: 0.75rem;
}

.btn--light {
  display: block;
  width: 100%;
  padding: 16px 16px;
  background: #fff;
  color: #171717;
  font-weight: 600;
  border-radius: 14px;
}

.btn--light:hover {
  background: #f5f5f5;
}

.btn--text {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  padding: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.btn--text:hover {
  color: #d4d4d4;
}

/* ─── Responsive: Mobile (default is mobile-first) ────────────────── */

@media (max-width: 380px) {
  .overlay {
    padding-right: calc(1rem + env(safe-area-inset-right, 0px));
    padding-left: calc(1rem + env(safe-area-inset-left, 0px));
  }

  .calculator {
    padding: 0.5rem 1rem 1rem;
  }

  .calculator__value {
    font-size: 2.75rem;
  }

  .calculator__keys {
    gap: 8px;
  }

  .key {
    font-size: 1.15rem;
    border-radius: 14px;
  }

  .modal__panel {
    padding: 1.5rem 1.25rem 1.25rem;
  }

  .glass {
    max-width: 100%;
  }

  .modal__heading {
    font-size: 1.125rem;
  }

  .checkout-form__row {
    gap: 6px;
  }

  .field__control {
    gap: 7px;
    padding: 0 11px;
    border-radius: 10px;
  }

  .field__control--select {
    padding-right: 26px;
  }

  .field input,
  .field select {
    font-size: 0.8125rem;
  }
}

/* ─── Responsive: Larger phones ──────────────────────────────────── */

@media (min-width: 381px) and (max-width: 480px) {
  .calculator__keys {
    gap: 10px;
  }

  .key {
    border-radius: 16px;
  }
}

/* ─── Responsive: Desktop ─────────────────────────────────────────── */

@media (min-width: 481px) {
  body {
    padding: 2rem;
    background:
      radial-gradient(ellipse at 50% 0%, rgba(124, 58, 237, 0.08) 0%, transparent 60%),
      var(--bg);
  }

  .app {
    min-height: auto;
    max-width: 400px;
  }

  .calculator {
    border-radius: 28px;
    border: 1px solid var(--glass-border);
    box-shadow:
      0 0 0 1px rgba(124, 58, 237, 0.12),
      0 32px 64px rgba(0, 0, 0, 0.5),
      inset 0 1px 0 rgba(255, 255, 255, 0.04);
    background: rgba(13, 13, 15, 0.96);
    min-height: auto;
    padding: 1.25rem 1.5rem 1.5rem;
  }

  .calculator__display {
    min-height: 140px;
  }

  .calculator__value {
    font-size: 3.75rem;
  }

  .key {
    aspect-ratio: auto;
    height: 64px;
    border-radius: 18px;
  }

  .key--zero {
    min-height: 64px;
  }

  .calculator__keys {
    gap: 12px;
  }
}

/* ─── Responsive: Wide desktop ────────────────────────────────────── */

@media (min-width: 768px) {
  .glass {
    max-width: min(380px, 100%);
  }
}

/* ─── Safe area for notched phones ────────────────────────────────── */

@supports (padding: env(safe-area-inset-bottom)) {
  .calculator {
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
  }
}
