@import url('https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@300;400;500;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --ink: #1c1713;
  --muted: #7a6f65;
  --subtle: #a89d93;
  --border: #e5ddd6;
  --bg: #f7f3ef;
  --card: #fdfaf7;
  --accent: #b85c2a;
  --accent-light: #f5ede6;
  --font: 'Instrument Sans', sans-serif;
}

html, body { height: 100%; background: var(--bg); font-family: var(--font); color: var(--ink); -webkit-font-smoothing: antialiased; }

#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); position: relative; }

/* ── Auth ── */
.auth-screen { padding: 48px 24px; display: flex; flex-direction: column; min-height: 100dvh; }
.auth-title { font-size: 36px; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 8px; }
.auth-sub { font-size: 14px; color: var(--muted); margin-bottom: 40px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-input { padding: 14px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--card); font-family: var(--font); font-size: 14px; color: var(--ink); outline: none; width: 100%; }
.auth-input:focus { border-color: var(--accent); }
.auth-btn { padding: 14px; border-radius: 12px; background: var(--accent); color: white; border: none; font-family: var(--font); font-size: 14px; font-weight: 500; cursor: pointer; }
.auth-switch { margin-top: 24px; text-align: center; font-size: 14px; color: var(--muted); background: none; border: none; font-family: var(--font); cursor: pointer; }
.auth-hint { font-size: 12px; color: var(--subtle); padding: 0 4px; }
.auth-error { font-size: 12px; color: var(--accent); padding: 0 4px; }
.auth-success { font-size: 12px; color: #4a7c59; padding: 0 4px; }

/* ── Top bar ── */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); background: rgba(247,243,239,0.96); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 10; }
.topbar-title { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.topbar-actions { display: flex; gap: 12px; align-items: center; }
.icon-btn { background: none; border: none; cursor: pointer; color: var(--muted); display: flex; align-items: center; justify-content: center; padding: 2px; }

/* ── Bottom nav ── */
.bottom-nav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; height: 58px; background: rgba(247,243,239,0.96); backdrop-filter: blur(14px); border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-around; z-index: 100; padding-bottom: env(safe-area-inset-bottom); }
.nav-tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: none; cursor: pointer; padding: 8px 0; color: var(--subtle); }
.nav-tab.active { color: var(--accent); }
.nav-tab svg { transition: all 0.2s; }
.nav-dot { width: 3px; height: 3px; border-radius: 50%; background: var(--accent); }
.nav-plus { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; border: none; cursor: pointer; }

/* ── Page ── */
.page { flex: 1; overflow-y: auto; padding-bottom: 72px; }
.page::-webkit-scrollbar { display: none; }

/* ── Story card ── */
.story-card { background: var(--card); border-bottom: 1px solid var(--border); }
.card-meta { display: flex; align-items: center; gap: 8px; padding: 12px 16px 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-light); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 500; flex-shrink: 0; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.meta-name { font-size: 13px; font-weight: 500; }
.meta-time { font-size: 11px; color: var(--subtle); margin-left: 6px; }
.bookmark-btn { margin-left: auto; background: none; border: none; cursor: pointer; color: var(--subtle); display: flex; padding: 4px; }
.bookmark-btn.saved { color: var(--accent); }
.article-body { padding: 2px 16px 12px; }
.article-title { font-size: 15px; font-weight: 600; line-height: 1.35; margin-bottom: 6px; letter-spacing: -0.01em; }
.article-excerpt { font-size: 13px; color: var(--muted); line-height: 1.6; }
.read-more-btn { font-size: 12px; color: var(--accent); font-weight: 500; background: none; border: none; cursor: pointer; padding: 6px 0 0; display: block; }
.photo-img { width: 100%; display: block; max-height: 400px; object-fit: cover; cursor: pointer; }
.photo-caption { padding: 10px 16px 4px; font-size: 13px; color: var(--ink); line-height: 1.5; }
.card-actions { display: flex; align-items: center; gap: 16px; padding: 8px 16px; border-top: 1px solid var(--border); }
.card-action { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--subtle); background: none; border: none; cursor: pointer; }
.card-tags { margin-left: auto; display: flex; gap: 6px; }
.tag-pill { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--accent-light); color: var(--accent); }

/* ── Skeleton loader ── */
.skeleton { background: var(--border); border-radius: 4px; animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }

/* ── Empty state ── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 64px 32px; text-align: center; gap: 8px; }
.empty-title { font-weight: 500; color: var(--ink); }
.empty-sub { font-size: 13px; color: var(--muted); line-height: 1.5; }

/* ── Discover ── */
.search-bar { display: flex; align-items: center; gap: 8px; margin: 12px 16px; padding: 10px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); }
.search-input { flex: 1; border: none; background: transparent; font-family: var(--font); font-size: 13px; color: var(--ink); outline: none; }
.tags-scroll { display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px 12px; scrollbar-width: none; }
.tags-scroll::-webkit-scrollbar { display: none; }
.tag-btn { font-size: 12px; padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--card); color: var(--muted); white-space: nowrap; cursor: pointer; font-family: var(--font); }
.tag-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.discover-tabs { display: flex; border-bottom: 1px solid var(--border); }
.discover-tab { flex: 1; padding: 10px 0; text-align: center; font-size: 13px; font-weight: 500; color: var(--subtle); background: none; border: none; cursor: pointer; font-family: var(--font); border-bottom: 2px solid transparent; }
.discover-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1px; background: var(--border); }
.grid-item { aspect-ratio: 1; overflow: hidden; cursor: pointer; position: relative; }
.grid-item img { width: 100%; height: 100%; object-fit: cover; transition: opacity 0.2s; }
.grid-item:hover img { opacity: 0.85; }
.grid-article { background: var(--card); display: flex; flex-direction: column; justify-content: space-between; padding: 10px; }
.grid-article-title { font-size: 10px; font-weight: 500; color: var(--muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.grid-article-user { font-size: 9px; color: var(--subtle); }
.people-list { padding: 4px 16px; }
.person-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.person-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--accent-light); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 600; flex-shrink: 0; overflow: hidden; }
.person-avatar img { width: 100%; height: 100%; object-fit: cover; }
.person-info { flex: 1; min-width: 0; }
.person-name { font-size: 13px; font-weight: 500; color: var(--ink); }
.person-bio { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.follow-btn { padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 500; font-family: var(--font); cursor: pointer; border: none; }
.follow-btn.following { background: var(--border); color: var(--muted); }
.follow-btn.follow { background: var(--accent); color: white; }

/* ── Compose ── */
.compose-page { padding: 0; }
.compose-topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); background: rgba(247,243,239,0.96); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 10; }
.compose-label { font-size: 13px; font-weight: 500; }
.post-btn { padding: 6px 18px; border-radius: 20px; background: var(--accent); color: white; border: none; font-family: var(--font); font-size: 13px; font-weight: 500; cursor: pointer; }
.post-btn:disabled { background: var(--border); color: var(--subtle); cursor: default; }
.compose-body { padding: 20px; }
.type-toggle { display: flex; gap: 0; background: var(--border); border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.type-btn { flex: 1; padding: 8px; border-radius: 8px; font-size: 13px; font-family: var(--font); border: none; background: transparent; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 500; }
.type-btn.active { background: var(--card); color: var(--ink); }
.compose-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; border: none; border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 4px; background: transparent; font-family: var(--font); color: var(--ink); width: 100%; outline: none; }
.compose-text { font-size: 13px; color: var(--muted); border: none; background: transparent; font-family: var(--font); width: 100%; outline: none; resize: none; line-height: 1.6; min-height: 200px; margin-top: 12px; }
.photo-upload-area { border: 2px dashed var(--border); border-radius: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 48px 20px; cursor: pointer; color: var(--subtle); margin-bottom: 16px; }
.photo-preview { position: relative; border-radius: 16px; overflow: hidden; margin-bottom: 16px; }
.photo-preview img { width: 100%; display: block; max-height: 320px; object-fit: cover; }
.photo-remove { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border-radius: 50%; background: rgba(0,0,0,0.45); border: none; color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.tags-field { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); margin-top: 12px; }
.tags-field-input { flex: 1; border: none; background: transparent; font-family: var(--font); font-size: 13px; color: var(--ink); outline: none; }

