:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #17181c;
  --muted: #5c626e;
  --border: #dfe2e8;
  --accent: #e02424;
  --accent-hover: #c81e1e;
  --accent-soft: #fdf0f0;
  --focus: #2563eb;
  --error-bg: #fdecec;
  --error-text: #a42020;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(20 22 26 / 0.05), 0 8px 24px rgb(20 22 26 / 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --card: #191c22;
    --text: #eceef2;
    --muted: #9aa1ad;
    --border: #2c313a;
    --accent: #f04444;
    --accent-hover: #ff5c5c;
    --accent-soft: #2a1b1c;
    --error-bg: #341c1e;
    --error-text: #ff9d9d;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
}

main {
  width: min(680px, 100% - 2rem);
  margin: 0 auto;
  flex: 1;
}

/* Header */
.site-header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
}

.logo {
  display: inline-grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 1rem;
  background: var(--accent);
  color: #fff;
  font-size: 1.6rem;
  box-shadow: var(--shadow);
}

.site-header h1 {
  margin: 0.75rem 0 0.25rem;
  font-size: 1.9rem;
  letter-spacing: -0.02em;
}

.tagline { margin: 0; color: var(--muted); }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

/* URL row */
.url-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.url-row input {
  flex: 1 1 16rem;
  min-width: 0;
  padding: 0.75rem 0.9rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.url-row input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: transparent;
}

button, .btn-primary, .btn-secondary {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1.3rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

#submit-btn, .btn-primary {
  background: var(--accent);
  color: #fff;
}

#submit-btn:hover:not(:disabled), .btn-primary:hover { background: var(--accent-hover); }
#submit-btn:disabled { opacity: 0.6; cursor: default; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

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

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.6rem 0 0;
}

.hint-inline { color: var(--muted); font-size: 0.85rem; }

/* Fieldsets */
fieldset {
  border: none;
  padding: 0;
  margin: 1.5rem 0 0;
}

fieldset:disabled { opacity: 0.45; }

legend {
  font-weight: 600;
  padding: 0;
  margin-bottom: 0.6rem;
}

/* Format tiles */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr));
  gap: 0.6rem;
}

.tile {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.tile:hover { border-color: var(--muted); }

.tile:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tile:has(input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.tile input {
  accent-color: var(--accent);
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.15rem;
  flex-shrink: 0;
}

.tile-body { display: block; }
.tile-title { display: block; font-weight: 600; }
.tile-desc {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

/* Quality pills */
.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pill span {
  display: inline-block;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

.pill:hover span { border-color: var(--muted); }

.pill:has(input:checked) span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pill:has(input:focus-visible) span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Advanced settings */
.advanced { margin-top: 1.5rem; }

.advanced summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}

.advanced summary:hover { color: var(--text); }

.switch-row {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  margin-top: 0.9rem;
  cursor: pointer;
}

.switch-row input {
  accent-color: var(--accent);
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.2rem;
  flex-shrink: 0;
}

/* Status */
.status-title { font-weight: 600; margin: 0 0 0.3rem; overflow-wrap: anywhere; }
.status-message { color: var(--muted); margin: 0 0 0.8rem; }

.bar {
  height: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

#bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.error {
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  margin: 0.8rem 0 0;
  font-size: 0.9rem;
}

.hidden { display: none !important; }

/* Footer */
footer {
  width: min(680px, 100% - 2rem);
  margin: 1rem auto 2rem;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (max-width: 480px) {
  .card { padding: 1.1rem; }
  .site-header { padding-top: 1.75rem; }
  #submit-btn { flex: 1 1 100%; }
}
