/* PhotoStream — single stylesheet, mobile-first, dark by default */

:root {
    --bg:           #0f1115;
    --bg-elev:     #161a21;
    --bg-card:     #1b2029;
    --border:      #262c36;
    --text:        #e7e9ee;
    --text-dim:    #9aa3b2;
    --accent:      #4f8cff;
    --accent-hov:  #6ea0ff;
    --danger:      #ff5b6b;
    --radius:      12px;
    --shadow:      0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
    --max-w:       720px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.55;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

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

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

/* --- Layout ------------------------------------------------------------- */
.container {
    width: 100%;
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 16px;
    flex: 1;
}
.container-narrow { max-width: 520px; }

.topbar {
    position: sticky; top: 0; z-index: 10;
    background: rgba(15,17,21,.85);
    backdrop-filter: saturate(140%) blur(12px);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 10px 16px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
}
.brand {
    font-weight: 700;
    font-size: 18px;
    color: var(--text);
    letter-spacing: .2px;
}
.topbar-actions {
    display: flex; align-items: center; gap: 8px;
}

.footer {
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    padding: 24px 16px 32px;
}

.meta-count {
    color: var(--text-dim);
    font-size: 13px;
    margin: 4px 2px 16px;
}

/* --- Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 14px;
    border-radius: 10px;
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s ease, border-color .15s ease, transform .05s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: #20262f; }
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}
.btn-primary:hover { background: var(--accent-hov); color: #fff; }
.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-dim);
}
.btn-ghost:hover { color: var(--text); background: var(--bg-elev); }
.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: rgba(255, 91, 107, .35);
}
.btn-danger:hover {
    background: rgba(255, 91, 107, .12);
    color: var(--danger);
}
.btn-block { width: 100%; padding: 12px 16px; font-size: 16px; }
.inline { display: inline; margin: 0; }

/* Compact New post button on narrow viewports — show a + icon only. */
.btn-new-post .btn-icon { display: none; }
@media (max-width: 479px) {
    .btn-new-post { padding: 8px 12px; min-width: 40px; }
    .btn-new-post .btn-text  { display: none; }
    .btn-new-post .btn-icon  {
        display: inline-block;
        font-size: 22px;
        line-height: 1;
        font-weight: 600;
    }
}

/* Back link in topbar: single ‹ character, compact on every viewport. */
.btn-back {
    padding: 8px 12px;
    min-width: 40px;
    font-size: 18px;
    line-height: 1;
}

/* --- Feed cards --------------------------------------------------------- */
.feed {
    list-style: none;
    margin: 0; padding: 0;
    display: grid;
    gap: 16px;
}
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.card-image {
    display: block;
    background: #000;
}
.card-image img {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}
.card-single .card-image-full {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    background: #000;
    display: block;
}
.card-single .card-video-full {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    background: #000;
    display: block;
    border-radius: 8px;
}
.card-caption {
    padding: 12px 14px 4px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 15px;
}
.card-location {
    padding: 2px 14px 6px;
    color: var(--text-dim);
    font-size: 13px;
    display: flex; align-items: flex-start; gap: 6px;
    line-height: 1.4;
}
.meta-loc {
    display: inline-flex; align-items: center; gap: 4px;
    color: var(--text-dim);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.location-pin {
    flex-shrink: 0;
    font-size: 12px;
    line-height: 1.4;
}
.meta-loc-link {
    text-decoration: none;
    cursor: pointer;
}
.meta-loc-link:hover {
    color: var(--text);
    text-decoration: underline;
}

/* Owner-only controls shown on the single-post view */
.post-actions {
    padding: 8px 14px 14px;
    display: flex; gap: 8px; align-items: center;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}
.post-actions .btn-danger { margin-left: auto; }

/* Inline edit form (replaces card-caption when ?edit=1) */
.edit-form {
    padding: 14px;
    display: grid; gap: 12px;
}
.edit-form textarea {
    width: 100%;
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    outline: none;
    resize: vertical;
    min-height: 80px;
}
.edit-form textarea:focus { border-color: var(--accent); }
.edit-actions {
    display: flex; gap: 8px; align-items: center;
}
.card-meta {
    padding: 6px 14px 12px;
    color: var(--text-dim);
    font-size: 13px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.meta-sep { opacity: .5; }
.meta-abs { font-variant-numeric: tabular-nums; }

/* --- Pagination --------------------------------------------------------- */
.pagination {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    margin: 24px 0 8px;
    flex-wrap: wrap;
}
.page-status {
    color: var(--text-dim);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

/* --- Empty state -------------------------------------------------------- */
.empty {
    text-align: center;
    color: var(--text-dim);
    padding: 60px 16px;
}
.empty p { margin: 0 0 16px; }

/* --- Forms -------------------------------------------------------------- */
h1 {
    font-size: 22px;
    margin: 16px 0 12px;
}
.muted { color: var(--text-dim); }
.muted small { font-size: 12px; }

.form {
    display: grid; gap: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; color: var(--text-dim); }
.field input[type=text],
.field input[type=password],
.field input[type=file],
.field textarea {
    width: 100%;
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    outline: none;
    transition: border-color .15s ease;
}
.field input:focus,
.field textarea:focus {
    border-color: var(--accent);
}
.field textarea { resize: vertical; min-height: 80px; }
.field input[type=file] { padding: 8px; }
.field small { color: var(--text-dim); font-size: 12px; }

/* Image preview before submit */
.preview {
    border: 1px dashed var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: #000;
    max-height: 320px;
    display: flex; align-items: center; justify-content: center;
    position: relative;
}
.preview img { max-height: 320px; width: auto; margin: 0 auto; }
.preview-duration {
    position: absolute;
    right: 8px; bottom: 8px;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(0,0,0,.7);
    color: #fff;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

/* Photo/Video segmented tabs on the new-post form */
.kind-tabs {
    display: flex;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    gap: 4px;
}
.kind-tab {
    flex: 1;
    padding: 8px 12px;
    background: transparent;
    border: 0;
    color: var(--text-dim);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    border-radius: 7px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.kind-tab.active {
    background: var(--accent);
    color: #fff;
}

/* Video card variants in feed */
.card-image-video { position: relative; }
.card-image-video video {
    width: 100%; height: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    display: block;
}
.play-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 56px; height: 56px;
    border-radius: 50%;
    background: rgba(0,0,0,.55);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    padding-left: 4px;
    pointer-events: none;
    backdrop-filter: blur(2px);
}
.duration-badge {
    position: absolute;
    right: 8px; bottom: 8px;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(0,0,0,.7);
    color: #fff;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}
.meta-duration { color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* Client-side file size hint under the input */
.size-hint {
    display: inline-block;
    margin-top: 4px;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
.size-hint:empty { display: none; }
.size-hint.size-ok   { color: var(--text-dim); }
.size-hint.size-warn { color: #e3b15a; }
.size-hint.size-err  { color: var(--danger); font-weight: 500; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* --- Flash messages ----------------------------------------------------- */
.flash {
    padding: 10px 14px;
    border-radius: 10px;
    margin-bottom: 14px;
    font-size: 14px;
}
.flash-ok  { background: rgba(80, 180, 120, .15); color: #6fd999; border: 1px solid rgba(80,180,120,.3); }
.flash-err { background: rgba(255, 91, 107, .12); color: #ff8b96; border: 1px solid rgba(255,91,107,.3); }

/* --- Lightbox ----------------------------------------------------------- */
.lightbox {
    position: fixed; inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, .88);
    display: none;
    align-items: center; justify-content: center;
    padding: 16px;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}
.lightbox.open { display: flex; }
.lightbox-stage {
    position: relative;
    max-width: min(100%, 1100px);
    max-height: calc(100vh - 32px);
    display: flex; flex-direction: column;
    align-items: center; gap: 10px;
}
.lightbox-media {
    max-width: 100%;
    max-height: calc(100vh - 140px);
    object-fit: contain;
    border-radius: 8px;
    background: #000;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.lightbox-caption {
    color: #e7e9ee;
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
    max-width: 720px;
    max-height: 80px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.lightbox-caption:empty { display: none; }
.lightbox-location {
    color: #9aa3b2;
    font-size: 13px;
    display: flex; align-items: center; gap: 6px;
}
.lightbox-actions {
    display: flex; gap: 8px; align-items: center;
    margin-top: 4px;
}
.lightbox-close {
    position: fixed;
    top: 14px; right: 14px;
    width: 40px; height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,.2);
    background: rgba(0,0,0,.5);
    color: #fff;
    font-size: 22px; line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
.lightbox-close:hover { background: rgba(0,0,0,.75); }

body.lightbox-open { overflow: hidden; }

/* Clickable feed image keeps the same affordance as before, but is now a
   <button> so it stays accessible (keyboard, no accidental full-page nav). */
.card-image-button {
    display: block;
    width: 100%;
    background: #000;
    border: 0;
    padding: 0;
    margin: 0;
    cursor: zoom-in;
    -webkit-tap-highlight-color: transparent;
    text-align: left;
    color: inherit;
    font: inherit;
}
.card-image-button img,
.card-image-button video {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    display: block;
}
.card-image-button.card-image-video { position: relative; }
.card-image-button.card-image-video video {
    width: 100%; height: 100%;
}
.card-image-button .play-overlay,
.card-image-button .duration-badge { pointer-events: none; }

/* Small "open details" affordance for the owner on each card */
.card-open-link {
    display: inline-flex;
    align-items: center;
    margin-left: auto;
    font-size: 13px;
    color: var(--text-dim);
}
.card-open-link:hover { color: var(--text); }

/* --- Larger screens ----------------------------------------------------- */
@media (min-width: 720px) {
    body { font-size: 17px; }
    .container { padding: 24px; }
    .card-image img { aspect-ratio: 16 / 10; }
    .card-caption { padding: 16px 18px 6px; font-size: 16px; }
    .card-meta { padding: 8px 18px 14px; }
    .topbar-inner { padding: 12px 24px; }
}

/* Respect users who prefer light mode */
@media (prefers-color-scheme: light) {
    :root {
        --bg:          #f6f7f9;
        --bg-elev:    #ffffff;
        --bg-card:    #ffffff;
        --border:     #e3e6eb;
        --text:       #1a1f2b;
        --text-dim:   #5d6678;
        --shadow:     0 1px 2px rgba(0,0,0,.05), 0 6px 16px rgba(0,0,0,.05);
    }
    .topbar { background: rgba(246,247,249,.85); }
    .card-image { background: #e9ecf1; }
    .btn:hover { background: #f0f2f5; }
}