:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #111418;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #111418;
  --accent-text: #ffffff;
  --focus: #2563eb;
  --danger: #dc2626;
  --radius: 10px;
  --panel-w: 336px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f12;
    --surface: #15181d;
    --text: #e6e8eb;
    --muted: #8b919a;
    --border: #262a31;
    --accent: #e6e8eb;
    --accent-text: #0d0f12;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f12;
  --surface: #15181d;
  --text: #e6e8eb;
  --muted: #8b919a;
  --border: #262a31;
  --accent: #e6e8eb;
  --accent-text: #0d0f12;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  min-height: 100vh;
}
.panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px 20px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand img { display: block; width: 140px; height: auto; max-width: 100%; }

/* ============ Landing ============ */
.site-header, .landing, .site-footer {
  width: min(1120px, 100% - 48px);
  margin-inline: auto;
}
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0;
}
.site-nav { display: flex; gap: 20px; align-items: center; font-size: 13px; }
.site-nav a, .site-nav button {
  color: var(--muted); text-decoration: none; background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
}
.site-nav a:hover, .site-nav button:hover { color: var(--text); }

.hero-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 64px;
  align-items: center;
  padding: 48px 0 72px;
  min-height: min(720px, calc(100vh - 80px));
}
.eyebrow {
  margin: 0 0 16px;
  font-size: 12px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.hero-copy h1 {
  margin: 0 0 20px;
  font-size: clamp(36px, 4.6vw, 56px);
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.lede { margin: 0 0 28px; font-size: 17px; line-height: 1.6; color: var(--muted); max-width: 46ch; }
.proof { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 14px; color: var(--muted); }
.proof li { padding-left: 18px; position: relative; }
.proof li::before {
  content: ""; position: absolute; left: 0; top: 8px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}
.proof strong { color: var(--text); font-weight: 600; }

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 24px 48px -24px rgba(0,0,0,.18);
}
.tool-card form { gap: 12px; }
.tool-card .field input, .tool-card .field select, .tool-card .segmented span, .tool-card .btn { height: 38px; }

.section { padding: 56px 0; border-top: 1px solid var(--border); }
.section h2 { margin: 0 0 28px; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.steps {
  margin: 0; padding: 0; list-style: none; counter-reset: step;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px;
}
.steps li { counter-increment: step; color: var(--muted); line-height: 1.6; }
.steps li::before {
  content: counter(step, decimal-leading-zero);
  display: block; margin-bottom: 10px;
  font-size: 12px; font-weight: 500; letter-spacing: 0.08em; color: var(--muted);
}
.steps strong { display: block; color: var(--text); font-weight: 600; margin-bottom: 4px; }

.faq { max-width: 720px; }
.faq details { border-bottom: 1px solid var(--border); }
.faq summary {
  padding: 16px 0; cursor: pointer; font-weight: 500; list-style: none;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--muted); font-size: 18px; line-height: 1; transition: transform .2s; }
.faq details[open] summary::after { transform: rotate(45deg); }
.faq p { margin: 0 0 18px; color: var(--muted); line-height: 1.65; max-width: 62ch; }

.site-footer {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 24px 0 32px; font-size: 12px; color: var(--muted);
}
.site-footer a { color: inherit; text-decoration: none; }
.site-footer a:hover { color: var(--text); }

@media (max-width: 900px) {
  .hero-grid { grid-template-columns: 1fr; gap: 40px; padding: 32px 0 48px; min-height: 0; }
  .hero-tool { order: 1; }
  .steps { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .site-header, .landing, .site-footer { width: calc(100% - 32px); }
  .tool-card { padding: 18px; }
  .tool-card .field-row { grid-template-columns: 1fr; }
}

/* Fields */
form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .field legend {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.field input, .field select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent);
}
.field-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }

/* Segmented control (Desktop / Mobile) */
fieldset.segmented {
  border: 0; padding: 0; margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 40px;
  gap: 0;
}
.segmented legend { grid-column: 1 / -1; padding: 0; margin-bottom: 6px; }
.segmented > label { display: block; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.segmented > label:first-of-type span { border-radius: var(--radius) 0 0 var(--radius); }
.segmented > label:last-of-type span { border-radius: 0 var(--radius) var(--radius) 0; margin-left: -1px; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); position: relative; z-index: 1; }
.segmented input:focus-visible + span { box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }

.btn {
  height: 40px;
  padding: 0 16px;
  font: inherit;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s, background .15s;
}
.btn.primary { background: var(--accent); color: var(--accent-text); width: 100%; }
.btn.primary:hover { opacity: .88; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); flex: 1; }
.btn.ghost:hover { background: var(--bg); }
.actions { display: flex; gap: 8px; }
.actions .btn { white-space: nowrap; padding: 0 10px; font-size: 13px; }

.error { margin: 0; color: var(--danger); font-size: 13px; }

.panel-footer {
  margin-top: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}
.panel-footer a, .panel-footer button {
  color: inherit; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-decoration: none;
}
.panel-footer a:hover, .panel-footer button:hover { color: var(--text); }

/* Results stage */
.stage-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.chip.muted { color: var(--muted); }
.frame-wrap { position: relative; flex: 1; display: flex; min-height: 0; }
.serp-frame { flex: 1; width: 100%; border: 0; background: #fff; min-height: 0; }
.frame-wrap.mobile {
  flex: 0 0 auto;
  width: 412px; max-width: 100%;
  height: 860px;
  margin: 24px auto;
  border: 1px solid var(--border);
  border-radius: 24px;
  overflow: hidden;
}
.frame-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: #fff;
  transition: opacity .3s;
}
.frame-loading span { width: 8px; height: 8px; border-radius: 50%; background: #c4c7cc; animation: pulse 1s infinite ease-in-out; }
.frame-loading span:nth-child(2) { animation-delay: .15s; }
.frame-loading span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { transform: scale(.6); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }
.frame-wrap.loaded .frame-loading { opacity: 0; pointer-events: none; }
.stage-hint { margin-left: auto; font-size: 12px; color: var(--muted); align-self: center; }
.stage-hint em { font-style: normal; color: var(--text); }

/* Recent searches */
.recent { margin-top: 16px; }
.recent-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: var(--muted); margin-bottom: 8px; padding: 0 2px;
}
.recent-head button { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.recent-head button:hover { color: var(--text); }
.recent ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.recent a {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
  color: var(--text); text-decoration: none; font-size: 13px;
  transition: border-color .15s, background .15s;
}
.recent a:hover { border-color: var(--muted); }
.recent a strong { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent a span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.panel .recent a { background: var(--bg); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px);
  padding: 8px 14px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  font-size: 13px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.btn svg { margin-right: 6px; }

/* Combobox dropdown (country + location) */
.field.combo { position: relative; }
.combo-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  z-index: 20;
  margin: 6px 0 0; padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  max-height: 300px;
  overflow-y: auto;
}
.combo-list li {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap; overflow: hidden;
}
.combo-list li span { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; }
.combo-list li small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.combo-list li:hover, .combo-list li.active { background: var(--bg); }

@media (max-width: 860px) {
  .stage-hint { display: none; }
  .app { grid-template-columns: 1fr; }
  .panel { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .frame-wrap { min-height: 100vh; }
}
