:root {
    --bg: #09090b;
    --bg-soft: #111114;
    --card: #17171c;
    --card-hover: #1f1f26;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);

    --text: #f5f5f7;
    --muted: #a1a1aa;
    --muted-2: #71717a;

    --primary: #f43f5e;
    --primary-hover: #fb7185;

    --danger: #ef4444;
    --danger-hover: #f87171;

    --success-bg: rgba(34, 197, 94, 0.12);
    --success-text: #86efac;

    --error-bg: rgba(239, 68, 68, 0.12);
    --error-text: #fca5a5;

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;

    --shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
}

/* -----------------------------
   Base
----------------------------- */

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100%;
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(244, 63, 94, 0.14), transparent 34rem),
        radial-gradient(circle at top right, rgba(99, 102, 241, 0.12), transparent 30rem),
        var(--bg);
    color: var(--text);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
    display: block;
}

button,
input,
select,
textarea {
    font: inherit;
}

/* -----------------------------
   Buttons
----------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 42px;
    padding: 0.65rem 1rem;
    border: 1px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.92rem;
    transition:
        transform 160ms ease,
        background-color 160ms ease,
        border-color 160ms ease,
        color 160ms ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-strong);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fecaca;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
}

.btn-small {
    min-height: 34px;
    padding: 0.45rem 0.72rem;
    font-size: 0.82rem;
}

/* -----------------------------
   Alerts
----------------------------- */

.alert {
    width: min(1120px, calc(100% - 2rem));
    margin: 1rem auto;
    padding: 0.9rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    font-size: 0.94rem;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: rgba(34, 197, 94, 0.24);
}

.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: rgba(239, 68, 68, 0.24);
}

/* -----------------------------
   Login Page
----------------------------- */

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-container {
    width: min(430px, 100%);
}

.auth-card {
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
        var(--card);
    box-shadow: var(--shadow);
}

.auth-logo {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    margin-bottom: 1.2rem;
    border-radius: 50%;
    background: rgba(244, 63, 94, 0.16);
    color: var(--primary-hover);
    font-size: 1.45rem;
}

.auth-card h1 {
    margin: 0;
    font-size: clamp(1.8rem, 5vw, 2.35rem);
    letter-spacing: -0.05em;
}

.auth-subtitle {
    margin: 0.35rem 0 1.6rem;
    color: var(--muted);
}

.auth-form {
    display: grid;
    gap: 0.85rem;
}

.auth-form label {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text);
}

.auth-form input {
    width: 100%;
    min-height: 48px;
    padding: 0.8rem 0.95rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    outline: none;
    background: rgba(255, 255, 255, 0.055);
    color: var(--text);
}

.auth-form input:focus {
    border-color: rgba(244, 63, 94, 0.65);
    box-shadow: 0 0 0 4px rgba(244, 63, 94, 0.13);
}

/* -----------------------------
   Topbar
----------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem clamp(1rem, 4vw, 2rem);
    background: rgba(9, 9, 11, 0.78);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(18px);
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 900;
    letter-spacing: -0.04em;
    font-size: 1.1rem;
}

.brand-mark {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(244, 63, 94, 0.16);
    color: var(--primary-hover);
}

.topnav {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

/* -----------------------------
   Page
----------------------------- */

.page {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 1.3rem clamp(1rem, 4vw, 2rem) 4rem;
}

.hero {
    width: min(1120px, 100%);
    margin: 1.5rem auto 1rem;
}

.hero h1 {
    max-width: 760px;
    margin: 0;
    font-size: clamp(2.15rem, 7vw, 5rem);
    line-height: 0.95;
    letter-spacing: -0.08em;
}

.hero p {
    max-width: 620px;
    margin: 1rem 0 0;
    color: var(--muted);
    font-size: 1.08rem;
}

/* -----------------------------
   Board Filter
----------------------------- */

.board-filter {
    width: min(1120px, 100%);
    margin: 1.4rem auto 1.5rem;
    display: flex;
    gap: 0.55rem;
    overflow-x: auto;
    padding-bottom: 0.2rem;
}

.chip {
    flex: 0 0 auto;
    padding: 0.55rem 0.88rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.045);
    color: var(--muted);
    font-weight: 700;
    font-size: 0.88rem;
    transition:
        background-color 160ms ease,
        color 160ms ease,
        border-color 160ms ease;
}

