:root {
  color-scheme: dark;
  --bg: #0b0b0f;
  --fg: #f4f4f6;
  --accent: #ffb020;
  --muted: #8a8a94;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

button {
  font-family: inherit;
}

.screen {
  height: 100dvh;
  width: 100vw;
  display: flex;
}

.screen[hidden] {
  display: none;
}

/* ---------- display screen ---------- */
#display {
  padding: 4vmin;
}

.frame {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3vmin;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}

.balance-wrap {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: flex-grow 0.35s ease, width 0.35s ease, max-width 0.35s ease;
}

.balance {
  font-size: min(22vmin, 140px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.balance-label {
  color: var(--muted);
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 8px;
}

.qr-wrap {
  flex: none;
  width: 26vmin;
  height: 26vmin;
  max-width: 150px;
  max-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
  transition: flex-grow 0.35s ease, width 0.35s ease, height 0.35s ease,
    max-width 0.35s ease, max-height 0.35s ease;
}

.qr-canvas {
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.35s ease, height 0.35s ease;
}

.qr-canvas img, .qr-canvas canvas, .qr-canvas table {
  width: 100% !important;
  height: 100% !important;
}

/* swapped state: balance shrinks to a header, QR takes over */
.frame.swapped .balance-wrap {
  flex: none;
  width: 100%;
}

.frame.swapped .balance {
  font-size: min(10vmin, 56px);
}

.frame.swapped .qr-wrap {
  flex: 1;
  width: 100%;
  height: auto;
  max-width: none;
  max-height: none;
  min-height: 0;
}

.frame.swapped .qr-canvas {
  /* largest square that fits both axes of .qr-wrap; height must be
     explicitly auto since aspect-ratio is ignored once both width and
     height resolve to definite values (the base rule sets height:100%). */
  width: min(90cqw, 90cqh);
  height: auto;
  aspect-ratio: 1;
  max-width: none;
  max-height: none;
}

.scan-fab {
  position: absolute;
  top: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.5);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  z-index: 1;
}

.toast {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, 0);
  background: var(--accent);
  color: #1a1200;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: 999px;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 12px);
}

/* ---------- give screen ---------- */
#give {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 16px;
}

#give h1 {
  font-size: 2rem;
  margin: 0;
}

.give-sub {
  color: var(--muted);
  margin: 0;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stepper-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: transparent;
  color: var(--fg);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#give-amount {
  width: 120px;
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  background: transparent;
  border: none;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

#give-amount::-webkit-inner-spin-button,
#give-amount::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#give-slider {
  width: min(78vw, 320px);
}

.error {
  color: var(--accent);
  max-width: 320px;
}

.give-buttons {
  display: flex;
  gap: 12px;
  width: min(78vw, 320px);
}

.give-btn {
  flex: 1;
  padding: 12px;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

.give-btn.primary {
  background: var(--accent);
  color: #1a1200;
}

.give-btn.primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.give-btn.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* ---------- scanner overlay ---------- */
.scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.scanner-overlay[hidden] {
  display: none;
}

#scan-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-frame {
  position: relative;
  width: min(70vw, 280px);
  aspect-ratio: 1;
  border: 3px solid var(--accent);
  border-radius: 16px;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.55);
}

.scan-cancel {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  background: rgba(0, 0, 0, 0.6);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
}

.scan-status {
  position: absolute;
  bottom: max(32px, env(safe-area-inset-bottom));
  left: 24px;
  right: 24px;
  color: #fff;
  font-size: 0.9rem;
  text-align: center;
  margin: 0;
}
