:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #141821;
  --panel-deep: #0f131b;
  --border: #232a37;
  --border-bright: #33405a;
  --text: #e7ecf3;
  --muted: #97a3b6;
  --accent: #6ea8fe;
  --accent-strong: #4b8ef8;
  --accent-ink: #06121f;
  --success: #4ade80;
  --danger: #ff6b6b;
  --radius: 16px;
  --shadow-pop: 0 18px 50px -12px rgba(0, 0, 0, 0.65);
  --glow-accent: 0 0 0 1px rgba(110, 168, 254, 0.35), 0 8px 32px -8px rgba(110, 168, 254, 0.45);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

/* Author display rules (e.g. .card) otherwise override the UA [hidden]
   style and panels never hide. */
[hidden] {
  display: none !important;
}

::selection {
  background: rgba(110, 168, 254, 0.35);
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 480px at 85% -5%, rgba(74, 222, 128, 0.07) 0%, transparent 60%),
    radial-gradient(1200px 600px at 15% -10%, #1b2436 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 72px 20px 160px;
  display: grid;
  gap: 22px;
}

/* ---------- Hero ---------- */

.hero {
  text-align: left;
  display: grid;
  gap: 10px;
  justify-items: start;
}

.hero img {
  filter: drop-shadow(0 10px 28px rgba(75, 142, 248, 0.35));
}

.hero h1 {
  margin: 6px 0 4px;
  font-size: clamp(2.1rem, 4.6vw, 3rem);
  letter-spacing: -0.03em;
  line-height: 1.05;
  background: linear-gradient(100deg, #ffffff 20%, var(--accent) 65%, var(--success) 110%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.eyebrow {
  margin: 0;
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(110, 168, 254, 0.1);
  border: 1px solid rgba(110, 168, 254, 0.35);
  padding: 5px 12px;
  border-radius: 999px;
}

.lede {
  margin: 0;
  color: var(--muted);
  max-width: 62ch;
  font-size: 1.02rem;
}

/* ---------- Cards ---------- */

.card {
  background: linear-gradient(180deg, rgba(24, 30, 43, 0.92), rgba(20, 24, 33, 0.92));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: grid;
  gap: 16px;
  box-shadow: var(--shadow-pop);
}

.card h2 {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card h2::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 0 12px rgba(110, 168, 254, 0.8);
  flex: none;
}

/* ---------- Form ---------- */

#analyze-form {
  border-color: var(--border-bright);
}

#analyze-form:focus-within {
  border-color: rgba(110, 168, 254, 0.55);
  box-shadow: var(--glow-accent), var(--shadow-pop);
}

.field {
  display: grid;
  gap: 7px;
}

.field__label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

input[type="url"],
input[type="number"] {
  width: 100%;
  padding: 13px 15px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--panel-deep);
  color: var(--text);
  font: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="url"]:hover,
input[type="number"]:hover {
  border-color: var(--border-bright);
}

input[type="url"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 168, 254, 0.22);
}

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

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: end;
}

.field--small {
  max-width: 130px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 0.9rem;
  padding-bottom: 10px;
  cursor: pointer;
  user-select: none;
}

.checkbox input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent-strong);
  cursor: pointer;
}

button {
  justify-self: start;
  padding: 13px 28px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 10px 28px -8px rgba(75, 142, 248, 0.6);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.07);
  box-shadow: 0 14px 34px -8px rgba(75, 142, 248, 0.7);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.55;
  cursor: progress;
}

/* ---------- Status & progress ---------- */

.status {
  font-size: 0.95rem;
  border-left: 3px solid var(--accent);
}

.status--error {
  border-color: var(--danger);
  border-left-color: var(--danger);
  color: var(--danger);
}

#status-text:empty {
  display: none;
}

.progress-wrap {
  display: grid;
  gap: 7px;
  margin-bottom: 10px;
}

.progress-bar {
  height: 10px;
  border-radius: 7px;
  background: var(--panel-deep);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  box-shadow: 0 0 14px rgba(110, 168, 254, 0.55);
  transition: width 0.4s ease;
}

.progress-wrap--indeterminate .progress-fill {
  background: linear-gradient(90deg, var(--accent-strong) 0%, var(--accent) 40%, var(--success) 50%, var(--accent) 60%, var(--accent-strong) 100%);
  background-size: 220% 100%;
  animation: progress-slide 1.6s linear infinite;
}

@keyframes progress-slide {
  from {
    background-position: 180% 0;
  }
  to {
    background-position: -80% 0;
  }
}