.chip:hover,
.chip.active {
    background: rgba(244, 63, 94, 0.14);
    color: white;
    border-color: rgba(244, 63, 94, 0.32);
}

/* -----------------------------
   Masonry Feed
----------------------------- */

.masonry-feed {
    width: min(1440px, 100%);
    margin: 0 auto;
    column-count: 5;
    column-gap: 1rem;
}

.pin-card {
    display: inline-block;
    width: 100%;
    margin: 0 0 1rem;
    break-inside: avoid;
    overflow: hidden;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--card);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
    transition:
        transform 180ms ease,
        background-color 180ms ease,
        border-color 180ms ease;
}

.pin-card:hover {
    transform: translateY(-2px);
    background: var(--card-hover);
    border-color: var(--border-strong);
}

.pin-image-wrap {
    background: rgba(255, 255, 255, 0.03);
}

.pin-image {
    width: 100%;
    height: auto;
    object-fit: cover;
}

.pin-content {
    padding: 0.85rem;
}

.pin-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-bottom: 0.85rem;
}

.pin-board {
    max-width: 65%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: white;
    font-weight: 800;
    font-size: 0.92rem;
}

.pin-date {
    color: var(--muted-2);
    font-size: 0.78rem;
}

.pin-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.inline-form {
    display: inline;
    margin: 0;
}

/* -----------------------------
   Upload Page
----------------------------- */

.upload-wrap {
    width: min(680px, 100%);
    margin: 1.5rem auto 4rem;
}

.upload-card {
    padding: clamp(1.2rem, 4vw, 2rem);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.025)),
        var(--card);
    box-shadow: var(--shadow);
}

.upload-card h1 {
    margin: 0;
    font-size: clamp(2rem, 7vw, 3.4rem);
    line-height: 0.95;
    letter-spacing: -0.07em;
}

.upload-card p {
    color: var(--muted);
}

.upload-form {
    display: grid;
    gap: 1rem;
    margin-top: 1.3rem;
}

.form-group {
    display: grid;
    gap: 0.45rem;
}

.form-group label {
    font-weight: 800;
    font-size: 0.92rem;
}

.form-group small {
    color: var(--muted-2);
}

.form-input {
    width: 100%;
    min-height: 48px;
    padding: 0.85rem 0.95rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    outline: none;
    background: rgba(255, 255, 255, 0.055);
    color: var(--text);
}

.form-input:focus {
    border-color: rgba(244, 63, 94, 0.65);
    box-shadow: 0 0 0 4px rgba(244, 63, 94, 0.13);
}

.file-input {
    padding: 0.9rem;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted);
}

.preview {
    display: none;
    overflow: hidden;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
}

.preview.active {
    display: block;
}

.preview img {
    width: 100%;
    max-height: 420px;
    object-fit: contain;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    flex-wrap: wrap;
    margin-top: 0.4rem;
}

/* -----------------------------
   Empty State
----------------------------- */

.empty-state {
    width: min(680px, calc(100% - 2rem));
    margin: 3rem auto;
    padding: 2rem;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.035);
}

.empty-icon {
    margin: 0 auto 1rem;
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(244, 63, 94, 0.14);
    color: var(--primary-hover);
    font-size: 1.4rem;
}

.empty-state h2 {
    margin: 0;
    letter-spacing: -0.04em;
}

.empty-state p {
    margin: 0.6rem 0 1.25rem;
    color: var(--muted);
}

/* -----------------------------
   Responsive
----------------------------- */

@media (max-width: 1200px) {
    .masonry-feed {
        column-count: 4;
    }
}

@media (max-width: 900px) {
    .masonry-feed {
        column-count: 3;
    }
}

@media (max-width: 680px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topnav {
        width: 100%;
    }

    .topnav .btn {
        flex: 1;
    }

    .masonry-feed {
        column-count: 2;
        column-gap: 0.8rem;
    }

    .pin-card {
        margin-bottom: 0.8rem;
        border-radius: 18px;
    }

    .pin-content {
        padding: 0.7rem;
    }

    .pin-actions .btn {
        flex: 1;
    }
}

@media (max-width: 420px) {
    .masonry-feed {
        column-count: 1;
    }

    .hero h1 {
        font-size: 2.3rem;
    }

    .auth-card {
        padding: 1.35rem;
    }
}

/* -----------------------------
   Search Tools
----------------------------- */

.feed-tools {
    width: min(1120px, 100%);
    margin: 1.3rem auto 0.6rem;
}

