/* ─────────────────────────────────────
       1. DESIGN TOKENS
       Para alterar cores/sombras/espaçamentos,
       edite apenas esta seção.
    ───────────────────────────────────── */

    /* Tema claro */
    :root {
      /* Paleta */
      --color-ink:       #16213e;
      --color-paper:     #f0f4ff;
      --color-surface:   #ffffff;
      --color-surface2:  #edf0ff;
      --color-accent:    #5b4dff;
      --color-accent-hv: #7b6fff;
      --color-teal:      #0abf8e;
      --color-muted:     #4a5280;
      --color-border:    #c5cef5;
      --color-border-dk: #16213e;
      --color-shadow:    rgba(22, 33, 62, .15);
      --color-error:     #e74c3c;

      /* Sombras */
      --shadow-card: 0 4px 24px var(--color-shadow), 3px 3px 0 var(--color-border-dk);
      --shadow-btn:  2px 2px 0 var(--color-border-dk);
      --shadow-btn-h:4px 4px 0 var(--color-border-dk);

      /* Forma */
      --radius:      10px;
      --radius-sm:   6px;

      /* Espaçamento responsivo — mobile first */
      --page-px:   1rem;
      --page-py:   4.5rem 1.5rem;
      --gap:       1rem;
      --card-pad:  1.25rem;
    }

    /* Tema escuro — sobrescreve apenas o que muda */
    [data-theme="dark"] {
      --color-ink:       #dde6ff;
      --color-paper:     #0b0d1a;
      --color-surface:   #13162a;
      --color-surface2:  #1a1e35;
      --color-accent:    #7b6fff;
      --color-accent-hv: #9d94ff;
      --color-teal:      #2dd4a7;
      --color-muted:     #454d6e;
      --color-border:    #252a45;
      --color-border-dk: #3a4070;
      --color-shadow:    rgba(0, 0, 0, .45);

      --shadow-card: 0 4px 32px var(--color-shadow), 3px 3px 0 var(--color-border-dk);
    }

    /* ─────────────────────────────────────
       2. RESET
    ───────────────────────────────────── */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    html { -webkit-text-size-adjust: 100%; }

    /* ─────────────────────────────────────
       3. BODY / LAYOUT RAIZ
    ───────────────────────────────────── */
    body {
      font-family: 'Plus Jakarta Sans', sans-serif;
      min-height: 100svh;
      background-color: var(--color-paper);
      color: var(--color-ink);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      padding: var(--page-py) var(--page-px);
      /* Respeita notch / home bar em iOS */
      padding-left:   max(var(--page-px), env(safe-area-inset-left));
      padding-right:  max(var(--page-px), env(safe-area-inset-right));
      padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
      overflow-x: hidden;
      transition: background-color .35s, color .35s;
    }

    /* Gradiente decorativo de fundo */
    body::before {
      content: '';
      position: fixed; inset: 0; z-index: 0; pointer-events: none;
      background:
        radial-gradient(ellipse 70% 50% at 5%  5%,  rgba(91,77,255,.08)  0%, transparent 60%),
        radial-gradient(ellipse 60% 45% at 95% 95%, rgba(10,191,142,.06) 0%, transparent 60%);
    }

    /* ─────────────────────────────────────
       4. ACESSIBILIDADE
    ───────────────────────────────────── */
    :focus-visible {
      outline: 2.5px solid var(--color-accent);
      outline-offset: 3px;
      border-radius: 4px;
    }

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

    .hidden { display: none !important; }

    /* ─────────────────────────────────────
       5. COMPONENTES GLOBAIS
    ───────────────────────────────────── */

    /* Barra de topo */
    .topbar {
      position: fixed; top: 0; left: 0; right: 0;
      height: 3px; z-index: 100;
      background: linear-gradient(90deg, var(--color-accent), var(--color-teal));
    }

    /* Botão de tema */
    .btn-theme {
      position: fixed; top: .75rem; right: 1rem; z-index: 200;
      min-width: 44px; min-height: 44px; /* área de toque mínima */
      background: var(--color-surface);
      border: 1.5px solid var(--color-border);
      border-radius: 50%;
      font-size: 1.1rem;
      cursor: pointer;
      box-shadow: var(--shadow-btn);
      display: flex; align-items: center; justify-content: center;
      transition: background .35s, border-color .35s, box-shadow .12s, transform .12s;
      -webkit-tap-highlight-color: transparent;
    }
    .btn-theme:hover  { transform: translate(-1px,-1px); box-shadow: var(--shadow-btn-h); }
    .btn-theme:active { transform: translate(1px,1px);   box-shadow: none; }

    /* Badge */
    .badge {
      display: inline-flex; align-items: center;
      font-family: 'DM Mono', monospace;
      font-size: .6rem; font-weight: 500;
      letter-spacing: .1em; text-transform: uppercase;
      padding: 3px 9px;
      border: 1.5px solid var(--color-border);
      border-radius: 2px;
      background: var(--color-surface2);
      color: var(--color-muted);
      white-space: nowrap;
      transition: background .35s, border-color .35s, color .35s;
    }
    .badge--accent { background: var(--color-accent);  color: #fff; border-color: var(--color-accent); }
    .badge--teal   { background: var(--color-teal);    color: #fff; border-color: var(--color-teal); }

    /* Card */
    .card {
      background: var(--color-surface);
      border: 1.5px solid var(--color-border);
      border-radius: var(--radius);
      box-shadow: var(--shadow-card);
      padding: var(--card-pad);
      transition: background .35s, border-color .35s, box-shadow .35s;
    }

    /* Label de campo */
    .label {
      display: block;
      font-family: 'DM Mono', monospace;
      font-size: .6875rem; font-weight: 500;
      letter-spacing: .08em; text-transform: uppercase;
      color: var(--color-muted);
      margin-bottom: .45rem;
      transition: color .35s;
    }

    /* Campo de formulário */
    .field {
      width: 100%;
      background: var(--color-surface2);
      border: 1.5px solid var(--color-border);
      border-radius: var(--radius-sm);
      color: var(--color-ink);
      font-family: 'DM Mono', monospace;
      font-size: 1rem; /* >= 16px evita zoom no iOS */
      padding: .75rem .875rem;
      appearance: none;
      -webkit-appearance: none;
      transition: border-color .2s, box-shadow .2s, background .35s, color .35s;
    }
    .field:focus {
      outline: none;
      border-color: var(--color-accent);
      box-shadow: 0 0 0 3px rgba(91, 77, 255, .15);
    }
    textarea.field { resize: none; line-height: 1.5; }

    /* Botão base */
    .btn {
      display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
      font-family: 'DM Mono', monospace;
      font-size: .6875rem; font-weight: 500;
      letter-spacing: .08em; text-transform: uppercase;
      border-radius: var(--radius-sm);
      border: 1.5px solid var(--color-border-dk);
      min-height: 44px; /* área de toque mínima */
      cursor: pointer;
      box-shadow: var(--shadow-btn);
      transition: box-shadow .12s, transform .12s,
                  background-color .15s, border-color .15s, color .15s;
      -webkit-tap-highlight-color: transparent;
      touch-action: manipulation;
    }
    .btn:hover  { box-shadow: var(--shadow-btn-h); transform: translate(-1px,-1px); }
    .btn:active { box-shadow: none;                transform: translate(1px,1px); }

    /* Variantes de botão */
    .btn--primary {
      width: 100%; padding: 1rem;
      margin-top: 1.5rem;
      background: var(--color-accent); color: #fff;
      border-color: var(--color-accent);
      font-size: .8125rem; min-height: 52px;
    }
    .btn--primary:hover { background: var(--color-accent-hv); border-color: var(--color-accent-hv); }

    .btn--dark {
      padding: .65rem .5rem;
      background: var(--color-ink); color: var(--color-paper);
    }
    .btn--dark:hover { background: var(--color-accent); border-color: var(--color-accent); }

    .btn--ghost {
      padding: .65rem .5rem;
      background: var(--color-surface2); color: var(--color-ink);
    }
    .btn--ghost:hover { background: var(--color-teal); border-color: var(--color-teal); color: #fff; }

    /* Divisor */
    .divider {
      border: none;
      border-top: 1px solid var(--color-border);
      margin: 1rem 0;
      transition: border-color .35s;
    }

    /* Mensagem de erro */
    .error-msg {
      font-family: 'DM Mono', monospace;
      font-size: .6875rem;
      color: var(--color-error);
      margin-top: .4rem;
    }

    /* Contador de caracteres */
    .char-counter {
      position: absolute; bottom: .5rem; right: .75rem;
      font-family: 'DM Mono', monospace;
      font-size: .625rem;
      color: var(--color-muted);
      pointer-events: none;
      transition: color .35s;
    }

    /* ─────────────────────────────────────
       6. LAYOUT — PAGE WRAPPER
    ───────────────────────────────────── */
    .page-wrapper {
      position: relative; z-index: 1;
      width: 100%; max-width: 64rem;
      display: flex; flex-direction: column;
      gap: var(--gap);
    }

    /* ─────────────────────────────────────
       7. CABEÇALHO
    ───────────────────────────────────── */
    .page-header__badges {
      display: flex; align-items: center;
      flex-wrap: wrap; gap: .4rem;
      margin-bottom: .75rem;
    }

    .page-header__title {
      font-size: clamp(1.75rem, 6vw, 2.5rem);
      font-weight: 800;
      line-height: 1.1;
      letter-spacing: -.03em;
    }

    .page-header__title-highlight {
      background: linear-gradient(135deg, var(--color-accent), var(--color-teal));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }

    .page-header__desc {
      font-family: 'DM Mono', monospace;
      font-size: clamp(.7rem, 2.5vw, .8rem);
      margin-top: .5rem;
      color: var(--color-muted);
      line-height: 1.6;
    }

    /* ─────────────────────────────────────
       8. GRID DUAS COLUNAS
       Mobile (< 700px): coluna única,
         formulário primeiro, QR abaixo.
       Desktop (≥ 700px): QR | Formulário,
         QR fica sticky no scroll.
    ───────────────────────────────────── */
    .two-col {
      display: grid;
      grid-template-columns: 1fr;
      gap: var(--gap);
      align-items: stretch;
    }

    .col-qr   { order: 2; display: flex; flex-direction: column; }
    .col-form { order: 1; display: flex; flex-direction: column; }

    @media (min-width: 700px) {
      :root {
        --page-px:  1.5rem;
        --page-py:  5rem 2rem;
        --gap:      1.5rem;
        --card-pad: 1.5rem;
      }

      .two-col { grid-template-columns: 1fr 1.6fr; }
      .col-qr  { order: 1; position: sticky; top: 1.5rem; }
      .col-form{ order: 2; }
    }

    @media (min-width: 1024px) {
      :root {
        --page-px:  2rem;
        --gap:      2rem;
        --card-pad: 2rem;
      }
    }

    /* ─────────────────────────────────────
       9. CARD QR
    ───────────────────────────────────── */
    .col-qr .card,
    .col-form .card { flex: 1; }

    .qr-card {
      display: flex; flex-direction: column;
      align-items: center; gap: 1rem;
    }

    /* Palco do QR: quadrado responsivo com placeholder */
    .qr-stage {
      position: relative;
      width: 100%;
      max-width: min(280px, 100%); /* mobile: não domina a tela */
      aspect-ratio: 1 / 1;
      display: flex; align-items: center; justify-content: center;
      background: var(--color-surface2);
      border: 1.5px dashed var(--color-border);
      border-radius: 8px;
      overflow: hidden;
      margin: 0 auto;
      transition: background .35s, border-color .35s;
    }

    @media (min-width: 700px) {
      .qr-stage { max-width: 100%; } /* desktop: ocupa toda a largura do card */
    }

    /* Cantos decorativos */
    .qr-stage__corner {
      position: absolute;
      width: 18px; height: 18px;
      border-color: var(--color-accent);
      transition: border-color .35s;
    }
    .qr-stage__corner--tl { top: 6px; left:  6px; border-top:    2px solid; border-left:   2px solid; border-radius: 3px 0 0 0; }
    .qr-stage__corner--tr { top: 6px; right: 6px; border-top:    2px solid; border-right:  2px solid; border-radius: 0 3px 0 0; }
    .qr-stage__corner--bl { bottom: 6px; left:  6px; border-bottom: 2px solid; border-left:   2px solid; border-radius: 0 0 0 3px; }
    .qr-stage__corner--br { bottom: 6px; right: 6px; border-bottom: 2px solid; border-right:  2px solid; border-radius: 0 0 3px 0; }

    /* Linha de scan (animada ao gerar) */
    .qr-stage__scan-line {
      position: absolute; left: 0; right: 0; top: 0; height: 2px;
      background: linear-gradient(to right, transparent, var(--color-accent), transparent);
      animation: scan 2s linear infinite;
      opacity: 0;
      transition: opacity .3s;
    }
    @keyframes scan { 0%{top:0%} 50%{top:100%} 100%{top:0%} }
    .qr-stage--scanning .qr-stage__scan-line { opacity: 1; }

    /* Placeholder */
    .qr-stage__placeholder {
      display: flex; flex-direction: column;
      align-items: center; gap: .5rem;
      opacity: .3; pointer-events: none; text-align: center; padding: 1rem;
    }
    .qr-stage__placeholder svg   { width: 2.5rem; height: 2.5rem; stroke: var(--color-accent); }
    .qr-stage__placeholder span  { font-family: 'DM Mono', monospace; font-size: .6875rem; color: var(--color-muted); line-height: 1.5; }

    /* Canvas */
    .qr-canvas {
      display: none;
      max-width: 100%; height: auto;
      image-rendering: pixelated;
      image-rendering: crisp-edges;
      border-radius: 4px;
    }
    .qr-canvas--visible { display: block; }

    /* Label do texto gerado */
    .qr-card__label {
      font-family: 'DM Mono', monospace;
      font-size: .625rem; color: var(--color-muted);
      text-align: center; word-break: break-all; line-height: 1.5;
      width: 100%;
      transition: color .35s;
    }

    /* Botões de ação (baixar / copiar) */
    .qr-card__actions {
      display: grid; grid-template-columns: 1fr 1fr;
      gap: .6rem; width: 100%;
    }
    .qr-card__actions--hidden { display: none; }

    /* ─────────────────────────────────────
       10. FORMULÁRIO
    ───────────────────────────────────── */

    /* Grid tamanho + cores, alinhados pela base */
    .options-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: .875rem;
      align-items: end;
    }

    .options-grid__col { display: flex; flex-direction: column; }

    /* Par de color pickers */
    .color-pair {
      display: grid; grid-template-columns: 1fr 1fr; gap: .5rem;
    }
    .color-pair__item { display: flex; flex-direction: column; gap: .3rem; }
    .color-pair__item .field[type="color"] {
      height: 2.75rem; padding: .25rem; cursor: pointer;
    }
    .color-pair__item .field[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
    .color-pair__item .field[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }

    /* ─────────────────────────────────────
       11. ANIMAÇÕES
       Desabilitadas se o usuário preferir
    ───────────────────────────────────── */
    @keyframes fadeUp {
      from { opacity: 0; transform: translateY(16px); }
      to   { opacity: 1; transform: translateY(0); }
    }
    @keyframes popIn {
      from { opacity: 0; transform: scale(.92); }
      to   { opacity: 1; transform: scale(1); }
    }

    .anim-fade-1 { animation: fadeUp .5s ease both; animation-delay: .05s; }
    .anim-fade-2 { animation: fadeUp .5s ease both; animation-delay: .15s; }
    .anim-fade-3 { animation: fadeUp .5s ease both; animation-delay: .25s; }
    .anim-pop    { animation: popIn .4s cubic-bezier(.34,1.56,.64,1) both; }

    @media (prefers-reduced-motion: reduce) {
      .anim-fade-1, .anim-fade-2, .anim-fade-3, .anim-pop { animation: none; }
      .qr-stage__scan-line { animation: none; }
    }

    /* ─────────────────────────────────────
       12. TOAST
    ───────────────────────────────────── */
    .toast {
      position: fixed; bottom: 2rem; left: 50%;
      transform: translateX(-50%) translateY(12px);
      background: var(--color-ink); color: var(--color-paper);
      font-family: 'DM Mono', monospace;
      font-size: .6875rem; letter-spacing: .08em;
      padding: .65rem 1.25rem;
      border-radius: var(--radius-sm);
      border: 1.5px solid var(--color-border-dk);
      box-shadow: var(--shadow-btn);
      opacity: 0; pointer-events: none; white-space: nowrap; z-index: 300;
      bottom: max(2rem, calc(env(safe-area-inset-bottom) + .5rem));
      transition: opacity .3s, transform .3s;
    }
    .toast--visible { opacity: 1; transform: translateX(-50%) translateY(0); }

    /* ─────────────────────────────────────
       13. RODAPÉ
    ───────────────────────────────────── */
    .page-footer {
      position: relative; z-index: 1;
      width: 100%;
      text-align: center;
      padding: .75rem 1rem;
      background: transparent;
    }

    .page-footer__line {
      display: block;
      font-family: 'DM Mono', monospace;
      font-size: .625rem;
      letter-spacing: .08em;
      line-height: 1.8;
      color: var(--color-muted);
    }

    .page-footer__author {
      font-size: .75rem;
      color: var(--color-ink);
    }
