:root {
  --accent: #f7931a;
  --accent-soft: rgba(247, 147, 26, 0.22); /* fallback for browsers without color-mix */
  --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
  --bg: #0a0b10;
  --bg-2: #0f111a;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-strong: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f4f6fb;
  --text-dim: #9aa3b8;
  --text-faint: #5c6478;
  --shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
  --radius: 22px;
}

:root[data-theme='light'] {
  --bg: #f3f5fa;
  --bg-2: #e9edf6;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-strong: rgba(255, 255, 255, 0.92);
  --border: rgba(16, 20, 40, 0.1);
  --text: #141726;
  --text-dim: #5a6276;
  --text-faint: #99a0b2;
  --shadow: 0 30px 70px -34px rgba(20, 30, 70, 0.4);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 80% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, var(--accent-soft), transparent 55%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  min-height: 100vh; /* fallback */
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background 0.4s ease, color 0.3s ease;
}

/* ---- SPONSORED BY (QRGO2 house ads — ported from byobtc.com) ---- */
.sponsor-bar {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.28);
  border-bottom: 1px solid var(--border);
}
:root[data-theme='light'] .sponsor-bar { background: rgba(16, 20, 40, 0.05); }
.sponsor-bar[hidden] { display: none; }
.sponsor {
  display: inline-flex;
  align-items: center;
  gap: 20px;
  color: var(--text);
  text-decoration: none;
}
.sponsor-label {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  padding-right: 20px;
  border-right: 1px solid var(--border);
}
.sponsor-by {
  font-family: 'Space Grotesk', ui-monospace, monospace;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}
.sponsor-ad {
  display: block;
  height: 140px;
  width: auto;
  max-width: calc(100vw - 280px);
  object-fit: contain;
  border-radius: 8px; /* 1164×300 billboard: sized by height */
  transition: transform 0.2s ease;
}
.sponsor:hover .sponsor-ad,
.sponsor:focus-visible .sponsor-ad { transform: translateY(-2px); }
.sponsor:focus-visible { outline: none; }
@media (max-height: 760px) { .sponsor-ad { height: 112px; } }
@media (max-width: 760px) {
  .sponsor-bar { padding: 8px 12px; }
  .sponsor { flex-direction: column; gap: 6px; width: 100%; }
  .sponsor-label { align-self: center; padding-right: 0; border-right: 0; }
  .sponsor-by { font-size: 10px; letter-spacing: 0.12em; }
  .sponsor-ad { width: 100%; max-width: 480px; height: auto; }
}
@media (prefers-reduced-motion: reduce) { .sponsor-ad { transition: none; } }

