*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #1a1a2e;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #6366f1;
  --accent-dark: #4f46e5;
  --accent-soft: #eef2ff;
  --ok: #059669;
  --bad: #dc2626;
  --warn-bg: #fffbeb;
  --warn-line: #fde68a;
  --warn-ink: #92400e;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.85em; background: #f3f4f6; padding: 1px 5px; border-radius: 4px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.fine { font-size: 0.8125rem; color: var(--faint); line-height: 1.45; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.row.end { justify-content: flex-end; }

/* -- Nav ------------------------------------------------- */
.site-nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255,255,255,0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 0 24px; height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
}
.nav-logo { font-size: 1rem; font-weight: 700; color: var(--ink); letter-spacing: -0.3px; }
.nav-logo:hover { color: var(--accent); text-decoration: none; }
.nav-links { display: flex; align-items: center; gap: 24px; list-style: none; }
.nav-links a { font-size: 0.875rem; color: var(--muted); font-weight: 500; }
.nav-links a:hover { color: var(--ink); text-decoration: none; }
.btn-install {
  display: inline-flex; align-items: center; padding: 8px 20px; border-radius: 8px;
  font-size: 0.875rem; font-weight: 600; background: var(--accent); color: #fff; white-space: nowrap;
}
.btn-install:hover { background: var(--accent-dark); text-decoration: none; }
@media (max-width: 640px) { .nav-links { display: none; } .site-nav { padding: 0 16px; } }

/* -- Layout ---------------------------------------------- */
.page-main { flex: 1; width: 100%; max-width: 1160px; margin: 0 auto; padding: 32px 16px 48px; }
.site-footer {
  background: #fff; border-top: 1px solid var(--line); padding: 28px 24px;
  text-align: center; font-size: 0.8125rem; color: var(--faint);
}
.site-footer a { color: var(--muted); }

/* -- Buttons --------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font: inherit; font-size: 0.875rem; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: background .15s, transform .1s;
}
.btn:hover { background: var(--accent-dark); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:disabled { background: #a5b4fc; border-color: #a5b4fc; cursor: not-allowed; transform: none; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line-strong); font-weight: 500; }
.btn-ghost:hover { background: #f9fafb; border-color: #b0b7be; }
.btn-ghost:disabled { background: #fff; color: var(--faint); border-color: var(--line); }
.btn-sm { padding: 5px 10px; font-size: 0.8125rem; }
.btn-run { padding: 10px 24px; font-size: 0.9375rem; }

/* -- Gallery --------------------------------------------- */
.page-intro { margin-bottom: 20px; }
.page-intro h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.5px; }
.page-intro p { margin-top: 6px; color: var(--muted); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.runbook-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: visible;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04); color: inherit; display: flex; flex-direction: column;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
a.runbook-card { overflow: hidden; }
.runbook-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.08); border-color: #c7d2fe; text-decoration: none; }
.card-thumb {
  width: 100%; aspect-ratio: 16 / 9; background: #f3f4f6 center/cover no-repeat;
  display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 0.8125rem;
}
.card-body { padding: 16px 18px; display: block; color: inherit; flex: 1; }
a.card-body:hover { text-decoration: none; }
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.card-desc { font-size: 0.875rem; color: var(--muted); line-height: 1.45; }
.pr-row { margin-top: 24px; text-align: center; }
.pr-banner {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 18px;
  background: #f6f8fa; border: 1px solid #d0d7de; border-radius: 20px; font-size: 0.875rem; color: #24292f;
}

