/* ---------------------------------------------------------------- */
/* Design tokens                                                    */
/* ---------------------------------------------------------------- */
:root {
    --bg: #f5f6fb;
    --surface: #ffffff;
    --surface-hover: #f7f8fc;
    --border: #e6e8f0;
    --border-strong: #d7dae4;
    --text: #14151a;
    --text-muted: #6b7080;
    --text-faint: #9a9eac;

    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: #edecfd;
    --accent-contrast: #ffffff;

    --danger: #e11d48;
    --danger-hover: #be123c;
    --danger-soft: #fdecef;
    --danger-text: #9f1239;

    --success: #059669;
    --success-soft: #e7f8f1;
    --success-text: #065f46;

    --header-bg: rgba(255, 255, 255, 0.78);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 999px;

    --shadow-sm: 0 1px 2px rgba(20, 21, 30, 0.05);
    --shadow-md: 0 6px 20px rgba(20, 21, 30, 0.08);
    --shadow-lg: 0 20px 45px rgba(20, 21, 30, 0.14);

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0c0d12;
        --surface: #16171f;
        --surface-hover: #1c1e28;
        --border: #262835;
        --border-strong: #33364399;
        --text: #f2f2f6;
        --text-muted: #a3a6b3;
        --text-faint: #6d7080;

        --accent: #818cf8;
        --accent-hover: #a5b4fc;
        --accent-soft: rgba(129, 140, 248, 0.16);
        --accent-contrast: #0c0d12;

        --danger: #fb7185;
        --danger-hover: #fda4af;
        --danger-soft: rgba(251, 113, 133, 0.14);
        --danger-text: #fecdd3;

        --success: #34d399;
        --success-soft: rgba(52, 211, 153, 0.14);
        --success-text: #a7f3d0;

        --header-bg: rgba(12, 13, 18, 0.72);

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
        --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
        --shadow-lg: 0 20px 45px rgba(0, 0, 0, 0.55);
    }
}

/* Explicit user choice (via the header toggle) always wins over the system setting. */
:root[data-theme="dark"] {
    --bg: #0c0d12;
    --surface: #16171f;
    --surface-hover: #1c1e28;
    --border: #262835;
    --border-strong: #33364399;
    --text: #f2f2f6;
    --text-muted: #a3a6b3;
    --text-faint: #6d7080;

    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: rgba(129, 140, 248, 0.16);
    --accent-contrast: #0c0d12;

    --danger: #fb7185;
    --danger-hover: #fda4af;
    --danger-soft: rgba(251, 113, 133, 0.14);
    --danger-text: #fecdd3;

    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.14);
    --success-text: #a7f3d0;

    --header-bg: rgba(12, 13, 18, 0.72);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 45px rgba(0, 0, 0, 0.55);
}

/* ---------------------------------------------------------------- */
/* Reset & base                                                     */
/* ---------------------------------------------------------------- */
* { box-sizing: border-box; }
.hidden { display: none !important; }

/* Applied briefly to <html> by the theme toggle so every element cross-fades
   its colors together, instead of only the few elements that already carry
   their own (much faster, hover-tuned) color transitions. Removed again once
   the switch has settled — see initThemeToggle() in app.js. */
html.theme-transition,
html.theme-transition * {
    transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, fill 0.25s ease !important;
}

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

svg { display: block; width: 100%; height: 100%; }

