/* ============ guitarmemo — mobile-first, theme-driven ============ */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #171412;
  --muted: #78716c;
  --border: #e7e5e4;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .07), 0 4px 14px rgba(0, 0, 0, .05);
  --topbar-h: 56px;
}

/* Theme palettes: [primary, primary-hover, soft-bg, primary-text] */
[data-theme="orange"] { --primary: #f97316; --primary-hover: #ea580c; --soft: #fff7ed; --on-primary: #ffffff; --ring: rgba(249, 115, 22, .25); }
[data-theme="blue"]   { --primary: #3b82f6; --primary-hover: #2563eb; --soft: #eff6ff; --on-primary: #ffffff; --ring: rgba(59, 130, 246, .25); }
[data-theme="green"]  { --primary: #22c55e; --primary-hover: #16a34a; --soft: #f0fdf4; --on-primary: #ffffff; --ring: rgba(34, 197, 94, .25); }
[data-theme="purple"] { --primary: #a855f7; --primary-hover: #9333ea; --soft: #faf5ff; --on-primary: #ffffff; --ring: rgba(168, 85, 247, .25); }
[data-theme="red"]    { --primary: #ef4444; --primary-hover: #dc2626; --soft: #fef2f2; --on-primary: #ffffff; --ring: rgba(239, 68, 68, .25); }
[data-theme="pink"]   { --primary: #ec4899; --primary-hover: #db2777; --soft: #fdf2f8; --on-primary: #ffffff; --ring: rgba(236, 72, 153, .25); }

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
}

img, video { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; -webkit-tap-highlight-color: transparent; }
input, textarea { font: inherit; color: inherit; }
svg { display: block; }

/* ------------------------------- top bar ------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}
.brand-icon { width: 26px; height: 26px; border-radius: 6px; }

.topbar-actions { display: flex; gap: 4px; align-items: center; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn:active, .icon-btn:hover { background: var(--soft); color: var(--primary); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }

/* -------------------------------- layout -------------------------------- */

.app {
  max-width: 620px;
  margin: 0 auto;
  padding: 16px 12px calc(96px + env(safe-area-inset-bottom));
}

/* --------------------------------- cards -------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.post-card { margin-bottom: 16px; animation: fadeUp .3s ease both; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.post-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--soft);
}
.avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--primary);
  font-weight: 700;
  font-size: 1rem;
  user-select: none;
}
.avatar.lg { width: 72px; height: 72px; font-size: 1.6rem; }
.avatar.sm { width: 30px; height: 30px; font-size: .8rem; }

.post-meta { min-width: 0; flex: 1; }
.post-author { font-weight: 600; font-size: .95rem; }
.post-author:hover { color: var(--primary); }
.post-date { font-size: .78rem; color: var(--muted); }

.post-delete {
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: color .15s, background .15s;
}
.post-delete:hover { color: #dc2626; background: #fef2f2; }
.post-delete svg { width: 18px; height: 18px; }

.post-title {
  padding: 0 14px 10px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  word-break: break-word;
}

/* media slider */
.media-slider {
  position: relative;
  background: #0c0a09;
}
.media-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.media-track::-webkit-scrollbar { display: none; }
.media-item {
  flex: 0 0 100%;
  scroll-snap-align: center;
  display: grid;
  place-items: center;
  max-height: 70vh;
  min-height: 200px;
}
.media-item img, .media-item video {
  width: 100%;
  height: 100%;
  max-height: 70vh;
  object-fit: contain;
}
.media-dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, .35);
  border-radius: 999px;
}
.media-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .5);
  transition: background .2s, transform .2s;
}
.media-dot.active { background: #fff; transform: scale(1.25); }
.media-count {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  font-size: .72rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}

.post-actions {
  display: flex;
  align-items: center;
  padding: 6px 8px;
}
.action-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 600;
  transition: background .15s, color .15s;
}
.action-btn:hover { background: var(--soft); color: var(--primary); }
.action-btn svg { width: 20px; height: 20px; }

/* -------------------------------- buttons ------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: .95rem;
  transition: transform .12s, background .15s, opacity .15s, box-shadow .15s;
  user-select: none;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 2px 10px var(--ring);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--soft); color: var(--primary); }
.btn-ghost:hover { filter: brightness(.96); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }

.fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 60;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 16px var(--ring), 0 2px 6px rgba(0,0,0,.15);
  transition: transform .15s, background .15s;
}
.fab:hover { background: var(--primary-hover); }
.fab:active { transform: scale(.92); }
.fab svg { width: 26px; height: 26px; }
.fab.hidden { display: none; }

/* --------------------------------- forms -------------------------------- */

.auth-wrap {
  max-width: 400px;
  margin: 6vh auto 0;
  padding: 28px 22px;
}
.auth-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 4px; }
.auth-sub { color: var(--muted); font-size: .92rem; margin-bottom: 22px; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--muted);
}
.field input, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  font-size: 1rem; /* prevents iOS zoom */
}
.field input:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--ring);
}
.field textarea { resize: vertical; min-height: 90px; }

