:root {
  --bg: #f7f7f8;
  --card: #ffffff;
  --text: #1c1c1f;
  --muted: #6b7280;
  --border: #e4e4e7;
  --accent: #2563eb;
  --danger: #dc2626;
  --ok: #16a34a;
  --err: #dc2626;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 22px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
header .hero { grid-column: 2; }
header nav { grid-column: 3; justify-self: end; }
/* Hero brand title — gradient "mdx" + muted subtitle, sized to sit inline
 * in the header next to the nav. Whole element links to /. */
.hero {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  text-decoration: none;
  font-weight: 800;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: -0.01em;
}
.hero-mdx {
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 45%, #db2777 100%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
}
.hero-sub {
  font-weight: 400;
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 0;
}
.hero:hover .hero-mdx { filter: brightness(1.08); }
header nav a, header nav .user { margin-left: 16px; color: var(--muted); text-decoration: none; font-size: 14px; }
header nav a:hover { color: var(--accent); }

main { max-width: 820px; margin: 24px auto; padding: 0 18px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 22px 26px;
  margin-bottom: 22px;
}
h1 { margin-top: 0; }

label {
  display: block;
  margin: 12px 0 4px;
  font-size: 14px;
  color: var(--text);
}
label.check { display: flex; gap: 8px; align-items: center; }

/* Restore the HTML `hidden` attribute semantics: a global `label {display:block}`
 * rule above has the same specificity as the browser's user-agent `[hidden]
 * {display:none}` rule but wins by cascade order. `!important` here re-asserts
 * the platform behaviour so <label hidden> actually disappears. */
[hidden] { display: none !important; }
input[type=text], input[type=password], input[type=file], select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--bg);
}
button {
  margin-top: 14px;
  padding: 9px 16px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
button.danger { background: var(--danger); }
button:hover { filter: brightness(1.08); }

/* Primary CTA at the top of the convert form: visually anchored above the
 * configuration sections so users can re-submit without scrolling. */
button.primary-cta {
  display: block;
  width: 100%;
  margin: 4px 0 18px;
  padding: 12px 18px;
  font-size: 15px;
  letter-spacing: 0.01em;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 18px 18px;
  margin: 16px 0;
}
legend { padding: 0 6px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }

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

/* --- Help tooltips ("?" icon next to fields) --------------------------- */
.check-row { display: flex; align-items: center; gap: 6px; }
.check-row label.check { margin: 0; }

.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  position: relative;
  vertical-align: middle;
  user-select: none;
}
.help-tip:hover, .help-tip:focus {
  background: var(--accent);
  color: #fff;
  outline: none;
}
/* The popup bubble */
.help-tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 260px;
  background: #0f172a;
  color: #f1f5f9;
  padding: 8px 11px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  z-index: 20;
  pointer-events: none;
}
/* Little arrow under the bubble */
.help-tip::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #0f172a;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  z-index: 20;
}
.help-tip:hover::after, .help-tip:focus::after,
.help-tip:hover::before, .help-tip:focus::before {
  opacity: 1;
  visibility: visible;
}

.upload-status {
  display: block;
  margin: 4px 0 8px;
  font-size: 13px;
  min-height: 1.2em;
}
.upload-status:not(:empty) {
  padding: 6px 10px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 6px;
  color: #075985;
}

/* --- Drag-and-drop upload zone ------------------------------------------ */
.dropzone {
  display: block;
  padding: 28px 20px;
  margin: 12px 0 10px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  background: var(--bg);
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone:hover {
  border-color: #94a3b8;
  background: #f1f5f9;
}
.dropzone:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
  outline: none;
}
.dropzone.dragging {
  border-color: var(--accent);
  background: #eff6ff;
}
/* Visually hide the file input but keep it focusable/clickable through the label. */
.dropzone input[type=file] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
/* Make decorative children transparent to pointer events so dragenter/leave
 * fire on the zone itself, not on icon/text children (avoids flicker). */
.dropzone-inner,
.dropzone-icon,
.dropzone-text,
.dropzone-hint { pointer-events: none; }

