/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f6f7fb;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --border: #e2e5ed;
  --border-strong: #cfd4e0;
  --text: #171923;
  --text-dim: #565c6e;
  --text-faint: #8a90a2;
  --accent: #4f5bd5;
  --accent-hover: #3f4ac0;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(79, 91, 213, .10);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, .12);
  --error: #e11d48;
  --error-soft: rgba(225, 29, 72, .12);
  --warn: #d97706;

  --code-bg: #1e2130;
  --code-gutter-bg: #191b28;
  --code-gutter-text: #565c74;
  --code-text: #e6e8f0;

  --tok-key: #7fb0ff;
  --tok-string: #9fe6a0;
  --tok-number: #f7b76d;
  --tok-boolean: #d9a5f2;
  --tok-null: #d9a5f2;
  --tok-punct: #8890ac;
  --tok-brace: #b9bfd6;

  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 40, .06);
  --shadow-md: 0 8px 24px rgba(20, 22, 40, .08);
  --shadow-lg: 0 16px 48px rgba(20, 22, 40, .14);

  --font-sans: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --header-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0e14;
    --bg-elevated: #14151f;
    --surface: #14151f;
    --border: #262838;
    --border-strong: #33364a;
    --text: #eef0f7;
    --text-dim: #a4a8bd;
    --text-faint: #6b7086;
    --accent: #7c86ea;
    --accent-hover: #8f98ee;
    --accent-contrast: #0d0e14;
    --accent-soft: rgba(124, 134, 234, .16);
    --success: #34d16f;
    --success-soft: rgba(52, 209, 111, .14);
    --error: #f4527a;
    --error-soft: rgba(244, 82, 122, .16);

    --code-bg: #0c0d15;
    --code-gutter-bg: #0a0b11;
    --code-gutter-text: #4a4e66;
    --code-text: #e6e8f0;
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .32);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .45);
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  overscroll-behavior-y: none;
}

img, svg, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.15; letter-spacing: -0.01em; font-weight: 800; }
::selection { background: var(--accent-soft); color: var(--text); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* =============================================================
   3. Utilities
   ============================================================= */
.container { width: 100%; max-width: 1080px; margin-inline: auto; padding-inline: 20px; }

.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .6rem 1rem; background: var(--accent); color: var(--accent-contrast);
  z-index: 9999; border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 1rem; }

/* =============================================================
   4. Typography
   ============================================================= */
h1 { font-size: clamp(1.9rem, 4vw, 2.9rem); }
h2 { font-size: clamp(1.5rem, 2.6vw, 2rem); margin-bottom: .9rem; }
.hero-sub { color: var(--text-dim); font-size: clamp(1rem, 1.6vw, 1.15rem); max-width: 62ch; margin-top: .9rem; }

/* =============================================================
   5. Components
   ============================================================= */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .6rem 1rem; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-weight: 600; font-size: .88rem;
  white-space: nowrap; transition: background .15s var(--ease-out), border-color .15s var(--ease-out), transform .1s var(--ease-out);
}
.btn:hover { border-color: var(--border-strong); background: var(--bg); }
.btn:active { transform: translateY(1px); }
.btn svg { flex: 0 0 auto; }
.btn--accent { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn--accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn--ghost:hover { background: var(--bg); color: var(--text); }
.btn--small { padding: .4rem .7rem; font-size: .8rem; }
.btn--file { position: relative; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  color: var(--text-dim); border: 1px solid transparent;
}
.icon-btn:hover:not(:disabled) { background: var(--bg); color: var(--text); border-color: var(--border); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* Dropdown */
.dropdown { position: relative; }
.dropdown .chev { transition: transform .15s var(--ease-out); }
.dropdown.is-open .chev { transform: rotate(180deg); }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); padding: .35rem; z-index: 20;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .15s var(--ease-out), transform .15s var(--ease-out), visibility .15s;
}
.dropdown.is-open .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-menu button {
  display: block; width: 100%; text-align: left; padding: .55rem .7rem;
  border-radius: 6px; font-size: .87rem; font-weight: 500;
}
.dropdown-menu button:hover { background: var(--accent-soft); color: var(--accent); }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: .5rem; font-size: .85rem; font-weight: 600; color: var(--text-dim); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative; width: 34px; height: 20px; border-radius: 999px;
  background: var(--border-strong); transition: background .15s var(--ease-out); flex: 0 0 auto;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .15s var(--ease-out);
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

