* { box-sizing: border-box; }

:root {
    --page-bg: #111;
    --page-text: #fff;
    --heading-text: azure;
    --card-bg: #000;
    --card-text: #fff;
    --muted-text: rgba(255, 255, 255, 0.72);
    --admin-box-bg: #121212;
    --modal-bg: rgba(0, 0, 0, 0.92);
    --field-bg: #fff;
    --field-text: #111;
    --counter-bg: rgba(0, 0, 0, 0.42);
    --counter-text: rgba(255, 255, 255, 0.70);
}

body.theme-light {
    --page-bg: #f4f4f0;
    --page-text: #111;
    --heading-text: #123;
    --card-bg: #fff;
    --card-text: #111;
    --muted-text: rgba(0, 0, 0, 0.72);
    --admin-box-bg: #ffffff;
    --modal-bg: rgba(255, 255, 255, 0.94);
    --field-bg: #fff;
    --field-text: #111;
    --counter-bg: rgba(255, 255, 255, 0.72);
    --counter-text: rgba(0, 0, 0, 0.72);
}

body {
    margin: 0;
    background: var(--page-bg);
    color: var(--page-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    text-align: center;
}

.page-phrase { color: var(--heading-text); }

/* ===== FULLSCREEN BACKGROUND ===== */
#background-layer {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    z-index: -1;
}

/* GLYPHS */
.glyph {
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0.85;
    pointer-events: none;
    will-change: transform;
    user-select: none;
}

@keyframes fly {
    0% { transform: translate3d(var(--x-start), var(--y-start), 0) rotate(0deg); }
    100% { transform: translate3d(var(--x-end), var(--y-end), 0) rotate(360deg); }
}

.admin-tools {
    width: min(850px, 100%);
    margin: 8px auto 0;
    padding: 0 20px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
}

.inline-form { display: inline-flex; margin: 0; }

button {
    font-family: inherit;
    border: 1px solid #8a8a8a;
    border-radius: 8px;
    padding: 8px 14px;
    background: #f4f4f4;
    color: #222;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
    filter: grayscale(1);
}

.theme-switch {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: auto;
    font-size: 12px;
    font-weight: bold;
    color: var(--page-text);
}

.theme-switch select {
    border: 0;
    border-radius: 999px;
    padding: 5px 24px 5px 9px;
    background: #e8e8e8;
    color: #111;
    font-weight: bold;
    font-size: 12px;
    cursor: pointer;
}

.message-panel {
    width: min(810px, calc(100% - 24px));
    margin: 12px auto;
    text-align: left;
}

.message {
    margin: 6px 0;
    padding: 8px 10px;
    border-radius: 8px;
}

.message.ok { background: rgba(38,140,80,0.78); }
.message.error { background: rgba(170,45,45,0.82); }

/* VIDEO GRID */
.youtube-grid,
.video-grid,
.audio-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    column-gap: 15px;
    row-gap: 26px;
    padding: 20px;
    width: min(100%, 850px);
    margin: 0 auto;
}

.youtube-card,
.video-card,
.audio-card {
    flex: 0 1 260px;
    max-width: 260px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    position: relative;
}

.youtube-card iframe,
.video-card video {
    width: 100%;
    height: 160px;
    object-fit: cover;
    border-radius: 8px;
    border: 0;
}

.youtube-broken-link {
    width: 100%;
    height: 160px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #000;
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}
.audio-card {
    padding: 14px 12px 16px;
    border-radius: 14px;
    background: var(--card-bg);
    color: var(--card-text);
}

.audio-icon {
    width: 100%;
    height: 72px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: rgba(255,255,255,0.08);
    font-size: 36px;
}

body.theme-light .audio-icon {
    background: rgba(0,0,0,0.06);
}

.audio-card audio {
    width: 100%;
    margin-top: 8px;
}

.delete-preview-frame.audio-preview-frame {
    aspect-ratio: auto;
    min-height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.delete-preview-frame.audio-preview-frame audio {
    width: 100%;
}


.media-filename {
    font-size: 11px;
    line-height: 1.2;
    color: var(--muted-text);
    text-align: center;
    word-break: break-word;
}


.media-comment-text {
    font-weight: 800;
    white-space: pre-line;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
    line-height: 1.45;
}

.media-card-actions {
    box-sizing: border-box;
    width: 100%;
    padding: 0 12px 14px;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
}

.media-card-action-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}

