/* DESIGN TOKENS */
:root {
    --preview-slot-width: 360px;
    --main-column-max-width: 900px;
    --settings-panel-width: 340px;
    --panel-gap: 20px;
    --content-max-width: 900px;
    --main-content-max-width: 900px;
    --content-top-padding: 40px;
    --header-height: 60px;
    --setting-group-pad-x: 12px;
    --setting-group-pad-top: 6px;
    --setting-group-pad-bottom: 12px;
    --setting-control-gap: 6px;
    --onboarding-coachmark-reserve: 0px;
    --toast-bottom-offset: 0px;
    --workflow-stage-duration-ms: 420;
    --viewer-stage-max-width: 1560px;

    --bg: #f4f4f9;
    --card: #ffffff;
    --text: #333333;
    --textStrong: #2d3748;
    --muted: #64748b;
    --mutedStrong: #4a5568;
    --mutedSoft: #a0aec0;
    --border: #e2e8f0;
    --borderStrong: #cbd5e0;
    --surfaceAlt: #f8fafc;

    --primary: #3498db;
    --primaryHover: #2980b9;
    --danger: #e53e3e;
    --dangerHover: #b91c1c;
    --focusRing: #93c5fd;
    --disabled: #95a5a6;

    --shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    --shadowSoft: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadowHover: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* BASIC RESETS */

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    /* Professional font stack */
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

html,
body {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
    overscroll-behavior-y: auto;
    background: var(--bg);
}

* {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

*:hover,
*:focus-within {
    scrollbar-color: #cbd5e1 transparent;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: content-box;
}

*:hover::-webkit-scrollbar-thumb,
*:focus-within::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: content-box;
}

/* LAYOUT */
.app-layout {
    display: flex;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    padding-top: var(--header-height);
}

.main-content {
    width: 100%;
    max-width: var(--main-content-max-width);
    padding: 20px;
    padding-left: clamp(18px, 4vw, 28px);
    padding-right: clamp(18px, 4vw, 28px);
    padding-top: var(--content-top-padding);
    box-sizing: border-box;
}

.container {
    padding-bottom: 150px;
}

.workflow-layout {
    display: flex;
    flex-direction: column;
    gap: var(--panel-gap);
    align-items: stretch;
    position: relative;
    width: 100%;
}

.workflow-main {
    display: flex;
    flex-direction: column;
    gap: var(--panel-gap);
}

.workflow-main > .card {
    margin-bottom: 0;
}

.workflow-stage-viewport {
    width: 100%;
    overflow: hidden;
    overflow: clip;
    position: relative;
    contain: paint;
    isolation: isolate;
}

.workflow-stage-track {
    display: flex;
    width: 100%;
    transform: translate3d(calc(var(--workflow-stage-index, 0) * -100%), 0, 0);
    transition: transform calc(var(--workflow-stage-duration-ms) * 1ms) cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform;
}

.workflow-stage-track.is-transitioning {
    pointer-events: none;
}

.workflow-stage-panel {
    flex: 0 0 100%;
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
    backface-visibility: hidden;
}

body.workflow-stage-history .main-content,
body.workflow-stage-create .main-content,
body.workflow-stage-viewer .main-content {
    max-width: var(--main-content-max-width);
}

body.workflow-stage-transitioning {
    cursor: progress;
}

body.workflow-stage-transitioning .app-header,
body.workflow-stage-transitioning .app-layout,
body.workflow-stage-transitioning .onboarding-coachmark,
body.workflow-stage-transitioning #toastContainer {
    pointer-events: none;
}

body.viewer-popout-running {
    cursor: progress;
}

body.viewer-popout-running .app-header,
body.viewer-popout-running .app-layout,
body.viewer-popout-running .onboarding-coachmark,
body.viewer-popout-running #toastContainer {
    pointer-events: none;
}

.viewer-popout-shell {
    position: fixed;
    z-index: 3900;
    border-radius: 14px;
    overflow: hidden;
    background: #0f172a;
    box-shadow: 0 14px 36px rgba(2, 6, 23, 0.4);
    pointer-events: none;
    transition:
        left 360ms cubic-bezier(0.22, 1, 0.36, 1),
        top 360ms cubic-bezier(0.22, 1, 0.36, 1),
        width 360ms cubic-bezier(0.22, 1, 0.36, 1),
        height 360ms cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 260ms ease;
}

.viewer-popout-shell.is-expanded {
    box-shadow: 0 28px 78px rgba(2, 6, 23, 0.52);
}

.viewer-popout-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.workflow-settings {
    width: 100%;
}

.settings-panel {
    position: relative;
    z-index: 1;
    align-self: stretch;
    margin-bottom: 0;
}
.settings-panel .collapsible-card-body {
    width: 100%;
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
}
.settings-panel .card-subtitle {
    margin-bottom: 18px;
}

@media (max-width: 1200px) {
    .settings-panel {
        position: static;
        top: auto;
    }

    .container {
        padding-bottom: 150px;
    }
}

/* APP HEADER */
.app-header {
    height: var(--header-height);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    transform: translateZ(0);
    backface-visibility: hidden;
    will-change: transform;
}
.app-header-inner {
    height: var(--header-height);
    width: max-content;
    max-width: calc(100% - 24px);
    margin: 0 auto;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: max-content var(--main-content-max-width, 900px) max-content;
    align-items: center;
}
.app-title {
    margin: 0;
    font-size: 18px;
}
.app-title-link {
    color: inherit;
    text-decoration: none;
}
.app-title-link:hover {
    color: var(--primaryHover);
}
.app-title-link:focus-visible {
    outline: 2px solid var(--focusRing);
    outline-offset: 4px;
    border-radius: 6px;
}
.user-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    grid-column: 3;
}
.badge-anon {
    background: #f1f5f9;
    color: var(--muted);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.btn-login {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card);
    border: 1px solid var(--borderStrong);
    color: var(--textStrong);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
}
.btn-login:hover {
    background: var(--surfaceAlt);
}
.google-logo {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    display: block;
}
.auth-user {
    display: flex;
    align-items: center;
    gap: 10px;
}
.auth-user-meta {
    text-align: right;
    line-height: 1.2;
}
.u-meta-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--card);
    box-shadow: var(--shadowSoft);
}
.u-name {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
}
.u-logout {
    font-size: 11px;
    color: var(--muted);
    text-decoration: none;
    cursor: pointer;
}
.u-plan,
.u-quota {
    font-size: 11px;
    color: var(--muted);
}
.u-logout:hover {
    text-decoration: underline;
    color: #ef4444;
}
.u-admin {
    font-size: 11px;
    color: #0ea5e9;
    text-decoration: none;
    margin-right: 8px;
}
.u-admin:hover {
    text-decoration: underline;
    color: #0284c7;
}
.app-heading {
    margin-bottom: 20px;
    display: none;
}

/* AUTH GATE */
body.auth-gate-active {
    overflow: hidden;
}
body.download-modal-open {
    overflow: hidden;
}
html.page-scroll-locked,
body.page-scroll-locked {
    overflow: hidden;
    overscroll-behavior: none;
}
body.page-scroll-locked {
    width: 100%;
}
body.auth-gate-active .app-header,
body.auth-gate-active .app-layout {
    filter: blur(6px);
    pointer-events: none;
    user-select: none;
}
.auth-loading .app-header,
.auth-loading .app-layout {
    visibility: hidden;
}
.auth-loading #authGate {
    display: none;
}
.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    box-sizing: border-box;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(4px);
}
.auth-gate.hidden {
    display: none;
}
.auth-gate-card {
    width: min(420px, 100%);
    padding: 24px 28px;
    border-radius: 16px;
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--shadowHover);
    text-align: center;
}
.auth-gate-card h2 {
    margin: 0 0 8px 0;
    font-size: 20px;
    color: var(--textStrong);
}
.auth-gate-subtitle {
    margin: 0 0 18px 0;
    font-size: 13px;
    color: var(--muted);
}
.auth-gate-btn {
    justify-content: center;
}
.gis-button {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}
#authGateClose {
    margin-top: 10px;
}

/* UTILS */
.hidden { display: none !important; }

/* ONBOARDING COACHMARKS */
body.onboarding-active.onboarding-bottom-mode:not(.onboarding-intro-mode) .container {
    padding-bottom: calc(150px + var(--onboarding-coachmark-reserve, 0px));
}
body.onboarding-active::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 2500;
    pointer-events: none;
    opacity: 0;
}
body.onboarding-active.onboarding-intro-mode::before {
    pointer-events: auto;
    opacity: 1;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}