select {
  font: inherit; font-size: .85rem; font-weight: 600; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .45rem .6rem; cursor: pointer;
}
select:disabled { opacity: .5; cursor: default; }

/* Toolbars */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.toolbar--primary { padding: .9rem .9rem .6rem; }
.toolbar--options {
  padding: .5rem .9rem; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  gap: 1.1rem; row-gap: .6rem; background: var(--bg);
}
.opt-group { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--text-dim); }
.opt-group label:not(.switch) { font-weight: 600; }
.opt-group--sort { gap: .6rem; }
.opt-group--view { margin-inline-start: auto; }

.view-tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.view-tab { padding: .4rem .95rem; border-radius: 999px; font-size: .82rem; font-weight: 700; color: var(--text-dim); }
.view-tab.is-active { background: var(--accent); color: var(--accent-contrast); }

/* Search bar */
.searchbar {
  display: flex; align-items: center; gap: .5rem; padding: .6rem .9rem;
  color: var(--text-faint); border-bottom: 1px solid var(--border);
}
.searchbar input {
  flex: 1 1 auto; border: 0; background: transparent; font: inherit; font-size: .9rem;
  color: var(--text); outline: none;
}
.search-count { font-size: .78rem; font-weight: 600; color: var(--text-faint); white-space: nowrap; }

/* Status bar */
.status-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .6rem; padding: .7rem .9rem; border-top: 1px solid var(--border);
}
.validation-badge {
  display: inline-flex; align-items: center; gap: .45rem; font-size: .85rem; font-weight: 700;
  padding: .35rem .75rem; border-radius: 999px; color: var(--text-dim); background: var(--bg);
}
.validation-badge .ico-ok, .validation-badge .ico-err { display: none; }
.validation-badge[data-state="valid"] { background: var(--success-soft); color: var(--success); }
.validation-badge[data-state="valid"] .ico-ok { display: block; }
.validation-badge[data-state="invalid"] { background: var(--error-soft); color: var(--error); }
.validation-badge[data-state="invalid"] .ico-err { display: block; }
.stats-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.stat-chip {
  font-size: .78rem; color: var(--text-dim); background: var(--bg); border: 1px solid var(--border);
  border-radius: 999px; padding: .3rem .65rem;
}
.stat-chip strong { color: var(--text); font-weight: 700; }

/* =============================================================
   6. Sections
   ============================================================= */

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 30; height: var(--header-h);
  display: flex; align-items: center; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand-mark { color: var(--accent); }
.brand strong { color: var(--accent); }
.header-nav { display: flex; gap: 1.4rem; }
.header-nav a { font-size: .9rem; font-weight: 600; color: var(--text-dim); }
.header-nav a:hover { color: var(--text); }

/* Hero */
.hero { padding-block: clamp(2.2rem, 5vw, 3.4rem) 1.2rem; }

/* Tool section / card */
.tool-section { padding-bottom: 1.4rem; }
.tool-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); overflow: hidden;
}

/* Editor */
.editor-shell { position: relative; }
.editor-view { position: relative; }
.editor-wrap { display: flex; height: clamp(340px, 52vh, 540px); background: var(--code-bg); }
.gutter {
  flex: 0 0 auto; overflow: hidden; min-width: 3.6ch;
  padding: 14px 10px 14px 16px; text-align: right; user-select: none;
  font: 400 14px/1.62 var(--font-mono); color: var(--code-gutter-text); background: var(--code-gutter-bg);
  white-space: pre;
}
.code-area { position: relative; flex: 1 1 auto; overflow: hidden; }
.error-band {
  position: absolute; left: 0; right: 0; height: calc(14px * 1.62);
  background: var(--error-soft); pointer-events: none; z-index: 1; transition: top .1s var(--ease-out);
}
.highlight-layer, .editor-input {
  position: absolute; inset: 0; margin: 0; padding: 14px 16px;
  font: 400 14px/1.62 var(--font-mono); white-space: pre; tab-size: 2;
}
.highlight-layer {
  overflow: hidden; color: var(--code-text); z-index: 0; pointer-events: none;
}
.highlight-layer code { font: inherit; }
.editor-input {
  overflow: auto; background: transparent; color: transparent; caret-color: var(--code-text);
  border: 0; resize: none; outline: none; z-index: 2;
}
.editor-input::selection { background: rgba(124, 134, 234, .35); }
.editor-input::placeholder { color: var(--code-gutter-text); }