.media-edit-panel { margin: 0; }

.media-edit-panel summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 78px;
    min-height: 42px;
    padding: 10px 16px;
    border-radius: 11px;
    border: 1px solid rgba(31, 85, 52, .38);
    background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(248,252,247,.94));
    color: #245a42;
    box-shadow: 0 1px 0 rgba(255,255,255,.85) inset, 0 2px 0 rgba(31,85,52,.10), 0 8px 18px rgba(31,85,52,.10);
    cursor: pointer;
    font-weight: 800;
    list-style: none;
}

.media-edit-panel summary::-webkit-details-marker { display: none; }
.media-edit-panel summary::before { content: "✎"; margin-right: 8px; font-size: 18px; line-height: 1; }

.delete-media-button {
    margin: 0 0 0 auto;
    min-width: 88px;
    min-height: 42px;
    padding: 10px 16px;
    border-radius: 11px;
    border: 1px solid rgba(155,47,47,.48);
    background: linear-gradient(180deg, #b33a3a, #942828);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    box-shadow: 0 1px 0 rgba(255,255,255,.20) inset, 0 2px 0 rgba(90,20,20,.18), 0 8px 18px rgba(155,47,47,.18);
}

.delete-media-button::before { content: "🗑"; margin-right: 7px; font-size: 15px; }

.media-edit-form { display: none; width: 100%; margin: 0; }
.media-card-actions:has(.media-edit-panel[open]) .media-edit-form { display: block; }

.media-edit-form textarea {
    display: block;
    width: 100%;
    min-height: 112px;
    box-sizing: border-box;
    margin: 0 0 14px;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid rgba(31,85,52,.26);
    background: rgba(255,255,255,.96);
    color: #111;
    font: inherit;
    font-weight: 700;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-y: auto;
    resize: vertical;
}

.media-data-edit-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
    width: 100%;
}

.media-order-label {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: #e9f4ec;
    font-size: 12px;
    font-weight: 900;
    line-height: 1.15;
    white-space: nowrap;
}

.media-order-input {
    display: block;
    width: 112px;
    height: 42px;
    margin: 0;
    padding: 8px 10px;
    border-radius: 11px;
    border: 1px solid rgba(31,85,52,.34);
    background: rgba(255,255,255,.98);
    color: #111;
    font-size: 16px;
    font-weight: 800;
}

.media-edit-save-button {
    min-width: 92px;
    min-height: 44px;
    padding: 11px 18px;
    border-radius: 12px;
    border: 1px solid rgba(12,62,33,.42);
    background: linear-gradient(180deg, #2f8a5c, #245a42);
    color: #fff;
    font-weight: 800;
}

.media-edit-save-button::before { content: "✓"; margin-right: 8px; }


/* GALLERY */
.gallery {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    column-gap: 15px;
    row-gap: 32px;
    padding: 20px;
    width: min(100%, 850px);
    margin: 0 auto;
}

.picture-card {
    flex: 0 0 260px;
    width: 260px;
    max-width: 260px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: var(--card-bg);
    color: var(--card-text);
}

.thumb {
    display: block;
    width: 100%;
    height: 140px;
    box-sizing: border-box;
    object-fit: contain;
    object-position: center center;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    background: #000;
    padding: 0;
}

.thumb:hover { transform: scale(1.03); }

/* IMAGE VIEWER MODAL */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--modal-bg);
    z-index: 9999;
}

.modal img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 95%;
    max-height: 90vh;
    border-radius: 10px;
    opacity: 0;
    transition: opacity 0.25s;
}

.modal img.show { opacity: 1; }

/* ADMIN MODALS */
.admin-modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,0.72);
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.admin-modal-backdrop.open { display: flex; }

.admin-modal-box {
    width: min(440px, 100%);
    padding: 18px;
    border: 1px solid rgba(255,255,255,0.22);
    border-radius: 14px;
    background: var(--admin-box-bg);
    box-shadow: 0 16px 50px rgba(0,0,0,0.65);
    text-align: left;
}

