:root {
    --bg: #111113;
    --surface: #1a1a1f;
    --surface-2: #222228;
    --surface-3: #2a2a32;
    --border: #333340;
    --text: #e8e8ed;
    --text-dim: #8888a0;
    --accent: #39ff85;
    --accent-dim: #39ff8520;
    --accent-hover: #2de876;
    --danger: #ff4757;
    --danger-dim: #ff475720;
    --radius: 8px;
    --mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
    --sans: 'DM Sans', 'Segoe UI', system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
    font-size: 16px; /* Base size for rem calculations */
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden; /* Prevent horizontal scrolling */
    width: 100%;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Global Touch Target Minimums */
button, 
.btn-primary, 
.btn-small, 
.btn-copy, 
.btn-delete,
.pagination a, 
.pagination span {
    min-height: 48px;
    min-width: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

input[type="text"], 
input[type="password"], 
input[type="file"],
.form-select,
.share-input {
    min-height: 48px;
}

/* NAV */
.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: relative;
}
.nav-brand {
    font-family: var(--mono);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px; /* Touch target */
}
.nav-brand .dot { color: var(--accent); }

.menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
}

.nav-links { 
    display: flex; 
    gap: 1.5rem; 
    align-items: center; 
}
.nav-links a {
    color: var(--text-dim);
    font-size: 1rem;
    transition: color 0.2s;
    padding: 0.5rem;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
}
.nav-links a:hover { color: var(--accent); }

/* LAYOUT */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1rem; /* Fluid padding for mobile */
    width: 100%;
}
.container-wide {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
    width: 100%;
}

/* UPLOAD ZONE */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 1rem;
    text-align: center;
    transition: all 0.3s;
    cursor: pointer;
    background: var(--surface);
    position: relative;
    width: 100%;
}
.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-dim);
}
.upload-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}
.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.6;
}
.upload-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.upload-hint {
    color: var(--text-dim);
    font-size: 0.875rem;
    padding: 0 1rem;
}
.upload-hint kbd {
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-family: var(--mono);
    font-size: 0.875rem;
}

/* PROGRESS */
.progress-wrap { margin-top: 1.5rem; display: none; }
.progress-wrap.active { display: block; }
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--surface-3);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s;
    border-radius: 3px;
}
.progress-text {
    font-size: 0.875rem;
    color: var(--text-dim);
    margin-top: 0.75rem;
    font-family: var(--mono);
}

/* STATS BAR */
.stats {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    gap: 2rem;
    margin-top: 2rem;
    justify-content: center;
}
.stat { text-align: center; }
.stat-value {
    font-family: var(--mono);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
}
.stat-label {
    font-size: 0.875rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* VIEW PAGE */
.view-wrap { display: grid; gap: 2rem; width: 100%; }
.image-display {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    padding: 1rem;
}
.image-display img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
}
.image-meta {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
}
.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}
.meta-item { display: flex; flex-direction: column; gap: 0.25rem; }
.meta-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
}
.meta-value {
    font-family: var(--mono);
    font-size: 1rem;
    word-break: break-all; /* Prevent long filenames breaking layout */
}

/* SHARE LINKS */
.share-section { margin-top: 1.5rem; }
.share-title {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.share-row {
    display: flex;
    flex-wrap: wrap; /* Fluid response for mobile */
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    width: 100%;
}
.share-label {
    font-size: 0.875rem;
    color: var(--text-dim);
    min-width: 80px;
    font-family: var(--mono);
}
.share-input {
    flex: 1 1 200px; /* Grow, shrink, base width */
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.875rem;
    outline: none;
    width: 100%;
}
.share-input:focus { border-color: var(--accent); }

.btn-copy {
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 1rem;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.btn-copy:hover, .btn-copy.copied {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* DELETE */
.delete-zone {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}
.btn-delete {
    background: var(--danger-dim);
    border: 1px solid var(--danger);
    border-radius: 4px;
    padding: 0 1.25rem;
    color: var(--danger);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
    width: 100%; /* Full width for easy mobile tap */
}
.btn-delete:hover {
    background: var(--danger);
    color: white;
}

/* GALLERY */
.gallery-grid {
    display: grid;
    /* Fluid grid adapting automatically */
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    width: 100%;
}
.gallery-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
}
.gallery-item:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}
.gallery-thumb {
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--bg);
}
.gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}
.gallery-item:hover .gallery-thumb img {
    transform: scale(1.05);
}
.gallery-info { padding: 1rem; }
.gallery-name {
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}
.gallery-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-family: var(--mono);
    margin-top: 0.5rem;
}

/* PAGINATION */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 2.5rem;
}
.pagination a, .pagination span {
    padding: 0 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    color: var(--text-dim);
    transition: all 0.2s;
}
.pagination a:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.pagination .current {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* MESSAGE BOX (Deleted / Errors) */
.message-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3rem 1.5rem;
    text-align: center;
    margin-top: 2rem;
}
.message-box h2 { margin-bottom: 1.25rem; }
.message-box p { color: var(--text-dim); font-size: 1rem; }