/* -- Detail / Run ---------------------------------------- */
.detail-back { display: inline-flex; align-items: center; gap: 6px; font-size: 0.875rem; color: var(--muted); margin-bottom: 16px; }
.detail-back:hover { color: var(--ink); text-decoration: none; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 780px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
@media (max-width: 480px) { .detail-card { padding: 16px; } }
.detail-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.3px; }
.detail-desc { color: var(--muted); font-size: 0.9375rem; line-height: 1.55; margin-bottom: 18px; }
.runbook-note {
  display: flex; gap: 8px; background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 8px;
  padding: 12px 14px; margin-bottom: 18px; color: var(--warn-ink); font-size: 0.875rem; line-height: 1.5;
}
.runbook-note::before { content: "\26A0"; flex: none; }
.detail-gif { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #f3f4f6; aspect-ratio: 16 / 9; object-fit: cover; display: block; }
.gif-placeholder {
  width: 100%; aspect-ratio: 16 / 9; border-radius: 8px; background: #f3f4f6; border: 1px dashed var(--line-strong);
  display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 0.875rem;
}
.banner { background: var(--accent-soft); border: 1px solid #c7d2fe; border-radius: 8px; padding: 10px 14px; font-size: 0.875rem; margin-bottom: 16px; }

/* Form */
.field { margin-bottom: 16px; }
.label { display: block; font-size: 0.8125rem; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.required-mark { color: var(--bad); font-weight: 600; }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: 8px;
  font-family: inherit; font-size: 0.9375rem; color: #374151; background: #f9fafb; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { font-family: var(--mono); font-size: 0.8125rem; line-height: 1.6; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); background: #fff; }
.run-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
#status { font-size: 0.875rem; color: var(--muted); }
#status.success { color: var(--ok); }
#status.error { color: var(--bad); }
details.prompt-disclosure { margin-top: 14px; }
details.prompt-disclosure > summary, details.attachments > summary { cursor: pointer; font-size: 0.8125rem; color: var(--muted); user-select: none; padding: 4px 0; }
details.prompt-disclosure textarea { margin-top: 8px; min-height: 200px; }
details.attachments { margin-bottom: 16px; }
details.attachments .dropzone { margin-top: 8px; }

/* File widget */
.dropzone { border: 1px dashed var(--line-strong); border-radius: 10px; padding: 10px; background: #fafafa; transition: border-color .15s, background .15s; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.drop-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.dropzone.has-files .thumbs { margin-bottom: 10px; }
.thumb { position: relative; width: 84px; }
.thumb img, .thumb-file { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.thumb-name { display: block; font-size: 0.7rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.thumb-x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line-strong); background: #fff; cursor: pointer; font-size: 0.7rem; line-height: 1; }
.thumb-x:hover { background: #fee2e2; color: var(--bad); }

/* Result */
.result-card { margin-top: 24px; }
.result-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.result-title { font-size: 1.125rem; font-weight: 600; }
.result-meta { font-size: 0.8125rem; color: var(--faint); }
.result-frame { width: 100%; min-height: 160px; border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; }

/* -- Modal ----------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 500; background: rgba(17,24,39,0.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.modal-wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.modal-head h2 { font-size: 1.1rem; }
.modal-head button { border: none; background: none; cursor: pointer; font-size: 1rem; color: var(--muted); width: 32px; height: 32px; border-radius: 8px; }
.modal-head button:hover { background: #f3f4f6; }
.modal-body { padding: 18px 20px 20px; font-size: 0.9375rem; line-height: 1.5; }
.modal-body > p { margin-bottom: 12px; }
.steps { margin: 0 0 14px 20px; display: grid; gap: 8px; }
.scan-grid { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: start; margin: 8px 0; }
@media (max-width: 520px) { .scan-grid { grid-template-columns: 1fr; } }
.qr-box { width: 220px; height: 220px; border: 1px solid var(--line); border-radius: 10px; display: flex; align-items: center; justify-content: center; background: #fff; }
.qr-box svg { width: 100%; height: 100%; }
.qr-placeholder { color: var(--faint); font-size: 0.875rem; text-align: center; padding: 12px; }
.scan-steps { margin-left: 18px; display: grid; gap: 6px; font-size: 0.875rem; }
.scan-status { margin: 12px 0 8px; font-weight: 600; font-size: 0.875rem; color: var(--muted); min-height: 1.3em; }
.scan-status.phone, .scan-status.ready { color: var(--accent-dark); }
.scan-status.error, .scan-status.expired { color: var(--bad); }
.qr-link { flex: 1; min-width: 160px; font-size: 0.8rem !important; font-family: var(--mono) !important; }
.err { color: var(--bad); font-size: 0.8125rem; margin-top: 4px; }
.warn { color: var(--warn-ink); font-size: 0.8125rem; margin-top: 4px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 900;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 0.875rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--bad); }

/* -- Trace ("How it ran", for runbooks shared without a demo.gif) -- */
.trace-card { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; background: #fcfcfd; }
.trace-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; margin-bottom: 8px; }
.trace-title { font-weight: 600; }
.trace-meta { font-size: 0.8125rem; color: var(--faint); }
.trace-steps { list-style: none; margin: 0; padding: 0; }
.trace-step { padding: 7px 0; border-bottom: 1px solid #f1f2f4; font-size: 0.9rem; }
.trace-step:last-child { border-bottom: none; }
.trace-line { display: flex; gap: 8px; align-items: baseline; }
.trace-mark { color: var(--ok); font-weight: 700; flex: none; }
.trace-step.failed .trace-mark { color: var(--faint); }
.trace-label { line-height: 1.45; overflow-wrap: anywhere; }
.trace-times { color: var(--muted); font-weight: 600; }
.trace-sites { margin: 2px 0 0 22px; font-size: 0.78rem; color: var(--muted); }
.trace-actions { margin: 4px 0 0 22px; font-size: 0.82rem; }
.trace-actions summary { cursor: pointer; color: var(--muted); }
.trace-actions ul { margin: 4px 0 0 16px; color: #374151; line-height: 1.5; }
.trace-actions li.failed { color: var(--faint); }
.trace-url { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); overflow-wrap: anywhere; }
.trace-pill { display: inline-block; background: var(--accent-soft); color: var(--accent-dark); border-radius: 4px; padding: 0 5px; font-size: 0.92em; font-weight: 500; }
.trace-fine { margin-top: 10px; font-size: 0.75rem; color: var(--faint); }
.trace-thumb { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 12px;
  background: linear-gradient(135deg, #eef2ff, #f8fafc); color: var(--accent-dark); text-align: center; }
.trace-thumb-sites { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.trace-thumb-steps { font-size: 0.78rem; color: var(--muted); }
