
:root {
  --bg: #f6f4ef; --surface: #ffffff; --text: #1d1d1b; --muted: #6b6a65;
  --line: #e4e1d8; --accent: #2f6f5e; --accent-text: #ffffff; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151614; --surface: #1f201d; --text: #ecebe6; --muted: #9a998f; --line: #2e2f2b; --accent: #5fb39b; --accent-text: #0e1a16; --shadow: 0 1px 2px rgba(0,0,0,.4); }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
header { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.bar { max-width: 1200px; margin: 0 auto; padding: 14px 16px; display: flex; align-items: center; gap: 16px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand span { color: var(--accent); }
.search { flex: 1; max-width: 360px; margin-left: auto; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
.btn { border: 0; border-radius: 8px; padding: 10px 16px; font: 600 14px system-ui, sans-serif; cursor: pointer; background: var(--accent); color: var(--accent-text); white-space: nowrap; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
h1 { font-size: 28px; margin: 0 0 4px; letter-spacing: -.02em; }
.sub { color: var(--muted); margin: 0 0 24px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.card { background: var(--surface); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); cursor: pointer; transition: transform .15s; }
.card:hover { transform: translateY(-2px); }
.cover { aspect-ratio: 4/3; background: var(--line) center/cover; position: relative; }
.count { position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 3px 8px; border-radius: 99px; }
.card .body { padding: 14px 16px 16px; }
.card h3 { margin: 0 0 2px; font-size: 17px; }
.meta { color: var(--muted); font-size: 13px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }

/* detail view */
#detail { display: none; }
.back { margin-bottom: 16px; }
.hero { border-radius: 14px; aspect-ratio: 21/8; background: var(--line) center/cover; margin-bottom: 20px; }
.detail-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; }
.desc { max-width: 720px; margin: 12px 0 24px; }
.photos { columns: 3 260px; column-gap: 12px; }
.photos img { width: 100%; border-radius: 8px; margin-bottom: 12px; display: block; break-inside: avoid; cursor: zoom-in; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; padding: 24px; }
.modal h2 { margin: 0 0 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
input, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
textarea { min-height: 90px; resize: vertical; }
.drop { margin-top: 16px; border: 2px dashed var(--line); border-radius: 10px; padding: 28px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.hover { border-color: var(--accent); color: var(--accent); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 12px; }
.thumbs div { aspect-ratio: 1; background: center/cover; border-radius: 6px; position: relative; }
.thumbs div.is-cover::after { content: "Cover"; position: absolute; left: 4px; top: 4px; font-size: 10px; background: var(--accent); color: var(--accent-text); padding: 1px 5px; border-radius: 4px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 16px; display: none; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: none; align-items: center; justify-content: center; z-index: 30; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 6px; }
#login { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 16px; }
#login form { background: var(--surface); box-shadow: var(--shadow); border-radius: 14px; padding: 32px 28px; width: 100%; max-width: 360px; }
#login .brand { font-size: 24px; text-align: center; margin-bottom: 4px; }
#login .meta { text-align: center; margin-bottom: 12px; }
#login .btn { width: 100%; margin-top: 20px; }
#loginErr { color: crimson; font-size: 13px; min-height: 18px; margin-top: 8px; }
.short { display: none; }
.fab { display: none; }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  .long { display: none; }
  .short { display: inline; }
  body { font-size: 16px; }
  .bar { flex-wrap: wrap; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); gap: 10px; }
  .brand { flex: 1; }
  #openUpload { display: none; }
  #logout { padding: 8px 12px; }
  .search { display: block !important; order: 3; flex-basis: 100%; max-width: none; margin: 0; }
  main { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 24px; }
  .sub { margin-bottom: 16px; }
  .grid { grid-template-columns: 1fr; gap: 14px; }
  .card:hover { transform: none; }
  .cover { aspect-ratio: 16/10; }
  .hero { aspect-ratio: 4/3; border-radius: 10px; margin: 0 -16px 16px; border-radius: 0; }
  .detail-head { flex-direction: column; }
  .photos { columns: 2; column-gap: 6px; }
  .photos img { margin-bottom: 6px; border-radius: 4px; }
  .btn { min-height: 44px; }
  input, textarea { font-size: 16px; min-height: 44px; } /* stops iOS zoom-on-focus */
  .fab { display: flex; align-items: center; justify-content: center; position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
    width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); font-size: 30px;
    box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 10; cursor: pointer; }
  /* upload form becomes a bottom sheet */
  .overlay { align-items: flex-end; padding: 0; }
  .modal { max-width: none; max-height: 94vh; border-radius: 16px 16px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .22s ease-out; }
  .modal::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 12px; }
  .modal h2 { font-size: 20px; }
  .drop { padding: 22px; }
  .thumbs { grid-template-columns: repeat(4, 1fr); }
  .actions { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); background: var(--surface); padding: 12px 0 4px; margin-top: 12px; }
  .actions .btn { flex: 1; }
  #login form { padding: 28px 20px; }
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.15); color: #fff; border: 0; width: 48px; height: 48px; border-radius: 50%; font-size: 22px; cursor: pointer; }
.lightbox .prev { left: 12px; } .lightbox .next { right: 12px; }
.lightbox .pos { position: absolute; bottom: calc(16px + env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; color: #ddd; font-size: 13px; }
@media (max-width: 640px) { .lightbox .nav { display: none; } .lightbox img { max-width: 100vw; border-radius: 0; } }
.note { margin-top: 40px; font-size: 12px; color: var(--muted); text-align: center; }

#login { position: static; min-height: 100vh; min-height: 100dvh; }
.empty { text-align: center; padding: 60px 16px; color: var(--muted); border: 2px dashed var(--line); border-radius: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 60; max-width: calc(100vw - 32px); display: none; }
.progress-label { font-size: 12px; color: var(--muted); margin-top: 6px; min-height: 16px; }
.btn:disabled { opacity: .5; cursor: default; }
.photos img { background: var(--line); }

.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.danger { color: #c0392b; border-color: color-mix(in srgb, #c0392b 40%, var(--line)); }
.lb-del { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 8px; padding: 10px 14px; font: 600 14px system-ui, sans-serif; cursor: pointer; z-index: 1; }
.lb-del:hover { background: #c0392b; }
@media (max-width: 640px) { .detail-actions { width: 100%; } .detail-actions .btn { flex: 1; } }
