/* ============================================================
   Bookmarks — style.css
   Light reading-app theme, mobile-first
   ============================================================ */

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-raised: #fdfcfb;
  --border: #ece9e3;
  --border-strong: #d9d4cc;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.07), 0 1px 3px rgba(0,0,0,0.05);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);

  --text-primary: #1c1917;
  --text-secondary: #6b6560;
  --text-muted: #a8a29e;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-reading: Georgia, "Times New Roman", serif;

  --radius: 14px;
  --radius-sm: 8px;
  --radius-xs: 5px;
  --max-width: 760px;

  /* Area accent colors */
  --area-politics:   #3b82f6;
  --area-technical:  #10b981;
  --area-psychology: #8b5cf6;
  --area-lifestyle:  #f59e0b;
  --area-physical:   #ef4444;
  --area-family:     #14b8a6;
  --area-friends:    #ec4899;
  --area-default:    #94a3b8;

  --area-politics-bg:   #eff6ff;
  --area-technical-bg:  #f0fdf4;
  --area-psychology-bg: #f5f3ff;
  --area-lifestyle-bg:  #fffbeb;
  --area-physical-bg:   #fef2f2;
  --area-family-bg:     #f0fdfa;
  --area-friends-bg:    #fdf2f8;
  --area-default-bg:    #f8fafc;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---- */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(247, 246, 243, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.result-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.shuffle-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.shuffle-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.shuffle-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(168,162,158,0.18);
}

/* ---- Search ---- */
.search-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  line-height: 1;
}

.search-input {
  width: 100%;
  padding: 9px 36px 9px 34px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  color: var(--text-primary);
  font-family: var(--font-ui);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

.search-input::placeholder { color: var(--text-muted); }

.search-input:focus {
  outline: none;
  border-color: #a8a29e;
  box-shadow: 0 0 0 3px rgba(168,162,158,0.15);
}

.search-clear {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  line-height: 1;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
.search-clear:hover { color: var(--text-secondary); }

/* ---- Area chips ---- */
.area-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 2px;
}
.area-chips::-webkit-scrollbar { display: none; }

.area-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border-strong);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.area-chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.area-chip.active {
  color: white;
  border-color: transparent;
}

.area-chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

.area-chip.active .area-chip-dot {
  opacity: 1;
  background: rgba(255,255,255,0.7);
}

/* Area chip active colors */
.area-chip[data-area="all"].active       { background: var(--text-primary); }
.area-chip[data-area="politics"].active  { background: var(--area-politics); }
.area-chip[data-area="technical"].active { background: var(--area-technical); }
.area-chip[data-area="psychology"].active{ background: var(--area-psychology); }
.area-chip[data-area="lifestyle"].active { background: var(--area-lifestyle); }
.area-chip[data-area="physical"].active  { background: var(--area-physical); }
.area-chip[data-area="family"].active    { background: var(--area-family); }
.area-chip[data-area="friends"].active   { background: var(--area-friends); }

/* ---- Active tag filters ---- */
.active-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 8px;
}

.active-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 10px;
  background: var(--text-primary);
  color: white;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.active-tag:hover { background: #333; }
.active-tag-x { opacity: 0.7; font-size: 0.9rem; line-height: 1; }

/* ---- Note list ---- */
.note-list {
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  padding: 12px 12px 40px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---- Note card ---- */
.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 12px 20px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.1s;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.note-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: var(--radius) 0 0 var(--radius);
}

.note-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}

.note-card:active {
  transform: scale(0.99);
}

/* Area left-border colors */
.note-card[data-area="politics"]::before  { background: var(--area-politics); }
.note-card[data-area="technical"]::before { background: var(--area-technical); }
.note-card[data-area="psychology"]::before{ background: var(--area-psychology); }
.note-card[data-area="lifestyle"]::before { background: var(--area-lifestyle); }
.note-card[data-area="physical"]::before  { background: var(--area-physical); }
.note-card[data-area="family"]::before    { background: var(--area-family); }
.note-card[data-area="friends"]::before   { background: var(--area-friends); }
.note-card[data-area=""]::before          { background: var(--area-default); }

.note-meta-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
}

.note-area-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 2px 7px;
  border-radius: 20px;
}

.note-area-badge[data-area="politics"]  { background: var(--area-politics-bg);   color: var(--area-politics); }
.note-area-badge[data-area="technical"] { background: var(--area-technical-bg);  color: var(--area-technical); }
.note-area-badge[data-area="psychology"]{ background: var(--area-psychology-bg); color: var(--area-psychology); }
.note-area-badge[data-area="lifestyle"] { background: var(--area-lifestyle-bg);  color: var(--area-lifestyle); }
.note-area-badge[data-area="physical"]  { background: var(--area-physical-bg);   color: var(--area-physical); }
.note-area-badge[data-area="family"]    { background: var(--area-family-bg);     color: var(--area-family); }
.note-area-badge[data-area="friends"]   { background: var(--area-friends-bg);    color: var(--area-friends); }
.note-area-badge[data-area=""]          { background: var(--area-default-bg);    color: var(--area-default); }