/* ---- floating currency symbols ---- */
.symbol-field {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.symbol {
  position: absolute;
  bottom: -12vh;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  color: var(--text);
  opacity: 0.07;
  will-change: transform, opacity;
  animation: drift linear infinite;
  user-select: none;
}
@keyframes drift {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  10% { opacity: 0.09; }
  90% { opacity: 0.09; }
  100% { transform: translateY(-125vh) rotate(220deg); opacity: 0; }
}

/* ---- top bar ---- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(16px, 5vw, 48px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--accent);
  color: #0a0b10;
  font-weight: 700;
  font-size: 20px;
  box-shadow: 0 8px 24px -8px var(--accent);
}
.brand-word {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.topbar__actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}
.icon-btn:hover { background: var(--surface-strong); transform: translateY(-1px); }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 12, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal__card {
  position: relative;
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  animation: modalIn 0.22s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 14px;
}
.modal__title { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 20px; font-weight: 700; }
.modal__close {
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); font-size: 15px; cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.modal__close:hover { background: var(--surface-strong); color: var(--text); }
.modal__body { padding: 4px 22px 8px; }
.modal__note { color: var(--text-dim); font-size: 14px; padding: 10px 0 18px; }
.modal__foot {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between;
  padding: 14px 22px 20px; font-size: 12px; color: var(--text-faint);
}
.modal__foot a { color: var(--accent); text-decoration: none; }

/* stat sections + tiles */
.stat-group { margin-bottom: 18px; }
.stat-group__label {
  font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-faint); margin: 0 0 10px;
}
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 15px;
}
.stat__label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.stat__value { font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 700; line-height: 1.1; }
.stat__unit { font-size: 12px; font-weight: 500; color: var(--text-faint); margin-left: 3px; }
.stat__value--up { color: #39c17d; }
.stat__value--down { color: #ff6b6b; }

/* ---- stage ---- */
.stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(24px, 6vh, 64px) 16px 64px;
}
.tagline {
  margin: 0 0 28px;
  color: var(--text-dim);
  font-size: clamp(15px, 2.4vw, 19px);
  text-align: center;
  letter-spacing: 0.01em;
}

/* ---- card ---- */
.card {
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(22px, 4vw, 34px);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
}

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

/* ---- searchable currency picker ---- */
.currency-field { position: relative; }
.currency-pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.currency-pill:hover { background: color-mix(in srgb, var(--text) 8%, var(--surface-strong)); }
.currency-pill[aria-expanded='true'] { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.currency-pill__caret { font-size: 11px; color: var(--text-dim); }

.currency-pop {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  right: 0;
  width: min(320px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 10px;
  animation: modalIn 0.16s ease;
}
.currency-pop[hidden] { display: none; }
.currency-pop__search {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* ≥16px stops iOS Safari zooming in on focus */
  padding: 10px 12px;
  border-radius: 10px;
  outline: none;
  margin-bottom: 8px;
}
.currency-pop__search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.currency-pop__list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}
.currency-opt {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 9px 11px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}
.currency-opt:hover, .currency-opt.active { background: var(--surface-strong); }
.currency-opt[aria-selected='true'] { color: var(--accent); font-weight: 600; }
.currency-opt__sym { min-width: 26px; color: var(--text-dim); }
.currency-opt__code { font-weight: 600; }
.currency-opt__name { color: var(--text-dim); font-size: 13px; }
.currency-pop__empty { padding: 14px 11px; color: var(--text-faint); font-size: 13px; }

.field__label,
.control__label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}
.field__control {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 18px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field__control:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.field__prefix {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.field__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(26px, 6vw, 34px);
  font-weight: 600;
  letter-spacing: -0.01em;
  outline: none;
}
.field__input::placeholder { color: var(--text-faint); }
.field__input.flash { animation: flash 0.5s ease; }
.field__suffix {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}
/* clickable unit chip: sats <-> BTC */
.unit-toggle {
  flex: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid transparent;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  min-width: 54px;
  transition: background 0.2s ease, transform 0.15s ease;
}
.unit-toggle:hover { background: color-mix(in srgb, var(--accent) 32%, transparent); transform: translateY(-1px); }
.unit-toggle:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-soft); }

/* currency picker sitting inline inside the fiat field */
.pill-select--inline { flex: none; max-width: 48%; }

/* swap divider */
.swap {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 20px 2px;
}
.swap__line { flex: 1; height: 1px; background: var(--border); }
.swap__badge {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

/* result */
.result { text-align: center; margin-bottom: 26px; }
.result__value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(34px, 9vw, 52px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
  word-break: break-word;
}
.result__value.flash { animation: flash 0.5s ease; }
@keyframes flash {
  0% { color: var(--accent); }
  100% { color: var(--text); }
}
.result__meta { margin-top: 14px; display: flex; justify-content: center; }

.pill-select {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 36px 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.controls { margin-bottom: 22px; }
.remember {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.remember input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  cursor: pointer;
}
.select {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* ≥16px avoids iOS zoom on focus */
  font-weight: 500;
  padding: 13px 40px 13px 16px;
  border-radius: 14px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 15px) 55%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  transition: border-color 0.2s ease;
}
.select:focus-visible, .pill-select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
option { color: #141726; }

.card__foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-faint);
}
.foot__price { color: var(--text-dim); }
.foot__price--warn { color: #ffb020; font-weight: 600; }

.disclaimer {
  margin-top: 26px;
  max-width: 440px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
}

/* narrow phones: keep the header on one line, keep the card comfy */
@media (max-width: 400px) {
  .topbar { padding: 16px 14px; }
  .brand-mark { width: 34px; height: 34px; font-size: 18px; }
  .brand-word { font-size: 17px; }
  .stage { padding: 20px 14px 56px; }
  .card { padding: 20px 16px; }
  .field__input { font-size: clamp(22px, 7vw, 30px); }
}

@media (prefers-reduced-motion: reduce) {
  .symbol { animation: none; display: none; }
  .result__value.flash,
  .field__input.flash { animation: none; }
  * { transition: none !important; }
  .modal__card, .currency-pop { animation: none; }
}
