/* Moments design system */
:root {
  --bg: #09090b;
  --surface: #121215;
  --surface-2: #1a1a20;
  --border: #26262c;
  --text: #f4f3f0;
  --muted: #9b98a3;
  --accent: #d9a066;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, textarea, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
img, video { display: block; }

.logo { font-weight: 700; letter-spacing: .02em; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: rgba(9, 9, 11, .8);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.logo-lg { font-size: 1.35rem; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.count { font-size: .85rem; color: var(--muted); }

.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  color: var(--muted); transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .5; pointer-events: none; }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Buttons & inputs ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-md);
  font-size: .92rem; font-weight: 600;
  transition: background .15s, color .15s, filter .15s;
}
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); color: #171008; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 11px 14px; color: var(--text);
  font-size: .95rem; outline: none; transition: border-color .15s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--muted); }
textarea.input { resize: vertical; line-height: 1.5; }

/* ---- Feed (Instagram-style grid) ---- */
main { max-width: 1240px; margin: 0 auto; padding-bottom: 48px; }
.feed { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.tile {
  position: relative; aspect-ratio: 1; overflow: hidden; padding: 0;
  background: var(--surface-2);
}
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; transition: transform .25s ease; }
.tile:hover img, .tile:hover video { transform: scale(1.04); }
.tile::after { content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, 0); transition: background .2s; }
.tile:hover::after { background: rgba(0, 0, 0, .22); }
.tile .multi { position: absolute; top: 10px; right: 10px; z-index: 1; color: #fff; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .7)); }
.tile .play { position: absolute; inset: 0; margin: auto; z-index: 1; color: #fff; filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .6)); }

/* ---- States ---- */
.state { display: none; flex-direction: column; align-items: center; gap: 10px; padding: 90px 24px; text-align: center; }
.state.show { display: flex; }
.state h2 { font-size: 1.1rem; font-weight: 600; }
.state p { color: var(--muted); font-size: .92rem; line-height: 1.5; max-width: 340px; }
.state .btn { margin-top: 8px; }

/* ---- Sign-in ---- */
.state.login { gap: 14px; padding-top: 20vh; }
.state.login .logo { font-size: 1.6rem; }
.btn-google {
  display: inline-flex; align-items: center; gap: 10px;
  background: #fff; color: #1f1f1f;
  padding: 10px 20px; border-radius: var(--radius-md); font-size: .95rem; font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}
.btn-google:hover { filter: brightness(.96); }
.btn-google:disabled { opacity: .6; pointer-events: none; }
.auth-error { color: #e06c6c; font-size: .85rem; }

/* ---- Post viewer (full screen) ---- */
.viewer { position: fixed; inset: 0; z-index: 50; display: none; background: rgba(0, 0, 0, .9); }
.viewer.open { display: flex; align-items: center; justify-content: center; }
.viewer-backdrop { position: absolute; inset: 0; }
.viewer-panel { position: relative; width: 100%; height: 100%; background: var(--bg); display: flex; flex-direction: column; }

.media-cell {
  position: relative; flex: 0 0 auto; width: 100%; aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  background: #000; cursor: pointer; touch-action: pan-y; overflow: hidden;
}
.strip { display: flex; height: 100%; width: 100%; transition: transform .3s cubic-bezier(.25, .8, .25, 1); }
.slide { flex: 0 0 100%; height: 100%; min-width: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.slide img { width: 100%; height: 100%; object-fit: cover; }
.media-cell.fit .slide img { object-fit: contain; }
.slide video { width: 100%; height: 100%; object-fit: contain; }

.dots { position: absolute; bottom: 10px; left: 0; right: 0; display: flex; justify-content: center; gap: 6px; z-index: 2; }
.dots button { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, .45); transition: background .2s, transform .2s; }
.dots button.active { background: #fff; transform: scale(1.2); }

.info-cell {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.info-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 10px 18px; border-bottom: 1px solid var(--border); }
.info-head .date { flex: 1; font-size: .82rem; color: var(--muted); }
.info-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 18px 6px; overscroll-behavior: contain; }

.caption-comment { border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.caption-comment p { font-size: .82rem; color: var(--muted); }
.caption-comment .meta { font-size: .72rem; }

.caption-edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.comments-title { margin: 18px 0 8px; font-size: .72rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.comments-empty { color: var(--muted); font-size: .88rem; font-style: italic; }
.comment { margin: 12px 0; }
.comment p { font-size: .92rem; line-height: 1.45; word-break: break-word; }
.comment .author { font-weight: 700; margin-right: 6px; }
.comment .meta { font-size: .72rem; color: var(--muted); }

.composer {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.composer .input { flex: 1; padding: 10px 14px; }
.composer .icon-btn { color: var(--accent); width: 38px; height: 38px; flex-shrink: 0; }

/* ---- Caption page ---- */
.cap-page { display: flex; align-items: center; justify-content: center; padding: 24px; }
.cap-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px 28px; text-align: center;
}
.cap-card .logo { font-size: 1.5rem; margin-bottom: 20px; }
.msg { color: var(--accent); font-size: .95rem; margin-bottom: 14px; }
.bar-wrap { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; margin-bottom: 20px; }
.bar { height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .15s ease; }
.cap-card textarea.input { min-height: 90px; text-align: left; }
.cap-actions { display: flex; gap: 10px; margin-top: 16px; }
.cap-actions .btn { flex: 1; }

/* ---- Caption page debug log ---- */
.dbg {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-height: 40vh; overflow-y: auto;
  margin: 0; padding: 8px 12px;
  background: rgba(0, 0, 0, .85); color: #9f9aa6;
  font: 10px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap; word-break: break-all;
  z-index: 100; text-align: left;
}

/* ---- Desktop: side-by-side viewer ---- */
@media (min-width: 768px) {
  .viewer-panel {
    width: min(1100px, 94vw); height: min(680px, 90vh);
    flex-direction: row; overflow: hidden;
    border: 1px solid var(--border); border-radius: var(--radius-lg);
  }
  .media-cell { flex: 1 1 auto; width: auto; aspect-ratio: auto; min-width: 0; }
  .info-cell { flex: 0 0 400px; width: 400px; border-top: 0; border-left: 1px solid var(--border); }
}
