:root {
    color-scheme: light;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-alt: #fafafa;
    --border: #e1e4e8;
    --text: #1f2328;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --radius: 8px;

    --badge-bg: #eef2ff;
    --badge-recording-bg: #fff7ed;
    --badge-recording-text: #c2410c;
    --badge-shared-bg: #f0fdf4;
    --badge-shared-text: #15803d;

    --error-bg: #fef2f2;
    --error-border: #fecaca;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    --success-text: #15803d;

    --token-bg: #f0fdf4;
    --token-border: #bbf7d0;

    --overlay-bg: rgba(15, 17, 21, 0.5);
    --skeleton-shine: rgba(255, 255, 255, 0.6);
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #15171c;
        --surface: #1c1f26;
        --surface-alt: #23262e;
        --border: #2e323b;
        --text: #e6e8eb;
        --text-muted: #9aa1ac;
        --primary: #4f8cf6;
        --primary-hover: #6ea1f8;
        --danger: #f87171;
        --danger-hover: #fb9d9d;

        --badge-bg: rgba(79, 140, 246, 0.16);
        --badge-recording-bg: rgba(251, 146, 60, 0.16);
        --badge-recording-text: #fb923c;
        --badge-shared-bg: rgba(74, 222, 128, 0.14);
        --badge-shared-text: #4ade80;

        --error-bg: rgba(248, 113, 113, 0.12);
        --error-border: rgba(248, 113, 113, 0.4);
        --success-bg: rgba(74, 222, 128, 0.12);
        --success-border: rgba(74, 222, 128, 0.4);
        --success-text: #4ade80;

        --token-bg: rgba(74, 222, 128, 0.1);
        --token-border: rgba(74, 222, 128, 0.35);

        --overlay-bg: rgba(0, 0, 0, 0.6);
        --skeleton-shine: rgba(255, 255, 255, 0.08);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar .brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
}

.topbar nav a {
    margin-left: 16px;
    color: var(--text-muted);
    font-weight: 500;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 20px;
}

.container.narrow {
    max-width: 420px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}

h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
p.muted, span.muted { color: var(--text-muted); font-size: 0.9rem; }

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
    margin-top: 12px;
}

input[type=text], input[type=email], input[type=password], input[type=url], textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
}

textarea { resize: vertical; }

button, .btn {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

button:hover, .btn:hover { background: var(--primary-hover); text-decoration: none; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

button.secondary, .btn.secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
button.secondary:hover, .btn.secondary:hover { background: var(--bg); }

button.danger, .btn.danger { background: var(--danger); }
button.danger:hover, .btn.danger:hover { background: var(--danger-hover); }

.btn-row { display: flex; gap: 8px; margin-top: 16px; align-items: center; }

.error-msg {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-top: 12px;
}

.success-msg {
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success-text);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-top: 12px;
}

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs button {
    background: none; color: var(--text-muted); border: none; border-bottom: 2px solid transparent;
    border-radius: 0; padding: 8px 4px; margin-right: 16px; font-weight: 600;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs button:hover { background: none; text-decoration: none; }

.guide-list { display: flex; flex-direction: column; gap: 10px; }
.guide-row {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 18px;
}
.guide-row .title { font-weight: 600; }
.guide-row .meta { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }
.badge {
    display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
    background: var(--badge-bg); color: var(--primary); margin-left: 8px;
}
.badge.recording { background: var(--badge-recording-bg); color: var(--badge-recording-text); }
.badge.shared { background: var(--badge-shared-bg); color: var(--badge-shared-text); }
.badge.stalled { background: var(--error-bg); color: var(--danger); }

/* ---- Breadcrumbs ---- */
.breadcrumbs { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 16px; }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--primary); }
.breadcrumbs .sep { margin: 0 6px; }
.breadcrumbs .current { color: var(--text); font-weight: 600; }

