:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --ink: #1c2430;
  --ink-soft: #5b6878;
  --line: #e3e8ee;
  --accent: #1f3a5f;
  --accent-ink: #ffffff;
  --danger: #b3362b;
  --radius: 14px;
  --pad: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

/* The hidden attribute only applies UA-default display:none, which any
   author display rule (e.g. .lightbox { display:flex }) would override. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--accent);
  color: var(--accent-ink);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.topbar h1 { font-size: 1.15rem; margin: 0; font-weight: 700; letter-spacing: .3px; }
.topbar-btn {
  text-decoration: none;
  font-size: 1.25rem;
  line-height: 1;
  padding: 6px;
  border-radius: 8px;
}
.topbar-btn:active { background: rgba(255,255,255,.15); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-switch {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.12);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 6px 26px 6px 12px;
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='white' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.user-switch option { color: var(--ink); }

/* ---- Album bar ---- */
.album-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 12px;
  background: var(--bg);
  scrollbar-width: none;
}
.album-bar::-webkit-scrollbar { display: none; }
.album-chip {
  flex: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: .87rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.album-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.album-tag {
  border: 0;
  background: var(--bg);
  color: var(--accent);
  font-size: .74rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: 6px;
  cursor: pointer;
}
.album-select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font: inherit;
  font-size: .88rem;
  background: var(--bg);
  max-width: 46vw;
}

/* ---- Feed ---- */
#feed {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 0 110px;
}
.feed-status {
  text-align: center;
  color: var(--ink-soft);
  padding: 24px 16px 120px;
  font-size: .95rem;
}

.post {
  background: var(--card);
  border-radius: var(--radius);
  margin: 0 10px 14px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
  overflow: hidden;
}
.post-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--pad) var(--pad) 6px;
}
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: none;
}
.post-meta { flex: 1; min-width: 0; }
.post-author { font-weight: 650; font-size: .97rem; }
.post-time { color: var(--ink-soft); font-size: .8rem; }
.menu-btn {
  border: 0;
  background: none;
  font-size: 1.3rem;
  color: var(--ink-soft);
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.menu-btn:active { background: var(--line); }

.menu {
  position: absolute;
  right: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(16,24,40,.15);
  z-index: 30;
  overflow: hidden;
  min-width: 130px;
}
.menu button {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  padding: 11px 16px;
  font-size: .95rem;
  cursor: pointer;
}
.menu button:active { background: var(--bg); }
.menu .danger { color: var(--danger); }

.post-body {
  padding: 4px var(--pad) 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 1rem;
  line-height: 1.45;
}
.post-body:empty { display: none; }
.edited-tag { color: var(--ink-soft); font-size: .75rem; margin-left: 6px; }

.edit-area { padding: 4px var(--pad) 10px; }
.edit-area textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font: inherit;
  resize: vertical;
  min-height: 70px;
}
.edit-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.edit-area .album-select { margin-top: 8px; }
.edit-captions { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.edit-caption-row { display: flex; gap: 8px; align-items: center; }
.edit-caption-row img {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: 8px;
  flex: none;
}
.edit-caption-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: .85rem;
  min-width: 0;
}

/* ---- Photos ---- */
.photo-single img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 75vh;
  object-fit: contain;
  background: #0b1220;
  cursor: pointer;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
}
.photo-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.photo-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  cursor: pointer;
}
.video-single video {
  display: block;
  width: 100%;
  max-height: 75vh;
  background: #0b1220;
}
.media-caption {
  padding: 8px var(--pad) 2px;
  color: var(--ink-soft);
  font-size: .88rem;
  font-style: italic;
}
.video-tile { position: relative; }
.video-tile::after {
  content: '▶';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1.6rem;
  text-shadow: 0 1px 8px rgba(0,0,0,.7);
  pointer-events: none;
}
.photo-more {
  position: relative;
}
.photo-more::after {
  content: attr(data-more);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(12, 18, 28, .55);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  pointer-events: none;
}

/* ---- Reactions ---- */
.reactions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  padding: 8px var(--pad) 12px;
}
.react-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: .95rem;
  line-height: 1;
  cursor: pointer;
}
.react-chip:active { transform: scale(.92); }
.react-chip .cnt { font-size: .8rem; font-weight: 700; color: var(--ink-soft); }
.react-chip.mine {
  background: #e7eefb;
  border-color: var(--accent);
}
.react-chip.mine .cnt { color: var(--accent); }
.reactions-sm { padding: 6px 0 0; gap: 5px; }
.reactions-sm .react-chip { padding: 3px 8px; font-size: .8rem; background: var(--card); }

/* ---- "Seen on last visit" divider ---- */
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-soft);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 2px 18px 14px;
}
.divider::before, .divider::after {
  content: '';
  height: 1px;
  background: var(--line);
  flex: 1;
}

/* ---- Language toggle ---- */
.lang-btn {
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.12);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
}
.lang-btn:active { background: rgba(255,255,255,.25); }