body.onboarding-active.onboarding-spotlight-mode::before {
    display: none;
}
body.onboarding-active.onboarding-spotlight-mode .app-header {
    border-bottom-color: transparent;
}
body.onboarding-active.onboarding-spotlight-mode .app-header::after {
    content: "";
    position: absolute;
    inset: 0 0 -1px 0;
    background: rgba(15, 23, 42, 0.45);
    pointer-events: none;
}
.onboarding-spotlight {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    overflow: hidden;
    z-index: 2500;
    pointer-events: none;
}
.onboarding-spotlight-cutout {
    position: absolute;
    background: transparent;
    box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.45);
    border-radius: 12px;
    pointer-events: none;
}
.onboarding-highlight {
    position: relative;
    z-index: 2600 !important;
    box-shadow: none !important;
}
.onboarding-coachmark {
    position: fixed;
    z-index: 2700;
    width: min(380px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    background: #ffffff;
    border: 1px solid #dbe2ea;
    border-radius: 14px;
    box-shadow: 0 16px 34px rgba(2, 6, 23, 0.22);
    padding: 16px 16px 14px 16px;
    box-sizing: border-box;
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    color: #1f2937;
    pointer-events: auto;
}
.onboarding-coachmark.is-intro {
    min-height: 168px;
    display: grid;
    grid-template-rows: auto 1fr auto;
    row-gap: 10px;
    border-color: rgba(14, 165, 233, 0.30);
    background:
        radial-gradient(circle at 0% 0%, rgba(56, 189, 248, 0.10), transparent 42%),
        radial-gradient(circle at 100% 100%, rgba(251, 191, 36, 0.12), transparent 50%),
        #ffffff;
}
.onboarding-kicker {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #0ea5e9;
    margin-bottom: 6px;
}
.onboarding-title {
    margin: 0;
    font-size: 17px;
    line-height: 1.3;
    color: #0f172a;
}
.onboarding-body {
    margin: 8px 0 10px 0;
    font-size: 13px;
    line-height: 1.45;
    color: #334155;
}
.onboarding-coachmark.is-intro .onboarding-kicker,
.onboarding-coachmark.is-intro .onboarding-title {
    text-align: center;
}
.onboarding-coachmark.is-intro .onboarding-title {
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    width: 100%;
    margin: 0;
    font-weight: 400;
    font-size: 22px;
    line-height: 1.3;
}
.onboarding-coachmark.is-intro .onboarding-kicker {
    margin: 0;
}
.onboarding-coachmark.is-intro .onboarding-body {
    display: none;
}
.onboarding-coachmark.is-intro .onboarding-actions {
    margin-top: 0;
    justify-content: center;
    gap: 10px;
}
.onboarding-body:empty {
    min-height: 44px;
}
.onboarding-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.onboarding-actions .btn {
    width: auto;
    margin-top: 0;
    padding: 8px 11px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
}
.onboarding-coachmark.is-intro .onboarding-actions .btn {
    min-width: 112px;
}
.onboarding-coachmark .btn.secondary {
    border-color: #d0d7e2;
    color: #334155;
}
.onboarding-coachmark #onboardingNextBtn {
    color: #ffffff;
    -webkit-text-fill-color: #ffffff;
}
.onboarding-inline-status {
    margin-top: 8px;
    padding: 6px 8px;
    border-radius: 9px;
    border: 1px solid #fdba74;
    background: #fff7ed;
    color: #7c2d12;
    font-size: 11px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.onboarding-inline-status[data-priority="warn"] {
    border-color: #facc15;
    background: #fefce8;
    color: #713f12;
}
.onboarding-inline-status[data-priority="error"] {
    border-color: #fca5a5;
    background: #fef2f2;
    color: #7f1d1d;
}
body.onboarding-active.onboarding-bottom-mode .onboarding-coachmark:not(.is-intro) .onboarding-kicker {
    display: none;
}
.onboarding-coachmark.is-done {
    border-color: #86efac;
    background: #ecfdf3;
}
.onboarding-coachmark.is-done .onboarding-kicker {
    color: #16a34a;
}
.onboarding-coachmark.is-done .onboarding-title,
.onboarding-coachmark.is-done .onboarding-body {
    color: #14532d;
}

@media (max-width: 640px) {
    .onboarding-coachmark {
        width: min(420px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
    }
    .onboarding-title {
        font-size: 16px;
    }
    body.onboarding-active.onboarding-bottom-mode .onboarding-coachmark:not(.is-intro) {
        padding: 8px 10px;
        border-radius: 11px;
        max-height: min(180px, calc(100dvh - 20px));
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        column-gap: 8px;
        row-gap: 1px;
        align-items: start;
    }
    body.onboarding-active.onboarding-bottom-mode .onboarding-coachmark:not(.is-intro) .onboarding-title {
        font-size: 13px;
        line-height: 1.2;
        grid-column: 1 / -1;
        grid-row: 1;
        margin: 0;
    }
    body.onboarding-active.onboarding-bottom-mode .onboarding-coachmark:not(.is-intro) .onboarding-body {
        margin: 3px 0 1px 0;
        font-size: 12px;
        line-height: 1.3;
        grid-column: 1 / 2;
        grid-row: 2;
        align-self: end;
    }
    body.onboarding-active.onboarding-bottom-mode .onboarding-coachmark:not(.is-intro) .onboarding-actions {
        margin: 0 0 1px 0;
        gap: 0;
        grid-column: 2 / 3;
        grid-row: 2;
        align-self: end;
        justify-content: center;
    }
    body.onboarding-active.onboarding-bottom-mode .onboarding-coachmark:not(.is-intro) .onboarding-actions .btn {
        padding: 4px 8px;
        font-size: 11px;
        line-height: 1;
        min-width: 0;
        border-radius: 8px;
    }
    .onboarding-inline-status {
        margin-top: 5px;
        padding: 5px 6px;
        font-size: 10px;
        line-height: 1.2;
    }
}

/* CARDS */
.card {
    background: var(--card);
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.mosaic-step-card {
    border: 1px solid transparent;
    transition: border-color 0.2s ease;
}
.mosaic-step-card.is-engaged {
    background: var(--card);
    border-color: transparent;
}
.mosaic-step-card.is-selected {
    background: var(--card);
    border-color: transparent;
}
.mosaic-step-card.is-disabled,
.mosaic-step-card.is-disabled * {
    cursor: default;
}
.card h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 18px;
    color: var(--textStrong);
}
.card-subtitle {
    margin-top: -6px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--muted);
}

button.card-title-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin: 0;
    padding: 2px 0;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
}
button.card-title-toggle:hover {
    background: transparent;
    color: var(--primaryHover);
}
button.card-title-toggle:focus-visible {
    outline: 2px solid var(--focusRing);
    outline-offset: 3px;
}
.card-title-chevron {
    font-size: 12px;
    color: var(--muted);
    transition: transform 0.2s ease;
}
.collapsible-card.is-collapsed .card-title-chevron {
    transform: rotate(-90deg);
}
.collapsible-card.is-collapsed .collapsible-card-body {
    display: none;
}
.collapsible-card.is-collapsed,
.collapsible-card.is-collapsed * {
    cursor: pointer;
}
.collapsible-card.is-collapsed.is-disabled,
.collapsible-card.is-collapsed.is-disabled * {
    cursor: default;
}
.collapsible-card.is-collapsed.is-disabled button.card-title-toggle {
    pointer-events: none;
}
body.workflow-transition-locked button.card-title-toggle:disabled {
    cursor: wait;
}
body.workflow-scroll-lock .app-header,
body.workflow-scroll-lock .main-content,
body.workflow-scroll-lock .onboarding-coachmark,
body.workflow-scroll-lock #toastContainer {
    pointer-events: none;
}
.confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 3900;
}
.collapsed-summary {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 4px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surfaceAlt);
    color: #334155;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease;
    min-height: 64px;
}
.collapsed-summary-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}
.collapsed-summary:hover {
    background: #eff6ff;
    border-color: #bfdbfe;
}
.collapsed-summary.is-disabled,
.collapsed-summary.is-disabled:hover {
    background: var(--surfaceAlt);
    border-color: var(--border);
    cursor: default;
    pointer-events: none;
}
.collapsed-summary-media {
    flex-shrink: 0;
}
.collapsed-summary-thumb {
    width: 68px;
    height: 68px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #dbe2ea;
    background: var(--border);
}
.collapsed-summary-thumbs {
    display: flex;
    gap: 4px;
}
.collapsed-summary-thumbs img {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid #dbe2ea;
    background: var(--border);
}
.collapsed-summary-thumb-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px dashed #cbd5e1;
    background: var(--border);
    display: inline-block;
}
.collapsed-summary-content {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 1 auto;
}
.collapsed-summary-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.collapsed-summary strong {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.steps-summary {
    font-weight: 600;
    color: var(--mutedStrong);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.step-seq {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.step-index {
    font-weight: 700;
    color: var(--textStrong);
}
.step-sep {
    color: var(--mutedSoft);
}
.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-title-row .card-title-toggle {
    width: auto;
    flex: 1 1 auto;
}
.result-title-row {
    min-height: 30px;
}
#resultCard #resultToggle[disabled] {
    cursor: default;
    pointer-events: none;
    color: inherit;
    opacity: 1;
}
#resultCard #stopBtn {
    flex: 0 0 auto;
    margin-left: 10px;
}
#resultCard.is-collapsed #stopBtn {
    display: none !important;
}
.link-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
}
.link-btn:hover {
    color: var(--primaryHover);
    text-decoration: underline;
}

.create-mosaic-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
}
.create-header-inline {
    --create-header-row-height: 26px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: end;
    gap: 12px;
    margin-bottom: 14px;
    min-height: var(--create-header-row-height);
}
.card h3.create-mosaic-title {
    margin: 0;
    margin-bottom: 0;
    display: flex;
    align-items: flex-end;
    flex: 0 0 auto;
    height: var(--create-header-row-height);
    line-height: 1;
}
.create-mosaic-title #createMosaicToggle {
    height: 100%;
    min-height: 0;
    padding: 0;
    line-height: 1;
    display: inline-flex;
    align-items: flex-end;
}
.create-step-header {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
    gap: 4px;
    margin-bottom: 0;
    padding: 0;
    height: var(--create-header-row-height);
    min-height: var(--create-header-row-height);
    border: none;
    border-radius: 0;
    background: transparent;
    align-self: end;
}
.create-step-pill {
    width: 100%;
    min-height: 0;
    height: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 1px solid #d7dee8;
    border-radius: 7px;
    background: #e9eef5;
    color: #5b6b7f;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    padding: 0 5px;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, opacity 0.16s ease;
}
.create-step-pill:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
}
.create-step-pill.is-active {
    background: #ffffff;
    border-color: #d7dee8;
    color: #1e293b;
    box-shadow: inset 0 0 0 1px #e5e7eb;
}
.create-step-pill.is-done {
    background: #e2e8f0;
    border-color: #cbd5e1;
    color: #475569;
}
.create-step-pill.is-locked,
.create-step-pill:disabled {
    background:
        repeating-linear-gradient(
            135deg,
            #eef2f7 0,
            #eef2f7 6px,
            #e5ebf3 6px,
            #e5ebf3 12px
        );
    border-color: #d1d9e4;
    color: #94a3b8;
    opacity: 1;
    cursor: not-allowed;
    pointer-events: none;
}
.create-step-arrow {
    display: none;
}
.create-flow-panel.is-step-hidden {
    display: none !important;
}
.create-flow-panel.is-enter-from-right {
    animation: createPanelInFromRight 260ms cubic-bezier(0.22, 1, 0.36, 1);
}
.create-flow-panel.is-enter-from-left {
    animation: createPanelInFromLeft 260ms cubic-bezier(0.22, 1, 0.36, 1);
}
.create-step-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: -4px;
}
.create-step-next {
    min-width: 220px;
    height: 42px;
    font-weight: 700;
}

#createMosaicCard button.card-title-toggle,
#mainPhotoCard button.card-title-toggle,
#tileLibraryCard button.card-title-toggle,
#configCard button.card-title-toggle {
    cursor: default;
    pointer-events: none;
}

