:root {
    color-scheme: light dark;

    --bg: #fafafa;
    --surface: #ffffff;
    --surface-2: #f4f4f5;
    --text: #111111;
    --muted: #737373;
    --border: #dbdbdb;
    --border-soft: #ececec;
    --accent: #0095f6;
    --accent-hover: #1877f2;
    --danger: #ed4956;
    --success-bg: #eafaf0;
    --success-text: #16833a;
    --error-bg: #fff0f0;
    --error-text: #b4232a;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --surface: #121212;
        --surface-2: #1c1c1e;
        --text: #f5f5f5;
        --muted: #a8a8a8;
        --border: #2f2f2f;
        --border-soft: #232323;
        --accent: #0095f6;
        --accent-hover: #4cb5f9;
        --danger: #ff5a66;
        --success-bg: #092514;
        --success-text: #61d487;
        --error-bg: #2a1012;
        --error-text: #ff7a84;
        --shadow: none;
    }
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

a {
    color: inherit;
}

.page {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 60px;
    padding: 0 18px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-weight: 900;
    font-size: 22px;
    letter-spacing: -0.04em;
    text-decoration: none;
}

.main {
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
    padding: 24px 14px 48px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.auth-card {
    max-width: 420px;
    margin: 48px auto;
}

h1, h2 {
    margin: 0;
    letter-spacing: -0.035em;
}

h1 {
    font-size: 28px;
    line-height: 1.12;
}

h2 {
    font-size: 20px;
    line-height: 1.2;
}

p {
    line-height: 1.5;
}

.muted {
    color: var(--muted);
}

.small {
    font-size: 14px;
}

.form {
    display: grid;
    gap: 18px;
    margin-top: 22px;
}

.wide-form {
    max-width: 760px;
}

label {
    display: grid;
    gap: 8px;
    font-weight: 700;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-2);
    color: var(--text);
    padding: 0 14px;
    font-size: 16px;
    font-family: inherit;
}

input {
    height: 46px;
}

textarea {
    min-height: 92px;
    padding-top: 12px;
    resize: vertical;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

button,
.button {
    min-height: 44px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: #ffffff;
    padding: 0 18px;
    font-weight: 800;
    font-size: 15px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.link-button,
.text-danger-button {
    min-height: auto;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font-size: 14px;
}

.link-button:hover {
    background: transparent;
    text-decoration: underline;
}

.text-danger-button {
    color: var(--danger);
}

.text-danger-button:hover {
    background: transparent;
    text-decoration: underline;
}

.secondary-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
    font-weight: 800;
}

.alert {
    padding: 12px 14px;
    border-radius: 16px;
    margin-top: 16px;
    border: 1px solid var(--border);
}

.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.empty-state {
    margin-top: 20px;
    padding: 22px;
    border: 1px dashed var(--border);
    border-radius: 20px;
    background: var(--surface-2);
}

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 22px;
}

.mt {
    margin-top: 18px;
}

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

fieldset {
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 16px;
}

legend {
    padding: 0 8px;
    font-weight: 900;
}

.radio-row,
.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-weight: 600;
    margin-top: 12px;
}

.radio-row input,
.checkbox-row input {
    width: auto;
    height: auto;
    margin-top: 4px;
}

.checkbox-grid {
    display: grid;
    gap: 8px;
}

/* Admin event list */

.event-list {
    display: grid;
    gap: 10px;
    margin-top: 20px;
}

.event-item {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    text-decoration: none;
}

.event-item:hover {
    border-color: var(--accent);
}

.event-item div {
    display: grid;
    gap: 4px;
}

.event-item span,
.event-item em {
    color: var(--muted);
    font-size: 14px;
    font-style: normal;
}

/* QR */

.qr-layout {
    display: grid;
    grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
    gap: 22px;
    align-items: start;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.qr-box {
    width: 220px;
    max-width: 100%;
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 12px;
    background: #ffffff;
    overflow: hidden;
}

.qr-box img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
}

.share-box {
    display: grid;
    gap: 14px;
    min-width: 0;
}

.copy-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

.copy-row input {
    min-width: 0;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* Guest */

.guest-hero {
    display: grid;
    gap: 18px;
}

.guest-name-box {
    display: grid;
    gap: 16px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface-2);
}

.guest-name-box strong {
    display: block;
    margin-top: 4px;
    font-size: 22px;
    letter-spacing: -0.03em;
}