.form-error {
  display: none;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: .88rem;
  margin-bottom: 16px;
}
.form-error.show { display: block; animation: fadeUp .2s ease both; }

.auth-switch { text-align: center; margin-top: 18px; font-size: .9rem; color: var(--muted); }
.auth-switch a { color: var(--primary); font-weight: 700; }

/* --------------------------------- search -------------------------------- */

.search-bar { display: flex; gap: 8px; margin-bottom: 18px; }
.search-bar input {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  outline: none;
  font-size: 1rem;
  transition: border-color .15s, box-shadow .15s;
}
.search-bar input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }

.section-title { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; margin: 4px 2px 14px; }

/* -------------------------------- profile ------------------------------- */

.profile-head { padding: 24px 18px; margin-bottom: 16px; text-align: center; }
.profile-head .avatar { margin: 0 auto 10px; }
.profile-name { font-size: 1.3rem; font-weight: 800; letter-spacing: -0.02em; }
.profile-username { color: var(--muted); font-size: .9rem; margin-bottom: 4px; }
.profile-stats { color: var(--muted); font-size: .85rem; margin-top: 6px; }

.profile-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.theme-picker { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }
.theme-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: transform .15s, border-color .15s;
  position: relative;
}
.theme-swatch:active { transform: scale(.9); }
.theme-swatch.active { border-color: var(--text); transform: scale(1.08); }

/* ------------------------------- post page ------------------------------ */

.comments { padding: 14px; }
.comments-title { font-size: .95rem; font-weight: 700; margin-bottom: 12px; }

.comment {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  animation: fadeUp .25s ease both;
}
.comment-body-wrap { flex: 1; min-width: 0; }
.comment-head { display: flex; align-items: baseline; gap: 8px; }
.comment-author { font-weight: 600; font-size: .88rem; }
.comment-author:hover { color: var(--primary); }
.comment-date { font-size: .72rem; color: var(--muted); }
.comment-body { font-size: .92rem; word-break: break-word; white-space: pre-wrap; }
.comment-delete {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 600;
  align-self: flex-start;
  padding: 2px 6px;
  border-radius: 6px;
}
.comment-delete:hover { color: #dc2626; background: #fef2f2; }

.comment-form { display: flex; gap: 8px; margin-top: 14px; align-items: flex-end; }
.comment-form textarea {
  flex: 1;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  outline: none;
  resize: none;
  min-height: 46px;
  max-height: 140px;
  font-size: 1rem;
  transition: border-color .15s, box-shadow .15s;
}
.comment-form textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
.comment-form .btn { padding: 11px 18px; flex-shrink: 0; }

/* -------------------------------- upload -------------------------------- */

.upload-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.upload-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: #0c0a09;
  border: 1px solid var(--border);
}
.upload-thumb img, .upload-thumb video { width: 100%; height: 100%; object-fit: cover; }
.upload-thumb .remove {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: .8rem;
  line-height: 1;
}
.upload-add {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 2px dashed var(--border);
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: border-color .15s, color .15s, background .15s;
}
.upload-add:hover { border-color: var(--primary); color: var(--primary); background: var(--soft); }
.upload-add svg { width: 26px; height: 26px; }
.upload-hint { font-size: .8rem; color: var(--muted); margin: -8px 0 16px 2px; }

/* -------------------------------- states -------------------------------- */

.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
}
.empty svg { width: 44px; height: 44px; margin: 0 auto 12px; opacity: .5; }
.empty-title { font-weight: 700; color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }

.spinner {
  width: 34px;
  height: 34px;
  border: 3.5px solid var(--soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 48px auto;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.load-more { display: block; margin: 4px auto 24px; }

.back-row { margin-bottom: 14px; }
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-weight: 600;
  font-size: .9rem;
  padding: 8px 12px;
  border-radius: 999px;
  transition: background .15s, color .15s;
}
.back-btn:hover { background: var(--soft); color: var(--primary); }
.back-btn svg { width: 18px; height: 18px; }

/* --------------------------------- toast -------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(80px);
  background: #1c1917;
  color: #fafaf9;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  opacity: 0;
  transition: transform .25s ease, opacity .25s ease;
  z-index: 100;
  pointer-events: none;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ------------------------------- lightbox ------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, .92);
  display: grid;
  place-items: center;
  animation: fadeIn .18s ease both;
  cursor: zoom-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.lightbox img, .lightbox video { max-width: 100vw; max-height: 100dvh; object-fit: contain; }

/* -------------------------------- desktop ------------------------------- */

@media (min-width: 700px) {
  .app { padding-top: 24px; }
  .fab { right: calc(50vw - 340px); }
}
