:root {
  --bg: #1f1f1f;
  --surface: #2b2b2b;
  --surface-2: #363636;
  --text: #eee;
  --muted: #999;
  --border: #444;
  --accent: #4a9eff;
  --accent-2: #357ac4;
  --danger: #e85c5c;
  --success: #4caf50;
  --radius: 8px;
  --pad: 12px;
  --pad-lg: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f4f4;
    --surface: #fff;
    --surface-2: #f0f0f0;
    --text: #222;
    --muted: #666;
    --border: #ccc;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--pad) var(--pad-lg);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: calc(var(--pad) + env(safe-area-inset-top));
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--pad-lg);
}

.field {
  display: block;
  margin-bottom: var(--pad-lg);
}
.field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.field small.muted {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}

.field input[type="text"],
.field input[type="url"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
}

.field textarea {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  line-height: 1.5;
  resize: vertical;
  min-height: 160px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.field-row {
  display: flex;
  gap: var(--pad);
  align-items: flex-end;
  margin-bottom: var(--pad-lg);
}
.field-row .field { margin-bottom: 0; }
.field-row .grow { flex: 1; }

.field.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 0;
  padding: 10px 0;
}
.field.checkbox span {
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-size: 14px;
}

.btn {
  display: inline-block;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.actions {
  display: flex;
  gap: var(--pad);
  justify-content: flex-end;
  margin-top: var(--pad-lg);
  flex-wrap: wrap;
}

.photo-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--pad);
  margin-bottom: var(--pad);
}
.photo-list:empty { display: none; }

.photo-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.photo-item.dragging { opacity: 0.5; }
.photo-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}
.photo-item input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 12px;
  font-family: inherit;
}
.photo-item .remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-item .featured-badge {
  position: absolute;
  bottom: 40px;
  left: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.photo-item .drag-handle {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  font-size: 14px;
  user-select: none;
  touch-action: none;
}

.photo-add-row {
  display: flex;
  align-items: center;
  gap: var(--pad);
}

.muted { color: var(--muted); font-size: 13px; }

.preview-header {
  display: flex;
  align-items: center;
  gap: var(--pad);
  margin-bottom: var(--pad-lg);
}

.preview img { max-width: 100%; border-radius: var(--radius); }
.preview h1, .preview h2, .preview h3 { line-height: 1.2; }
.preview p { line-height: 1.6; }
.preview blockquote {
  border-left: 3px solid var(--border);
  margin: 0;
  padding-left: var(--pad);
  color: var(--muted);
}
.preview code {
  background: var(--surface-2);
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.9em;
}
.preview pre {
  background: var(--surface-2);
  padding: var(--pad);
  border-radius: var(--radius);
  overflow-x: auto;
}
.preview figure {
  margin: var(--pad-lg) 0;
  text-align: center;
}
.preview figcaption {
  font-style: italic;
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}
.preview .yt-placeholder {
  aspect-ratio: 16/9;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  margin: var(--pad-lg) 0;
}

.progress {
  list-style: none;
  padding: 0;
  margin: 0;
}
.progress li {
  padding: var(--pad);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--pad);
}
.progress li::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.progress li.active::before {
  border-color: var(--accent);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}
.progress li.done::before {
  content: "\2713";
  background: var(--success);
  border-color: var(--success);
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.progress li.failed::before {
  content: "\2717";
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.error {
  background: var(--surface);
  color: var(--danger);
  padding: var(--pad);
  border-radius: var(--radius);
  white-space: pre-wrap;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  border: 1px solid var(--border);
}

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad-lg);
  max-width: 480px;
  width: calc(100% - 32px);
}
dialog::backdrop {
  background: rgba(0,0,0,0.6);
}
dialog h2 {
  margin-top: 0;
  font-size: 18px;
}