#createMosaicCard button.card-title-toggle:hover {
    color: var(--textStrong);
}

#createMosaicCard .card-title-chevron,
#mainPhotoCard .card-title-chevron,
#tileLibraryCard .card-title-chevron,
#configCard .card-title-chevron {
    display: none;
}
#historyCard .card-title-chevron {
    display: none;
}
#historyCard #historyToggle {
    cursor: default;
    pointer-events: none;
}

#mainPhotoCard button.card-title-toggle,
#tileLibraryCard button.card-title-toggle,
#configCard button.card-title-toggle {
    gap: 6px;
}

@keyframes createPanelInFromRight {
    from {
        transform: translateX(28px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes createPanelInFromLeft {
    from {
        transform: translateX(-28px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}
.create-mosaic-body .card {
    margin-bottom: 0;
    box-shadow: var(--shadowSoft);
}
.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surfaceAlt);
    color: var(--mutedStrong);
    font-size: 11px;
    font-weight: 700;
}

.settings-actions-inline {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
    margin-bottom: 12px;
}
.settings-actions-inline #generateBtn {
    width: 100%;
    height: 48px;
    font-weight: 700;
}

.btn-tooltip {
    position: relative;
    display: inline-flex;
    width: 100%;
}
.collapsed-summary-actions .btn-tooltip {
    width: auto;
}
.btn-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    top: calc(100% + 6px);
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.95);
    color: #ffffff;
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 8px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 30;
}
.btn-tooltip.is-disabled:hover::after {
    opacity: 1;
}
.btn-tooltip.is-disabled,
.btn-tooltip.is-disabled button {
    cursor: not-allowed;
}
.settings-actions-inline .shortcuts-hint {
    margin-top: 0;
    font-size: 11px;
    line-height: 1.3;
}

@media (prefers-reduced-motion: reduce) {
    .card-title-chevron,
    .collapsed-summary,
    .mosaic-step-card,
    .btn-tooltip::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

.viewer-empty,
.empty-state {
    padding: 20px;
    background: var(--surfaceAlt);
    border: 1px dashed var(--border);
    border-radius: 10px;
    color: var(--muted);
    text-align: center;
}
.viewer-empty {
    margin-bottom: 16px;
}
.empty-state {
    margin-bottom: 12px;
}
.viewer-content.hidden {
    display: none;
}
.shortcuts-hint {
    margin-top: 10px;
    font-size: 12px;
    color: var(--muted);
}
kbd {
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    background: var(--border);
    border: 1px solid var(--borderStrong);
    border-radius: 4px;
    padding: 1px 5px;
}
.modal-panel.compact {
    width: min(460px, calc(100% - 32px));
}
.btn.danger {
    background: var(--danger);
}
.btn.danger:hover {
    background: var(--dangerHover);
}

/* SKELETON LOADING */
@keyframes skeleton-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: 0 0; }
}
.skeleton-box {
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 37%, #e2e8f0 63%);
    background-size: 400% 100%;
    animation: skeleton-shimmer 1.25s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
    .skeleton-box {
        animation: none;
    }
}
.skeleton-line {
    display: block;
    height: 10px;
    border-radius: 999px;
}
.history-skeleton {
    pointer-events: none;
}
.history-skeleton .meta {
    justify-content: flex-start;
    margin-top: 6px;
}
#historyError .hint {
    margin-top: 6px;
}
#historyError .btn {
    margin-top: 12px;
}

/* HISTORY STRIP */
.history-strip {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 10px;
}
.history-meta {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 6px;
    font-size: 12px;
    color: var(--mutedSoft);
}
.history-count {
    white-space: normal;
    margin-left: auto;
    text-align: right;
    max-width: 100%;
}
.history-load-more {
    width: auto;
    margin-top: 0;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surfaceAlt);
    color: var(--text);
}
.history-load-more:hover {
    background: var(--surfaceAlt);
}
.history-load-more:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.library-strip,
.recent-photos-strip {
    padding-bottom: 1px;
}
#libGrid,
#recentPhotosStrip {
    padding-bottom: 1px;
}

.history-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-radius: 8px;
    background: var(--card);
    box-shadow: var(--shadowSoft);
    overflow: visible;
    transition: transform 0.2s;
}
.history-item:focus-visible,
.recent-source-item:focus-visible,
.library-strip-item:focus-visible {
    outline: 2px solid var(--focusRing);
    outline-offset: 2px;
}
.history-item:hover {
    transform: translateY(-2px);
}
.history-create-cta .history-tile {
    display: grid;
    place-items: center;
    place-content: center;
    gap: 7px;
    border-style: dashed;
    border-color: #93c5fd;
    background:
        radial-gradient(circle at 18% 18%, rgba(147, 197, 253, 0.42), transparent 48%),
        linear-gradient(135deg, #eff6ff, #dbeafe 52%, #e2e8f0);
    color: #0f172a;
}
.history-create-cta .history-create-icon {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: #0ea5e9;
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    line-height: 1;
    font-weight: 300;
    box-shadow: 0 8px 20px rgba(14, 165, 233, 0.35);
}
.history-create-cta .history-create-copy {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.history-create-cta .meta {
    justify-content: center;
}
.history-create-cta .name {
    font-size: 12px;
    font-weight: 700;
    color: #0f172a;
    text-align: center;
}
.history-item.is-expiring-soon .history-tile::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(245, 101, 101, 0.08), rgba(229, 62, 62, 0.22));
    pointer-events: none;
    z-index: 4;
}
.history-tile {
    /* Match the visual scale of the "Most used photos" strip */
    flex: 0 0 144px;
    height: 144px;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s;
    background: #edf2f7;
}
.history-expiry-badge {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    padding: 4px 6px;
    border-radius: 8px;
    background: rgba(124, 45, 18, 0.88);
    color: #fff7ed;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
    letter-spacing: 0.01em;
    z-index: 11;
    pointer-events: none;
}
.history-finalize-badge {
    position: absolute;
    left: 6px;
    top: 6px;
    z-index: 6;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #1a202c;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(26, 32, 44, 0.15);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}
.history-legacy-badge {
    position: absolute;
    left: 6px;
    top: 6px;
    z-index: 6;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #7c2d12;
    background: rgba(255, 237, 213, 0.95);
    border: 1px solid rgba(251, 146, 60, 0.45);
    box-shadow: 0 1px 2px rgba(124, 45, 18, 0.16);
}
.history-tile.has-finalize-badge .history-legacy-badge {
    top: 25px;
}

/* Buttons should look like tiles, not like default form controls. */
.history-tile { padding: 0; background: #edf2f7; appearance: none;
    -webkit-appearance: none; }
.history-item:hover,
.history-tile:hover { transform: scale(1.05); }
.history-item img,
.history-tile img { width: 100%; height: 100%; object-fit: cover;
}
.history-item.is-selected .history-tile,
.history-tile.is-selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

/* UPLOAD AREAS */
.upload-area {
    border: 2px dashed #bdc3c7;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    border-radius: 8px;
    transition: 0.2s;
    background: #fafafa;
}
.upload-area:hover { border-color: var(--primary); background: #f0f8ff; }
.upload-area.source-selected {
    border-color: #bdc3c7;
    box-shadow: none;
    background: #fafafa;
}
.upload-area.is-dragover {
    border-color: #2b6cb0;
    background: #ebf8ff;
}

.main-photo-workspace {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    margin-top: 8px;
    min-height: 225px;
}
.main-photo-preview-slot {
    flex: 0 0 var(--preview-slot-width);
    max-width: var(--preview-slot-width);
    width: 100%;
    display: flex;
    align-items: flex-end;
}
.main-photo-preview-slot.full-width {
    flex: 1 1 auto;
    max-width: 100%;
}
.main-photo-workspace.is-focused {
    align-items: stretch;
    height: 338px;
    min-height: 338px;
}
.main-photo-workspace.is-focused .main-photo-preview-slot:not(.full-width) {
    flex: 1 1 auto;
    max-width: none;
    align-items: center;
    justify-content: center;
}
.main-photo-workspace.is-focused .main-source-dropzone {
    --source-focus-max-h: 338px;
    width: min(100%, calc(var(--source-focus-max-h) * var(--source-ratio, 1.6)));
    max-width: 100%;
    max-height: var(--source-focus-max-h);
    height: auto;
    transition: width 300ms cubic-bezier(0.25, 0.8, 0.25, 1);
    background: #ffffff;
    margin: 0 auto;
}
.main-photo-workspace.is-focused .source-preview-image {
    background: #ffffff;
}
.main-photo-preview-slot.full-width .main-source-dropzone {
    width: 100%;
    max-width: 100%;
    height: 225px;
    max-height: 225px;
    aspect-ratio: auto !important;
}
.main-photo-library-slot {
    flex: 1 1 auto;
    min-width: 0;
    height: 225px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 6px;
}
.main-photo-library-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
}
.recent-photos-strip-head {
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    gap: 8px;
    margin-bottom: 6px;
}
.recent-photos-empty {
    font-size: 12px;
    color: #94a3b8;
    padding: 0 4px;
    margin-bottom: 8px;
}
.recent-photos-strip {
    margin-bottom: 0;
    padding-bottom: 4px;
}
.recent-source-item {
    width: 144px;
    border-radius: 8px;
    background: var(--card);
    overflow: hidden;
    box-sizing: border-box;
    box-shadow: var(--shadowSoft);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}
.recent-source-item:hover {
    transform: translateY(-2px);
}
.recent-source-item .recent-source-tile {
    width: 100%;
    height: 144px;
    border-radius: 0;
    opacity: 1;
    transition: opacity 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.recent-source-item .recent-source-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.recent-source-item .meta {
    display: block;
    font-size: 11px;
    color: var(--mutedStrong);
    margin-top: 0;
    padding: 6px 8px;
    border-top: none;
    background: var(--card);
    max-width: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.main-photo-workspace.is-focused .main-photo-library-slot {
    flex: 0 0 156px;
    max-width: 156px;
    height: 100%;
    min-height: 0;
    justify-content: flex-start;
    gap: 0;
}
.main-photo-workspace.is-focused .main-photo-library-body {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}
.main-photo-workspace.is-focused .recent-photos-strip-head {
    display: none;
}
.main-photo-workspace.is-focused .recent-photos-strip {
    flex-direction: column;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    gap: 8px;
    padding: 0 4px 0 0;
}
.main-photo-workspace.is-focused .recent-source-item {
    width: 100%;
    flex: 0 0 auto;
}
.main-photo-workspace.is-focused .recent-source-item .recent-source-tile {
    height: 108px;
}
.recent-source-item.is-selected .recent-source-tile {
    opacity: 1;
}
.recent-source-item.is-selected {
    box-shadow: var(--shadowSoft);
}

.strip-head-label {
    margin-bottom: 0;
}

.source-preview-frame {
    position: relative;
    aspect-ratio: 16 / 10;
    width: 100%;
    max-width: 360px;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: #e5e7eb;
    background-image: var(--source-preview-backdrop, none);
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    border-style: solid;
}
.source-preview-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: transparent;
}
.source-preview-image.source-preview-swap-transition {
    transition:
        transform 800ms cubic-bezier(0.65, 0, 0.35, 1),
        opacity 800ms cubic-bezier(0.65, 0, 0.35, 1);
    will-change: transform;
}
.source-preview-image.source-preview-swap-out {
    transform: translateX(0%);
    opacity: 1;
    z-index: 2;
}
.source-preview-image.source-preview-swap-out.source-preview-swap-out-active {
    transform: translateX(100%);
    opacity: 0.88;
}
.source-preview-swap-incoming {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    right: auto;
    width: auto;
    height: 100%;
    max-width: none;
    object-fit: fill;
    background: transparent;
    transform: translateX(calc(-50% - 100%));
    opacity: 0.95;
    z-index: 3;
    pointer-events: none;
}
.source-preview-swap-incoming.source-preview-swap-in-active {
    transform: translateX(-50%);
    opacity: 1;
}
.source-preview-frame.source-preview-resizing .source-preview-image:not(.source-preview-swap-incoming) {
    opacity: 0;
}
.source-preview-frame.is-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        105deg,
        rgba(226, 232, 240, 0.85) 20%,
        rgba(241, 245, 249, 0.96) 45%,
        rgba(226, 232, 240, 0.85) 70%
    );
    background-size: 220% 100%;
    animation: preview-skeleton 1.05s ease-in-out infinite;
    z-index: 1;
}
@keyframes preview-skeleton {
    from { background-position: 100% 0; }
    to { background-position: -100% 0; }
}
.source-preview-placeholder {
    position: relative;
    z-index: 2;
    color: var(--mutedStrong);
    font-size: 14px;
    text-align: center;
    padding: 16px;
}
.source-preview-overlay {
    position: absolute;
    inset: auto 8px 8px 8px;
    min-height: 0;
    background: none;
    color: #334155;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    font-size: 12px;
    font-weight: 600;
    z-index: 3;
    opacity: 1;
}
.source-preview-overlay .overlay-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(248, 250, 252, 0.9);
    color: #334155;
    font-size: 11px;
    letter-spacing: 0.01em;
    backdrop-filter: blur(2px);
}