.dropzone-hint {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent-contrast);
  font-weight: 700; font-size: 1.1rem; border: 2px dashed var(--accent); pointer-events: none; z-index: 5;
}
.editor-shell.is-dragover .dropzone-hint { display: flex; }

/* Tree view */
.tree-view { min-height: clamp(340px, 52vh, 540px); max-height: clamp(340px, 52vh, 540px); overflow: auto; padding: 1rem 1.1rem; background: var(--code-bg); }
.tree-empty { color: var(--text-faint); font-size: .92rem; padding: 1rem 0; }
.tree-root, .tree-node { font: 400 13.5px/1.7 var(--font-mono); }
.tree-node { position: relative; }
.tree-row { display: flex; align-items: baseline; gap: .3rem; padding: 1px 0; border-radius: 4px; }
.tree-row:hover { background: rgba(255,255,255,.04); }
.tree-row:hover .tree-copy { opacity: 1; }
.tree-toggle {
  flex: 0 0 auto; width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--code-gutter-text); transform: rotate(0deg); transition: transform .12s var(--ease-out);
}
.tree-node[data-open="true"] > .tree-row .tree-toggle { transform: rotate(90deg); }
.tree-node[data-open="false"] > .tree-children { display: none; }
.tree-key { color: var(--tok-key); }
.tree-punct { color: var(--tok-punct); }
.tree-string { color: var(--tok-string); }
.tree-number { color: var(--tok-number); }
.tree-boolean { color: var(--tok-boolean); }
.tree-null { color: var(--tok-null); }
.tree-meta { color: var(--code-gutter-text); font-size: .85em; margin-inline-start: .3rem; }
.tree-children { margin-inline-start: 1.15rem; border-inline-start: 1px dashed rgba(255,255,255,.1); padding-inline-start: .55rem; }
.tree-copy {
  opacity: 0; margin-inline-start: auto; flex: 0 0 auto; width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 5px; color: var(--code-gutter-text);
}
.tree-copy:hover { color: var(--code-text); background: rgba(255,255,255,.08); }
.tree-copy.is-copied { color: var(--success); opacity: 1; }
.tree-ellipsis { display: none; color: var(--code-gutter-text) !important; }
.tree-node[data-open="false"] > .tree-row > .tree-ellipsis { display: inline; }
.tree-node[data-open="false"] > .tree-row > .tree-meta { display: none; }
.tree-node[data-open="false"] > .tree-row--close { display: none; }

/* Syntax highlighting tokens (editor pre/code layer) */
.tok-key { color: var(--tok-key); font-weight: 600; }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-boolean { color: var(--tok-boolean); font-weight: 600; }
.tok-null { color: var(--tok-null); font-style: italic; }
.tok-brace { color: var(--tok-brace); font-weight: 700; }
.tok-punct { color: var(--tok-punct); }

/* Noscript fallback */
.noscript-notice {
  margin: 1rem; padding: .9rem 1.1rem; border-radius: var(--radius-sm);
  background: var(--warn); color: #1a1300; font-weight: 600; font-size: .88rem;
}

/* CSV panel */
.csv-panel { border-top: 1px solid var(--border); padding: 1rem 1.1rem 1.2rem; background: var(--bg); }
.csv-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.csv-panel-header h2 { font-size: 1rem; margin: 0; }
.csv-help { font-size: .85rem; color: var(--text-dim); margin-bottom: .6rem; }
.csv-textarea {
  width: 100%; min-height: 160px; resize: vertical; font: 400 13px/1.6 var(--font-mono);
  padding: .8rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); margin-bottom: .6rem;
}
.csv-actions { display: flex; gap: .5rem; }

/* Privacy badge */
.privacy-badge {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .6rem;
  margin-top: .9rem; font-size: .85rem; color: var(--text-dim); color: var(--success);
}
.privacy-badge svg { color: var(--success); flex: 0 0 auto; }
.privacy-limits { color: var(--text-faint); font-weight: 500; }

/* Ad slots */
.ad-slot {
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  color: var(--text-faint); font-size: .78rem; font-weight: 700; letter-spacing: .08em;
  background: var(--surface);
}
.ad-slot--banner { min-height: 90px; margin-block: 1.4rem; }
.ad-slot--rail {
  position: fixed; top: 50%; transform: translateY(-50%);
  width: 160px; height: 480px; z-index: 5;
}
.ad-slot--left { left: max(12px, calc(50% - 700px)); }
.ad-slot--right { right: max(12px, calc(50% - 700px)); }