.admin-modal-box h2 { margin: 0 0 14px; font-size: 20px; }
.admin-modal-box label { display: block; margin: 10px 0 5px; font-weight: bold; font-size: 13px; }
.admin-modal-box input[type="text"],
.admin-modal-box input[type="password"],
.admin-modal-box input[type="file"],
.admin-modal-box input[type="url"] {
    width: 100%;
    max-width: 100%;
    padding: 8px;
    border: 1px solid #666;
    border-radius: 8px;
    background: var(--field-bg);
    color: var(--field-text);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
}

.delete-preview-name {
    margin-bottom: 8px;
    color: rgba(255,255,255,0.8);
    font-size: 13px;
    word-break: break-word;
}

.delete-preview-frame {
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 1px solid rgba(255,255,255,0.22);
    border-radius: 10px;
    background: #000;
    overflow: hidden;
}

.delete-preview-frame img,
.delete-preview-frame video,
.delete-preview-frame iframe {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #000;
    border: 0;
}

.danger-button { background: #ffb8b8; }

/* NAV */
.nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 60px;
    color: var(--page-text);
    cursor: pointer;
    user-select: none;
}

.prev { left: 20px; }
.next { right: 20px; }

/* CLOSE */
.close {
    position: absolute;
    top: 15px;
    right: 25px;
    font-size: 35px;
    cursor: pointer;
    user-select: none;
}

.empty-note {
    opacity: 0.75;
    padding: 10px 20px;
}

.visit-counter {
    position: fixed;
    left: 8px;
    bottom: 6px;
    z-index: 20;
    padding: 4px 7px;
    border-radius: 7px;
    background: var(--counter-bg);
    color: var(--counter-text);
    font-size: 11px;
    line-height: 1;
    pointer-events: none;
    user-select: none;
    text-decoration: none;
}

.visit-counter-link {
    pointer-events: auto;
    cursor: pointer;
}

.visit-counter-link:hover,
.visit-counter-link:focus {
    color: rgba(255, 255, 255, 0.95);
    background: rgba(0, 0, 0, 0.68);
    text-decoration: underline;
    outline: none;
}



/* MEDIA NAVIGATION */
.media-nav {
    width: min(850px, calc(100% - 28px));
    margin: 18px auto 22px;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 22px;
    background: rgba(0, 0, 0, 0.34);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(8px);
}

body.theme-light .media-nav {
    border-color: rgba(0, 0, 0, 0.12);
    background: rgba(255, 255, 255, 0.62);
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.12);
}

.media-nav-card {
    min-height: 96px;
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 17px;
    background: linear-gradient(180deg, rgba(255,255,255,0.14), rgba(255,255,255,0.05));
    color: var(--page-text);
    text-decoration: none;
    box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset;
    transition: transform 0.16s ease, background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

body.theme-light .media-nav-card {
    border-color: rgba(0, 0, 0, 0.10);
    background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(245,245,240,0.84));
}

.media-nav-card:hover,
.media-nav-card:focus {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.34);
    background: linear-gradient(180deg, rgba(255,255,255,0.22), rgba(255,255,255,0.08));
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
    outline: none;
}

body.theme-light .media-nav-card:hover,
body.theme-light .media-nav-card:focus {
    border-color: rgba(0, 0, 0, 0.20);
    background: #fff;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
}

.media-nav-icon {
    font-size: 28px;
    line-height: 1;
}

.media-nav-label {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: .02em;
}

.media-nav-count {
    min-width: 34px;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    color: var(--muted-text);
    font-size: 12px;
    font-weight: 800;
    line-height: 1.35;
}

body.theme-light .media-nav-count {
    background: rgba(0, 0, 0, 0.08);
}

.section-title {
    scroll-margin-top: 18px;
}

@media (max-width: 640px) {
    .admin-tools {
        justify-content: center;
        padding: 8px 12px 0;
        flex-wrap: wrap;
    }

    .theme-switch {
        margin-right: 0;
    }

    button {
        font-size: 11px;
        padding: 5px 7px;
    }


    .media-nav {
        grid-template-columns: 1fr;
        gap: 9px;
        margin-top: 14px;
        padding: 10px;
    }

    .media-nav-card {
        min-height: 72px;
        flex-direction: row;
        justify-content: flex-start;
        padding: 11px 14px;
        text-align: left;
    }

    .media-nav-icon { font-size: 25px; }
    .media-nav-label { flex: 1; }

}