/* ---------------------------------------------------------------- */
/* Header                                                            */
/* ---------------------------------------------------------------- */
header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--header-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}
.header-inner {
    max-width: 900px;
    margin: 0 auto;
    padding: 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 1.02rem;
    letter-spacing: -0.01em;
}
.theme-toggle {
    position: relative;
    width: 2.3rem;
    height: 2.3rem;
    padding: 0;
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); box-shadow: var(--shadow-md); }
.theme-toggle:active { transform: translateY(1px); }
.theme-toggle .icon {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    /* !important + higher specificity than html.theme-transition * so this
       bespoke crossfade always wins instead of being flattened by it. */
    transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease !important;
}
.theme-toggle .icon-sun { transform: translate(-50%, -50%) rotate(0deg) scale(1); opacity: 1; }
.theme-toggle .icon-moon { transform: translate(-50%, -50%) rotate(-65deg) scale(0.3); opacity: 0; }
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .theme-toggle .icon-sun { transform: translate(-50%, -50%) rotate(65deg) scale(0.3); opacity: 0; }
    html:not([data-theme="light"]) .theme-toggle .icon-moon { transform: translate(-50%, -50%) rotate(0deg) scale(1); opacity: 1; }
}
html[data-theme="dark"] .theme-toggle .icon-sun { transform: translate(-50%, -50%) rotate(65deg) scale(0.3); opacity: 0; }
html[data-theme="dark"] .theme-toggle .icon-moon { transform: translate(-50%, -50%) rotate(0deg) scale(1); opacity: 1; }
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 8px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #9333ea);
    color: #fff;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

/* ---------------------------------------------------------------- */
/* Layout                                                             */
/* ---------------------------------------------------------------- */
main.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 4rem;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.25rem;
    box-shadow: var(--shadow-md);
}
.panel.narrow { max-width: 480px; margin-left: auto; margin-right: auto; }
@media (max-width: 560px) {
    .panel { padding: 1.5rem; border-radius: var(--radius-md); }
    .link-row { flex-direction: column; }
    .copy-btn { justify-content: center; }
}

h1 {
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 0.4rem;
}
p.hint { color: var(--text-muted); font-size: 0.95rem; line-height: 1.5; margin-top: 0; }

/* ---------------------------------------------------------------- */
/* Forms                                                              */
/* ---------------------------------------------------------------- */
label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.4rem; margin-top: 1.25rem; }
input[type="text"] {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input[type="text"]::placeholder { color: var(--text-faint); }
input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.real-file-input { display: none; }
ul.errorlist { color: var(--danger); padding-left: 1.1rem; margin: 0.35rem 0 0; font-size: 0.85rem; list-style: none; }
ul.errorlist li::before { content: "⚠ "; }

/* ---------------------------------------------------------------- */
/* Buttons                                                            */
/* ---------------------------------------------------------------- */
button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0.68rem 1.3rem;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    transition: background 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.1s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}
button:hover, .btn:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible, .dropzone:focus-visible, .upload-dropzone:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
button:disabled {
    background: var(--border);
    color: var(--text-faint);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}
.icon { width: 16px; height: 16px; flex-shrink: 0; }

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

button.secondary, .btn.secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
    box-shadow: none;
}
button.secondary:hover, .btn.secondary:hover { background: var(--surface-hover); border-color: var(--text-faint); }