.eyebrow {
    display: block;
    font-size: 12px;
    color: var(--muted);
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.inline-name-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

/* Upload */

.upload-box {
    display: grid;
    gap: 14px;
}

.file-input {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

.upload-drop {
    display: grid;
    place-items: center;
    gap: 8px;
    min-height: 136px;
    padding: 24px;
    border: 1px dashed var(--border);
    border-radius: 24px;
    background: var(--surface-2);
    text-align: center;
    cursor: pointer;
}

.upload-drop strong {
    font-size: 18px;
}

.upload-drop span {
    color: var(--muted);
    font-size: 14px;
}

.upload-list {
    display: grid;
    gap: 10px;
}

.upload-item {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
}

.upload-info {
    display: grid;
    gap: 4px;
    margin-bottom: 10px;
}

.upload-info strong {
    overflow-wrap: anywhere;
}

.upload-info span {
    color: var(--muted);
    font-size: 14px;
}

.progress-bar {
    height: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-2);
}

.progress-fill {
    width: 0%;
    height: 100%;
    background: var(--accent);
    transition: width 0.15s ease;
}

.upload-success {
    border-color: color-mix(in srgb, var(--success-text) 45%, var(--border));
}

.upload-failed {
    border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
}

.gallery-note {
    margin-top: 18px;
    padding: 14px;
    border-radius: 18px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 14px;
}

/* Instagram-like gallery */

.media-grid,
.admin-media-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
    margin-top: 18px;
    border-radius: 20px;
    overflow: hidden;
    background: var(--border);
}

.media-card,
.admin-media-card {
    position: relative;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: #000000;
}

.media-card img,
.media-card video,
.admin-media-preview img,
.admin-media-preview video,
.video-thumb-link img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: #000000;
}

.media-meta,
.admin-media-body {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    gap: 3px;
    padding: 26px 8px 8px;
    font-size: 12px;
    color: #ffffff;
    background: linear-gradient(to top, rgba(0,0,0,0.72), rgba(0,0,0,0));
    opacity: 0;
    transition: opacity 0.15s ease;
}

.media-card:hover .media-meta,
.admin-media-card:hover .admin-media-body {
    opacity: 1;
}

.media-meta span,
.admin-media-body span {
    color: rgba(255,255,255,0.82);
    overflow-wrap: anywhere;
}

.admin-media-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 4px;
}

.admin-media-actions a {
    color: #ffffff;
    font-weight: 800;
    font-size: 12px;
}

.admin-media-actions .text-danger-button {
    color: #ff9aa2;
    font-size: 12px;
}

.video-thumb-link {
    position: relative;
    display: block;
    background: #000000;
}

.play-badge {
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.58);
    color: #ffffff;
    font-size: 22px;
    line-height: 1;
}

/* Danger */

.danger-zone {
    max-width: 980px;
    margin: 18px auto 0;
    padding: 20px;
    border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
    background: color-mix(in srgb, var(--danger) 8%, var(--surface));
    border-radius: 22px;
}

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

.danger-button:hover {
    background: color-mix(in srgb, var(--danger) 82%, #000000);
}

/* Mobile */

@media (max-width: 760px) {
    .topbar {
        min-height: 54px;
        padding: 0 14px;
    }

    .main {
        padding: 14px 8px 38px;
    }

    .card {
        padding: 16px;
        border-radius: 20px;
    }

    h1 {
        font-size: 24px;
        overflow-wrap: anywhere;
    }

    h2 {
        font-size: 19px;
    }

    .page-head {
        display: grid;
        gap: 12px;
    }

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

    .qr-layout {
        display: block;
    }

    .qr-box {
        width: 178px;
        max-width: 178px;
        margin: 0 auto 18px;
        padding: 10px;
    }

    .share-box,
    .copy-row,
    .button-row {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    .copy-row,
    .inline-name-form {
        grid-template-columns: 1fr;
    }

    .button-row {
        display: grid;
        grid-template-columns: 1fr;
    }

    .button-row .button,
    .button-row button,
    .inline-name-form button {
        width: 100%;
    }

    .event-item {
        display: grid;
    }

    .upload-drop {
        min-height: 116px;
        padding: 18px;
    }

    .media-grid,
    .admin-media-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 2px;
        border-radius: 16px;
    }

    .media-meta,
    .admin-media-body {
        position: static;
        opacity: 1;
        padding: 7px;
        background: #000000;
        font-size: 11px;
    }

    .admin-media-actions {
        display: grid;
        align-items: start;
        justify-content: stretch;
    }

    .play-badge {
        width: 38px;
        height: 38px;
        font-size: 17px;
    }
}

@media (max-width: 420px) {
    .main {
        padding-left: 0;
        padding-right: 0;
    }

    .card {
        border-left: 0;
        border-right: 0;
        border-radius: 0;
    }

    .auth-card {
        margin-top: 24px;
    }

    .media-grid,
    .admin-media-grid {
        border-radius: 0;
    }
}

.viewer {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0,0,0,0.96);
    display: flex;
    align-items: center;
    justify-content: center;
}