.dropzone-icon {
  font-size: 32px;
  line-height: 1;
  color: var(--muted);
  margin-bottom: 6px;
}
.dropzone-text {
  font-size: 14px;
  color: var(--text);
}
.dropzone-text strong { color: var(--accent); }
.dropzone-hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

/* --- Selected file chips ------------------------------------------------ */
.upload-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.upload-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 8px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  max-width: 100%;
  cursor: grab;
  user-select: none;
  transition: transform 0.08s, box-shadow 0.08s, opacity 0.08s;
}
.upload-item:active { cursor: grabbing; }
.upload-item.is-md { background: #ecfeff; border-color: #a5f3fc; }
.upload-item.is-main {
  font-weight: 700;
  border-color: var(--accent);
  background: #dbeafe;
}
.upload-item.is-main .name::before {
  content: '★ ';
  color: var(--accent);
  font-weight: 700;
}
.upload-item.dragging {
  opacity: 0.4;
  transform: scale(0.97);
}
.upload-item.drag-over {
  box-shadow: -4px 0 0 0 var(--accent);
}
.upload-item .handle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  padding-right: 2px;
}
.upload-item .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}
.upload-item .size {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.upload-item .remove {
  background: transparent;
  color: var(--muted);
  border: 0;
  margin: 0;
  padding: 0 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 999px;
  font-weight: 600;
}
.upload-item .remove:hover {
  background: #fee2e2;
  color: var(--danger);
  filter: none;
}
.upload-clear {
  display: inline-flex;
}
.upload-clear .clear-all {
  background: transparent;
  color: var(--muted);
  border: 0;
  margin: 0;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  font-weight: 400;
}
.upload-clear .clear-all:hover {
  color: var(--danger);
  filter: none;
}

/* --- Advanced options (native <details>) -------------------------------- */
.advanced {
  margin: 16px 0;
  border-radius: 6px;
}
.advanced > summary {
  cursor: pointer;
  display: inline-block;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--muted);
  user-select: none;
  list-style: none;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary::before {
  content: '▸ ';
  display: inline-block;
  width: 1em;
  transition: transform 0.12s;
}
.advanced[open] > summary::before {
  transform: rotate(90deg);
}
.advanced > summary:hover { color: var(--accent); }
.advanced > fieldset { margin-top: 8px; }

table { width: 100%; border-collapse: collapse; margin-top: 8px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

form.inline { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
form.inline input { flex: 1 1 200px; width: auto; }
form.inline button { margin-top: 0; }

.flashes { list-style: none; padding: 0; max-width: 820px; margin: 12px auto 0; }
.flash { padding: 10px 16px; border-radius: 6px; margin: 6px 18px; font-size: 14px; }
.flash.ok { background: #ecfdf5; color: var(--ok); border: 1px solid #a7f3d0; }
.flash.error { background: #fef2f2; color: var(--err); border: 1px solid #fecaca; }

/* --- Rendered help.md (the /help page) --------------------------------- */
.help-content { line-height: 1.65; }
.help-content h1 { margin-top: 0; }
.help-content h2 {
  margin-top: 1.8em;
  padding-bottom: 0.25em;
  border-bottom: 1px solid var(--border);
}
.help-content h3 { margin-top: 1.4em; }
.help-content p { margin: 0.8em 0; }
.help-content ul, .help-content ol { padding-left: 1.5em; }
.help-content li { margin: 0.25em 0; }
.help-content a { color: var(--accent); }
.help-content code {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.help-content pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}
.help-content pre code { background: transparent; padding: 0; color: inherit; }
.help-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 14px;
}
.help-content th, .help-content td {
  border: 1px solid var(--border);
  padding: 7px 12px;
  text-align: left;
  vertical-align: top;
}
.help-content th { background: var(--bg); font-weight: 600; }
.help-content hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}
.help-content blockquote {
  border-left: 3px solid var(--border);
  margin: 1em 0;
  padding: 0.2em 1em;
  color: var(--muted);
}
