:root {
  --accent: #5b6cff;
  --accent-hover: #4a5ae8;
  --accent-soft: rgba(91, 108, 255, 0.12);
  --accent-text: #ffffff;
  --bg: #f4f5f8;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --card-border: #e6e8ec;
  --text: #1c1e22;
  --text-strong: #0b0c0f;
  --muted: #6b7280;
  --link: #4a5ae8;
  --danger: #e0463a;
  --danger-soft: #fdecea;
  --shadow-sm: 0 1px 2px rgba(15, 17, 25, 0.06), 0 1px 1px rgba(15, 17, 25, 0.04);
  --shadow-md: 0 4px 16px rgba(15, 17, 25, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 17, 25, 0.14);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --topbar-bg: rgba(255, 255, 255, 0.85);
  --topbar-border: #e6e8ec;
  --input-bg: #ffffff;
  --input-border: #d8dbe2;
  --hover-bg: #f0f2f7;
}

[data-theme="dark"] {
  --accent: #7c8aff;
  --accent-hover: #95a1ff;
  --accent-soft: rgba(124, 138, 255, 0.18);
  --accent-text: #0b0c0f;
  --bg: #0d0f14;
  --bg-elevated: #161a22;
  --card: #161a22;
  --card-border: #232936;
  --text: #e6e8ee;
  --text-strong: #ffffff;
  --muted: #8a93a6;
  --link: #95a1ff;
  --danger: #ff6b5e;
  --danger-soft: rgba(255, 107, 94, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
  --topbar-bg: rgba(13, 15, 20, 0.85);
  --topbar-border: #232936;
  --input-bg: #1d222c;
  --input-border: #2c3340;
  --hover-bg: #1d222c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: light dark; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}
a { color: var(--link); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { color: var(--text-strong); margin: 0 0 .5em; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 700; }
p { margin: 0 0 .8em; }
img { max-width: 100%; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--topbar-border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 980px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; height: 56px;
  gap: 16px;
}
.brand {
  color: var(--text-strong);
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -.015em;
  display: inline-flex; align-items: center; gap: 8px;
}
.brand:hover { color: var(--accent); }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #8e59ff);
  color: #fff; font-weight: 800; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}
.topnav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.topnav a {
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.topnav a:hover { background: var(--hover-bg); color: var(--text-strong); }
.topnav a.logout { color: var(--muted); }
.theme-toggle {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  padding: 0;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.theme-toggle:hover { background: var(--hover-bg); border-color: var(--accent); transform: rotate(15deg); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: inline; }
[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- Layout ---------- */
.wrap {
  max-width: 680px;
  margin: 24px auto 60px;
  padding: 0 16px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease, transform .2s ease, border-color .2s ease;
}
a.card { color: inherit; display: block; }
a.card:hover { box-shadow: var(--shadow-md); border-color: var(--accent); transform: translateY(-1px); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}

/* ---------- Auth pages ---------- */
.auth-card {
  max-width: 400px;
  margin: 80px auto 40px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
.auth-card h1 { margin-top: 0; text-align: center; }
.auth-card label { display: block; margin: 14px 0 6px; font-weight: 600; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.auth-card input[type=email],
.auth-card input[type=password],
.auth-card input[type=text] {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-card button {
  width: 100%;
  margin-top: 20px;
  padding: 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  cursor: pointer;
  font-size: 14.5px;
  transition: background .15s ease, transform .1s ease;
}
.auth-card button:hover { background: var(--accent-hover); }
.auth-card button:active { transform: scale(.98); }

/* ---------- Compose ---------- */
.compose textarea {
  width: 100%;
  min-height: 64px;
  padding: 12px 14px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  resize: vertical;
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.compose textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.compose textarea::placeholder { color: var(--muted); }
.compose-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 12px; gap: 12px; flex-wrap: wrap;
}
.file-label {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s ease, color .15s ease;
}
.file-label:hover { background: var(--hover-bg); color: var(--accent); }
.file-label::before { content: "📷"; font-size: 15px; }
.file-label input[type=file] { display: none; }
.file-label.is-uploading {
  background: var(--accent-soft);
  color: var(--accent);
  pointer-events: none;
}
.file-label.is-uploading::before {
  content: "⏳";
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons ---------- */
button, .btn {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
}
button:hover, .btn:hover { background: var(--accent-hover); }
button:active { transform: scale(.97); }
button.danger { background: var(--danger); }
button.danger:hover { background: #c93a30; }

/* ---------- Posts ---------- */
.post { padding: 18px; }
.post-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.post-head-main { flex: 1; min-width: 0; }
.post-delete { margin: 0; margin-left: auto; }
.icon-btn {
  background: transparent;
  color: var(--muted);
  border: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }
.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8e59ff);
  color: #fff;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
  text-transform: uppercase;
  letter-spacing: .02em;
}
.avatar.small { width: 30px; height: 30px; font-size: 11px; }
.avatar.big { width: 72px; height: 72px; font-size: 26px; }
.post .name { font-weight: 700; color: var(--text-strong); }
.post .name:hover { color: var(--accent); }
.post .meta { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.post .meta a { color: var(--muted); }
.post .meta a:hover { color: var(--accent); }
.post-body {
  margin: 8px 0 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
}

/* ---------- Photo grids ---------- */
.photos { display: grid; gap: 4px; margin: 10px 0; border-radius: var(--radius-sm); overflow: hidden; }
.photos-1 { grid-template-columns: 1fr; }
.photos-2 { grid-template-columns: 1fr 1fr; }
.photos-3 { grid-template-columns: 1fr 1fr 1fr; }
.photos-4 { grid-template-columns: 1fr 1fr; }
.photo-tile { position: relative; margin: 0; overflow: hidden; }
.photo-tile a { display: block; overflow: hidden; }
.photos img {
  width: 100%; display: block;
  background: var(--hover-bg);
  aspect-ratio: 1/1;
  object-fit: cover;
  transition: transform .3s ease;
}
.photos-1 img { aspect-ratio: auto; max-height: 560px; object-fit: contain; }
.photo-tile a:hover img { transform: scale(1.03); }

/* ---------- Photo like button (overlay) ---------- */
.photo-like-form { margin: 0; position: absolute; bottom: 8px; right: 8px; z-index: 2; }
.photo-like {
  background: rgba(15, 17, 25, 0.62);
  color: #fff;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 0;
  padding: 6px 11px;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
  transition: background .15s ease, transform .1s ease, color .15s ease;
}
.photo-like:hover { background: rgba(15, 17, 25, 0.85); }
.photo-like:active { transform: scale(.92); }
.photo-like .heart { font-size: 15px; line-height: 1; }
.photo-like .count { font-size: 12px; }
.photo-like.liked { background: var(--accent); color: #fff; }
.photo-like.liked:hover { background: var(--accent-hover); }
@keyframes heartbeat { 0%, 100% { transform: scale(1); } 30% { transform: scale(1.35); } 60% { transform: scale(.9); } }
.photo-like.liked .heart { animation: heartbeat .4s ease; }

/* ---------- Post actions ---------- */
.post-actions {
  display: flex; gap: 8px; align-items: center;
  padding-top: 10px; margin-top: 12px;
  border-top: 1px solid var(--card-border);
  font-size: 13px;
}
.post-actions form.inline { margin: 0; }
button.react {
  background: transparent;
  color: var(--muted);
  padding: 7px 14px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
button.react::before { content: "♡"; font-size: 16px; line-height: 1; }
button.react:hover { background: var(--hover-bg); color: var(--accent); }
button.react.liked { background: var(--accent-soft); color: var(--accent); }
button.react.liked::before { content: "♥"; }
button.react:active { transform: scale(.92); }
.comment-count { color: var(--muted); margin-left: auto; font-size: 12.5px; }

/* ---------- Comments ---------- */
.comments { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 10px; }
.comments li { display: flex; gap: 10px; align-items: flex-start; }
.comments li > div:last-child {
  background: var(--hover-bg);
  border-radius: 16px;
  padding: 8px 12px;
  flex: 1;
  font-size: 13.5px;
}
.comments .name { font-size: 13px; font-weight: 700; color: var(--text-strong); }
.comments .meta { font-size: 11.5px; color: var(--muted); }
.comment-form {
  display: flex; gap: 8px; margin-top: 14px; align-items: center;
}
.comment-form input[type=text] {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius-pill);
  font: inherit;
  font-size: 13.5px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.comment-form input[type=text]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.comment-form button {
  padding: 8px 16px;
  border-radius: var(--radius-pill);
}

/* ---------- Album card (in feed) ---------- */
.album-card .post-head .muted { font-size: 14px; }
.album-card-body {
  display: block;
  margin-top: 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--card-border);
  color: inherit;
  transition: border-color .2s ease, transform .2s ease;
}
.album-card-body:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.album-card-body img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  display: block;
  transition: transform .3s ease;
}
.album-card-body:hover img { transform: scale(1.03); }
.album-card-body .empty-cover {
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--hover-bg), var(--card-border));
  color: var(--muted);
}
.album-card-meta {
  padding: 12px 14px;
  background: var(--card);
}
.album-card-meta .name {
  font-weight: 700;
  color: var(--text-strong);
  font-size: 15px;
  margin-bottom: 2px;
}

/* ---------- Profile ---------- */
.profile-head { display: flex; gap: 18px; align-items: center; }
.profile-head h1 { margin: 0 0 4px; }
.profile-head p { margin: 0; }

/* ---------- People ---------- */
.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.person { display: flex; gap: 12px; align-items: center; margin: 0; }

/* ---------- Albums ---------- */
.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.album-tile {
  padding: 0;
  overflow: hidden;
  margin: 0;
  display: flex;
  flex-direction: column;
}
.album-tile img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  transition: transform .3s ease;
}
.album-tile:hover img { transform: scale(1.04); }
.album-tile .empty-cover {
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--hover-bg), var(--card-border));
  color: var(--muted);
  font-size: 13px;
}
.album-meta { padding: 12px 14px; }
.album-meta .name { font-weight: 700; color: var(--text-strong); }

.album-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
}
.album-photo {
  position: relative;
  margin: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.album-photo.is-cover {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.album-photo a { display: block; overflow: hidden; border-radius: var(--radius-sm); }
.album-photo img {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  display: block;
  transition: transform .3s ease;
}
.album-photo a:hover img { transform: scale(1.05); }

.cover-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}
.photo-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity .15s ease;
}
.album-photo:hover .photo-actions,
.album-photo:focus-within .photo-actions {
  opacity: 1;
}
.photo-actions form.inline { margin: 0; }
.photo-btn {
  background: rgba(15, 17, 25, 0.72);
  color: #fff;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 0;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
.photo-btn:hover { background: var(--accent); }
.photo-btn.danger { padding: 5px 9px; }
.photo-btn.danger:hover { background: var(--danger); }
.photo-btn:active { transform: scale(.94); }
a.photo-btn {
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; line-height: 1;
}

/* ---------- Album header ---------- */
.album-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.album-header-main { flex: 1; min-width: 0; }
.album-header-actions { display: flex; gap: 6px; flex-shrink: 0; padding-top: 4px; }
.album-edit-form { margin-top: 12px; }
.album-edit-form label { display: block; margin: 8px 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.album-edit-form input[type=text] {
  width: 100%; max-width: 420px;
  padding: 10px 13px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.album-edit-form input[type=text]:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.album-edit-buttons { display: flex; gap: 8px; margin-top: 12px; }

/* Download-only actions (non-owner) */
.photo-actions-dl { opacity: 0; transition: opacity .15s ease; }
.album-photo:hover .photo-actions-dl,
.album-photo:focus-within .photo-actions-dl { opacity: 1; }

/* ---------- Forms (album/invite) ---------- */
.album-new label, .invite-new label, .album-upload label { display: block; margin: 8px 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.album-new input[type=text],
.invite-new input[type=text],
.invite-new input[type=email] {
  width: 100%;
  max-width: 420px;
  padding: 10px 13px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.album-new input:focus, .invite-new input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Invites ---------- */
.invite { display: flex; gap: 14px; align-items: center; justify-content: space-between; }
.invite.used { opacity: .6; }
.invite-url-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  max-width: 540px;
  margin-top: 6px;
}
.invite-url {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}
.copy-btn {
  flex: none;
  padding: 0 14px;
  font-size: 12.5px;
  min-width: 72px;
}
.copy-btn.copied {
  background: #2ea66b;
}

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  color: var(--muted);
  padding: 30px 0 40px;
  font-size: 12.5px;
}

/* ---------- Animations ---------- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.card { animation: fadeInUp .35s ease both; }
.card:nth-child(2) { animation-delay: .03s; }
.card:nth-child(3) { animation-delay: .06s; }
.card:nth-child(4) { animation-delay: .09s; }
.card:nth-child(5) { animation-delay: .12s; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar-inner { padding: 0 14px; height: 52px; }
  .brand { font-size: 17px; }
  .topnav a { padding: 6px 8px; font-size: 13px; }
  .wrap { padding: 0 12px; margin-top: 16px; }
  .card { padding: 14px; border-radius: 12px; }
  .post { padding: 14px; }
  .auth-card { margin: 40px 16px; padding: 24px; }
  h1 { font-size: 20px; }
}
