* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --background: #0d0f12;
    --panel: #171a1f;
    --panel-raised: #1d2127;
    --border: rgba(255, 255, 255, 0.12);
    --muted: #9aa3ad;
    --text: #f5f7f9;
    --accent: #79c2ad;
    --accent-strong: #9addca;
    --danger: #ef8d8d;
}

[hidden] {
    display: none !important;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 82% 0, rgba(72, 132, 113, 0.13), transparent 30rem),
        var(--background);
}

button,
input,
textarea,
select {
    font: inherit;
}

.page-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 1rem;
    min-height: 4rem;
    padding: 0.7rem max(1rem, env(safe-area-inset-right)) 0.7rem max(1rem, env(safe-area-inset-left));
    border-bottom: 1px solid var(--border);
    background: rgba(13, 15, 18, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.page-header h1 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
}

.back-link {
    color: var(--muted);
    text-decoration: none;
}

.edit-control {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 2.65rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid #343a40;
    border-radius: 999px;
    color: var(--muted);
    background: #11151a;
    cursor: pointer;
}

.edit-control input {
    width: 2.2rem;
    height: 1.2rem;
    margin: 0;
    accent-color: var(--accent);
}

.edit-control:has(input:checked) {
    border-color: var(--accent);
    color: var(--text);
    background: rgba(121, 194, 173, 0.12);
}

.gallery-tabs {
    min-height: 3.55rem;
}

.gallery-tabs .add-gallery-tab {
    border-color: transparent;
    color: var(--accent-strong);
    background: rgba(121, 194, 173, 0.12);
}

.controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem max(1rem, env(safe-area-inset-right)) 0.7rem max(1rem, env(safe-area-inset-left));
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.category-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.filter-button,
.quiet-button,
.primary-button,
.danger-button {
    min-height: 2.65rem;
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    color: var(--text);
    background: #181c21;
    cursor: pointer;
}

.filter-button {
    min-height: 2.35rem;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.04);
}

.filter-button:hover,
.filter-button.is-active {
    color: var(--text);
    background: rgba(255, 255, 255, 0.14);
}

.primary-button {
    border-color: var(--accent);
    color: #07110e;
    background: var(--accent);
    font-weight: 750;
}

.danger-button {
    border-color: rgba(239, 141, 141, 0.4);
    color: var(--danger);
    background: rgba(239, 141, 141, 0.07);
}

button:disabled {
    cursor: wait;
    opacity: 0.55;
}

.sort-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.sort-control select {
    min-height: 2.35rem;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.45rem;
    color: inherit;
    background: #181c21;
}

.status-message {
    width: min(100% - 2rem, 78rem);
    min-height: 1.35rem;
    margin: 0.75rem auto 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.status-message[data-tone="error"] {
    color: var(--danger);
}

.status-message[data-tone="success"] {
    color: var(--accent-strong);
}

.gallery-main,
.inline-panel {
    width: min(100% - 1.4rem, 78rem);
    margin-inline: auto;
}

.gallery-main {
    padding: 0.7rem 0 3rem;
}

.maintenance-main {
    width: min(100% - 1.4rem, 48rem);
    margin-inline: auto;
    padding: 1rem 0 3rem;
}

.maintenance-main .inline-panel {
    width: 100%;
}

.maintenance-note {
    margin: 0.6rem 0 1rem;
    color: var(--muted);
    line-height: 1.5;
}

.gallery {
    width: 100%;
}

.inline-panel {
    margin-top: 0.75rem;
    padding: clamp(0.9rem, 2.5vw, 1.25rem);
    border: 1px solid rgba(121, 194, 173, 0.3);
    border-radius: 0.85rem;
    background: rgba(23, 26, 31, 0.96);
}

.gallery-main .inline-panel {
    width: 100%;
    margin: 0 0 0.85rem;
}

.compact-panel {
    padding-block: 0.75rem;
}

.compact-panel summary {
    color: var(--muted);
    cursor: pointer;
}

.inline-panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.inline-panel h2,
.eyebrow {
    margin: 0;
}

.inline-panel h2 {
    font-size: 1.15rem;
}

.eyebrow {
    margin-bottom: 0.25rem;
    color: var(--accent-strong);
    font-size: 0.7rem;
    font-weight: 750;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem;
}

.field {
    display: grid;
    gap: 0.35rem;
}

.field > span {
    color: #dce1e5;
    font-size: 0.8rem;
    font-weight: 650;
}

.field input,
.field textarea {
    width: 100%;
    min-height: 2.65rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    color: var(--text);
    background: #0e1216;
}

.field textarea {
    resize: vertical;
}

.field-wide {
    grid-column: 1 / -1;
}

.check-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.65rem;
}