.ad-corner {
  position: fixed; bottom: 16px; right: 16px; z-index: 40;
  display: flex; align-items: center; gap: .5rem; padding: .55rem .9rem .55rem 1rem;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: 999px;
  box-shadow: var(--shadow-md); font-size: .74rem; font-weight: 800; letter-spacing: .06em;
  color: var(--text-faint); opacity: 0; visibility: hidden; transform: translateY(8px);
  transition: opacity .2s var(--ease-out), transform .2s var(--ease-out), visibility .2s;
}
.ad-corner.is-visible { opacity: 1; visibility: visible; transform: translateY(0); }
.ad-corner-close { font-size: 1rem; line-height: 1; color: var(--text-faint); }
.ad-corner-close:hover { color: var(--text); }

/* Content sections */
.section { padding-block: clamp(2rem, 4vw, 3.2rem); border-top: 1px solid var(--border); }

.steps-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem; }
.step-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.3rem 1.2rem;
}
.step-card h3 { font-size: 1.02rem; margin-bottom: .5rem; }
.step-card p { color: var(--text-dim); font-size: .92rem; }

.seo-text p { color: var(--text-dim); margin-bottom: 1rem; max-width: 76ch; }
.seo-text p:last-child { margin-bottom: 0; }
.seo-text strong { color: var(--text); }

.usecases-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.usecase-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.usecase-card h3 { font-size: .98rem; margin-bottom: .4rem; }
.usecase-card p { color: var(--text-dim); font-size: .88rem; }

.faq-list { display: flex; flex-direction: column; gap: .6rem; max-width: 74ch; }
.faq-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .2rem .2rem;
}
.faq-item summary {
  cursor: pointer; list-style: none; padding: .9rem 1rem; font-weight: 700; font-size: .96rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+"; font-size: 1.3rem; font-weight: 400; color: var(--text-faint); flex: 0 0 auto;
  transition: transform .15s var(--ease-out);
}
.faq-item[open] summary::after { transform: rotate(45deg); }
.faq-item p { padding: 0 1rem 1rem; color: var(--text-dim); font-size: .92rem; }

.tools-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.tool-mini-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; transition: border-color .15s var(--ease-out), transform .15s var(--ease-out);
}
.tool-mini-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.tool-mini-card h3 { font-size: .92rem; margin-bottom: .3rem; }
.tool-mini-card p { color: var(--text-dim); font-size: .82rem; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding-block: 2rem 1.2rem; margin-top: 1rem; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1.4rem; }
.footer-brand span { font-weight: 700; }
.footer-brand strong { color: var(--accent); }
.footer-brand p { color: var(--text-faint); font-size: .85rem; margin-top: .4rem; max-width: 40ch; }
.footer-links { display: flex; gap: 1.1rem; }
.footer-links a { font-size: .87rem; color: var(--text-dim); }
.footer-links a:hover { color: var(--text); }
.footer-copy { color: var(--text-faint); font-size: .8rem; margin-top: 1.4rem; }

/* =============================================================
   7. Effects
   ============================================================= */
.tree-node, .step-card, .usecase-card, .tool-mini-card { animation: none; }

/* =============================================================
   8. Responsive
   ============================================================= */
@media (min-width: 540px) {
  .toolbar--primary { padding-inline: 1.2rem; }
}

@media (min-width: 720px) {
  .header-nav a:nth-child(4) { display: none; }
}

@media (min-width: 960px) {
  .header-nav a:nth-child(4) { display: inline; }
  .usecases-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1280px) {
  .steps-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 959px) {
  .ad-slot--rail { display: none; }
}

@media (max-width: 719px) {
  .header-nav { display: none; }
  .steps-grid { grid-template-columns: 1fr; }
  .usecases-grid { grid-template-columns: 1fr; }
  .tools-grid { grid-template-columns: repeat(2, 1fr); }
  .opt-group--view { margin-inline-start: 0; }
  .toolbar--options { gap: .7rem; }
  .status-bar { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 539px) {
  .tools-grid { grid-template-columns: 1fr; }
  .btn span.label-full { display: none; }
  .ad-corner { right: 10px; bottom: 10px; padding: .45rem .75rem .45rem .9rem; }
}

/* =============================================================
   9. Reduced-motion (solo lo intrusivo)
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  .tool-mini-card { transition: none; }
}
