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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background-color: #fafafa;
    color: #333;
    line-height: 1.6;
}

a { color: #2563eb; text-decoration: none; }
a:hover { color: #1d4ed8; }

/* === Header === */
header {
    padding: 1.5rem 0;
    text-align: center;
}

header h1 { font-size: 1.5rem; }
header h1 a { color: #111; }
header h1 a:hover { color: #333; }

/* === Nav === */
nav {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    padding: 0.75rem 0;
    margin-bottom: 2rem;
    border-top: 1px solid #e5e5e5;
    border-bottom: 1px solid #e5e5e5;
}

nav a {
    color: #555;
    font-weight: 500;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

nav a:hover { color: #111; }

/* === Flash Messages === */
.flash {
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

.flash-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.flash-error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* === Photo Grid === */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.photo-card {
    display: block;
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: box-shadow 0.2s, transform 0.2s;
}

.photo-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.photo-card img {
    width: 100%;
    height: 250px;
    object-fit: cover;
    display: block;
}

.photo-title {
    display: block;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    color: #333;
    font-weight: 500;
}

.empty-state {
    text-align: center;
    color: #999;
    font-style: italic;
    padding: 3rem;
}

/* === Filters === */
.gallery-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    align-items: center;
}

.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
}

.filter-group strong {
    font-size: 0.8rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 0.25rem;
}

.filter-tag, .filter-toggle {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    background: #f0f0f0;
    color: #555;
    border: 1px solid #ddd;
}

.filter-tag:hover, .filter-toggle:hover { background: #e5e5e5; color: #333; }
.filter-tag.active, .filter-toggle.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.sort-controls {
    margin-left: auto;
    display: flex;
    gap: 0.25rem;
}

.load-more-wrap {
    text-align: center;
    margin: 2rem 0 1rem;
}

.load-more-btn {
    padding: 0.5rem 2rem;
    font-size: 0.95rem;
}

/* === Single Photo === */
.photo-page { max-width: 900px; margin: 0 auto; }

.photo-view {
    text-align: center;
    margin-bottom: 1.5rem;
}

.photo-browse {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.browse-arrow {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #999;
    flex-shrink: 0;
    transition: color 0.2s;
    width: 80px;
}

.browse-arrow:hover { color: #333; }
.browse-disabled { visibility: hidden; }

.browse-arrow .arrow {
    font-size: 2.5rem;
    line-height: 1;
    font-weight: 300;
}

.browse-thumb {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.browse-arrow:hover .browse-thumb { opacity: 1; }

.browse-prev { justify-content: flex-end; }
.browse-next { justify-content: flex-start; }

.photo-full {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    min-width: 0;
}

.photo-info { margin-bottom: 1.5rem; }
.photo-info .photo-title { padding: 0; font-size: 1.5rem; margin-bottom: 0.5rem; }
.photo-info .photo-caption { color: #666; margin-bottom: 1rem; }

.photo-ratings {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: flex-start;
}

.rating-wrap {
    position: relative;
}

.rating {
    font-size: 0.9rem;
    color: #555;
    background: #fef3c7;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
}

.rating-tappable {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.rating-tappable:hover { background: #fde68a; }

.rating-picker {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 0.25rem;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 0.35rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 10;
    white-space: nowrap;
}

.rating-picker.open { display: flex; gap: 0.25rem; }

.rating-btn {
    width: 36px;
    height: 36px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #f9fafb;
    color: #333;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
    font-family: inherit;
}

.rating-btn:hover { background: #fef3c7; border-color: #f59e0b; }
.rating-btn-clear { color: #999; font-weight: 400; }
.rating-btn-clear:hover { background: #fee2e2; border-color: #f87171; color: #dc2626; }

.photo-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.tag {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
}

.tag:hover { background: #dbeafe; }

.photo-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e5e5e5;
}

.photo-nav-mobile { display: none; }

/* === Comments === */
.comments-section { margin-top: 2rem; }
.comments-section h3 { margin-bottom: 1rem; font-size: 1.1rem; }

.comment {
    background: #fff;
    padding: 1rem;
    margin-bottom: 0.75rem;
    border-radius: 6px;
    border-left: 3px solid #2563eb;
}

.comment-author { font-weight: 600; color: #333; margin-right: 0.75rem; }
.comment-date { color: #999; font-size: 0.8rem; }
.comment-body { margin-top: 0.5rem; color: #555; }
.no-comments { color: #999; font-style: italic; }

.comment-form {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

/* === Forms === */
.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: #555;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

button[type="submit"], .btn {
    display: inline-block;
    background: #2563eb;
    color: #fff;
    padding: 0.6rem 1.5rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
}

button[type="submit"]:hover, .btn:hover { background: #1d4ed8; }

.btn-danger {
    background: #dc2626;
    color: #fff;
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-danger:hover { background: #b91c1c; }

/* === Login === */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.login-form {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 360px;
}

.login-form h2 { margin-bottom: 1.5rem; text-align: center; }

/* === Upload === */
.upload-page { max-width: 600px; margin: 0 auto; }
.upload-page h2 { margin-bottom: 1.5rem; }

/* === Edit === */
.edit-page { max-width: 600px; margin: 0 auto; }
.edit-page h2 { margin-bottom: 1.5rem; }

.edit-preview {
    text-align: center;
    margin-bottom: 1.5rem;
}

.edit-preview img {
    max-width: 300px;
    border-radius: 8px;
}

.tag-group { margin-bottom: 0.5rem; }
.tag-group strong { font-size: 0.85rem; color: #555; display: block; margin-bottom: 0.25rem; }

.tag-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-right: 0.75rem;
    font-size: 0.85rem;
    font-weight: normal;
}

/* === Inline Edit Buttons === */
.btn-inline-edit {
    background: none;
    border: none;
    color: #2563eb;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    padding: 0;
    font-weight: 500;
}

.btn-inline-edit:hover { color: #1d4ed8; text-decoration: underline; }

.tag-edit-btn {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    background: #f0fdf4;
    color: #16a34a;
    border: 1px dashed #86efac;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.tag-edit-btn:hover { background: #dcfce7; border-color: #4ade80; }

/* === Inline Caption Editor === */
.photo-caption-empty {
    color: #bbb;
    font-style: italic;
}

.photo-caption-empty kbd {
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 0 0.3rem;
    font-size: 0.8rem;
    font-family: inherit;
}

.caption-editor textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #2563eb;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.caption-editor-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* === Button variants === */
.btn-sm {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
}

.btn-muted {
    background: #e5e5e5;
    color: #555;
}

.btn-muted:hover { background: #d4d4d4; }

.btn-danger.btn-sm {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
}

.delete-inline { display: inline; }

/* === Rating Feedback === */
.rating-feedback {
    font-size: 0.8rem;
    color: #059669;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s;
}

.rating-feedback.visible { opacity: 1; }

/* === Tag Picker === */
.photo-tags-empty {
    color: #bbb;
    font-style: italic;
    font-size: 0.85rem;
}

.photo-tags-empty kbd {
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 0 0.3rem;
    font-size: 0.8rem;
    font-family: inherit;
}

.tag-picker {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 1rem;
    margin-top: 0.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.tag-filter-input {
    width: 100%;
    padding: 0.4rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: inherit;
    margin-bottom: 0.75rem;
}

.tag-filter-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.tag-picker-group {
    margin-bottom: 0.5rem;
}

.tag-picker-group strong {
    display: block;
    font-size: 0.75rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.tag-pill {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    background: #f0f0f0;
    color: #555;
    border: 1px solid #ddd;
    cursor: pointer;
    margin: 0.15rem;
    font-family: inherit;
    transition: all 0.15s;
}

.tag-pill:hover { background: #e5e5e5; }

.tag-pill.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.tag-picker-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e5e5;
}

.tag-picker-create {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    margin-top: 0.5rem;
    border-top: 1px solid #e5e5e5;
    font-size: 0.85rem;
    flex-wrap: wrap;
}

.tag-picker-create .tag-type-input {
    padding: 0.25rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.8rem;
    font-family: inherit;
    background: #fff;
    width: 7rem;
}

.tag-picker-empty {
    color: #999;
    font-style: italic;
    font-size: 0.85rem;
}

/* === Keybinds Help === */
.keybinds-help {
    margin-top: 2rem;
    padding: 1rem 1.25rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.keybinds-help h4 {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    color: #555;
}

.keybinds-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.4rem 1rem;
    align-items: center;
    font-size: 0.85rem;
}

.keybinds-grid kbd {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    font-size: 0.8rem;
    font-family: inherit;
    box-shadow: 0 1px 0 #d1d5db;
    white-space: nowrap;
}

.keybinds-grid span { color: #666; }

/* === Footer === */
footer {
    text-align: center;
    margin-top: 3rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e5e5;
    color: #999;
    font-size: 0.85rem;
}

/* === Responsive === */
@media (max-width: 768px) {
    body { padding: 12px; }

    /* Header */
    header { padding: 1rem 0; }
    header h1 { font-size: 1.25rem; }

    /* Nav — bigger touch targets */
    nav { gap: 0.5rem; padding: 0.5rem 0; margin-bottom: 1rem; }
    nav a { padding: 0.4rem 0.75rem; font-size: 0.85rem; }

    /* Filters — scrollable row on mobile */
    .gallery-filters {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
        gap: 0.4rem;
        margin-bottom: 1rem;
    }

    .filter-group {
        flex-wrap: nowrap;
        flex-shrink: 0;
    }

    .filter-tag, .filter-toggle {
        white-space: nowrap;
        padding: 0.35rem 0.75rem;
        font-size: 0.75rem;
    }

    .filter-group strong {
        font-size: 0.7rem;
        white-space: nowrap;
    }

    /* Photo grid — 2 columns on mobile */
    .photo-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .photo-card img { height: 150px; }

    .photo-title {
        padding: 0.4rem 0.5rem;
        font-size: 0.8rem;
    }

    /* Single photo — stack vertically, image fills width */
    .photo-page { padding: 0; }

    .photo-browse {
        flex-direction: column;
        gap: 0;
        position: relative;
    }

    .photo-browse .photo-full {
        order: -1;
        max-height: 55vh;
        width: 100%;
        border-radius: 4px;
    }

    .photo-browse .browse-arrow {
        display: none;
    }

    /* Swipe hint: show simple prev/next text links below image */
    .photo-nav-mobile {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
    }

    .photo-full {
        max-height: 60vh;
        border-radius: 4px;
    }

    /* Photo info */
    .photo-info .photo-title { font-size: 1.2rem; }

    .photo-ratings {
        gap: 0.75rem;
        flex-wrap: wrap;
    }

    .rating { font-size: 0.85rem; }

    .rating-btn {
        width: 44px;
        height: 44px;
        font-size: 1rem;
    }

    .rating-picker {
        left: auto;
        right: 0;
    }

    .photo-nav {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-bottom: 1.5rem;
    }

    /* Comments */
    .comments-section { margin-top: 1.5rem; }
    .comment { padding: 0.75rem; }

    /* Forms — prevent iOS zoom (requires 16px font) */
    .form-group input,
    .form-group textarea,
    .form-group select {
        font-size: 16px;
    }

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

    .comment-form { padding: 1rem; }

    button[type="submit"], .btn {
        width: 100%;
        text-align: center;
        padding: 0.75rem 1rem;
    }

    /* Upload */
    .upload-page { padding: 0; }

    /* Tag picker */
    .tag-picker { padding: 0.75rem; }

    /* Keybinds help */
    .keybinds-grid { gap: 0.3rem 0.75rem; font-size: 0.8rem; }

    /* Footer */
    footer { margin-top: 2rem; }
}

/* Small phones */
@media (max-width: 380px) {
    .photo-grid {
        grid-template-columns: 1fr;
    }

    .photo-card img { height: 200px; }
}