.drop-zone {
    display: grid;
    place-items: center;
    gap: 0.3rem;
    min-height: 8.5rem;
    padding: 1rem;
    border: 1px dashed rgba(121, 194, 173, 0.55);
    border-radius: 0.75rem;
    color: var(--muted);
    background: rgba(121, 194, 173, 0.04);
    text-align: center;
    cursor: pointer;
}

.drop-zone.is-dragging {
    border-color: var(--accent-strong);
    background: rgba(121, 194, 173, 0.12);
}

.drop-icon {
    display: grid;
    place-items: center;
    width: 2.7rem;
    height: 2.7rem;
    border-radius: 50%;
    color: var(--accent-strong);
    background: rgba(121, 194, 173, 0.12);
    font-size: 1.6rem;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.gallery-entry {
    display: grid;
    align-content: start;
    gap: 0.5rem;
    min-width: 0;
}

.gallery-entry .media-card {
    width: 100%;
}

.add-image-card {
    display: grid;
    place-items: center;
    min-height: 13rem;
    border: 1px dashed rgba(121, 194, 173, 0.55);
    border-radius: 0.75rem;
    color: var(--accent-strong);
    background: rgba(121, 194, 173, 0.04);
    cursor: pointer;
}

.add-image-card.is-dragging {
    border-color: var(--accent-strong);
    background: rgba(121, 194, 173, 0.14);
}

.upload-queue {
    display: grid;
    gap: 0.45rem;
    margin: 0.75rem 0;
}

.upload-queue label {
    display: grid;
    grid-template-columns: minmax(8rem, 0.7fr) minmax(12rem, 1.3fr);
    align-items: center;
    gap: 0.65rem;
    color: var(--muted);
    font-size: 0.8rem;
}

.upload-queue input {
    min-width: 0;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 0.45rem;
    color: var(--text);
    background: #0e1216;
}

.add-image-card span {
    display: block;
    font-size: 2.5rem;
    line-height: 1;
}

.add-image-card strong {
    font-size: 0.85rem;
}

.card-editor {
    display: grid;
    gap: 0.45rem;
    padding: 0.65rem;
    border: 1px solid rgba(121, 194, 173, 0.28);
    border-radius: 0.65rem;
    background: var(--panel-raised);
}

.card-editor input,
.card-editor textarea {
    width: 100%;
    min-height: 2.35rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.45rem;
    color: var(--text);
    background: #0e1216;
    font-size: 0.8rem;
}

.card-editor textarea {
    min-height: 4.5rem;
    resize: vertical;
}

.assignment-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.2rem 0.45rem;
    color: var(--muted);
    font-size: 0.7rem;
}

.assignment-options .check-field {
    min-width: 0;
    min-height: 1.55rem;
    gap: 0.35rem;
}

.assignment-options .check-field input {
    flex: 0 0 auto;
    width: 0.9rem;
    height: 0.9rem;
    margin: 0;
}

.assignment-options .check-field span {
    overflow-wrap: anywhere;
}

.card-editor-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.empty-gallery {
    grid-column: 1 / -1;
    margin: 0;
    padding: 2rem;
    border: 1px dashed var(--border);
    border-radius: 0.75rem;
    color: var(--muted);
    text-align: center;
}

@media (max-width: 640px) {
    .page-header {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .session-controls {
        grid-column: 1 / -1;
        width: 100%;
        justify-content: flex-end;
    }

    .controls {
        align-items: stretch;
        flex-direction: column;
    }

    .sort-control {
        justify-content: space-between;
    }

    .gallery-main,
    .inline-panel,
    .status-message {
        width: min(100% - 1rem, 78rem);
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .field-wide {
        grid-column: auto;
    }

    .inline-panel-heading {
        flex-direction: column;
    }

    .inline-panel-heading button {
        width: 100%;
    }

    .add-image-card {
        min-height: 9.5rem;
    }

    .assignment-options {
        grid-template-columns: 1fr;
    }

    .upload-queue label {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition: none !important;
    }
}
