/* ============================================================
   Backlink Engine — design system
   Dark signal-console theme · Space Grotesk + JetBrains Mono
   Scoped to tool IDs + page chrome. JS contracts preserved.
   ============================================================ */

:root {
  --bg: #0a0e13;
  --bg-2: #0e141b;
  --card: #121926;
  --card-2: #16202e;
  --line: #223047;
  --line-2: #2c3c55;
  --ink: #edf2f9;
  --ink-2: #9fb0c7;
  --muted: #6b7c95;
  --accent: #ffb224;
  --accent-2: #ff8a3d;
  --on-accent: #141005;
  --ok: #3ddc97;
  --bad: #ff6b6b;
  --warn: #ffb224;
  --ring: rgba(255, 178, 36, 0.28);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 22px;
  --font: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 85% -10%, rgba(255, 178, 36, 0.07), transparent 60%),
    radial-gradient(900px 480px at -10% 30%, rgba(255, 138, 61, 0.05), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* film grain — breaks digital flatness */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.05;
  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='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
}

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

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

/* ---------- header ---------- */
.site-head {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(14px);
  background: rgba(10, 14, 19, 0.78);
  border-bottom: 1px solid var(--line);
}

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

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

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

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

.brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.brand-tag {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.head-pill {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-2);
  border: 1px solid var(--line);
  background: var(--card);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

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

.head-pill-link {
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.head-pill-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.head-pill-active {
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  font-weight: 600;
}

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

.eyebrow {
  display: inline-block;
  margin: 0 0 18px;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid rgba(255, 178, 36, 0.35);
  background: rgba(255, 178, 36, 0.08);
  padding: 6px 12px;
  border-radius: 999px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.1rem, 5.2vw, 3.5rem);
  font-weight: 700;
  line-height: 1.04;
  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-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--card);
  border: 1px solid var(--line);
  padding: 7px 13px;
  border-radius: 999px;
}

.chip-hot {
  color: var(--accent);
  border-color: rgba(255, 178, 36, 0.4);
  background: rgba(255, 178, 36, 0.08);
}

/* ---------- console (tool card) ---------- */
.console {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 28px);
  margin-bottom: clamp(48px, 8vw, 88px);
}

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

#urlInput {
  width: 100%;
  min-width: 0;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

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

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

#urlInput:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

#startBtn,
#toggleAdvancedBtn,
#copyBtn,
#downloadBtn {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 14px 20px;
  border-radius: var(--radius-s);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, filter 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

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

#startBtn {
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 26px rgba(255, 178, 36, 0.22);
}

#startBtn:hover { filter: brightness(1.06); }

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

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

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

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

#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.92rem;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

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

#advancedPanel select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

#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: 700;
  color: var(--accent);
  min-width: 2ch;
  text-align: right;
}

#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: 13px 16px;
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--ink-2);
  background: var(--bg-2);
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-s);
}

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

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

#copyBtn:hover {
  border-color: var(--accent);
  background: var(--bg-2);
}

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

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

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

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

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

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

#progressContainer > div:first-child {
  height: 10px;
  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), var(--accent-2));
  background-size: 200% 100%;
  transition: width 0.35s ease;
  animation: progress-shimmer 1.6s linear infinite;
}

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

#progressText {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* ---------- 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);
}

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

.results-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.results-hint {
  font-family: var(--mono);
  font-size: 0.7rem;
  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-family: var(--mono);
  font-size: 0.84rem;
  color: var(--muted);
  background: var(--bg-2);
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-s);
}

.results-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 11px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  animation: row-in 0.25s ease both;
}

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

.results-list li:hover { border-color: var(--line-2); }

.results-list a {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-2);
  word-break: break-all;
  text-decoration: none;
  transition: color 0.15s 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: rgba(255, 178, 36, 0.1);
  border-color: rgba(255, 178, 36, 0.35);
}

.status.success {
  background: rgba(61, 220, 151, 0.1);
  border-color: rgba(61, 220, 151, 0.35);
}

.status.failure {
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.35);
}

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

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

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

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 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;
  }
}
