/* ============================================================
   Backlink Engine — design system
   Light editorial-green theme (matches High DR backlink page)
   Manrope body · Space Grotesk display · JetBrains Mono
   Scoped to tool IDs + page chrome. JS contracts preserved.
   ============================================================ */

:root {
  color-scheme: light;

  /* surfaces */
  --bg: #f4f7f5;
  --bg-2: #edf1ef;
  --card: #ffffff;
  --card-2: #f7faf8;
  --surface-tint: rgba(7, 20, 14, 0.035);

  /* lines */
  --line: rgba(7, 20, 14, 0.09);
  --line-2: rgba(7, 20, 14, 0.2);

  /* text */
  --ink: #0e1512;
  --ink-2: #33403a;
  --muted: #5e6b64;

  /* accent */
  --accent: #0a8056;
  --accent-2: #16b984;
  --accent-soft: rgba(10, 128, 86, 0.09);
  --accent-line: rgba(10, 128, 86, 0.38);
  --on-accent: #ffffff;

  /* semantic */
  --ok: #0e9c68;
  --bad: #c0392b;
  --warn: #b7791f;
  --ring: rgba(10, 128, 86, 0.28);

  /* shape */
  --shadow: 0 18px 44px -26px rgba(8, 24, 17, 0.32);
  --shadow-lift: 0 22px 50px -30px rgba(10, 128, 86, 0.45);
  --radius-s: 10px;
  --radius-m: 15px;
  --radius-l: 22px;

  /* motion */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* type */
  --font: "Manrope", "Avenir Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Space Grotesk", "Avenir Next", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

img, svg { max-width: 100%; }

a { color: inherit; }

button { font: inherit; color: inherit; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16.5px;
  line-height: 1.6;
  font-weight: 400;
  color: var(--ink);
  background:
    radial-gradient(60vw 60vw at 12% -8%, rgba(10, 128, 86, 0.1), transparent 62%),
    radial-gradient(52vw 46vw at 96% 8%, rgba(10, 128, 86, 0.055), transparent 60%),
    radial-gradient(70vw 60vw at 50% 118%, rgba(10, 128, 86, 0.06), transparent 65%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* film grain — breaks digital flatness */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

.shell {
  width: min(1080px, calc(100% - 40px));
  margin-inline: auto;
  position: relative;
  z-index: 2;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  z-index: 1000;
  padding: 10px 18px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
  border-radius: 999px;
  transition: top 0.25s var(--ease);
}
.skip-link:focus { top: 16px; }

/* ---------- header ---------- */
.site-head {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(18px) saturate(1.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
}

.head-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: inherit;
  flex: 0 0 auto;
  min-width: 0;
}

.brand-mark { display: grid; place-items: center; }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-tag {
  font-size: 0.64rem;
  color: var(--muted);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
}

.head-pill {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-2);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
  transition: color 0.3s var(--ease), border-color 0.3s var(--ease),
    background 0.3s var(--ease), transform 0.3s var(--ease);
}

.head-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.head-pill-link { text-decoration: none; }
.head-pill-link:hover {
  border-color: var(--line-2);
  color: var(--ink);
  transform: translateY(-1px);
}
.head-pill-link:active { transform: translateY(0) scale(0.98); }

.head-pill-active {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------- hero ---------- */
.hero {
  padding: clamp(48px, 8vw, 88px) 0 clamp(28px, 4vw, 44px);
  text-wrap: balance;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 22px;
  font-size: 0.69rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid rgba(10, 128, 86, 0.22);
  background: var(--accent-soft);
  padding: 7px 15px;
  border-radius: 999px;
}

.hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.3rem, 5.6vw, 3.6rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.035em;
  max-width: 17ch;
  text-wrap: balance;
}

.hero-sub {
  margin: 20px 0 0;
  max-width: 62ch;
  font-size: 1.06rem;
  color: var(--ink-2);
}

.hero-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 26px 0 0;
  padding: 0;
}

.chip {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-2);
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  padding: 7px 14px;
  border-radius: 999px;
  transition: border-color 0.3s var(--ease), color 0.3s var(--ease);
}
.chip:hover { border-color: var(--line-2); color: var(--ink); }