/* ---- List toolbar (search / filter / sort) ---- */
.list-toolbar {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px;
}
.list-toolbar input[type=text] { max-width: 260px; }
.list-toolbar select {
    padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem;
    background: var(--surface); color: var(--text); font-family: inherit;
}
.list-toolbar .spacer { flex: 1; }
.list-toolbar .result-count { color: var(--text-muted); font-size: 0.85rem; }

/* ---- Bulk selection ---- */
.select-row { display: flex; align-items: center; gap: 12px; }
.select-row input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; }
.bulk-bar {
    display: none; align-items: center; gap: 10px; background: var(--badge-bg); border: 1px solid var(--primary);
    border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; font-size: 0.9rem;
}
.bulk-bar.visible { display: flex; }
.bulk-bar .spacer { flex: 1; }
.select-all-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--text-muted); font-size: 0.85rem; }
.select-all-row input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }

.empty-state { text-align: center; color: var(--text-muted); padding: 48px 20px; }
.empty-state h2 { font-size: 1.15rem; margin: 0 0 8px; color: var(--text); }
.empty-state .onboarding-steps {
    text-align: left; max-width: 340px; margin: 16px auto; padding-left: 20px; color: var(--text);
}
.empty-state .onboarding-steps li { margin-bottom: 6px; }

.step-card {
    display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; margin-bottom: 16px; cursor: grab;
}
.step-card.dragging { opacity: 0.4; }
.step-card .screenshot-wrap { position: relative; }
.step-card img {
    display: block; width: 100%; max-height: 560px; object-fit: contain; border: 1px solid var(--border);
    border-radius: 6px; background: var(--surface-alt);
}
.click-marker {
    position: absolute; width: 16px; height: 16px; margin-left: -11px; margin-top: -11px;
    border-radius: 50%; background: #dc2626; border: 3px solid #fff;
    box-shadow: 0 0 0 2px #dc2626, 0 2px 6px rgba(0,0,0,0.35); pointer-events: none;
}
.click-marker::after {
    content: ''; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid #dc2626;
    animation: marker-ping 1.6s ease-out infinite;
}
.click-marker.editable { pointer-events: auto; cursor: grab; touch-action: none; }
.click-marker.editable.dragging-marker { cursor: grabbing; }
.click-marker.editable.dragging-marker::after { animation: none; opacity: 0; }
@keyframes marker-ping {
    0% { transform: scale(0.6); opacity: 0.8; }
    100% { transform: scale(1.8); opacity: 0; }
}
.step-card .step-body { flex: 1; min-width: 0; }
.step-card .step-num {
    display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
    background: var(--primary); color: #fff; border-radius: 50%; font-size: 0.75rem; font-weight: 700;
    margin-right: 8px;
}
.step-card .step-url { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 8px; word-break: break-all; }
.step-card textarea { min-height: 50px; margin-top: 4px; }
.step-card .step-actions { margin-top: 8px; display: flex; gap: 8px; align-items: center; }
.step-card .step-status { font-size: 0.8rem; }

.token-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0; border-bottom: 1px solid var(--border);
}

/* ---- Extension connection status ---- */
.extension-status { display: flex; align-items: center; gap: 12px; }
.status-dot {
    width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; background: var(--text-muted);
}
.extension-status.status-ok .status-dot { background: var(--success-text); box-shadow: 0 0 0 4px var(--success-bg); }
.extension-status.status-idle .status-dot,
.extension-status.status-warn .status-dot { background: var(--badge-recording-text); box-shadow: 0 0 0 4px var(--badge-recording-bg); }
.extension-status.status-none .status-dot { background: var(--danger); box-shadow: 0 0 0 4px var(--error-bg); }
.token-plaintext {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--token-bg); border: 1px solid var(--token-border);
    padding: 10px 12px; border-radius: 6px; word-break: break-all; font-size: 0.9rem; margin-top: 8px;
    color: var(--text);
}