.tile-library-workspace {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    margin-top: 6px;
    min-height: 225px;
}
.tile-library-upload-slot {
    flex: 0 0 var(--preview-slot-width);
    max-width: var(--preview-slot-width);
    width: 100%;
    display: flex;
    align-items: flex-end;
}
.tile-library-upload-slot.full-width {
    flex: 1 1 auto;
    max-width: 100%;
}
.tile-library-workspace.is-focused {
    align-items: flex-end;
    height: 288px;
    min-height: 288px;
}
.tile-library-workspace.is-focused .tile-library-upload-slot:not(.full-width) {
    flex: 1 1 auto;
    max-width: none;
    height: 288px;
}
.tile-library-workspace.is-focused .library-dropzone {
    width: 100%;
    max-width: none;
    height: 288px;
    max-height: 288px;
    aspect-ratio: auto !important;
}
.tile-library-upload-slot.full-width .library-dropzone {
    width: 100%;
    max-width: 100%;
    height: 225px;
    max-height: 225px;
    aspect-ratio: auto !important;
}
.tile-library-strip-slot {
    flex: 1 1 auto;
    min-width: 0;
    height: 225px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 6px;
}
.library-strip {
    margin-bottom: 0;
    padding-bottom: 4px;
}
.library-strip-item {
    width: 144px;
    flex: 0 0 144px;
    border-radius: 8px;
    background: var(--card);
    overflow: hidden;
    box-sizing: border-box;
    box-shadow: var(--shadowSoft);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}
.library-strip-item:hover {
    transform: translateY(-2px);
}
.library-strip-item .library-strip-tile {
    width: 100%;
    height: 144px;
    position: relative;
    border-radius: 0;
}
.library-strip-item .meta {
    display: block;
    font-size: 11px;
    color: var(--mutedStrong);
    margin-top: 0;
    padding: 6px 8px;
    border-top: none;
    background: var(--card);
    max-width: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tile-library-workspace.is-focused .tile-library-strip-slot {
    flex: 0 0 156px;
    max-width: 156px;
    height: 288px;
    justify-content: flex-start;
    min-height: 0;
    gap: 0;
}
.tile-library-workspace.is-focused .recent-photos-strip-head {
    display: none;
}
.tile-library-workspace.is-focused #libGrid {
    flex-direction: column;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    gap: 8px;
    padding: 0 4px 0 0;
}
.tile-library-workspace.is-focused .library-strip-item {
    width: 100%;
    flex: 0 0 auto;
}
.tile-library-workspace.is-focused .library-strip-item .library-strip-tile {
    height: 108px;
}
.tile-library-workspace.is-focused .library-drop-preview-grid {
    inset: 0;
    left: 0;
    top: 0;
    width: auto;
    height: auto;
    margin: 0;
    justify-content: flex-start;
    align-content: flex-start;
    background: transparent;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    padding: 2px;
    box-sizing: border-box;
}
.library-strip-item.is-selected .library-strip-tile {
    border-color: transparent;
    box-shadow: none;
}
.library-strip-item.is-selected {
    border-color: transparent;
    box-shadow: none;
}
.library-strip-create .library-strip-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f4f8;
    color: #4a5568;
    font-weight: 700;
}
.library-create-body {
    text-align: center;
}
.library-strip-create .library-create-plus {
    font-size: 28px;
    margin-bottom: 4px;
}
.library-strip-bg-grid {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 1px;
    background: #dbe2ea;
    opacity: 1;
}
.library-strip-bg-cell {
    background-size: cover;
    background-position: center;
    background-color: #e2e8f0;
}
.library-preview-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
}
.library-dropzone {
    background: #eceff3;
    border-style: solid;
}
.library-dropzone.disabled-zone {
    pointer-events: auto;
    opacity: 1;
    background: #f3f4f6;
    border-color: var(--borderStrong);
}
.library-drop-icon {
    font-size: 32px;
    line-height: 1;
    margin-bottom: 4px;
}
.library-drop-sub {
    color: var(--muted);
    font-size: 12px;
}
.upload-limit-hint {
    color: var(--muted);
    font-size: 12px;
    margin-top: 6px;
    text-align: center;
}
.library-drop-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 6px;
}
.library-drop-preview-grid {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2px;
    z-index: 1;
    background: #dbe2ea;
    box-sizing: border-box;
    justify-content: flex-start;
    align-content: flex-start;
}
.library-drop-preview-cell {
    background-size: cover;
    background-position: center;
    background-color: #e2e8f0;
}
.library-drop-overlay {
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    padding: 8px;
    background: none;
}
.library-drop-overlay .overlay-chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(248, 250, 252, 0.9);
    color: #334155;
    font-size: 11px;
    letter-spacing: 0.01em;
    backdrop-filter: blur(2px);
}
.library-overlay-actions {
    display: flex;
    gap: 8px;
}
.library-overlay-actions .library-drop-btn {
    min-width: 92px;
    padding: 6px 10px;
    font-size: 11px;
}
.library-drop-btn {
    width: auto;
    min-width: 114px;
    padding: 8px 12px;
    font-size: 12px;
    margin-top: 0;
}
.library-drop-btn.is-alt {
    background: #718096;
}
.library-drop-btn.is-alt:hover {
    background: #5b6b7f;
}
.library-strip-tile .lib-del,
.library-strip-tile .lib-ren,
.library-strip-tile .lib-priv {
    font-size: 12px;
    padding: 2px 5px;
    border-radius: 6px;
}

.library-public-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.86);
    color: #334155;
    z-index: 10;
    pointer-events: none;
}

.library-preview-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 8px;
}

.library-preview-actions.hidden {
    display: none;
}

.library-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.5);
    background: rgba(248, 250, 252, 0.9);
    color: #334155;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.library-action-btn:hover {
    background: rgba(226, 232, 240, 0.9);
}

.library-action-btn.danger {
    border-color: rgba(239, 68, 68, 0.6);
    color: #b91c1c;
}

.library-action-btn.danger:hover {
    background: rgba(254, 226, 226, 0.8);
}

.main-source-dropzone {
    aspect-ratio: 16 / 10;
}

/* LIBRARY GRID */
.lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.lib-card {
    background: #f7fafc;
    border: 2px solid #edf2f7;
    border-radius: 8px;
    height: 100px;
    cursor: pointer;
    position: relative;
    transition: 0.2s;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lib-card:hover { border-color: var(--borderStrong); transform: translateY(-2px); }
.lib-card.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.lib-bg-grid {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr;
    opacity: 0.25; z-index: 1; pointer-events: none;
}
.lib-bg-thumb { background-size: cover; background-position: center;
    width: 100%; height: 100%; }

.lib-del { position: absolute; top: 5px; right: 5px; color: var(--danger); font-size: 14px; padding: 2px 6px;
    border-radius: 4px; cursor: pointer; z-index: 10; background: rgba(255,255,255,0.8);
    opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; }
.library-strip-item:hover .lib-del,
.lib-card:hover .lib-del { opacity: 1; pointer-events: auto; }
.lib-del:hover { transform: scale(1.08); }
.lib-ren { position: absolute; top: 5px; left: 5px; color: var(--primary); font-size: 14px;
    padding: 2px 6px; border-radius: 4px; cursor: pointer; z-index: 10; background: rgba(255,255,255,0.8); }

.lib-priv {
    position: absolute;
    top: 5px;
    right: 35px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.86);
    z-index: 10;
}

