/* System fonts only — no webfont downloads */
:root {
  color-scheme: light dark;

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;

  --bg: #f4f6f9;
  --bg-elevated: #ffffff;
  --bg-input: #ffffff;
  --border: #d8dee8;
  --border-focus: #2563eb;
  --text: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-pressed: #1d4ed8;
  --accent-subtle: #eff6ff;
  --success: #15803d;
  --success-bg: #ecfdf3;
  --success-border: #86efac;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --danger-border: #fca5a5;
  --warning: #a16207;
  --warning-bg: #fffbeb;
  --warning-border: #fcd34d;
  --neutral-bg: #f3f4f6;
  --neutral-border: #d1d5db;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-pill: 999px;
  --touch: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-elevated: #161b22;
    --bg-input: #0d1117;
    --border: #30363d;
    --border-focus: #58a6ff;
    --text: #f0f6fc;
    --text-secondary: #c9d1d9;
    --text-muted: #8b949e;
    --accent: #388bfd;
    --accent-pressed: #1f6feb;
    --accent-subtle: #13253d;
    --success: #3fb950;
    --success-bg: #12261e;
    --success-border: #238636;
    --danger: #f85149;
    --danger-bg: #2d1214;
    --danger-border: #da3633;
    --warning: #d29922;
    --warning-bg: #2a1f07;
    --warning-border: #9e6a03;
    --neutral-bg: #21262d;
    --neutral-border: #484f58;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 12px 32px rgba(0, 0, 0, 0.28);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  max-width: 36rem;
  margin: 0 auto;
  padding:
    calc(1.25rem + var(--safe-top))
    calc(1rem + var(--safe-right))
    calc(2rem + var(--safe-bottom))
    calc(1rem + var(--safe-left));
}

/* Header */
.site-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.brand {
  display: flex;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.site-header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.5rem, 4vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 22rem;
  margin-inline: auto;
}

/* Panels */
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-form {
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Form fields — 16px prevents iOS zoom on focus */
.field {
  margin-bottom: 1.1rem;
}

.field label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.field-hint {
  margin: 0.4rem 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

input[type="url"],
textarea {
  display: block;
  width: 100%;
  min-height: var(--touch);
  padding: 0.75rem 0.875rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

textarea {
  min-height: 5rem;
  resize: vertical;
  max-height: 10rem;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--border-focus) 22%, transparent);
}

input:invalid:not(:placeholder-shown):not(:focus) {
  border-color: var(--danger-border);
}

/* Submit button — full native tap target */
.btn-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  width: 100%;
  min-height: var(--touch);
  margin-top: 0.25rem;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-submit:hover:not(:disabled) {
  background: var(--accent-pressed);
}

.btn-submit:active:not(:disabled) {
  transform: scale(0.985);
}

.btn-submit:disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.btn-submit:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn-spinner {
  width: 1.125rem;
  height: 1.125rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Loading */
.loading-status {
  margin-bottom: 1rem;
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-sm);
  background: var(--accent-subtle);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--border));
}

.loading-bar {
  height: 4px;
  margin-bottom: 0.5rem;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  overflow: hidden;
}

.loading-bar-fill {
  display: block;
  height: 100%;
  width: 35%;
  border-radius: inherit;
  background: var(--accent);
  animation: loading-slide 1.4s ease-in-out infinite;
}

@keyframes loading-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}

.loading-label {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Error panel */
.panel-error {
  display: flex;
  gap: 0.875rem;
  padding: 1.1rem 1.15rem;
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.panel-icon {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-weight: 700;
  font-size: 1rem;
}

.panel-icon-error {
  background: var(--danger);
  color: #fff;
}

.panel-body h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--danger);
}