.chip-hot {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
  font-weight: 600;
}

/* ---------- console (tool card) ---------- */
.console {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  padding: clamp(18px, 3vw, 28px);
  margin-bottom: clamp(48px, 8vw, 88px);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

/* ---------- controls ---------- */
#controls {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
}

#urlInput {
  width: 100%;
  min-width: 0;
  padding: 13px 15px;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color 0.3s var(--ease), background 0.3s var(--ease);
}

#urlInput::placeholder { color: var(--muted); font-weight: 400; }

#urlInput:hover { border-color: var(--line-2); }

#urlInput:focus {
  outline: none;
  border-color: var(--accent-line);
  background: rgba(10, 128, 86, 0.07);
}

#startBtn,
#toggleAdvancedBtn,
#copyBtn,
#downloadBtn {
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 13px 19px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.2s var(--ease), background 0.25s var(--ease),
    border-color 0.25s var(--ease), color 0.25s var(--ease),
    box-shadow 0.25s var(--ease);
}

#startBtn:active,
#toggleAdvancedBtn:active,
#copyBtn:active,
#downloadBtn:active { transform: translateY(1px) scale(0.99); }

#startBtn {
  color: var(--on-accent);
  background: linear-gradient(150deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 18px -10px rgba(10, 128, 86, 0.55);
}

#startBtn:hover {
  box-shadow: 0 12px 26px -12px rgba(10, 128, 86, 0.7);
}

#toggleAdvancedBtn {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

#toggleAdvancedBtn:hover {
  background: var(--card-2);
  border-color: var(--accent-line);
  color: var(--accent);
}

/* ---------- advanced panel ---------- */
#advancedPanel {
  margin-top: 14px;
  padding: 6px;
  background: var(--surface-tint);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
}

#advancedPanel > * {
  background: var(--card);
  border-radius: 11px;
}

#advancedPanel label {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 12px;
  margin-bottom: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink-2);
  font-size: 0.9rem;
  transition: border-color 0.3s var(--ease), background 0.3s var(--ease);
}

#advancedPanel label:hover { border-color: var(--line-2); }

#advancedPanel label:last-child { margin-bottom: 0; }

#advancedPanel .field-label {
  flex: 0 0 auto;
  min-width: 150px;
  font-weight: 500;
  color: var(--ink-2);
}

#advancedPanel select {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  transition: border-color 0.3s var(--ease), background 0.3s var(--ease);
}

#advancedPanel select:hover { border-color: var(--accent-line); }

#advancedPanel select:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(10, 128, 86, 0.07);
}

#advancedPanel select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#advancedPanel input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.range-count {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  min-width: 2ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#advancedPanel .check-field {
  cursor: pointer;
  user-select: none;
}

#advancedPanel .check-field input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  cursor: pointer;
  flex: 0 0 auto;
}

#advancedPanel .check-field span { color: var(--ink); }

/* ---------- share row ---------- */
#shareControls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 14px;
}

#newUrl {
  width: 100%;
  min-width: 0;
  padding: 12px 15px;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  background: #fff;
  border: 1px dashed var(--line-2);
  border-radius: 12px;
  transition: border-color 0.3s var(--ease);
}

#newUrl:focus {
  outline: none;
  border-color: var(--accent-line);
}

#copyBtn {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

#copyBtn:hover {
  border-color: var(--accent-line);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- actions ---------- */
.actions-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
}

#downloadBtn {
  color: var(--ink-2);
  background: transparent;
  border-color: var(--line);
}

#downloadBtn:hover {
  border-color: var(--accent-line);
  color: var(--accent);
  background: var(--accent-soft);
}

#externalLink {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s var(--ease);
}

