/* ============================================================
   Portal do BPC — Tweaks (paleta + tipografia + textura)
   tweaks.css
   
   Aplica overrides via [data-theme] e [data-accent] no <html>.
   Camada opcional — não removida em produção, mas inerte
   quando nenhum atributo está setado.
   ============================================================ */

/* ---------- ACENTOS ---------- */
html[data-accent="olive"] {
  --terra-400: #b5c89a;
  --terra-500: #8a9a76;
  --terra-600: #8a9a76;
  --terra-700: #6e7d5d;
  --terra-800: #4a5640;
  --terra-100: #2a3025;
  --terra-200: #3a4232;
  --terra-300: #a5b58e;
  --glow-terra: 0 0 40px rgba(138, 154, 118, 0.25);
}

html[data-accent="indigo"] {
  --terra-400: #8a9bd6;
  --terra-500: #5b6bc4;
  --terra-600: #5b6bc4;
  --terra-700: #4858a8;
  --terra-800: #2f3b80;
  --terra-100: #1c2440;
  --terra-200: #2a3454;
  --terra-300: #a8b6e0;
  --glow-terra: 0 0 40px rgba(91, 107, 196, 0.28);
}

html[data-accent="bordeaux"] {
  --terra-400: #c97a86;
  --terra-500: #a04050;
  --terra-600: #a04050;
  --terra-700: #823340;
  --terra-800: #5e2530;
  --terra-100: #2e1820;
  --terra-200: #3e2028;
  --terra-300: #d99aa5;
  --glow-terra: 0 0 40px rgba(160, 64, 80, 0.25);
}

/* ---------- TEMA ---------- */
/* "Light" — paper/cream */
html[data-theme="light"] {
  --cream:    #f7f1e6;
  --bone:     #ffffff;
  --bone-2:   #fbf5ea;
  --line:     #e6d9c4;
  --line-2:   #d4c4a8;
  --ink-900:  #1a140e;
  --ink-700:  #2a1f15;
  --ink-500:  #6a5848;
  --ink-300:  #a89678;
  --shadow-sm: 0 1px 2px rgba(60, 30, 10, 0.06);
  --shadow-md: 0 8px 24px rgba(60, 30, 10, 0.08), 0 1px 2px rgba(60, 30, 10, 0.05);
  --shadow-lg: 0 24px 60px rgba(60, 30, 10, 0.12), 0 6px 12px rgba(60, 30, 10, 0.06);
  --shadow-xl: 0 40px 100px rgba(60, 30, 10, 0.16), 0 12px 24px rgba(60, 30, 10, 0.08);
}

html[data-theme="light"] body {
  background-image:
    linear-gradient(rgba(196, 103, 58, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(196, 103, 58, 0.06) 1px, transparent 1px);
}

/* "Noir" — alto contraste, fundo profundo */
html[data-theme="noir"] {
  --cream:    #0a0806;
  --bone:     #14100c;
  --bone-2:   #1f1812;
  --line:     #2a2018;
  --line-2:   #382a20;
  --ink-500:  #9e8c78;
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.6), 0 1px 2px rgba(0, 0, 0, 0.4);
}

html[data-theme="noir"] body {
  background-image:
    linear-gradient(rgba(196, 103, 58, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(196, 103, 58, 0.025) 1px, transparent 1px);
}

/* ---------- TEXTURA DE GRÃO (atmosfera editorial) ---------- */
/* Sempre ativa, mas sutil. Pode ser desligada via [data-grain="off"]. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.22;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.18 0'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
}

html[data-grain="off"] body::before { display: none; }
html[data-theme="light"] body::before { opacity: 0.14; mix-blend-mode: multiply; }

/* ---------- PARES DE FONTES ---------- */
html[data-font="playfair"] {
  --font-serif: 'Playfair Display', 'Fraunces', Georgia, serif;
  --font-sans:  'Manrope', 'Inter', system-ui, sans-serif;
}
html[data-font="dmserif"] {
  --font-serif: 'DM Serif Display', 'Fraunces', Georgia, serif;
  --font-sans:  'IBM Plex Sans', 'Inter', system-ui, sans-serif;
}
html[data-font="instrument"] {
  --font-serif: 'Instrument Serif', 'Fraunces', Georgia, serif;
  --font-sans:  'Geist', 'Inter', system-ui, sans-serif;
}

/* ============================================================
   PAINEL DE TWEAKS
   ============================================================ */
.tweaks-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--bone);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  z-index: 9998;
  font-family: var(--font-sans);
  color: var(--ink-900);
  overflow: hidden;
  animation: tweaks-in 320ms var(--ease-spring);
}

@keyframes tweaks-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.tweaks-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.tweaks-head .label {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.tweaks-head .label em {
  color: var(--terra-500);
  font-style: italic;
}
.tweaks-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--ink-500);
  font-size: 18px;
  cursor: pointer;
  border-radius: 999px;
  transition: background var(--dur-micro) var(--ease-out);
}
.tweaks-close:hover { background: var(--bone-2); color: var(--ink-900); }

.tweaks-body {
  padding: 14px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 70vh;
  overflow-y: auto;
}

.tweaks-row { display: flex; flex-direction: column; gap: 8px; }
.tweaks-row > .key {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-500);
}

.tweaks-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.tweaks-swatch {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--dur-micro) var(--ease-out), border-color var(--dur-micro) var(--ease-out);
  position: relative;
}
.tweaks-swatch:hover { transform: scale(1.1); }
.tweaks-swatch.is-active { border-color: var(--ink-900); }
.tweaks-swatch.is-active::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
  font-weight: 700;
  mix-blend-mode: difference;
}

.tweaks-seg {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 4px;
  background: var(--bone-2);
  padding: 4px;
  border-radius: 10px;
}
.tweaks-seg button {
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--ink-500);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-micro) var(--ease-out), color var(--dur-micro) var(--ease-out);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tweaks-seg button.is-active {
  background: var(--bone);
  color: var(--ink-900);
  box-shadow: var(--shadow-sm);
}

.tweaks-reset {
  margin-top: 4px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--ink-500);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  align-self: flex-start;
  transition: all var(--dur-micro) var(--ease-out);
}
.tweaks-reset:hover { color: var(--ink-900); border-color: var(--ink-500); }

/* Compact em telas pequenas */
@media (max-width: 480px) {
  .tweaks-panel { right: 12px; bottom: 12px; left: 12px; width: auto; }
}
