:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1d1f1e;
  --muted: #5f6662;
  --border: #dcd9d0;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-soft: #e2efe9;
  --danger: #a33a2c;
  --danger-soft: #f8e6e2;
  --warn: #9a6a12;
  --ok: #2f8a5b;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141615;
    --surface: #1c1f1e;
    --surface-2: #252928;
    --text: #e8ebe9;
    --muted: #a0a8a4;
    --border: #333836;
    --accent: #6cc3a7;
    --accent-text: #0e1513;
    --accent-soft: #1f3530;
    --danger: #f08b7b;
    --danger-soft: #3a211d;
    --warn: #e0b45c;
    --ok: #6cc3a7;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141615;
  --surface: #1c1f1e;
  --surface-2: #252928;
  --text: #e8ebe9;
  --muted: #a0a8a4;
  --border: #333836;
  --accent: #6cc3a7;
  --accent-text: #0e1513;
  --accent-soft: #1f3530;
  --danger: #f08b7b;
  --danger-soft: #3a211d;
  --warn: #e0b45c;
  --ok: #6cc3a7;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
}

[hidden] { display: none !important; }

.top, main, .foot {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 20px;
  padding-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 1.1rem;
}

.brand-mark { width: 26px; height: 26px; color: var(--accent); }

.network {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--muted);
  white-space: nowrap;
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.network[data-state="connecting"] .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.network[data-state="connected"] .dot { background: var(--ok); }
.network[data-state="failed"] .dot { background: var(--danger); }

@keyframes pulse { 50% { opacity: 0.35; } }

main { flex: 1; display: flex; flex-direction: column; gap: 16px; }

.open, .progress, .error, .result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.open label { display: block; font-weight: 600; margin-bottom: 8px; }

.open-row { display: flex; gap: 8px; }

input {
  flex: 1;
  min-width: 0;
  font: 0.95rem var(--mono);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
}

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

input[aria-invalid="true"] { border-color: var(--danger); }

button {
  font: 600 0.95rem var(--sans);
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  padding: 10px 18px;
  cursor: pointer;
  white-space: nowrap;
}

button:disabled { opacity: 0.55; cursor: default; }
button.secondary { background: transparent; color: var(--accent); }

button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-weight: 500;
  text-decoration: underline;
}

.hint { margin: 10px 0 0; color: var(--muted); font-size: 0.875rem; }

.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }

.bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.25s ease;
}

.bar[data-indeterminate] .bar-fill {
  width: 30%;
  animation: slide 1.4s ease-in-out infinite;
}

@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

@media (prefers-reduced-motion: reduce) {
  .bar[data-indeterminate] .bar-fill, .network[data-state="connecting"] .dot { animation: none; }
}

.error { border-color: var(--danger); background: var(--danger-soft); }
.error strong { color: var(--danger); }
.error p { margin: 6px 0 8px; }
.error summary { cursor: pointer; color: var(--muted); font-size: 0.875rem; }
.error pre { white-space: pre-wrap; word-break: break-word; font: 0.8rem var(--mono); color: var(--muted); }

.result { display: flex; flex-direction: column; gap: 20px; }

.preview {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--surface-2);
  border-radius: 8px;
  min-height: 120px;
  overflow: hidden;
}

.preview img, .preview video { display: block; max-width: 100%; max-height: 70vh; }
.preview audio { width: 100%; margin: 24px; }
.preview iframe { width: 100%; height: 75vh; border: 0; background: #fff; }

.preview pre {
  width: 100%;
  margin: 0;
  padding: 16px;
  max-height: 60vh;
  overflow: auto;
  font: 0.85rem/1.45 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  text-align: left;
}

.preview .none { color: var(--muted); padding: 32px 16px; text-align: center; font-size: 0.95rem; }

.facts { margin: 0; display: grid; gap: 10px; }
.facts div { display: grid; grid-template-columns: 96px 1fr; gap: 12px; }
.facts dt { color: var(--muted); font-size: 0.875rem; }
.facts dd { margin: 0; min-width: 0; }
.mono { font: 0.85rem var(--mono); word-break: break-all; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.foot { padding-top: 24px; padding-bottom: 28px; color: var(--muted); font-size: 0.8rem; }
.foot p { margin: 0; }

@media (max-width: 560px) {
  .open-row { flex-direction: column; }
  .facts div { grid-template-columns: 1fr; gap: 2px; }
  .top { padding-top: 14px; padding-bottom: 14px; }
}

/* The listings index */
.listings {
  margin-top: 1.5rem;
}
.listings h2 {
  font-size: 1rem;
  margin: 0 0 0.5rem;
}
.listings ol {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.listings li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  align-items: baseline;
  padding: 0.6rem 0.9rem;
  border-top: 1px solid var(--border);
}
.listings li:first-child {
  border-top: none;
}
.listings a {
  color: var(--accent);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.listing-details {
  color: var(--muted);
  font-size: 0.875rem;
}