.note-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: auto;
}

.note-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
  margin-bottom: 4px;
  /* Clamp to 2 lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-ainote {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-bottom: 9px;
  /* Clamp to 2 lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.tag:hover, .tag.active {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: white;
}

.tag-overflow {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  padding: 2px 4px;
}

/* ---- Load more ---- */
.load-more-wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  padding: 4px 12px 48px;
  display: flex;
  justify-content: center;
}

.load-more-btn {
  padding: 10px 28px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.load-more-btn:hover {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: white;
}

/* ---- Empty state ---- */
.empty-state {
  max-width: var(--max-width);
  margin: 60px auto 0;
  text-align: center;
  padding: 0 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state-text { font-size: 0.9rem; line-height: 1.6; }

/* ---- Loading skeleton ---- */
.skeleton {
  background: linear-gradient(90deg, #eeece8 25%, #f4f3f0 50%, #eeece8 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
  color: transparent !important;
  user-select: none;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ============================================================
   Detail Panel
   ============================================================ */

.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 50;
  pointer-events: none;
  transition: background 0.25s ease;
}

.panel-backdrop.open {
  background: rgba(0, 0, 0, 0.28);
  pointer-events: auto;
}

.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(860px, 92vw);
  background: var(--surface-raised);
  box-shadow: var(--shadow-lg);
  z-index: 51;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
}

.panel.open {
  transform: translateX(0);
}

/* Mobile: bottom sheet */
@media (max-width: 600px) {
  .panel {
    top: 5vh;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
  }
  .panel.open {
    transform: translateY(0);
  }
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Mobile drag handle */
@media (max-width: 600px) {
  .panel-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
  }
  .panel-header { padding-top: 22px; position: relative; }
}

.panel-back {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px 6px 6px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.panel-back:hover { background: var(--bg); color: var(--text-primary); }

.panel-source-btn {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--bg);
  border: 1.5px solid var(--border-strong);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.panel-source-btn:hover {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: white;
}

.panel-body {
  overflow-y: auto;
  flex: 1;
  padding: 28px 44px 56px;
  -webkit-overflow-scrolling: touch;
}

.panel-note-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.35;
  margin-bottom: 10px;
  letter-spacing: -0.2px;
}

.panel-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.panel-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}

/* ---- Rendered markdown content ---- */
.note-content {
  font-family: var(--font-reading);
  font-size: 1.03rem;
  line-height: 1.72;
  color: var(--text-primary);
  max-width: 72ch;
}

.note-content h1,
.note-content h2,
.note-content h3 {
  font-family: var(--font-ui);
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 1.4em;
  margin-bottom: 0.4em;
  line-height: 1.3;
  letter-spacing: -0.2px;
}

.note-content h1 { font-size: 1.15rem; }
.note-content h2 { font-size: 1rem; }
.note-content h3 { font-size: 0.92rem; color: var(--text-secondary); }

.note-content h3:first-child,
.note-content h1:first-child { margin-top: 0; }

.note-content p { margin-bottom: 1em; }
.note-content p:last-child { margin-bottom: 0; }

.note-content strong { font-weight: 700; color: var(--text-primary); }
.note-content em { font-style: italic; }

.note-content a {
  color: #3b82f6;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-word;
}
.note-content a:hover { color: #2563eb; }

.note-content blockquote {
  border-left: 3px solid var(--border-strong);
  padding: 2px 0 2px 16px;
  margin: 1em 0;
  color: var(--text-secondary);
}

.note-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}

.note-content ul, .note-content ol {
  padding-left: 1.4em;
  margin-bottom: 1em;
}
.note-content li { margin-bottom: 0.3em; }

.note-content code {
  font-family: "SF Mono", SFMono-Regular, Consolas, Menlo, monospace;
  font-size: 0.85em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.note-content pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin-bottom: 1em;
}
.note-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
}

.note-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 0.5em 0;
  display: block;
}

/* Post separator lines from Twitter threads */
.note-content h3 + p { margin-top: 0; }

.panel-loading {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
}

/* ============================================================
   Login
   ============================================================ */

.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
}

.login-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.2px;
}

.login-subtitle {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.login-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text-primary);
  font-family: var(--font-ui);
  margin-bottom: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}
.login-input:focus {
  outline: none;
  border-color: #a8a29e;
  box-shadow: 0 0 0 3px rgba(168,162,158,0.15);
}

.login-btn {
  width: 100%;
  padding: 11px;
  background: var(--text-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background 0.15s;
}
.login-btn:hover { background: #333; }

.login-error {
  font-size: 0.82rem;
  color: #ef4444;
  margin-bottom: 12px;
  background: #fef2f2;
  border-radius: var(--radius-xs);
  padding: 6px 10px;
}

/* ---- Responsive ---- */
@media (min-width: 600px) {
  .topbar { padding: 14px 20px 12px; }
  .note-list { padding: 16px 20px 48px; }
  .load-more-wrap { padding: 4px 20px 60px; }
}

@media (max-width: 400px) {
  .note-title { font-size: 0.9rem; }
  .note-ainote { font-size: 0.8rem; }
}