.disabled-zone { opacity: 0.5; pointer-events: none; background: #f7fafc;
    border-style: solid; }

/* --- Library Items (New) --- */
.lib-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: var(--card);
    box-shadow: var(--shadowSoft);
    transition: transform 0.2s;
}
.lib-item:hover { transform: translateY(-2px); }
.lib-item img {
    width: 100%;
    height: 110px; /* Bigger */
    object-fit: cover;
    display: block;
}
.lib-item .name {
    font-size: 11px;
    color: var(--mutedStrong);
    padding: 6px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: #f7fafc;
    border-top: 1px solid #edf2f7;
}
.lib-item .del-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(229, 62, 62, 0.9);
    color: var(--card);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 10;
}
.lib-item:hover .del-btn {
    opacity: 1;
    pointer-events: auto;
}
.lib-item .del-btn:hover { transform: scale(1.1); }

/* --- History Items (Deletion Style) --- */
.history-tile .del-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(229, 62, 62, 0.9);
    color: var(--card);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 10;
}
.icon-btn {
    border: none;
    padding: 0;
    margin: 0;
    background: transparent;
    font: inherit;
    line-height: 1;
}
.source-preview-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    background: rgba(229, 62, 62, 0.92);
    color: var(--card);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 4;
}
.source-preview-delete:focus-visible,
.history-tile .del-btn:focus-visible,
.lib-item .del-btn:focus-visible {
    outline: 2px solid var(--focusRing);
    outline-offset: 2px;
}
.source-preview-frame:hover .source-preview-delete {
    opacity: 1;
    pointer-events: auto;
}
.source-preview-delete:hover {
    transform: scale(1.08);
}
.history-item:hover .del-btn {
    opacity: 1;
    pointer-events: auto;
}
.recent-source-item:hover .del-btn {
    opacity: 1;
    pointer-events: auto;
}
.history-tile .del-btn:hover { transform: scale(1.1); }

.library-preview-panel {
    position: relative;
    margin-top: 20px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}
.library-strip-item:hover .library-delete-x,
.library-strip-item:hover .source-preview-delete {
    opacity: 1;
    pointer-events: auto;
}
.library-strip-item .library-delete-x,
.library-strip-item .source-preview-delete {
    z-index: 12;
}
.library-preview-toggle {
    gap: 8px;
    padding: 2px 0 8px;
    font-weight: 400;
    color: var(--mutedSoft);
}
button.library-preview-toggle {
    display: flex;
    align-items: center;
    cursor: pointer;
}
button.library-preview-toggle .card-title-chevron {
    color: var(--textStrong);
    font-size: 14px;
    font-weight: 700;
    opacity: 1;
}
button.library-preview-toggle:hover .card-title-chevron {
    color: var(--primaryHover);
}
.library-preview-label {
    margin-bottom: 0;
}
.library-preview-panel #libPreviewBody {
    margin-top: 10px;
}
#libPreviewGrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
}
.library-preview-panel #libPreviewCollapsedSummary {
    margin-top: 0;
}
.library-preview-panel.is-collapsed #libPreviewBody {
    display: none;
}
.library-preview-panel.is-collapsed .card-title-chevron {
    transform: rotate(-90deg);
}


/* Unified button styling for both <button> and <a> inside the UI */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    user-select: none;
    text-decoration: none;
    line-height: 1;
}

/* Ensure .btn overrides the global button defaults (full width + margin) */
button.btn {
    width: auto;
    margin-top: 0;
    background: var(--primary);
    color: var(--card);
}
a.btn {
    background: var(--primary);
    color: var(--card);
}

.btn.primary {
    width: 100%;
    background: var(--primary);
    color: var(--card);
}
.btn.primary:hover { background: var(--primaryHover); }
.btn.primary.compact {
    width: auto;
    padding: 10px 16px;
    font-size: 12px;
    min-width: 130px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.result-actions { display: flex; gap: 10px; }
.result-actions .btn {
    font-weight: 400;
}
.result-actions .btn-tooltip {
    width: auto;
    flex: 1 1 0;
}
.result-actions .btn-tooltip .btn {
    width: 100%;
}
.result-actions.secondary-actions { margin-top: 10px;
}
.result-actions.secondary-actions {
    justify-content: flex-end;
}
.result-actions.secondary-actions .btn-tooltip {
    flex: 0 0 auto;
    width: auto;
}
.result-actions.secondary-actions .btn-tooltip .btn {
    width: auto;
    min-width: 128px;
}
.result-actions.primary-actions {
    margin-top: 15px;
    align-items: center;
}
.result-actions.primary-actions .download-btn {
    flex: 1 1 auto;
    width: auto;
}
.result-actions.create-another-actions {
    flex-direction: column;
    align-items: stretch;
    margin-top: 10px;
    gap: 8px;
}
.create-another-btn {
    width: 100%;
    min-height: 42px;
    font-weight: 700;
    background: #e2e8f0;
    color: #0f172a;
    border: 1px solid #cbd5e1;
}
.create-another-btn:hover {
    background: #cbd5e1;
}
.create-another-quick-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
}
.create-another-quick-row .secondary-action {
    width: 100%;
}
.download-options {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-content: stretch;
    gap: 8px;
    width: 100%;
}
.download-option {
    width: 100%;
    max-width: none;
    justify-self: stretch;
    text-align: left;
    min-height: 86px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 3px;
    line-height: 1.2;
    padding-top: 7px;
    padding-bottom: 7px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--textPrimary);
}
.download-option:hover {
    background: var(--surfaceAlt);
}
.download-option-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.download-option-title {
    display: block;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: 0.01em;
    color: var(--textStrong);
}
.download-option-sub {
    display: block;
    font-size: 11px;
    color: var(--mutedStrong);
}
.download-option-size {
    display: block;
    font-size: 11px;
    color: var(--textStrong);
}
.download-option-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    border-radius: 999px;
    border: 1px solid var(--border);
    padding: 3px 7px;
    color: var(--textStrong);
    background: var(--surfaceAlt);
}
.download-option.is-ready {
    border-color: #60a5fa;
    background: #eff6ff;
}
.download-option.is-ready .download-option-status {
    color: #1e40af;
    border-color: #93c5fd;
    background: #dbeafe;
}
.download-option.is-included {
    border-color: #22c55e;
    background: #f0fdf4;
}
.download-option.is-included .download-option-status {
    color: #166534;
    border-color: #86efac;
    background: #dcfce7;
}
.download-option.is-locked {
    border-color: #f59e0b;
    background: var(--surfaceAlt);
    color: var(--textPrimary);
}
.download-option.is-locked .download-option-status {
    color: #92400e;
    border-color: #fcd34d;
    background: #fef3c7;
}
.download-option.is-locked:hover {
    background: var(--surfaceElevated);
}
.download-plan-hint {
    margin-top: 8px;
    font-size: 12px;
    color: var(--textMuted);
}
#downloadModal .modal-panel {
    --download-option-side-pad: 12px;
    max-width: 640px;
    padding: 18px 20px;
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}
#downloadModalTitle {
    margin-bottom: 10px;
}
#downloadModalOptions {
    margin: 8px auto 0;
    width: 100%;
    max-width: 100%;
    padding: 0 var(--download-option-side-pad, 12px);
    box-sizing: border-box;
}
.download-upsell {
    box-sizing: border-box;
    width: calc(100% - (2 * var(--download-option-side-pad, 12px)));
    margin: 10px auto 0;
    padding: 12px 14px;
    border: 1px solid rgba(14, 116, 144, 0.22);
    border-radius: 12px;
    background:
        radial-gradient(circle at 0% 100%, rgba(14, 165, 233, 0.14), transparent 60%),
        radial-gradient(circle at 100% 0%, rgba(251, 191, 36, 0.16), transparent 52%),
        linear-gradient(180deg, #f8fafc, #f1f5f9);
    cursor: pointer;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}
.download-upsell:hover {
    border-color: rgba(14, 116, 144, 0.40);
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.10);
    transform: translateY(-1px);
}
.download-upsell:focus-visible {
    outline: 2px solid rgba(14, 116, 144, 0.55);
    outline-offset: 1px;
}
.download-upsell-title {
    font-size: 13px;
    font-weight: 700;
    color: #0f172a;
}
.download-upsell-copy {
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.4;
    color: #334155;
}
.download-upsell-actions {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}
.download-upsell-btn {
    height: 34px;
    padding: 0 12px;
    font-size: 12px;
}
.download-upsell-note {
    font-size: 11px;
    color: #475569;
}
@media (max-width: 640px) {
    #downloadModal {
        box-sizing: border-box;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        padding-left: max(10px, env(safe-area-inset-left));
    }
    #downloadModal .modal-panel {
        --download-option-side-pad: 6px;
        width: min(420px, calc(100% - 8px));
        max-height: calc(100dvh - 20px);
        border-radius: 14px;
        padding: 14px 12px;
    }
    #downloadModalOptions {
        width: 100%;
        margin-top: 8px;
        padding: 0 6px;
    }
    .download-upsell {
        margin: 8px auto 0;
        padding: 11px 12px;
    }
    .download-options {
        gap: 6px;
    }
    .download-option {
        min-height: 76px;
    }
    .collapsed-summary-content {
        justify-content: center;
    }
    #createMosaicCollapsedText,
    #resultCollapsedText {
        display: inline-flex;
        width: 100%;
        justify-content: flex-start;
        text-align: left;
        flex-wrap: wrap;
    }
}

.secondary-action {
    flex: 1;
    background: #64748b;
    color: #ffffff;
}
.secondary-action:hover { background: #475569;
}
.result-action-tooltip::after {
    top: auto;
    bottom: calc(100% + 6px);
}
.result-action-tooltip:hover::after,
.result-action-tooltip:focus-within::after {
    opacity: 1;
}