/* FOOTER */
.footer {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-dim);
    font-size: 0.875rem;
    border-top: 1px solid var(--border);
    margin-top: 4rem;
    font-family: var(--mono);
}

/* TOAST */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translate(-50%, 100px);
    background: var(--surface-2);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    font-size: 1rem;
    color: var(--accent);
    font-family: var(--mono);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
    width: max-content;
    max-width: 90vw;
    text-align: center;
}
.toast.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

/* AUTH FORMS */
.auth-box {
    max-width: 420px;
    margin: 2rem auto 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    width: 100%;
}
.auth-box h2 {
    margin-bottom: 1.5rem;
    font-size: 1.75rem;
}
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.form-group input {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 1rem;
    color: var(--text);
    font-family: var(--sans);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
}
.form-group input:focus { border-color: var(--accent); }
.form-group input::placeholder { color: var(--text-dim); opacity: 0.6; }
.form-hint { font-size: 0.875rem; color: var(--text-dim); }
.btn-primary {
    background: var(--accent);
    border: none;
    border-radius: 4px;
    padding: 0 1.25rem;
    color: var(--bg);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
    font-family: var(--sans);
    width: 100%; /* Optimised for tap */
}
.btn-primary:hover { background: var(--accent-hover); }
.auth-footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 1rem;
    color: var(--text-dim);
}
.auth-footer a {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
}

/* ALERTS */
.alert {
    padding: 1rem;
    border-radius: 4px;
    font-size: 1rem;
    margin-bottom: 1.25rem;
}
.alert-error {
    background: var(--danger-dim);
    border: 1px solid var(--danger);
    color: var(--danger);
}

/* ADMIN PANEL */
.admin-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
    width: 100%;
}
.admin-section h3 {
    font-size: 1.25rem;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

/* Settings form */
.settings-form { display: flex; flex-direction: column; gap: 1.25rem; }
.setting-row {
    display: flex;
    flex-wrap: wrap; /* Fluid wrap */
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.setting-row:last-of-type { border-bottom: none; }
.setting-info { display: flex; flex-direction: column; gap: 0.25rem; flex: 1 1 200px; }
.setting-info label { font-weight: 500; font-size: 1rem; }
.setting-hint { font-size: 0.875rem; color: var(--text-dim); }
.form-select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 1rem;
    color: var(--text);
    font-family: var(--sans);
    font-size: 1rem;
    outline: none;
    cursor: pointer;
    min-width: 140px;
    flex: 1 1 auto;
}
.form-select:focus { border-color: var(--accent); }

/* Toggle switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 52px; /* Increased size for touch */
    height: 32px;
    flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 32px;
    transition: all 0.2s;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    height: 24px;
    width: 24px;
    left: 3px;
    bottom: 3px;
    background: var(--text-dim);
    border-radius: 50%;
    transition: all 0.2s;
}
.toggle input:checked + .toggle-slider {
    background: var(--accent-dim);
    border-color: var(--accent);
}
.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: var(--accent);
}

/* Admin table */
.admin-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 600px; /* Force scroll on extremely narrow devices */
}
.admin-table th {
    text-align: left;
    padding: 1rem 0.75rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    font-weight: 500;
}
.admin-table td {
    padding: 1rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table .mono { font-family: var(--mono); font-size: 0.875rem; }
.admin-table .actions { display: flex; gap: 0.5rem; align-items: center; }
.admin-table .text-dim { color: var(--text-dim); font-size: 0.875rem; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--surface-3);
    color: var(--text-dim);
    border: 1px solid var(--border);
}
.badge-admin, .badge-active {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
}
.badge-used { border-color: var(--border); }

/* Small buttons (admin actions) */
.btn-small {
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 1rem;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
    font-family: var(--sans);
    white-space: nowrap;
}
.btn-small:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}
.btn-small-danger {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--danger-dim);
}
.btn-small-danger:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

/* ====================== */
/* RESPONSIVE BREAKPOINTS  */
/* ====================== */
@media (max-width: 768px) {
    .nav { padding: 0.75rem 1rem; }
    
    /* Hamburger Menu Logic */
    .menu-toggle { display: inline-flex; }
    .nav-links {
        display: none;
        flex-direction: column;
        width: 100%;
        position: absolute;
        top: 100%;
        left: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        z-index: 1000;
        padding: 0;
        box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    }
    .nav-links.active { display: flex; }
    .nav-links a {
        width: 100%;
        padding: 1rem;
        border-bottom: 1px solid var(--border);
        justify-content: center; /* Centered links for touch */
    }
    .nav-links a:last-child { border-bottom: none; }

    /* Layout adjustments */
    .container, .container-wide { padding: 1rem; }
    .upload-zone { padding: 2rem 1rem; }
    .stats { gap: 1rem; flex-direction: column; }
    .meta-grid { grid-template-columns: 1fr; gap: 1rem; }
    
    .share-row { flex-direction: column; align-items: stretch; }
    .share-label { min-width: 100%; margin-bottom: 0.25rem; }
    .btn-copy, .btn-delete { width: 100%; } /* Maximize hit area */

    .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    
    .setting-row { flex-direction: column; align-items: flex-start; }
    .admin-table .actions { flex-wrap: wrap; }
}