.share-box { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.share-box input { flex: 1; }

.share-meta { margin-top: 10px; font-size: 0.85rem; }
.share-meta .sep { margin: 0 6px; }
.share-settings {
    display: flex; flex-direction: column; gap: 10px; margin-top: 14px; padding-top: 14px;
    border-top: 1px solid var(--border);
}
.share-setting-row { display: flex; align-items: center; gap: 8px; }
.share-setting-row label { flex-shrink: 0; width: 90px; margin: 0; font-size: 0.85rem; font-weight: 600; }
.share-setting-row select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font-family: inherit; font-size: 0.9rem; }
.share-setting-row input[type=text] { max-width: 220px; }

.loading { color: var(--text-muted); padding: 20px; text-align: center; }

/* ---- Skeleton loading placeholders ---- */
.skeleton {
    position: relative; overflow: hidden; background: var(--border); border-radius: 4px;
}
.skeleton::after {
    content: ''; position: absolute; inset: 0; transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, var(--skeleton-shine), transparent);
    animation: skeleton-shimmer 1.4s infinite;
}
@keyframes skeleton-shimmer { 100% { transform: translateX(100%); } }
.skeleton-row { pointer-events: none; }

/* ---- Toasts ---- */
.toast-container {
    position: fixed; bottom: 20px; right: 20px; z-index: 1000;
    display: flex; flex-direction: column; gap: 8px; max-width: 340px;
}
.toast {
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
    border-left: 4px solid var(--text-muted); border-radius: 6px; padding: 12px 14px;
    font-size: 0.9rem; box-shadow: 0 4px 16px rgba(0,0,0,0.15); cursor: pointer;
    opacity: 0; transform: translateY(8px); transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--success-text); }

/* ---- Confirm modal ---- */
.modal-overlay {
    position: fixed; inset: 0; background: var(--overlay-bg); z-index: 1001;
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; max-width: 380px; width: 100%; box-shadow: 0 12px 32px rgba(0,0,0,0.25);
}
.modal h3 { margin: 0 0 8px; font-size: 1.05rem; }
.modal-actions { justify-content: flex-end; }

/* ---- Copy feedback ---- */
button.copied, button.copied:hover { background: var(--success-text); }

/* ---- Toast with action (undo) ---- */
.toast-action { display: flex; align-items: center; gap: 12px; }
.toast-action-btn {
    background: none; border: none; color: var(--primary); font-weight: 700; font-size: 0.85rem;
    padding: 0; cursor: pointer; text-decoration: underline; flex-shrink: 0;
}
.toast-action-btn:hover { background: none; color: var(--primary-hover); }

/* ---- Lightbox (click-to-zoom) ---- */
.lightbox-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 1002;
    display: flex; align-items: center; justify-content: center; padding: 32px;
    opacity: 0; transition: opacity 0.2s ease;
}
.lightbox-overlay.show { opacity: 1; }
.lightbox-frame { position: relative; max-width: 100%; max-height: 100%; line-height: 0; }
.lightbox-frame img {
    display: block; max-width: 100%; max-height: calc(100vh - 64px); object-fit: contain;
    border-radius: 6px; background: var(--surface-alt);
}
.lightbox-close {
    position: absolute; top: -16px; right: -16px; width: 32px; height: 32px; border-radius: 50%;
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
    font-size: 1.1rem; line-height: 1; display: flex; align-items: center; justify-content: center;
    padding: 0; cursor: pointer;
}
.lightbox-close:hover { background: var(--bg); }
.zoom-btn {
    position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 6px;
    background: rgba(0,0,0,0.55); color: #fff; border: none; font-size: 0.95rem; line-height: 1;
    display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer;
}
.zoom-btn:hover { background: rgba(0,0,0,0.75); }

/* The lightbox re-parents the real .screenshot-wrap (and, in the editor,
   its annotation toolbar) rather than cloning it — see openScreenshotLightbox
   in common.js — so marker drag / annotation drawing keep working at the
   larger size. These overrides keep the wrap's box exactly matching the
   image's rendered box (shrink-wrapped), so percentage-based marker/
   annotation coordinates still line up correctly. */