.download-btn {
    height: 48px;
}
#resultCard {
    scroll-margin-top: 0;
}
body.workflow-stage-viewer #resultCard {
    min-height: 0;
}
body.workflow-stage-viewer #resultBody {
    min-height: 0;
}
body.workflow-stage-viewer #viewerContent {
    min-height: 0;
}
body.workflow-stage-viewer #compareContainer {
    width: 100%;
    max-width: 100%;
}
#resultCard.is-loading #jobConfig,
#resultCard.is-loading .result-actions,
#resultCard.is-loading #triviaCard {
    display: none;
}
#resultCard.is-loading #compareContainer {
    min-height: min(320px, 56vh);
    background: var(--surfaceAlt);
    border: 1px dashed var(--border);
}
#resultCard.is-loading.build-preview-mode #compareContainer {
    background-image: linear-gradient(
        110deg,
        rgba(148, 163, 184, 0.18) 8%,
        rgba(203, 213, 225, 0.32) 18%,
        rgba(148, 163, 184, 0.18) 33%
    );
    background-size: 220% 100%;
    animation: buildPreviewShimmer 1.8s linear infinite;
}
#resultCard.is-loading #overlayDiv {
    display: none;
}
#resultCard.is-loading #resImg,
#resultCard.is-loading #origImg {
    opacity: 0;
}
#resultCard.is-loading.build-preview-mode.has-live-preview #compareContainer {
    min-height: 0;
    background: var(--surfaceAlt);
    border: 1px dashed var(--border);
}
#resultCard.is-loading.build-preview-mode.has-live-preview #overlayDiv {
    display: none;
}
#resultCard.is-loading.build-preview-mode.has-live-preview #resImg {
    opacity: 1;
    clip-path: inset(0 0 calc(100% - var(--build-frontier-pct, 0%)) 0);
    filter: blur(1.4px);
    transition: clip-path 120ms linear, filter 180ms ease;
}
#resultCard.is-loading.build-preview-mode.has-live-preview #origImg {
    opacity: 0;
}
#resultCard.is-loading.compare-intro-mode #compareContainer {
    background: transparent;
    border-color: transparent;
    animation: none;
}
#resultCard.is-loading.compare-intro-mode #overlayDiv {
    display: block;
}
#resultCard.is-loading.compare-intro-mode #resultLoader {
    display: none;
}
#resultCard.is-loading.compare-intro-mode #resImg,
#resultCard.is-loading.compare-intro-mode #origImg {
    opacity: 1;
}
#resultCard.is-loading.compare-intro-mode #resImg {
    clip-path: none;
    filter: none;
    transition: none;
}
#jobConfig {
    margin: 0;
}

@keyframes buildPreviewShimmer {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: -100% 0;
    }
}
#triviaCard {
    margin-top: 15px;
    position: relative;
}
#triviaCard .stats-grid {
    margin-bottom: 12px;
}
.trivia-stats-wrap {
    position: relative;
}
.stats-grid.trivia-stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
    align-items: stretch;
}
.nerd-stats-pop {
    position: relative;
    align-self: stretch;
    justify-self: end;
    display: flex;
    align-items: center;
    height: 100%;
    z-index: 5;
}
.nerd-stats-btn {
    padding: 0 12px;
    font-size: 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    cursor: default;
    pointer-events: none;
    height: 100%;
    display: flex;
    align-items: center;
}
.nerd-stats-pop:hover .nerd-stats-btn {
    background: var(--primaryHover);
    color: #fff;
}
.stats-grid.nerd-stats {
    background: var(--card);
    border: 1px dashed var(--border);
    font-size: 12px;
    margin-bottom: 12px;
}
.stats-grid.nerd-stats .stat-label {
    text-transform: none;
    font-size: 11px;
    letter-spacing: 0.2px;
}
.nerd-stats-panel {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 240px;
    max-width: 360px;
    z-index: 20;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.15);
    transform: none;
}
.nerd-stats-pop:hover .nerd-stats-panel,
.nerd-stats-pop:focus-within .nerd-stats-panel,
.nerd-stats-pop.is-open .nerd-stats-panel {
    display: grid;
}
.stats-grid.trivia-stats-grid .nerd-stats-pop {
    min-width: max-content;
}
@media (max-width: 900px) {
    .stats-grid.trivia-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
    }
}
@media (max-width: 640px) {
    .stats-grid.trivia-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .stats-grid.trivia-stats-grid .nerd-stats-pop {
        grid-column: 1 / -1;
        justify-self: center;
        margin-top: 6px;
    }
    .stats-grid.trivia-stats-grid .nerd-stats-pop .nerd-stats-panel {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: min(360px, calc(100vw - 32px));
        max-width: calc(100vw - 32px);
        min-width: min(240px, calc(100vw - 32px));
        box-sizing: border-box;
    }
}
.trivia-top .strip-head-label {
    margin-bottom: 6px;
}

/* Presets */
.preset-row label { margin-bottom: 6px;
}
.preset-select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card);
    font-size: 14px;
}

/* SETTINGS */
.setting-row {
    position: relative;
    margin-bottom: 0;
}
.setting-group {
    background: var(--surfaceAlt);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: var(--setting-group-pad-top) var(--setting-group-pad-x) var(--setting-group-pad-bottom);
    margin-bottom: 12px;
}
.setting-row.setting-group {
    margin-bottom: 12px;
}
.setting-row.setting-group:last-child,
.setting-group:last-child {
    margin-bottom: 0;
}
#advancedControls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
#advancedControls .setting-group {
    margin-bottom: 0;
}
#advancedControls .toggle-pair {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: start;
}
.toggle-pair-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
label { font-weight: bold; display: block; margin-bottom: 8px; font-size: 0.95em; }
.setting-group > label {
    margin-bottom: var(--setting-control-gap);
}
input[type="range"] { width: 100%;
}
input[type="range"]:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
input[type="range"]:disabled::-webkit-slider-thumb {
    background: var(--border);
}
input[type="range"]:disabled::-moz-range-thumb {
    background: var(--border);
}
.setting-row select {
    margin-top: var(--setting-control-gap);
}
.preset-row select {
    margin-top: 0;
}
.val-display { float: right; color: var(--primary); font-weight: bold; }
#simpleControls .setting-label-row label {
    margin: 0;
}
#simpleControls .val-display {
    float: none;
    color: var(--primary);
}
#simpleControls .val-display { color: var(--primary); }
#proControls .val-display { color: var(--primary); }
.settings-mode {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-direction: column;
    align-items: stretch;
}
.settings-mode .setting-label-row {
    margin-bottom: var(--setting-control-gap);
}
.settings-mode-toggle {
    flex: 1;
    width: 100%;
}
.settings-mode-toggle .seg-btn {
    background: var(--surfaceAlt);
    border: 1px solid var(--border);
    color: var(--textStrong);
}
.settings-mode-toggle .seg-btn:hover {
    background: #e2e8f0;
}
.settings-mode-toggle .seg-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--card);
}
.simple-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}
.simple-stats.setting-group {
    margin-bottom: 12px;
}
.simple-stat {
    min-width: 0;
}
.stats-grid.setting-group {
    margin-bottom: 12px;
}
.simple-stat strong {
    display: block;
    color: var(--textStrong);
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.simple-controls-layout {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.simple-controls-layout > .setting-group {
    margin-bottom: 0;
}
#simpleControls {
    display: contents;
}
#simpleControls .setting-group {
    margin-bottom: 0;
}
.setting-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: var(--setting-control-gap);
}
.setting-label-row label {
    flex: 1 1 auto;
    margin-bottom: 0;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.toggle-row {
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
}
.toggle-row .toggle-switch {
    margin-left: auto;
}
.setting-label-row .val-display {
    float: none;
    display: inline-flex;
    align-items: center;
}
.setting-group .hint {
    margin-top: var(--setting-control-gap);
}
.simple-detail-extreme-hint {
    color: #9a3412;
    font-weight: 600;
}
.help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid var(--borderStrong);
    background: var(--surfaceAlt);
    color: var(--muted);
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    flex: 0 0 auto;
    position: relative;
    z-index: 1;
    line-height: 1;
    align-self: center;
}
.help-btn:hover {
    color: var(--textStrong);
    border-color: var(--primary);
    background: var(--surfaceAlt);
}
.help-btn:focus-visible {
    outline: 2px solid var(--focusRing);
    outline-offset: 2px;
}
.help-popover {
    position: absolute;
    right: 0;
    bottom: calc(100% + 10px);
    box-sizing: border-box;
    min-width: 0;
    width: 280px;
    max-width: calc(100vw - 32px);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadowHover);
    padding: 12px;
    z-index: 910;
    display: none;
}
.help-popover.is-open {
    display: block;
}
.help-popover.is-hover {
    pointer-events: none;
}
.help-backdrop {
    position: fixed;
    inset: 0;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    background: rgba(15, 23, 42, 0.18);
    z-index: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.help-backdrop.is-active {
    opacity: 1;
    pointer-events: auto;
}
body.help-blur-active .app-layout,
body.help-blur-active .app-header {
    filter: blur(3px);
}
body.help-blur-hover .app-layout,
body.help-blur-hover .app-header {
    filter: blur(2px);
}
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
    }
    .main-content {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    .simple-controls-layout {
        grid-template-columns: minmax(0, 1fr);
    }
    .help-popover {
        max-width: calc(100vw - 40px);
        padding: 12px;
    }
    .help-loop-preview-full {
        padding-left: 6px;
        padding-right: 6px;
    }
}
.help-popover {
    z-index: 910;
}
.help-popover-title {
    font-weight: 700;
    color: var(--textStrong);
    font-size: 13px;
    margin-bottom: 8px;
}
.help-popover-body {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.help-popover-body-single {
    display: block;
}
.help-figure {
    margin: 0;
    text-align: center;
}
.help-figure img {
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surfaceAlt);
}
.help-figure figcaption {
    margin-top: 6px;
    font-size: 11px;
    color: var(--muted);
}
#help-tileheight {
    width: 280px;
}
.help-loop-preview {
    display: block;
}
.help-loop-preview-full {
    padding-left: 4px;
    padding-right: 4px;
}
.help-loop-title {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 8px;
}
.help-loop-title-value {
    font-weight: 800;
    font-size: 16px;
    color: var(--textStrong);
    line-height: 1;
}
.help-loop-image {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surfaceAlt);
}
.help-loop-value {
    display: inline;
    white-space: nowrap;
    padding: 0;
    border: 0;
    background: transparent;
}
.help-popover-note {
    margin-top: 10px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--mutedStrong);
}