/* ---- Comments ---- */
.comments { border-top: 1px solid var(--line); padding: 8px var(--pad) 12px; }
.comment { display: flex; gap: 9px; padding: 6px 0; }
.comment .avatar { width: 28px; height: 28px; font-size: .8rem; }
.comment-bubble {
  background: var(--bg);
  border-radius: 12px;
  padding: 7px 11px;
  flex: 1;
  min-width: 0;
}
.comment-author { font-weight: 650; font-size: .85rem; }
.comment-body { font-size: .93rem; white-space: pre-wrap; word-wrap: break-word; }
.comment-foot { color: var(--ink-soft); font-size: .74rem; margin-top: 2px; }
.comment-foot button {
  border: 0; background: none; color: var(--ink-soft);
  font-size: .74rem; padding: 0; margin-left: 10px; cursor: pointer;
}

.comment-form { display: flex; gap: 8px; margin-top: 8px; }
.comment-form input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  font: inherit;
  font-size: .93rem;
  background: var(--bg);
}
.comment-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.comment-form button {
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  width: 40px;
  font-size: 1rem;
  cursor: pointer;
  flex: none;
}
.comment-form button:disabled { opacity: .5; }

/* ---- FAB ---- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.9rem;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(31, 58, 95, .45);
  cursor: pointer;
  z-index: 25;
}
.fab:active { transform: scale(.94); }

/* ---- Compose sheet ---- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 25, .45);
  z-index: 40;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 14px);
  box-shadow: 0 -8px 30px rgba(16,24,40,.25);
  max-width: 640px;
  margin: 0 auto;
}
.sheet-handle {
  width: 42px; height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 4px auto 10px;
}
.sheet textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  font-size: 1rem;
  resize: none;
  min-height: 84px;
}
.sheet textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.previews {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 2px;
}
.previews:empty { display: none; }
.preview {
  position: relative;
  flex: none;
}
.preview { width: 96px; }
.preview img, .preview video {
  width: 96px; height: 76px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  background: #0b1220;
}
.preview-video::before {
  content: '🎬';
  position: absolute;
  top: 4px; left: 6px;
  font-size: .8rem;
  z-index: 1;
}
.caption-input {
  width: 100%;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 7px;
  font: inherit;
  font-size: .75rem;
}
.preview button {
  position: absolute;
  top: -6px; right: -6px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 0;
  background: var(--ink);
  color: #fff;
  font-size: .7rem;
  line-height: 1;
  cursor: pointer;
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.spacer { flex: 1; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 18px;
  font: inherit;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-block;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:disabled { opacity: .55; }
.btn-secondary { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.btn-ghost { background: none; color: var(--ink-soft); }
.btn-danger { background: var(--danger); color: #fff; }

/* ---- Lightbox ---- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(5, 8, 14, .96);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox img, .lightbox video {
  max-width: 100vw;
  max-height: 100dvh;
  object-fit: contain;
}
.lightbox video { width: 100vw; }
.lightbox-download {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 10px);
  right: 64px;
  z-index: 61;
  background: rgba(255,255,255,.12);
  border: 0;
  color: #fff;
  font-size: 1.1rem;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  text-decoration: none;
}
.lightbox-caption {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 40px);
  left: 16px; right: 16px;
  text-align: center;
  color: #fff;
  font-size: .95rem;
  text-shadow: 0 1px 6px rgba(0,0,0,.8);
}
.lightbox-caption:empty { display: none; }
.lightbox-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 10px);
  right: 14px;
  z-index: 61;
  background: rgba(255,255,255,.12);
  border: 0;
  color: #fff;
  font-size: 1.1rem;
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 61;
  background: rgba(255,255,255,.12);
  border: 0;
  color: #fff;
  font-size: 1.8rem;
  width: 44px; height: 44px;
  border-radius: 50%;
  cursor: pointer;
}
.lightbox-prev { left: 10px; }
.lightbox-next { right: 10px; }
.lightbox-count {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  left: 0; right: 0;
  text-align: center;
  color: rgba(255,255,255,.8);
  font-size: .85rem;
}

/* ---- Admin page ---- */
.admin-wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 12px 60px;
}
.admin-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
.admin-card h2 { margin: 0 0 6px; font-size: 1.05rem; }
.admin-note { color: var(--ink-soft); font-size: .88rem; margin: 0 0 12px; }
.email-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: .95rem;
  word-break: break-all;
}
.email-row:last-child { border-bottom: 0; }
.email-row .btn { padding: 6px 12px; font-size: .85rem; }
.add-email-form { display: flex; gap: 8px; margin-top: 4px; }
.pref-select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: .88rem;
  background: var(--bg);
  flex: none;
}
.add-email-form input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: .95rem;
  min-width: 0;
}

.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 90px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 70;
  max-width: 88vw;
  text-align: center;
}

@media (min-width: 700px) {
  .post { margin-left: 0; margin-right: 0; }
}