.lightbox-frame .screenshot-wrap {
    display: inline-block;
    max-width: min(92vw, 1100px);
}
.lightbox-frame .screenshot-wrap img {
    display: block; width: auto; height: auto;
    max-width: min(92vw, 1100px); max-height: calc(100vh - 140px);
}
.lightbox-frame .annotation-toolbar { margin-top: 12px; justify-content: center; }
.screenshot-wrap.lightbox-active .zoom-btn { display: none; }
.screenshot-wrap.zoomable { cursor: zoom-in; }

/* ---- Annotation overlay (rect/arrow/blur) ---- */
.annotation-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.annotation-shape {
    stroke: var(--danger); stroke-width: 2; fill: none; vector-effect: non-scaling-stroke;
}
.annotation-arrowhead-fill { fill: var(--danger); }
.annotation-blur {
    position: absolute; backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(8px);
    background: rgba(0,0,0,0.12); border-radius: 2px; pointer-events: none;
}
.annotation-delete {
    position: absolute; width: 18px; height: 18px; margin-top: -24px; margin-left: -2px;
    border-radius: 50%; background: var(--danger); color: #fff; border: 2px solid var(--surface);
    font-size: 0.7rem; line-height: 1; display: flex; align-items: center; justify-content: center;
    padding: 0; cursor: pointer; z-index: 3;
}
.annotation-delete:hover { background: var(--danger-hover); }

/* Move (rect/blur body drag) and resize/endpoint handles. */
.annotation-move {
    position: absolute; cursor: move; pointer-events: auto; z-index: 1;
}
.annotation-handle {
    position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px;
    border-radius: 50%; background: var(--surface); border: 2px solid var(--danger);
    pointer-events: auto; z-index: 2; box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.annotation-handle[data-corner="x1y1"], .annotation-handle[data-corner="x2y2"] { cursor: nwse-resize; }
.annotation-handle[data-corner="x2y1"], .annotation-handle[data-corner="x1y2"] { cursor: nesw-resize; }
.annotation-handle[data-corner="start"], .annotation-handle[data-corner="end"] { cursor: crosshair; }

/* Tool-active cursor feedback on the screenshot itself. */
.screenshot-wrap[data-tool="rect"], .screenshot-wrap[data-tool="arrow"], .screenshot-wrap[data-tool="blur"] {
    cursor: crosshair;
}

/* ---- Add-marker hint (click-to-place) ---- */
.add-marker-hint {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.25); color: #fff; font-size: 0.85rem; font-weight: 600;
    opacity: 0; transition: opacity 0.15s ease; cursor: crosshair; border-radius: 6px;
}
.step-card .screenshot-wrap:hover .add-marker-hint { opacity: 1; }

/* ---- Editor: step title, annotation toolbar, reorder buttons ---- */
.step-title-input {
    font-weight: 600; border: 1px solid transparent; background: transparent; padding: 2px 4px;
    border-radius: 4px; margin: 0;
}
.step-title-input:hover, .step-title-input:focus { border-color: var(--border); background: var(--surface); }
.step-heading-row { display: flex; align-items: center; gap: 4px; }
.step-heading-row .step-title-input { flex: 1; font-size: 1rem; }

.annotation-toolbar { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tool-btn {
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
    padding: 5px 10px; font-size: 0.8rem; font-weight: 600; border-radius: 6px; cursor: pointer;
}
.tool-btn:hover { background: var(--bg); }
.tool-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.step-actions .icon-btn { padding: 8px 10px; line-height: 1; }
.step-actions .icon-btn:disabled { opacity: 0.35; }

.preview-banner {
    background: var(--badge-bg); border: 1px solid var(--primary); color: var(--text);
    padding: 10px 14px; border-radius: 6px; font-size: 0.85rem; margin-bottom: 16px;
}
.preview-banner a { font-weight: 600; margin-left: 6px; }