#externalLink:hover { border-bottom-color: var(--accent); }

/* ---------- progress ---------- */
#progressContainer {
  margin: 20px 0 0;
  color: var(--muted);
}

#progressContainer > div:first-child {
  height: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

#progressBar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  background-size: 200% 100%;
  transition: width 0.45s var(--ease);
  animation: progress-shimmer 1.8s linear infinite;
}

@keyframes progress-shimmer {
  0% { background-position: 0% 0; }
  100% { background-position: 200% 0; }
}

#progressText {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- screenshot preview ---------- */
#previewwebsite {
  display: none;
  width: 100%;
  height: auto;
  max-height: 320px;
  object-fit: cover;
  object-position: top;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  margin: 18px 0 0;
  background: var(--bg-2);
  box-shadow: var(--shadow);
}

/* ---------- results ---------- */
.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 26px 0 12px;
}

.results-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.results-hint {
  font-size: 0.76rem;
  color: var(--muted);
}

.results-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* empty state (JS clears with innerHTML='') */
.results-list:empty::before {
  content: "No links yet — enter a URL and press Generate.";
  display: block;
  padding: 26px 18px;
  text-align: center;
  font-size: 0.86rem;
  color: var(--muted);
  background: var(--surface-tint);
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-m);
}

.results-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 11px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  transition: border-color 0.3s var(--ease), transform 0.3s var(--ease),
    box-shadow 0.3s var(--ease);
  animation: row-in 0.3s var(--ease-out) both;
}

@keyframes row-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.results-list li:hover {
  border-color: var(--line-2);
  transform: translateY(-2px);
  box-shadow: 0 14px 30px -22px rgba(8, 24, 17, 0.4);
}

.results-list a {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--ink-2);
  word-break: break-all;
  text-decoration: none;
  transition: color 0.25s var(--ease);
}

.results-list a:hover { color: var(--accent); }

/* status chips — JS sets .status.loading/.success/.failure + emoji */
.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  padding: 4px 9px;
  font-size: 0.78rem;
  line-height: 1;
  border-radius: 999px;
  border: 1px solid transparent;
  flex: 0 0 auto;
}

.status.loading {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.status.success {
  background: rgba(14, 156, 104, 0.1);
  border-color: rgba(14, 156, 104, 0.35);
}

.status.failure {
  background: rgba(192, 57, 43, 0.09);
  border-color: rgba(192, 57, 43, 0.32);
}

/* ---------- footer ---------- */
.site-foot {
  border-top: 1px solid var(--line);
  padding: 30px 0 44px;
}

.foot-inner p {
  margin: 0;
  max-width: 70ch;
  font-size: 0.85rem;
  color: var(--muted);
}

.foot-inner p + p {
  margin-top: 14px;
}

.foot-credit a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--accent-line);
  transition: color 0.3s var(--ease), border-color 0.3s var(--ease);
}

.foot-credit a:hover {
  color: var(--accent-2);
  border-bottom-color: var(--accent-2);
}

/* ---------- focus visibility ---------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .shell { width: min(100% - 28px, 1080px); }

  .head-pill { display: none; }

  .head-nav .head-pill { display: inline-block; }

  #controls { grid-template-columns: 1fr; }

  #startBtn,
  #toggleAdvancedBtn { width: 100%; }

  #shareControls { grid-template-columns: 1fr; }

  #copyBtn { width: 100%; }

  #advancedPanel label {
    flex-wrap: wrap;
    gap: 8px;
  }

  #advancedPanel .field-label {
    min-width: 0;
    width: 100%;
  }

  #advancedPanel select,
  #advancedPanel input[type="range"] { width: 100%; flex: 1 1 100%; }

  .actions-row { flex-direction: column; align-items: stretch; }

  #downloadBtn { width: 100%; }

  #externalLink { text-align: center; }

  .results-list li { grid-template-columns: 1fr auto; }
}

/* ---------- motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
