:root {
    --bg: #0f172a;
    --panel: #ffffff;
    --text: #172033;
    --muted: #64748b;
    --line: #e2e8f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --shadow: 0 18px 45px rgba(15, 23, 42, .14);
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
}

button,
.button {
    border: 0;
    background: var(--primary);
    color: #fff;
    padding: 10px 16px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

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

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

.button.ghost {
    background: #eef4ff;
    color: var(--primary-dark);
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 11px 12px;
    font: inherit;
    background: #fff;
}

textarea {
    resize: vertical;
}

label {
    display: block;
    font-weight: 700;
    margin: 12px 0 6px;
}

small,
.hint {
    color: var(--muted);
}

.admin-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #eff6ff 0%, #ffffff 45%, #f8fafc 100%);
}

.auth-card {
    width: min(420px, calc(100vw - 32px));
    margin: 8vh auto;
    background: var(--panel);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: 32px;
}

.auth-card h1 {
    margin-top: 0;
}

.alert {
    border-radius: 14px;
    padding: 12px 14px;
    margin: 16px 0;
    font-weight: 650;
}

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

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

.admin-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
}

.admin-topbar div {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.admin-topbar span {
    font-size: 13px;
    color: var(--muted);
}

.admin-topbar nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.admin-topbar nav a {
    text-decoration: none;
    background: #f1f5f9;
    padding: 8px 12px;
    border-radius: 999px;
    font-weight: 700;
}

.admin-wrap {
    width: min(1120px, calc(100vw - 32px));
    margin: 28px auto 60px;
}

.admin-wrap.wide {
    width: min(1400px, calc(100vw - 28px));
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 10px 28px rgba(15, 23, 42, .08);
    padding: 22px;
    margin-bottom: 22px;
}

.panel h1,
.panel h2,
.panel h3 {
    margin-top: 0;
}

.grid-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 140px minmax(260px, 1fr) auto;
    gap: 14px;
    align-items: end;
}

.align-end {
    align-self: end;
}

.slide-list {
    display: grid;
    gap: 16px;
}

.slide-card {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 12px;
    background: #f8fafc;
}

.slide-card img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 14px;
    background: #e2e8f0;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.editor-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 22px;
    align-items: start;
}

.image-editor {
    position: relative;
    width: 100%;
    line-height: 0;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: #020617;
    cursor: crosshair;
}

.image-editor img {
    width: 100%;
    display: block;
}

.marker,
.present-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: #2563eb;
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 14px;
    font-weight: 900;
    box-shadow: 0 0 0 6px rgba(37, 99, 235, .20), 0 12px 24px rgba(15, 23, 42, .25);
    border: 2px solid #fff;
    z-index: 5;
    line-height: 1;
}

.marker.draft {
    background: #16a34a;
    box-shadow: 0 0 0 6px rgba(22, 163, 74, .22), 0 12px 24px rgba(15, 23, 42, .25);
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    padding: 12px;
}

th {
    background: #f8fafc;
}

.tiny {
    width: 80px;
    border-radius: 10px;
}

.viewer-body {
    min-height: 100vh;
    background: #020617;
    color: #fff;
    overflow: hidden;
}

.presentation {
    height: 100vh;
    width: 100vw;
    position: relative;
    display: grid;
    place-items: center;
    padding: 56px 24px 80px;
}

.present-slide {
    display: none;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
}

.present-slide.active {
    display: flex;
}

.present-canvas {
    position: relative;
    line-height: 0;
    max-width: 100%;
    max-height: 100%;
}

.present-canvas img {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 150px);
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 30px 80px rgba(0,0,0,.45);
}

.present-marker {
    border: 2px solid #fff;
    font-size: 13px;
    padding: 0;
    animation: pulse 1.8s infinite;
}

.present-marker:hover {
    background: #1d4ed8;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(37,99,235,.55), 0 12px 24px rgba(0,0,0,.25); }
    70% { box-shadow: 0 0 0 12px rgba(37,99,235,0), 0 12px 24px rgba(0,0,0,.25); }
    100% { box-shadow: 0 0 0 0 rgba(37,99,235,0), 0 12px 24px rgba(0,0,0,.25); }
}

.slide-caption {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: min(960px, calc(100vw - 32px));
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    color: rgba(255,255,255,.86);
    background: rgba(15,23,42,.56);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 999px;
    padding: 10px 16px;
    backdrop-filter: blur(12px);
    line-height: 1.4;
}

.viewer-nav {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    background: rgba(15,23,42,.56);
    border: 1px solid rgba(255,255,255,.12);
    padding: 10px;
    border-radius: 999px;
    backdrop-filter: blur(12px);
}

.viewer-nav a {
    color: #fff;
    text-decoration: none;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
    font-weight: 700;
}

.popup-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(2, 6, 23, .72);
    display: grid;
    place-items: center;
    padding: 24px;
}

.popup-backdrop[hidden] {
    display: none;
}

.popup-box {
    width: min(760px, 100%);
    max-height: calc(100vh - 48px);
    overflow: auto;
    background: #fff;
    color: var(--text);
    border-radius: 26px;
    padding: 28px;
    position: relative;
    box-shadow: 0 32px 90px rgba(0,0,0,.4);
}

.popup-box h2 {
    margin: 0 42px 14px 0;
}

.popup-box p {
    white-space: pre-wrap;
    font-size: 18px;
    line-height: 1.65;
}

.popup-box img {
    width: 100%;
    max-height: 420px;
    object-fit: contain;
    border-radius: 18px;
    background: #f8fafc;
    margin-bottom: 14px;
}

.popup-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 38px;
    height: 38px;
    border-radius: 999px;
    padding: 0;
    font-size: 24px;
    background: #0f172a;
}

.empty-viewer {
    width: min(620px, calc(100vw - 32px));
    margin: 14vh auto;
    background: #fff;
    color: var(--text);
    border-radius: 26px;
    padding: 32px;
    text-align: center;
}

@media (max-width: 900px) {
    .grid-form,
    .editor-layout,
    .slide-card {
        grid-template-columns: 1fr;
    }

    .admin-topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    .presentation {
        padding-left: 12px;
        padding-right: 12px;
    }

    .viewer-nav {
        width: calc(100vw - 24px);
        border-radius: 18px;
        justify-content: center;
        flex-wrap: wrap;
    }

    .slide-caption {
        border-radius: 18px;
        font-size: 13px;
    }
}
