:root {
    --bg: #F4F4F6;
    --card: #FFFFFF;
    --ink: #0F1115;
    --ink-2: #4B4F5A;
    --muted: #8A8E99;
    --line: #ECECF0;
    --line-2: #E2E2E8;
    --fill: #F6F6F8;
    --accent: #a033ea;
    --accent-strong: #8a1ed4;
    --accent-soft: #f5ebff;
    --accent-ring: rgba(160, 51, 234, .18);
    --good: #16A34A;
    --warn: #B45309;
    --warn-bg: #FFF7E6;
    --warn-line: #F5DDA8;
    --info: #1D4ED8;
    --info-bg: #EEF2FF;
    --info-line: #DBE2FE;
    --danger: #DC2626;
    --radius-card: 20px;
    --radius-field: 14px;
    --radius-btn: 12px;
  }

  * { box-sizing: border-box; }
  html, body {
    margin: 0; padding: 0;
    font-family: 'Uncut Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.01em;
  }
  button, input, select { font-family: inherit; }
  input:focus, select:focus { outline: none; }
  .tnum { font-variant-numeric: tabular-nums; }

  /* layout */
  .page {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 48px 16px;
  }
  .wrap { width: 440px; max-width: calc(100vw - 32px); }

  /* header */
  .hd { padding-left: 2px; margin-bottom: 18px; }
  .hd-row {
    display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  }
  .logo {
    width: 22px; height: 22px; border-radius: 6px;
    background: var(--accent); color: #fff;
    display: grid; place-items: center;
    font-size: 12px; font-weight: 700;
  }
  .brand { font-size: 12px; font-weight: 600; color: var(--ink-2); }
  .env {
    margin-left: auto;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11.5px; font-weight: 600;
  }
  .env::before {
    content: ""; width: 6px; height: 6px; border-radius: 99px;
  }

  /* env badge tones (selected at build time via class) */
  .env--warn {
    background: rgba(180, 83, 9, .10);
    color: var(--warn);
  }
  .env--warn::before {
    background: #E0A100;
  }
  .env--prod {
    background: rgba(22, 163, 74, .10);
    color: var(--good);
  }
  .env--prod::before {
    background: var(--good);
  }
  .banner--prod {
    background: rgba(22, 163, 74, .08);
    border-color: rgba(22, 163, 74, .22);
  }
  .banner--prod svg { color: var(--good); }
  .banner--prod .banner-body { color: #166534; }
  .banner--prod .banner-body strong { color: #14532D; }
  .banner--prod .banner-body a { color: #14532D; }

  .h1 {
    margin: 0; font-size: 22px; font-weight: 600; color: var(--ink);
    letter-spacing: -0.02em;
  }
  .sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); font-weight: 500; }

  /* card */
  .card {
    background: var(--card);
    border-radius: var(--radius-card);
    border: 1px solid rgba(15,23,42,.04);
    box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 12px 40px -12px rgba(16,24,40,.10);
    padding: 28px;
    position: relative;
  }

  /* warning banner */
  .banner {
    margin-bottom: 18px;
    display: flex; gap: 10px;
    padding: 10px 12px;
    background: var(--warn-bg);
    border: 1px solid var(--warn-line);
    border-radius: 12px;
  }
  .banner svg { flex-shrink: 0; margin-top: 1px; color: #B45309; }
  .banner-body { font-size: 12px; line-height: 1.5; color: #92400E; font-weight: 500; }
  .banner-body strong { color: #78350F; font-weight: 600; }

  /* hidden radios drive CSS tab highlight + address-row + wc-info */
  .mode-buy, .mode-sell, .wc-none, .wc-true, .wc-false {
    position: absolute; opacity: 0; pointer-events: none;
  }

  /* segmented mode tabs */
  .tabs {
    position: relative;
    display: flex; padding: 4px;
    background: var(--fill); border-radius: 12px;
    margin-bottom: 22px;
  }
  /* sliding pill — JS adds .is-buy to move it right */
  .tab-pill {
    position: absolute;
    left: 4px; top: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background: #FFFFFF;
    border-radius: 9px;
    box-shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
    transition: left .24s cubic-bezier(.34,1.36,.64,1);
    pointer-events: none;
    z-index: 0;
  }
  .tab-pill.is-buy { left: 50%; }
  .tabs label {
    position: relative; z-index: 1;
    flex: 1; height: 36px;
    display: grid; place-items: center;
    cursor: pointer;
    border-radius: 9px;
    font-size: 13.5px; font-weight: 600;
    color: var(--muted);
    transition: color .18s ease;
  }
  .mode-sell:checked ~ .card .tabs label[for="mode-sell"],
  .mode-buy:checked  ~ .card .tabs label[for="mode-buy"] {
    color: var(--accent);
  }

  /* content fade when mode switches */
  @keyframes rowsFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .rows-area.is-switching {
    animation: rowsFadeIn .2s ease-out both;
  }

  /* form rows */
  .row { margin-bottom: 16px; }
  .row:last-of-type { margin-bottom: 0; }
  .label {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: 6px; padding-left: 2px;
    font-size: 12px; font-weight: 500; color: var(--muted);
  }
  .label-strong { color: var(--ink-2); font-weight: 600; }

  /* select */
  .select-wrap { position: relative; }
  .select-wrap::after {
    content: "";
    position: absolute; right: 14px; top: 50%;
    width: 8px; height: 8px;
    border-right: 1.6px solid var(--muted);
    border-bottom: 1.6px solid var(--muted);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
  }
  select.field {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    width: 100%; height: 48px;
    padding: 0 36px 0 14px;
    background: var(--fill);
    border: 1px solid transparent;
    border-radius: var(--radius-field);
    font-size: 14px; font-weight: 600;
    color: var(--ink);
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease;
  }
  select.field:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }

  /* amount field — hero */
  .amount-shell {
    background: var(--fill);
    border: 1px solid transparent;
    border-radius: var(--radius-field);
    padding: 14px 16px;
    display: flex; align-items: center; gap: 12px;
    transition: border-color .15s ease, box-shadow .15s ease;
  }
  .amount-shell:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-ring);
  }
  .amount {
    flex: 1; min-width: 0;
    background: transparent; border: none;
    font-size: 32px; font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.02em;
    padding: 0;
    font-variant-numeric: tabular-nums;
  }
  .amount::placeholder { color: #C5C7D1; }
  .ticker {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    background: #FFFFFF;
    border: 1px solid var(--line-2);
    border-radius: 999px;
    font-size: 12.5px; font-weight: 600;
    color: var(--ink);
  }

  /* text input */
  input.field {
    width: 100%; height: 48px;
    padding: 0 14px;
    background: var(--fill);
    border: 1px solid transparent;
    border-radius: var(--radius-field);
    font-size: 14px; font-weight: 500;
    color: var(--ink);
    transition: border-color .15s ease, box-shadow .15s ease;
  }
  input.field::placeholder { color: var(--muted); font-weight: 500; }
  input.field:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }

  /* WalletConnect three-way segmented */
  .wc-tabs {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
    padding: 4px;
    background: var(--fill); border-radius: 12px;
  }
  .wc-tabs label {
    height: 36px;
    display: grid; place-items: center;
    cursor: pointer;
    border-radius: 9px;
    font-size: 13px; font-weight: 600;
    color: var(--muted);
    transition: all .15s ease;
  }
  .wc-none:checked  ~ .card label[for="wc-none"],
  .wc-true:checked  ~ .card label[for="wc-true"],
  .wc-false:checked ~ .card label[for="wc-false"] {
    background: #FFFFFF;
    color: var(--accent);
    box-shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
  }

  /* WalletConnect info — only when "None" selected */
  .wc-info {
    display: none;
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--info-bg);
    border: 1px solid var(--info-line);
    border-radius: 10px;
    font-size: 11.5px; font-weight: 500;
    color: #1E40AF; line-height: 1.5;
    align-items: flex-start; gap: 8px;
  }
  .wc-info svg { flex-shrink: 0; margin-top: 1px; color: var(--info); }
  .wc-none:checked ~ .card .wc-info { display: flex; }

  /* Address field — only on Buy (CSS-driven) */
  .address-row { display: none; }
  .mode-buy:checked ~ .card .address-row { display: block; }

  /* WalletConnect row — only on Sell */
  .wc-row { display: block; }
  .mode-buy:checked ~ .card .wc-row { display: none; }

  /* error message */
  .error {
    color: var(--danger);
    font-size: 12px;
    font-weight: 500;
    margin-top: 6px;
    padding-left: 2px;
    display: none;
  }

  /* CTA */
  .cta {
    width: 100%; height: 52px;
    margin-top: 20px;
    border-radius: var(--radius-btn); border: none;
    background: var(--accent); color: #FFFFFF;
    font-size: 14.5px; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    cursor: pointer;
    transition: background .15s ease, opacity .15s ease;
    box-shadow: 0 1px 2px rgba(16,24,40,.06), 0 6px 18px -8px rgba(160,51,234,.5);
  }
  .cta:hover:not(:disabled) { background: var(--accent-strong); }
  .cta:active:not(:disabled) { background: var(--accent-strong); transform: translateY(1px); }
  .cta:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

  /* Reference */
  .ref {
    margin-top: 14px;
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    background: var(--fill);
    border-radius: var(--radius-field);
  }
  .ref-label { font-size: 11.5px; font-weight: 500; color: var(--muted); }
  .ref-val {
    flex: 1; min-width: 0;
    font-family: inherit;
    font-size: 12px; color: var(--ink-2);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }

  /* footnote */
  .foot {
    margin-top: 14px; text-align: center;
    font-size: 11.5px; font-weight: 500; color: var(--muted);
  }

  /* wallet modal */
  .modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2147483647;
    align-items: center;
    justify-content: center;
  }
  .modal-overlay.active { display: flex; }
  .modal {
    background: var(--card);
    border-radius: var(--radius-card);
    padding: 28px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  }
  .modal h3 {
    margin: 0 0 18px;
    color: var(--ink);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.02em;
  }
 .modal-field { margin-bottom: 14px; }
  
  /* Force the QR code container field to perfectly center its items */
  .modal-field.qr-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
  }
  .modal-field label {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }
  .modal-field p {
    margin-top: 4px;
    font-size: 14px;
    font-weight: 500;
    color: var(--ink);
    word-break: break-all;
    font-family: inherit;
  }
  .modal-close {
    width: 100%;
    height: 48px;
    margin-top: 6px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-btn);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease;
  }
  .modal-close:hover { background: var(--accent-strong); }