/* ── Profile ── */
.profile-header { padding: 20px; border-bottom: 1px solid var(--border); }
.profile-top { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.profile-avatar { width: 60px; height: 60px; border-radius: 50%; background: var(--accent-light); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 600; flex-shrink: 0; cursor: pointer; position: relative; overflow: hidden; }
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-badge { position: absolute; bottom: 0; right: 0; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); display: flex; align-items: center; justify-content: center; }
.profile-stats { flex: 1; display: flex; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); }
.stat-item { flex: 1; padding: 8px 0; text-align: center; border-right: 1px solid var(--border); cursor: pointer; background: none; border-top: none; border-bottom: none; font-family: var(--font); }
.stat-item:last-child { border-right: none; }
.stat-n { font-size: 14px; font-weight: 600; color: var(--ink); display: block; }
.stat-l { font-size: 11px; color: var(--subtle); display: block; }
.profile-bio { font-size: 13px; color: var(--muted); line-height: 1.5; }
.profile-tabs { display: flex; border-bottom: 1px solid var(--border); }
.profile-tab { flex: 1; padding: 12px 0; text-align: center; font-size: 13px; font-weight: 500; color: var(--subtle); background: none; border: none; cursor: pointer; font-family: var(--font); border-bottom: 2px solid transparent; display: flex; align-items: center; justify-content: center; gap: 5px; }
.profile-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Modals & sheets ── */
.overlay { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 24px; pointer-events: none; }
.overlay::before { content: ''; position: absolute; inset: 0; background: rgba(20,15,10,0); backdrop-filter: blur(0px); transition: background 0.5s ease, backdrop-filter 0.5s ease; z-index: -1; }
.overlay.visible { pointer-events: all; }
.overlay.visible::before { background: rgba(20,15,10,0.78); backdrop-filter: blur(20px); }
.overlay-img { max-width: 100%; max-height: 88dvh; border-radius: 16px; object-fit: contain; transform: scale(0.88); opacity: 0; transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s ease; box-shadow: 0 32px 80px rgba(0,0,0,0.5); }
.overlay.visible .overlay-img { transform: scale(1); opacity: 1; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 200; background: rgba(20,15,10,0); backdrop-filter: blur(0px); transition: background 0.35s ease, backdrop-filter 0.35s ease; pointer-events: none; }
.sheet-backdrop.visible { background: rgba(20,15,10,0.6); backdrop-filter: blur(8px); pointer-events: all; }
.sheet { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%) translateY(100%); transition: transform 0.45s cubic-bezier(0.32,0.72,0,1); width: 100%; max-width: 480px; background: var(--card); border-radius: 24px 24px 0 0; z-index: 201; display: flex; flex-direction: column; box-shadow: 0 -8px 40px rgba(0,0,0,0.15); }
.sheet.visible { transform: translateX(-50%) translateY(0); }
.sheet.full { max-height: 98dvh; }
.sheet.half { max-height: 75dvh; }
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 12px auto 0; flex-shrink: 0; }
.sheet-close { position: absolute; top: 14px; right: 14px; width: 28px; height: 28px; border-radius: 50%; background: var(--border); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 16px; }
.sheet-scroll { overflow-y: auto; flex: 1; padding: 20px 24px; scrollbar-width: none; }
.sheet-scroll::-webkit-scrollbar { display: none; }
.sheet-title { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 16px; line-height: 1.3; }
.sheet-body { font-size: 15px; color: var(--muted); line-height: 1.8; }
.sheet-divider { height: 1px; background: var(--border); margin: 16px 0; }
.sheet-author { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }

/* Comments */
.comments-section { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); }
.comments-title { font-size: 13px; font-weight: 500; margin-bottom: 16px; }
.comment-row { display: flex; gap: 10px; margin-bottom: 16px; }
.comment-name { font-size: 12px; font-weight: 500; }
.comment-time { font-size: 11px; color: var(--subtle); margin-left: 6px; }
.comment-text { font-size: 13px; color: var(--muted); margin-top: 2px; line-height: 1.5; }
.comment-input-row { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border); margin-top: 8px; }
.comment-input { flex: 1; border: none; background: transparent; font-family: var(--font); font-size: 13px; color: var(--ink); outline: none; }
.send-btn { background: none; border: none; cursor: pointer; color: var(--border); }
.send-btn.active { color: var(--accent); }

/* Profile sheet */
.profile-sheet-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.profile-sheet-avatar { width: 60px; height: 60px; border-radius: 50%; background: var(--accent-light); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 600; flex-shrink: 0; overflow: hidden; }
.profile-sheet-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-sheet-name { font-size: 18px; font-weight: 600; }
.profile-sheet-bio { font-size: 13px; color: var(--muted); margin-top: 2px; }
.profile-sheet-stats { display: flex; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); margin-bottom: 16px; }
.follow-action-btn { width: 100%; padding: 14px; border-radius: 16px; font-size: 14px; font-weight: 600; font-family: var(--font); border: none; cursor: pointer; margin-bottom: 20px; }
.follow-action-btn.follow { background: var(--accent); color: white; }
.follow-action-btn.following { background: var(--border); color: var(--muted); }

/* Follow list sheet */
.follow-list { padding: 8px 16px; overflow-y: auto; }
.follow-list-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.follow-list-title { font-size: 15px; font-weight: 600; }

/* Delete confirm */
.delete-sheet-body { padding: 20px 24px 12px; }
.delete-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.delete-sub { font-size: 13px; color: var(--muted); }
.delete-btns { padding: 8px 16px; display: flex; flex-direction: column; gap: 8px; padding-bottom: calc(env(safe-area-inset-bottom) + 80px); }
.delete-confirm-btn { padding: 14px; border-radius: 16px; background: #c0392b; color: white; border: none; font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; }
.delete-cancel-btn { padding: 14px; border-radius: 16px; background: var(--border); color: var(--ink); border: none; font-family: var(--font); font-size: 14px; font-weight: 500; cursor: pointer; }

/* Activity */
.activity-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 60vh; gap: 12px; text-align: center; padding: 0 32px; }

/* Page host container */
.page-host {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.page {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 72px;
  -webkit-overflow-scrolling: touch;
}
.page::-webkit-scrollbar { display: none; }