.progress-meta {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Result JSON ---------- */

.result pre {
  margin: 0;
  padding: 16px;
  border-radius: 11px;
  background: #080b10;
  border: 1px solid var(--border);
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.55;
  max-height: 420px;
}

.note {
  color: var(--muted);
  font-size: 0.86rem;
  border-left: 2px solid var(--border-bright);
  padding: 4px 0 4px 16px;
}

.note strong {
  color: var(--text);
}

/* ---------- Selection ---------- */

.selection-stats {
  display: flex;
  gap: 10px 20px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--muted);
}

.selection-stats strong {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.candidate-list {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.candidate-item {
  display: grid;
  gap: 7px;
  padding: 13px 15px;
  border-radius: 11px;
  background: var(--panel-deep);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-bright);
  font-size: 0.88rem;
  transition: border-color 0.2s ease, transform 0.15s ease;
}

.candidate-item:hover {
  transform: translateX(2px);
}

.candidate-item--selected {
  border-color: rgba(110, 168, 254, 0.45);
  border-left-color: var(--accent);
  background: linear-gradient(180deg, rgba(110, 168, 254, 0.07), rgba(15, 19, 27, 1));
}

.candidate-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.candidate-title {
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.candidate-path {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  background: rgba(151, 163, 182, 0.1);
  padding: 1px 7px;
  border-radius: 6px;
}

.candidate-badges {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.7rem;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.badge--selected {
  background: rgba(110, 168, 254, 0.16);
  color: var(--accent);
  border: 1px solid rgba(110, 168, 254, 0.45);
}

.badge--excluded {
  background: #1e2430;
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge--source {
  background: #141a24;
  color: #a0aec0;
  border: 1px solid #232d3d;
}

.candidate-reason {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

/* ---------- Screenshots ---------- */

#screenshot-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.screenshot-preview figure {
  margin: 0;
  overflow: hidden;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--panel-deep);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.screenshot-preview figure:hover {
  transform: translateY(-3px);
  border-color: rgba(110, 168, 254, 0.5);
  box-shadow: var(--glow-accent);
}

.screenshot-preview img {
  max-width: 100%;
  display: block;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  object-position: top;
  border: 0;
  border-radius: 0;
}

.screenshot-preview figcaption {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--mono);
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.screenshot-preview figure.shot-meta {
  padding: 14px;
  color: var(--muted);
  font-size: 0.85rem;
}

.screenshot-preview h3 {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-shots {
  display: contents;
}

/* ---------- Budget ---------- */

.budget-bar {
  height: 10px;
  border-radius: 7px;
  background: var(--panel-deep);
  border: 1px solid var(--border);
  overflow: hidden;
}

.budget-fill {
  height: 100%;
  width: 0;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--success), var(--accent));
  transition: width 0.5s ease;
}

.budget-fill--hot {
  background: linear-gradient(90deg, var(--accent), var(--danger));
}

.budget-text,
.package-info {
  font-size: 0.88rem;
  color: var(--muted);
}

/* ---------- Analyzed pages ---------- */

.pages-list {
  display: grid;
  gap: 10px;
}

.page-card {
  padding: 13px 15px;
  border-radius: 11px;
  background: var(--panel-deep);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  font-size: 0.88rem;
  display: grid;
  gap: 6px;
}

.page-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
}

.page-reason,
.page-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.page-limits {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---------- Sticky download bar ---------- */

#download-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  border-top: 1px solid var(--border-bright);
  background: rgba(13, 16, 23, 0.88);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 -18px 50px -12px rgba(0, 0, 0, 0.7);
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
}

#download-panel:not([hidden]) {
  animation: bar-rise 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes bar-rise {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

#download-panel h2 {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#download-panel h2::before {
  display: none;
}

#download-panel .package-info {
  margin: 0;
  max-width: 860px;
  margin-inline: auto;
  padding-bottom: 10px;
}

#download-panel button {
  display: block;
  width: 100%;
  max-width: 860px;
  margin-inline: auto;
  padding: 15px 28px;
  font-size: 1rem;
  background: linear-gradient(135deg, var(--success) 0%, #22c55e 100%);
  color: #04140a;
  box-shadow: 0 12px 32px -8px rgba(74, 222, 128, 0.55);
}

#download-panel button:hover:not(:disabled) {
  box-shadow: 0 16px 40px -8px rgba(74, 222, 128, 0.65);
}

/* ---------- Responsive & motion ---------- */

@media (max-width: 560px) {
  .shell {
    padding: 48px 14px 170px;
  }

  .card {
    padding: 18px;
  }

  .candidate-header {
    align-items: flex-start;
    flex-direction: column;
  }

  #screenshot-container {
    grid-template-columns: 1fr 1fr;
  }
}

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

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