@media (max-width: 1200px) {
    .shortcuts-hint {
        display: none;
    }
    .main-content {
        padding-left: clamp(18px, 4vw, 28px);
        padding-right: clamp(18px, 4vw, 28px);
    }
    .workflow-layout {
        padding: 0;
        box-sizing: border-box;
        width: 100%;
    }
    .workflow-main,
    .workflow-settings {
        min-width: 0;
        width: 100%;
    }
    .settings-panel .collapsible-card-body {
        max-width: 100%;
    }
    #advancedControls {
        grid-template-columns: minmax(0, 1fr);
    }
    #advancedControls .toggle-pair {
        grid-template-columns: minmax(0, 1fr);
    }
    .help-popover {
        position: static;
        margin-top: 10px;
    }
    #help-tileheight {
        width: min(280px, calc(100vw - 40px));
    }
}

@media (max-width: 820px) {
    .create-header-inline {
        --create-header-row-height: auto;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        min-height: 0;
    }
    .create-mosaic-title {
        height: auto;
    }
    .create-mosaic-title #createMosaicToggle {
        height: auto;
        min-height: 0;
        line-height: 1.1;
    }
    .create-another-quick-row {
        grid-template-columns: minmax(0, 1fr);
    }
    .create-step-header {
        gap: 8px;
        padding: 8px;
        height: auto;
        min-height: 0;
        border: 1px solid var(--border);
        border-radius: 10px;
        background: var(--surfaceAlt);
    }
    .create-step-pill {
        min-height: 34px;
        height: auto;
        white-space: normal;
        font-size: 11px;
        padding: 6px 8px;
    }
    .create-step-next {
        min-width: 180px;
        width: 100%;
    }
}
#advToggle {
    cursor: pointer;
    color: var(--primary);
    margin-bottom: 15px;
}
#advBox {
    border-top: 1px solid #eee;
    padding-top: 15px;
}
#colorMode {
    width: 100%;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid var(--borderStrong);
}

/* --- ELEGANT GREY TOOLBARS (UNIFIED STYLE) --- */
.stats-grid, .config-display {
    background: var(--surfaceAlt);
    /* Neutral light grey background */
    border: 1px solid var(--border);
    /* Subtle grey border */
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    font-size: 13px;
    color: var(--mutedStrong);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 12px;
}
.trivia-stats-grid .stat-item {
    align-items: center;
    text-align: center;
}
.stats-grid.nerd-stats-panel {
    display: none;
}
.nerd-stats-pop:hover .stats-grid.nerd-stats-panel,
.nerd-stats-pop:focus-within .stats-grid.nerd-stats-panel,
.nerd-stats-pop.is-open .stats-grid.nerd-stats-panel {
    display: grid;
}

.stat-item, .config-item {
    display: flex;
    flex-direction: column;
}

.stat-label, .config-label {
    font-weight: 600;
    color: var(--mutedSoft);
    /* Muted label color */
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.stat-item strong, .config-val {
    color: var(--textStrong);             /* Deep grey value color */
    font-weight: 600;
    /* Increased weight for visibility */
    font-size: 1.1em;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* COMPARE & RESULTS */
.compare-container { position: relative; width: 100%; overflow: hidden; border-radius: 8px; cursor: grab; touch-action: none;
}
.compare-container:active { cursor: grabbing; }
.compare-container #resImg {
    width: 100%;
    display: block;
    user-select: none;
}
.compare-debug {
    margin-top: 6px;
    font-size: 11px;
    color: var(--mutedSoft);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    background: var(--surfaceAlt);
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    white-space: pre-wrap;
    word-break: break-word;
}
#overlayDiv {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 50%;
    overflow: hidden;
    pointer-events: none;
}
#origImg {
    height: 100%;
    max-width: none;
    user-select: none;
    display: block;
}
.compare-separator { position: absolute; top: 0; right: 0; width: 3px; height: 100%; background: var(--card); box-shadow: 0 0 10px rgba(0,0,0,0.5);
    z-index: 20; }
.compare-handle {
    position: absolute; top: 50%; right: -15px; width: 34px; height: 34px;
    background: var(--card);
    border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    z-index: 21; margin-top: -17px; display: flex; align-items: center;
    justify-content: center; color: var(--text);
    font-size: 14px;
    cursor: grab;
}
.compare-container:active .compare-handle { cursor: grabbing; }

/* PROGRESS */
.source-upload-icon {
    font-size: 34px;
    margin-bottom: 10px;
}
#libUploadArea {
    margin-top: 15px;
}
#libUploadBar {
    background: var(--primary);
}
#libUploadStopBtn {
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    width: auto;
    padding: 5px 15px;
    font-size: 12px;
    margin-top: 8px;
}
#libUploadStopBtn:hover {
    background: var(--dangerHover);
}
#progressArea {
    margin-top: 20px;
}
.progress-toolbar {
    text-align: right;
    margin-bottom: 10px;
}
#stopBtn {
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    width: auto;
    padding: 5px 15px;
    font-size: 12px;
    margin-top: 0;
    display: none;
}
#stopBtn:hover {
    background: var(--dangerHover);
}
.progress-stage { margin-bottom: 15px; }
.stage-label { display: flex; justify-content: space-between; font-size: 0.9em; margin-bottom: 5px;
}
.stage-sub {
    font-size: 0.85em;
    color: var(--mutedStrong);
    margin-bottom: 6px;
}
.progress-track { width: 100%; background: #eee; height: 8px; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: #bdc3c7;
    transition: width 0.3s; }
.active-scan { background: #e67e22 !important; }
.active-build { background: #27ae60 !important;
}
.progress-fill.heartbeat-live {
    background-image: linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.22) 25%,
        transparent 25%,
        transparent 50%,
        rgba(255, 255, 255, 0.22) 50%,
        rgba(255, 255, 255, 0.22) 75%,
        transparent 75%,
        transparent
    );
    background-size: 20px 20px;
    animation: heartbeat-stripes 1.05s linear infinite;
}

@keyframes heartbeat-stripes {
    from { background-position: 0 0; }
    to { background-position: 20px 0; }
}

/* INSPECT MODAL & ZOOM */
#zoomModal {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.95);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#zoomModalImg {
    max-width: none;
    transform-origin: center center;
    cursor: grab;
    will-change: transform;
    user-select: none;
    -webkit-user-drag: none;
}

.modal-close-btn {
    position: absolute;
    top: 25px;
    right: 25px;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    z-index: 1010;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    backdrop-filter: blur(5px);
}

/* X-RAY TOOLTIP */
#xrayTooltip {
    position: fixed;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-family: 'Consolas', 'Monaco', monospace;
    /* Monospaced for data */
    z-index: 2000;
    border: 1px solid rgba(255,255,255,0.2);
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

#xrayName {
    font-weight: bold;
    color: #4fd1c5;
    /* Teal accent for filename */
    display: block;
    margin-bottom: 2px;
}

#xrayCoords {
    color: #a0aec0;
    font-size: 10px;
    margin-top: 2px;
}

/* --- Modal (Create Library) --- */
.modal.hidden { display: none; }
.modal { position: fixed; inset: 0; z-index: 3000;
    display: flex; align-items: center; justify-content: center;
    overscroll-behavior: contain;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    box-sizing: border-box; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(2px);
}
.modal-panel {
    position: relative;
    width: min(520px, 100%);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadowHover);
    padding: 18px;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    color: var(--textStrong);
}
.modal-panel h3 {
    margin: 0 0 10px 0;
}
.modal-field { margin-top: 12px; }
.modal-field label { display: block; font-size: 12px;
    color: var(--mutedSoft); margin-bottom: 6px; }
.modal-field input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    box-sizing: border-box;
    border-radius: 10px;
    border: 1px solid var(--borderStrong);
    background: #ffffff;
    color: var(--textStrong);
    outline: none;
}
.modal-field input:focus { border-color: rgba(99,102,241,0.75);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.18); }
.segmented { display: flex; gap: 8px; }
.seg-btn {
    flex: 1;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--borderStrong);
    background: var(--surfaceAlt);
    color: var(--textStrong);
    cursor: pointer;
}
.seg-btn.active { background: rgba(99,102,241,0.25);
    border-color: rgba(99,102,241,0.6); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px;
}

/* Make secondary buttons consistent */
.btn.secondary { background: var(--surfaceAlt); border: 1px solid var(--borderStrong); color: var(--textStrong); }
.btn.secondary:hover { background: #e5edf6;
}

.hint { font-size: 12px; color: #94a3b8; line-height: 1.3; }
.modal-panel .hint {
    margin-top: 6px;
}
#confirmModal .modal-actions .btn {
    font-weight: 400;
}
.account-summary-panel {
    width: min(820px, calc(100% - 32px));
    max-height: min(82vh, 920px);
    overflow: auto;
    border-radius: 16px;
    border-color: rgba(148, 163, 184, 0.32);
    background:
        radial-gradient(circle at 100% 0%, rgba(14, 165, 233, 0.12), transparent 48%),
        radial-gradient(circle at 0% 100%, rgba(249, 115, 22, 0.10), transparent 42%),
        #ffffff;
}
.account-summary-grid {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.account-summary-card {
    border: 1px solid rgba(148, 163, 184, 0.30);
    border-radius: 12px;
    padding: 12px;
    background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(248,250,252,0.95));
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}
.account-summary-card h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    letter-spacing: 0;
    color: #0f172a;
    text-transform: none;
}
.account-summary-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    font-size: 12.5px;
    color: var(--textStrong);
    padding: 4px 0;
    border-top: 1px dashed rgba(148, 163, 184, 0.20);
}
.account-summary-line:first-of-type {
    border-top: 0;
}
.account-summary-line span:first-child {
    color: var(--mutedStrong);
}
.account-summary-line strong {
    color: #0f172a;
    font-weight: 600;
    text-align: right;
}
.plan-compare-panel {
    width: min(1080px, calc(100% - 28px));
    max-height: min(86vh, 940px);
    overflow: auto;
    border-radius: 16px;
    border-color: rgba(148, 163, 184, 0.30);
    background:
        radial-gradient(circle at 0% 0%, rgba(14, 165, 233, 0.12), transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(251, 191, 36, 0.12), transparent 48%),
        #ffffff;
}
.plan-compare-table-wrap {
    margin-top: 14px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 12px;
    overflow: auto;
    background: rgba(255, 255, 255, 0.95);
}
.plan-compare-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 760px;
}
.plan-compare-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}
.plan-compare-table th,
.plan-compare-table td {
    padding: 12px 10px;
    font-size: 12px;
    line-height: 1.35;
    text-align: center;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}
