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

:root {
  --bg: #111; --bg2: #1a1a1a; --fg: #e0e0e0; --fg2: #888;
  --accent: #f59e0b; --border: #333; --radius: 6px;
  --font: system-ui, -apple-system, sans-serif;
  --mono: 'SF Mono', 'Fira Code', monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fff; --bg2: #f5f5f5; --fg: #111; --fg2: #666;
    --accent: #d97706; --border: #ddd;
  }
}

body { font-family: var(--font); background: var(--bg); color: var(--fg); height: 100dvh; overflow: hidden; }

/* layout */
#app { display: flex; height: 100dvh; }
.sidebar { width: auto; min-width: 0; background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* sidebar */
.profile-area { padding: 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; cursor: pointer; }
.profile-area:hover { background: var(--border); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--border); object-fit: cover; }
.profile-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-npub { font-size: 11px; color: var(--fg2); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.feed-list { flex: 1; overflow-y: auto; padding: 8px; }
.feed-item { padding: 8px 12px; border-radius: var(--radius); cursor: pointer; font-size: 14px; margin-bottom: 2px; }
.feed-item:hover { background: var(--border); }
.feed-item.active { background: var(--accent); color: #000; font-weight: 600; }

.sidebar-logout { padding: 8px 12px; font-size: 13px; color: var(--fg2); cursor: pointer; border-top: 1px solid var(--border); }
.sidebar-logout:hover { color: var(--fg); background: var(--border); }
.relay-status { padding: 8px 12px; border-top: 1px solid var(--border); font-size: 11px; color: var(--fg2); }
.relay-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 4px; }
.relay-dot.on { background: #22c55e; }
.relay-dot.off { background: #ef4444; }

/* main content */
.toolbar { padding: 12px; border-bottom: 1px solid var(--border); font-size: 16px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.toolbar-reload { background: none; border: none; color: var(--fg2); cursor: pointer; font-size: 18px; padding: 4px; line-height: 1; }
.toolbar-reload:hover { color: var(--fg); }

.feed { flex: 1; overflow-y: auto; padding: 0; }
.note { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.note-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.note-author { font-weight: 600; font-size: 14px; }
.note-time { font-size: 12px; color: var(--fg2); margin-left: auto; }
.note-content { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.note-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--border); object-fit: cover; flex-shrink: 0; }

.compose { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.compose textarea { flex: 1; background: var(--bg2); color: var(--fg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; font-family: var(--font); font-size: 14px; resize: none; min-height: 40px; max-height: 120px; }
.compose textarea:focus { outline: none; border-color: var(--accent); }
.compose button { background: var(--accent); color: #000; border: none; border-radius: var(--radius); padding: 8px 16px; font-weight: 600; cursor: pointer; font-size: 14px; align-self: flex-end; }
.compose button:hover { opacity: 0.9; }
.compose button:disabled { opacity: 0.4; cursor: not-allowed; }

/* login */
.login-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100dvh; gap: 16px; }
.login-screen button { background: var(--accent); color: #000; border: none; border-radius: var(--radius); padding: 12px 24px; font-size: 16px; font-weight: 600; cursor: pointer; }
.login-input { width: 300px; max-width: 90vw; background: var(--bg2); color: var(--fg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; font-size: 13px; }
.login-input:focus { outline: none; border-color: var(--accent); }
.login-input-mono { font-family: var(--mono); }

/* smesh loader animation */
.smesh-loader { width: 180px; height: 180px; }
.smesh-loader-edge { stroke-linecap: round; opacity: 0; animation: smeshEdgeFade 0.4s ease forwards; }
.smesh-loader-center { opacity: 0; animation: smeshNodePop 0.3s ease forwards; transform-origin: 400px 400px; }
@keyframes smeshEdgeFade { to { opacity: 1; } }
@keyframes smeshNodePop { 0% { opacity: 0; transform: scale(0); } 70% { transform: scale(1.2); } 100% { opacity: 1; transform: scale(1); } }

/* settings */
.settings { padding: 16px; overflow-y: auto; flex: 1; }
.settings h2 { font-size: 16px; margin-bottom: 12px; }
.settings section { margin-bottom: 24px; }
.relay-input { display: flex; gap: 8px; margin-bottom: 8px; }
.relay-input input { flex: 1; background: var(--bg2); color: var(--fg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; font-size: 14px; }
.relay-input button { background: var(--accent); color: #000; border: none; border-radius: var(--radius); padding: 8px 12px; font-weight: 600; cursor: pointer; }
.relay-list-item { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 14px; font-family: var(--mono); }
.relay-list-item button { background: none; border: none; color: var(--fg2); cursor: pointer; font-size: 16px; }

/* thread view */
.thread-back { padding: 8px 12px; cursor: pointer; color: var(--accent); font-size: 14px; border-bottom: 1px solid var(--border); }
.thread-back:hover { background: var(--bg2); }
.thread-root { border-left: 3px solid var(--accent); }
.thread-reply { border-left: 2px solid var(--border); }
.note-actions { display: flex; gap: 16px; margin-top: 6px; }
.note-action { font-size: 12px; color: var(--fg2); cursor: pointer; display: flex; align-items: center; gap: 4px; }
.note-action:hover { color: var(--accent); }
.header-action { margin-left: 0; }

/* reply compose */
.reply-compose { margin-top: 8px; }
.reply-input { width: 100%; background: var(--bg2); color: var(--fg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; font-family: var(--font); font-size: 14px; resize: none; min-height: 60px; max-height: 120px; }
.reply-input:focus { outline: none; border-color: var(--accent); }
.reply-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.reply-cancel { background: none; border: 1px solid var(--border); color: var(--fg2); border-radius: var(--radius); padding: 4px 12px; font-size: 13px; cursor: pointer; }
.reply-cancel:hover { border-color: var(--fg2); }
.reply-submit { background: var(--accent); color: #000; border: none; border-radius: var(--radius); padding: 4px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.reply-submit:hover { opacity: 0.9; }
.reply-submit:disabled { opacity: 0.4; cursor: not-allowed; }
.orly-badge { display: inline-block; background: var(--accent); color: #000; font-size: 10px; padding: 1px 5px; border-radius: 3px; font-weight: 700; margin-left: 6px; vertical-align: middle; }

/* snackbar */
.snackbar { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 20px; border-radius: var(--radius); font-size: 14px; z-index: 999; animation: fadein 0.3s; cursor: pointer; }
@keyframes fadein { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

/* new notes pill */
.new-notes-pill { position: sticky; top: 8px; left: 50%; transform: translateX(-50%); width: fit-content; background: var(--accent); color: #000; padding: 6px 16px; border-radius: 20px; font-size: 13px; font-weight: 600; cursor: pointer; z-index: 5; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.new-notes-pill:hover { opacity: 0.9; }

/* rich content */
.rich-link { color: var(--accent); text-decoration: none; word-break: break-all; }
.rich-link:hover { text-decoration: underline; }
.rich-image { max-width: 100%; max-height: 400px; border-radius: var(--radius); margin: 6px 0; display: block; cursor: pointer; }
.rich-video { max-width: 100%; max-height: 400px; border-radius: var(--radius); margin: 6px 0; display: block; }
.rich-mention { color: var(--accent); cursor: pointer; font-weight: 600; }
.rich-mention:hover { text-decoration: underline; }

/* embedded notes */
.embedded-note { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; margin: 6px 0; background: var(--bg2); cursor: pointer; }
.embedded-note:hover { border-color: var(--accent); }
.embedded-header { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.embedded-content { font-size: 13px; color: var(--fg2); line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.embedded-loading, .embedded-missing { color: var(--fg2); font-size: 13px; font-style: italic; }

/* repost */
.repost-label { font-size: 12px; color: var(--fg2); margin-bottom: 4px; padding-left: 36px; }

/* lightbox */
.lightbox-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 100; display: flex; align-items: center; justify-content: center; }
.lightbox-close { position: fixed; top: 12px; right: 16px; background: none; border: none; color: #fff; font-size: 28px; cursor: pointer; z-index: 101; }
.lightbox-img { max-width: 95vw; max-height: 90vh; object-fit: contain; touch-action: pinch-zoom; }

/* hashtag feed */
.hashtag-input { width: 100%; background: var(--bg2); color: var(--fg); border: none; border-bottom: 1px solid var(--border); padding: 10px 12px; font-size: 14px; font-family: var(--font); outline: none; }
.hashtag-input:focus { border-color: var(--accent); }

/* DMs */
.dm-list { flex: 1; overflow-y: auto; }
.dm-list-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.dm-list-item:hover { background: var(--bg2); }
.dm-preview { flex: 1; min-width: 0; }
.dm-preview-name { font-size: 14px; font-weight: 600; }
.dm-preview-text { font-size: 13px; color: var(--fg2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-preview-time { font-size: 11px; color: var(--fg2); flex-shrink: 0; }
.dm-chat { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.dm-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.dm-bubble { max-width: 75%; padding: 8px 12px; border-radius: 12px; font-size: 14px; line-height: 1.4; word-break: break-word; white-space: pre-wrap; }
.dm-bubble.mine { background: var(--accent); color: #000; align-self: flex-end; border-bottom-right-radius: 4px; }
.dm-bubble.theirs { background: var(--bg2); align-self: flex-start; border-bottom-left-radius: 4px; }
.dm-protocol { font-size: 10px; color: var(--fg2); margin-top: 2px; }
.dm-protocol.legacy { color: #ef4444; }
.dm-time { font-size: 10px; color: var(--fg2); margin-top: 1px; }
.dm-compose { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.dm-compose textarea { flex: 1; background: var(--bg2); color: var(--fg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; font-family: var(--font); font-size: 14px; resize: none; min-height: 40px; max-height: 100px; }
.dm-compose textarea:focus { outline: none; border-color: var(--accent); }
.dm-compose button { background: var(--accent); color: #000; border: none; border-radius: var(--radius); padding: 8px 16px; font-weight: 600; cursor: pointer; font-size: 14px; align-self: flex-end; }
.dm-compose button:disabled { opacity: 0.4; cursor: not-allowed; }
.dm-new-input { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.dm-new-input input { width: 100%; background: var(--bg2); color: var(--fg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; font-size: 13px; font-family: var(--mono); }
.dm-new-input input:focus { outline: none; border-color: var(--accent); }

/* loading */
.loading { display: flex; align-items: center; justify-content: center; height: 100dvh; color: var(--fg2); }

/* mobile */
@media (max-width: 600px) {
  .sidebar { position: fixed; left: -100%; z-index: 10; height: 100dvh; transition: left 0.2s; width: auto; }
  .sidebar.open { left: 0; }
  .sidebar-toggle { display: block; padding: 8px 12px; cursor: pointer; font-size: 20px; }
}
@media (min-width: 601px) {
  .sidebar-toggle { display: none; }
}