.search-form {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.045);
}

.search-input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 0.7rem 1rem;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text);
}

.search-input::placeholder {
    color: var(--muted-2);
}

.result-summary {
    width: min(1120px, 100%);
    margin: -0.35rem auto 1.2rem;
    color: var(--muted);
    font-size: 0.93rem;
}

.result-summary strong {
    color: var(--text);
}

/* -----------------------------
   Clickable Pin Image
----------------------------- */

.pin-image-button {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    cursor: zoom-in;
    background: rgba(255, 255, 255, 0.03);
    overflow: hidden;
}

.pin-image-button .pin-image {
    transition:
        transform 240ms ease,
        filter 240ms ease;
}

.pin-image-button:hover .pin-image {
    transform: scale(1.035);
    filter: brightness(1.05);
}

/* -----------------------------
   Image Preview Modal
----------------------------- */

body.modal-open {
    overflow: hidden;
}

.image-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    place-items: center;
    padding: 1.2rem;
}

.image-modal.is-open {
    display: grid;
}

.image-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(14px);
}

.image-modal-card {
    position: relative;
    z-index: 1;
    width: min(1100px, 100%);
    max-height: min(86vh, 900px);
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
    border-radius: 28px;
    border: 1px solid var(--border-strong);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.025)),
        var(--card);
    box-shadow: 0 30px 100px rgba(0, 0, 0, 0.62);
}

.modal-close {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    z-index: 2;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.48);
    color: white;
    font-size: 1.55rem;
    line-height: 1;
    transition:
        background-color 160ms ease,
        transform 160ms ease;
}

.modal-close:hover {
    transform: scale(1.04);
    background: rgba(244, 63, 94, 0.78);
}

.modal-image-wrap {
    min-height: 0;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.28);
}

.modal-image-wrap img {
    max-width: 100%;
    max-height: 72vh;
    object-fit: contain;
}

.modal-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.modal-info h2 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: -0.03em;
}

.modal-info p {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.86rem;
}

/* -----------------------------
   Search + Modal Responsive
----------------------------- */

@media (max-width: 680px) {
    .search-form {
        align-items: stretch;
        flex-direction: column;
        border-radius: var(--radius-lg);
    }

    .search-input {
        width: 100%;
        text-align: center;
    }

    .search-form .btn {
        width: 100%;
    }

    .image-modal {
        padding: 0.7rem;
    }

    .image-modal-card {
        max-height: 90vh;
        border-radius: 22px;
    }

    .modal-info {
        align-items: stretch;
        flex-direction: column;
    }

    .modal-info .btn {
        width: 100%;
    }
}

/* -----------------------------
   Modal Emergency Fix
   Forces modal to stay closed unless JS adds .is-open
----------------------------- */

.image-modal {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

.image-modal.is-open {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid !important;
    place-items: center;
    padding: 1.2rem;
    opacity: 1;
    pointer-events: auto;
}

.image-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.74);
    backdrop-filter: blur(14px);
}

.image-modal-card {
    position: relative;
    z-index: 2;
    width: min(980px, calc(100vw - 2rem));
    max-height: 88vh;
    display: grid;
    grid-template-rows: minmax(260px, 1fr) auto;
    overflow: hidden;
    border-radius: 28px;
    border: 1px solid var(--border-strong);
    background: var(--card);
    box-shadow: 0 30px 100px rgba(0, 0, 0, 0.65);
}

.modal-image-wrap {
    min-height: 260px;
    max-height: 72vh;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.35);
}

.modal-image-wrap img {
    max-width: 100%;
    max-height: 72vh;
    object-fit: contain;
}

.modal-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
    background: rgba(23, 23, 28, 0.96);
}

.modal-info h2 {
    margin: 0;
    font-size: 1rem;
}

.modal-info p {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.modal-close {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    z-index: 5;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.68);
    color: white;
    font-size: 1.6rem;
    line-height: 1;
}

.modal-close:hover {
    background: var(--primary);
}

body.modal-open {
    overflow: hidden;
}

@media (max-width: 680px) {
    .image-modal.is-open {
        padding: 0.7rem;
    }

    .image-modal-card {
        width: 100%;
        max-height: 90vh;
        grid-template-rows: minmax(220px, 1fr) auto;
        border-radius: 22px;
    }

    .modal-info {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-info .btn {
        width: 100%;
    }
}