.plan-compare-table tbody tr:last-child th,
.plan-compare-table tbody tr:last-child td {
    border-bottom: 0;
}
.plan-compare-table th:first-child {
    text-align: left;
    min-width: 0;
    width: 1%;
    white-space: nowrap;
    padding-right: 16px;
    color: #334155;
    font-weight: 600;
    background: #f8fafc;
}
.plan-col-head {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.plan-col-head strong {
    color: #0f172a;
    font-size: 14px;
}
.plan-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}
.plan-chip-best {
    color: #92400e;
    background: #fef3c7;
    border: 1px solid #fcd34d;
}
.plan-chip-current {
    color: #065f46;
    background: #d1fae5;
    border: 1px solid #6ee7b7;
}
.plan-compare-table [data-plan-col].is-selected {
    background: #eff6ff;
}
.plan-compare-table .plan-col-head.is-selected {
    background: rgba(37, 99, 235, 0.08);
    border-radius: 10px;
    padding: 6px;
}
.plan-compare-panel .modal-actions .btn {
    font-size: 13px;
    font-weight: 400;
}
@media (max-width: 900px) {
    .plan-compare-panel {
        width: min(980px, calc(100% - 18px));
        padding: 14px;
    }
    .plan-compare-table th,
    .plan-compare-table td {
        padding: 10px 8px;
        font-size: 11.5px;
    }
}
@media (max-width: 920px) {
    .account-summary-grid {
        grid-template-columns: 1fr;
    }
}
#privacyDesc {
    font-size: 13px;
    color: var(--mutedStrong);
    line-height: 1.35;
}
#confirmBody {
    font-size: 13px;
    line-height: 1.4;
    color: var(--textStrong);
    white-space: pre-line;
}
.checkbox-row .checkbox-label { display: flex; gap: 10px; align-items: center;
}
.checkbox-row input[type="checkbox"] { transform: scale(1.05); }

/* --- Toasts --- */
.toast-container { position: fixed; right: 16px; bottom: calc(16px + var(--toast-bottom-offset, 0px)); z-index: 4000;
    --toast-dynamic-max-width: calc(100vw - 32px);
    display: flex; flex-direction: column; gap: 10px; }
.toast {
    background: rgba(15,23,42,0.92);
    border: 1px solid rgba(255,255,255,0.10);
    color: #e2e8f0;
    padding: 10px 12px;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.35);
    width: min(340px, var(--toast-dynamic-max-width, calc(100vw - 32px)));
    max-width: var(--toast-dynamic-max-width, calc(100vw - 32px));
    font-size: 13px;
}
.toast[data-priority="warn"] {
    border-color: rgba(245, 158, 11, 0.45);
}
.toast[data-priority="error"] {
    border-color: rgba(248, 113, 113, 0.58);
    background: rgba(69, 10, 10, 0.92);
}
.toast strong { display: block; margin-bottom: 4px; }
.toast-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.toast-content {
    padding-right: 10px;
}
.toast-body-content {
    font-size: 0.9em;
    margin-top: 4px;
    color: #ddd;
    white-space: pre-line;
    word-break: break-word;
}
.toast-close {
    cursor: pointer;
    font-size: 16px;
    opacity: 0.6;
    line-height: 1;
}
.toast-close:hover {
    opacity: 1;
}
.toast .toast-small { font-size: 12px; color: #a0aec0;
}

@media (hover: none) and (pointer: coarse) {
    .modal-field input {
        font-size: 16px;
    }
}

/* --- Trivia card --- */
.trivia-card {
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 12px;
    padding: 14px;
}
.trivia-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.trivia-sub { font-size: 12px; color: #718096;
}
.trivia-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.trivia-item { background: #ffffff; border: 1px solid #e2e8f0; border-radius: 12px;
    padding: 10px; }
.trivia-label { font-size: 11px; color: #718096; margin-bottom: 4px; }
.trivia-val { font-size: 16px; font-weight: 700; color: #2d3748;
}
.trivia-top { margin-top: 12px; }
.trivia-list { display: grid; grid-template-columns: 1fr; gap: 6px; margin-top: 6px; }
.trivia-row { display: flex; justify-content: space-between;
    gap: 10px; font-size: 12px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); }
.trivia-row .name { color: #e2e8f0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trivia-row .count { color: #a0aec0; flex-shrink: 0;
}
@media (max-width: 1120px) {
    .app-header-inner {
        display: flex;
        justify-content: space-between;
        width: 100%;
        max-width: 940px;
        padding: 0 20px;
    }
    .user-controls {
        grid-column: auto;
    }
}
@media (max-width: 520px) {
    .trivia-grid { grid-template-columns: 1fr; }
    .collapsed-summary {
        align-items: center;
    }
}

@media (max-width: 860px) {
    .main-photo-workspace {
        flex-direction: column;
        align-items: stretch;
        min-height: 0;
    }
    .main-photo-preview-slot,
    .main-photo-library-slot {
        width: 100%;
        max-width: 100%;
        flex: 1 1 auto;
        height: auto;
    }
    .main-photo-library-slot {
        margin-top: 10px;
    }
    .source-preview-frame {
        max-width: 100%;
    }
    .tile-library-workspace {
        flex-direction: column;
        align-items: stretch;
        min-height: 0;
    }
    .tile-library-upload-slot,
    .tile-library-strip-slot {
        width: 100%;
        max-width: 100%;
        flex: 1 1 auto;
        height: auto;
    }
    .tile-library-strip-slot {
        margin-top: 10px;
    }
    .recent-source-item {
        width: 132px;
    }
    .recent-source-item .recent-source-tile {
        width: 100%;
        height: 132px;
    }
    .library-strip-item {
        width: 132px;
        flex-basis: 132px;
    }
    .library-strip-item .library-strip-tile {
        width: 100%;
        height: 132px;
    }
    .main-photo-workspace.is-focused .main-photo-preview-slot,
    .tile-library-workspace.is-focused .tile-library-upload-slot {
        width: 100%;
        max-width: 100%;
        flex: 1 1 auto;
    }
    .main-photo-workspace.is-focused {
        height: auto;
        min-height: 0;
    }
    .main-photo-workspace.is-focused .main-source-dropzone {
        width: 100%;
        max-height: 360px;
    }
    .main-photo-workspace.is-focused .main-photo-library-slot,
    .tile-library-workspace.is-focused .tile-library-strip-slot {
        width: 100%;
        max-width: 100%;
        flex: 1 1 auto;
        height: auto;
    }
    .tile-library-workspace.is-focused {
        height: auto;
        min-height: 0;
    }
    .main-photo-workspace.is-focused .recent-photos-strip,
    .tile-library-workspace.is-focused #libGrid {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 0;
    }
    .main-photo-workspace.is-focused .recent-source-item {
        width: 132px;
        flex-basis: 132px;
    }
    .main-photo-workspace.is-focused .recent-source-item .recent-source-tile {
        height: 132px;
    }
    .tile-library-workspace.is-focused .library-strip-item {
        width: 132px;
        flex-basis: 132px;
    }
    .tile-library-workspace.is-focused .library-strip-item .library-strip-tile {
        height: 132px;
    }
}


/* Fun stats thumbnails */
.trivia-thumbs{display:flex; gap:8px; overflow-x:auto; overflow-y:hidden;
    padding:6px 2px;}
.trivia-thumb{flex:0 0 auto; width:144px;}
.trivia-thumb img{width:144px; height:144px; border-radius:10px; object-fit:cover; display:block; box-shadow:0 1px 3px rgba(0,0,0,0.12);}
.trivia-thumb .meta{display:flex; justify-content:space-between; font-size:11px;
    color:#718096; margin-top:6px;}
.history-item .meta {
    display: block;
    margin-top: 0;
    padding: 6px 8px;
    border-top: none;
    background: var(--card);
    white-space: normal;
}
.history-item .name {
    max-width: none;
    white-space: normal;
    line-height: 1.2;
    overflow: visible;
    text-overflow: clip;
}
.trivia-thumb .name{max-width:112px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.history-strip .history-item .name {
    max-width: none;
    display: block;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
}
.trivia-thumb .count{font-weight:800; color:#2d3748;}
#tvTopThumbs .trivia-thumb {
    width: 101px;
}
#tvTopThumbs .trivia-thumb img {
    width: 101px;
    height: 101px;
}
#tvTopThumbs .trivia-thumb .meta {
    justify-content: flex-start;
    gap: 6px;
}
#tvTopThumbs .trivia-thumb .count {
    color: #1e293b;
}
#tvTopThumbs .trivia-thumb .name {
    max-width: 82px;
}
.compact-history-strip {
    gap: 6px;
    padding: 0;
    margin-left: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.compact-history-strip::-webkit-scrollbar {
    display: none;
}
.compact-history-strip .history-tile {
    flex: 0 0 68px;
    width: 68px;
    height: 68px;
    border-radius: 8px;
}
.compact-history-strip .history-date,
.compact-history-strip .del-btn,
.compact-history-strip .history-expiry-badge {
    display: none;
}
.compact-history-strip .history-tile:hover {
    transform: none;
}
.compact-history-strip .history-more-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed #94a3b8;
    background: linear-gradient(135deg, #eef2ff, #f8fafc);
    color: #334155;
    font-size: 11px;
    font-weight: 700;
}
#tileLibraryCollapsedSummary {
    align-items: center;
    gap: 10px;
}
.tile-library-collapsed-name {
    flex: 0 0 auto;
    white-space: nowrap;
}
#tileLibraryCollapsedStrip {
    flex: 1 1 auto;
    min-width: 0;
    margin-top: 0;
}
#historyCollapsedStrip,
#libPreviewCollapsedStrip {
    flex: 1 1 auto;
    min-width: 0;
    margin-top: 0;
}


.result-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    background: rgba(255, 255, 255, 0.9);
    padding: 15px 25px;
    border-radius: 30px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: #2d3748;
    pointer-events: none;
    transition: opacity 0.2s;
}

/* The spinner animation */
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #cbd5e0;
    border-top-color: #3498db;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Helper to hide the image while loading to prevent "wonky" jumps */
.img-loading {
    opacity: 0;
}