button.is-loading { position: relative; color: transparent !important; pointer-events: none; }
button.is-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    animation: spin 0.7s linear infinite;
}
button.secondary.is-loading::after { border-color: var(--border-strong); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

.actions { margin-top: 1.75rem; display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ---------------------------------------------------------------- */
/* Messages                                                           */
/* ---------------------------------------------------------------- */
.messages { list-style: none; padding: 0; margin: 0 0 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; }
.message {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    background: var(--success-soft);
    color: var(--success-text);
    border: 1px solid transparent;
}
.message .icon { color: var(--success); }
.message-error { background: var(--danger-soft); color: var(--danger-text); }
.message-error .icon { color: var(--danger); }

/* ---------------------------------------------------------------- */
/* Manage: link row                                                   */
/* ---------------------------------------------------------------- */
.link-row { display: flex; gap: 0.6rem; align-items: stretch; margin-top: 0.5rem; }
.link-box {
    flex: 1;
    min-width: 0;
    background: var(--accent-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.7rem 1rem;
    word-break: break-all;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    color: var(--text);
}
.copy-btn { flex-shrink: 0; }
.copy-btn.copied { background: var(--success-soft); color: var(--success-text); border-color: transparent; }
.copy-btn.copied:hover { background: var(--success-soft); }

/* ---------------------------------------------------------------- */
/* Photo grid                                                         */
/* ---------------------------------------------------------------- */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-top: 1.75rem;
}
.photo-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}
.photo-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.photo-thumb {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    display: block;
    background: var(--surface-hover);
}
.card-body { padding: 0.85rem; }
.card-actions { display: flex; gap: 0.5rem; }
.card-actions button { flex: 1; font-size: 0.82rem; padding: 0.55rem 0.5rem; }

/* Delete confirm panel */
.confirm-box {
    background: var(--danger-soft);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0.75rem;
}
.confirm-box p {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0 0 0.65rem;
    font-size: 0.83rem;
    color: var(--danger-text);
    font-weight: 600;
}
.confirm-box p .icon { color: var(--danger); }
.confirm-actions { display: flex; gap: 0.5rem; }
.confirm-actions button { flex: 1; font-size: 0.8rem; padding: 0.5rem; }

/* Replace / add panel with dropzone */
.dropzone {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.9rem 0.6rem;
    text-align: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.8rem;
    background: var(--surface-hover);
    transition: border-color 0.15s var(--ease), background 0.15s var(--ease), color 0.15s var(--ease);
}
.dropzone:hover { border-color: var(--accent); color: var(--accent); }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone .dz-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin: 0 auto 0.35rem;
    color: var(--text-faint);
}
.dropzone:hover .dz-icon, .dropzone.dragover .dz-icon { color: var(--accent); }
.dropzone .dz-filename {
    display: block;
    margin-top: 0.25rem;
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.preview-img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-top: 0.6rem;
    display: none;
    box-shadow: var(--shadow-sm);
}
.preview-img.visible { display: block; }
.replace-form .actions, .add-form .actions { margin-top: 0.65rem; gap: 0.5rem; }
.replace-form .actions button, .add-form .actions button { flex: 1; font-size: 0.8rem; padding: 0.5rem; }

.empty-slot {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    padding: 0.9rem;
    min-height: 210px;
    background: var(--surface-hover);
}
.empty-slot .add-form { width: 100%; }
.empty-slot .dropzone { background: transparent; border: none; padding: 0.4rem; }
.empty-slot .dz-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 8px;
    border-radius: var(--radius-full);
    background: var(--accent-soft);
    color: var(--accent);
}

/* ---------------------------------------------------------------- */
/* Upload page dropzone                                               */
/* ---------------------------------------------------------------- */
.upload-dropzone {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-md);
    padding: 2.25rem 1.5rem;
    text-align: center;
    cursor: pointer;
    background: var(--surface-hover);
    transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.upload-dropzone:hover { border-color: var(--accent); }
.upload-dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.upload-dropzone .dz-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    margin: 0 auto 0.75rem;
    padding: 12px;
    border-radius: var(--radius-full);
    background: var(--accent-soft);
    color: var(--accent);
}
.upload-dropzone p { margin: 0.3rem 0 0; }
.upload-dropzone .dz-sub { color: var(--text-muted); font-size: 0.85rem; }

.selected-files {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem;
    margin-top: 1.1rem;
}
.selected-file {
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface-hover);
    box-shadow: var(--shadow-sm);
}
.selected-file img { width: 100%; height: 90px; object-fit: cover; display: block; }
.selected-file .filename {
    font-size: 0.68rem;
    padding: 0.3rem 0.4rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.selected-file .remove-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 22px;
    height: 22px;
    padding: 5px;
    border-radius: 50%;
    background: rgba(15, 15, 20, 0.65);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: none;
}
.selected-file .remove-btn:hover { background: rgba(15, 15, 20, 0.9); }
.count-hint { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.7rem; }
.count-hint.limit { color: var(--danger); font-weight: 600; }

/* ---------------------------------------------------------------- */
/* Locked presentation notice                                         */
/* ---------------------------------------------------------------- */
.locked-icon {
    width: 52px;
    height: 52px;
    padding: 13px;
    border-radius: var(--radius-full);
    background: var(--accent-soft);
    color: var(--accent);
    margin-bottom: 1.1rem;
}
.date-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.9rem;
    padding: 0.6rem 1rem;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.92rem;
}
.date-badge .icon { color: var(--accent); }