.panel-body p {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

.error-code {
  margin-top: 0.5rem !important;
  font-family: var(--font-mono);
  font-size: 0.75rem !important;
  color: var(--text-muted) !important;
}

.error-suggestions {
  margin: 0.75rem 0 0;
  padding-left: 1.15rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.error-suggestions li + li {
  margin-top: 0.35rem;
}

.error-debug {
  margin-top: 0.75rem;
  font-size: 0.8125rem;
}

.error-debug summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
}

.error-debug pre {
  margin: 0.5rem 0 0;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  line-height: 1.4;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 16rem;
  overflow-y: auto;
}

.field-checkbox {
  margin-bottom: 0.75rem;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  min-height: var(--touch);
  padding: 0.25rem 0;
}

.checkbox-label input[type="checkbox"] {
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.15rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.btn-text-action {
  margin-top: 0.75rem;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  min-height: var(--touch);
  text-align: left;
}

.btn-text-action:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Results */
.panel-results {
  overflow: hidden;
}

.verdict-header {
  display: flex;
  gap: 1rem;
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.verdict-header.compatible {
  background: var(--success-bg);
  border-bottom-color: var(--success-border);
}

.verdict-header.incompatible {
  background: var(--danger-bg);
  border-bottom-color: var(--danger-border);
}

.verdict-header.unknown {
  background: var(--warning-bg);
  border-bottom-color: var(--warning-border);
}

.verdict-icon {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 1.25rem;
  font-weight: 700;
  background: var(--neutral-bg);
  border: 1px solid var(--neutral-border);
}

.verdict-header.compatible .verdict-icon {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.verdict-header.incompatible .verdict-icon {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.verdict-header.unknown .verdict-icon {
  background: var(--warning);
  border-color: var(--warning);
  color: #fff;
}

.verdict-label {
  margin: 0 0 0.15rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.verdict-title {
  margin: 0 0 0.35rem;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.verdict-summary {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.result-block {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.result-block:last-child {
  border-bottom: none;
}

.result-block h3 {
  margin: 0 0 0.65rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.detail-list {
  display: grid;
  grid-template-columns: minmax(5rem, auto) 1fr;
  gap: 0.35rem 1rem;
  margin: 0;
  font-size: 0.9375rem;
}

.detail-list dt {
  color: var(--text-muted);
  font-weight: 500;
}

.detail-list dd {
  margin: 0;
  color: var(--text);
  word-break: break-word;
}

.detail-list-compact {
  font-size: 0.8125rem;
  margin-top: 0.75rem;
}

.bullet-list {
  margin: 0;
  padding-left: 1.15rem;
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

.bullet-list li + li {
  margin-top: 0.35rem;
}

.timings-block summary {
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  list-style: none;
  user-select: none;
}

.timings-block summary::-webkit-details-marker {
  display: none;
}

.timings-block summary::before {
  content: "▸ ";
}

.timings-block[open] summary::before {
  content: "▾ ";
}

/* Footer */
.site-footer {
  margin-top: 2rem;
  text-align: center;
}

.site-footer p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hidden {
  display: none !important;
}

/* Input mode tabs */
.mode-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
  padding: 0.25rem;
  background: var(--neutral-bg);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
}

.mode-tab {
  flex: 1;
  min-height: 40px;
  padding: 0.5rem 0.65rem;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.mode-tab.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
}

.mode-panel.hidden {
  display: none !important;
}

.optional {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.875em;
}

.bookmarklet-help {
  margin-bottom: 0.5rem;
}

.bookmarklet-help ol {
  margin: 0.75rem 0;
  padding-left: 1.25rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.bookmarklet-help li + li {
  margin-top: 0.35rem;
}

.bookmarklet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 1rem;
}

.btn-bookmarklet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  cursor: grab;
}

.btn-bookmarklet:active {
  cursor: grabbing;
  background: var(--accent-pressed);
}

.import-banner {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--accent-subtle);
  border: 1px solid var(--border-focus);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Wider screens */
@media (min-width: 480px) {
  .app {
    padding-top: calc(2rem + var(--safe-top));
  }

  .panel-form {
    padding: 1.5rem;
  }

  .verdict-header {
    padding: 1.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