.viewer.hidden {
    display: none;
}

.viewer-content {
    max-width: 95vw;
    max-height: 85vh;
}

.viewer-content img,
.viewer-content video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.viewer-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 12px 16px;
    color: #fff;
    font-size: 14px;
}

.viewer-top a {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

.viewer-close {
    position: absolute;
    top: 10px;
    right: 12px;
    font-size: 32px;
    border: 0;
    background: none;
    color: #fff;
    cursor: pointer;
}

.viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 42px;
    border: 0;
    background: none;
    color: #fff;
    cursor: pointer;
}

.viewer-prev {
    left: 10px;
}

.viewer-next {
    right: 10px;
}

.viewer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100vh;
    padding: 54px 0 34px;
}

.viewer-content img,
.viewer-content video {
    max-width: 100vw;
    max-height: calc(100vh - 88px);
}

.viewer-top {
    z-index: 103;
    background: linear-gradient(to bottom, rgba(0,0,0,0.72), rgba(0,0,0,0));
    padding-right: 60px;
}

.viewer-close {
    z-index: 104;
}

.viewer-nav {
    z-index: 102;
    width: 76px;
    height: 50vh;
    opacity: 0.75;
}

.viewer-prev {
    left: 0;
}

.viewer-next {
    right: 0;
}

@media (max-width: 760px) {
    .viewer-nav {
        display: none;
    }

    .viewer-top {
        padding: 14px 58px 30px 14px;
        font-size: 13px;
    }

    .viewer-close {
        top: 6px;
        right: 10px;
        font-size: 36px;
    }

    .viewer-content {
        padding: 48px 0 24px;
    }

    .viewer-content img,
    .viewer-content video {
        width: 100vw;
        max-width: 100vw;
        max-height: calc(100vh - 72px);
        object-fit: contain;
    }

    .media-card img,
    .admin-media-preview img,
    .video-thumb-link img {
        image-rendering: auto;
    }
}

.viewer-content img {
    user-select: none;
    -webkit-user-drag: none;
}

.viewer-content {
    background: #000;
}

.viewer-content img,
.viewer-content video {
    background: #000;
}

/* Force black media backgrounds */
.viewer,
.viewer-content,
.viewer-content a,
.viewer-content img,
.viewer-content video,
.media-grid,
.admin-media-grid,
.media-card,
.admin-media-card,
.admin-media-preview,
.video-thumb-link,
.media-card a,
.admin-media-card a {
    background: #000 !important;
}

.media-card img,
.media-card video,
.admin-media-preview img,
.admin-media-preview video,
.video-thumb-link img {
    background-color: #000 !important;
}

.viewer-content img {
    max-width: 100%;
    max-height: 100%;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    will-change: transform;
}

.viewer {
    touch-action: auto;
}

.viewer-content {
    background: #000;
}

.viewer-content img,
.viewer-content video {
    background: #000;
}

.viewer-content img {
    max-width: 100%;
    max-height: 100%;
    user-select: auto;
    -webkit-user-select: auto;
    -webkit-user-drag: none;
    will-change: auto;
}

.viewer-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 103;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 12px 14px 30px;
    color: #fff;
    font-size: 14px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.72), rgba(0,0,0,0));
}

.viewer-top a {
    justify-self: start;
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

#viewer-date {
    justify-self: center;
    text-align: center;
}

.viewer-close {
    position: static;
    justify-self: end;
    min-height: 0;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: #fff;
    font-size: 36px;
    line-height: 1;
    cursor: pointer;
}

body.viewer-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}
