/* ==========================================================================
   Clean Notes-App Typography & Pure Design System
   Auto Dark / Light Mode via @media (prefers-color-scheme)
   ========================================================================== */

:root {
  /* Light Theme (Default) */
  --bg-main: #fbfbfb;
  --bg-surface: #ffffff;
  --bg-subtle: #f4f4f5;
  --bg-muted: #e4e4e7;
  --border-color: #e4e4e7;
  --border-subtle: #f4f4f5;

  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  --text-dim: #a1a1aa;

  --accent-primary: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-subtle: #eff6ff;
  --accent-border: #bfdbfe;

  --badge-bg: #f4f4f5;
  --badge-text: #52525b;

  --code-bg: #f4f4f5;
  --code-border: #e4e4e7;
  --code-color: #09090b;

  --danger-bg: #fef2f2;
  --danger-text: #dc2626;
  --danger-border: #fecaca;

  --success-bg: #f0fdf4;
  --success-text: #16a34a;
  --success-border: #bbf7d0;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --max-content-width: 720px;
  --max-wide-width: 1040px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Newsreader", "Georgia", "Cambria", "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-main: #09090b;
    --bg-surface: #121215;
    --bg-subtle: #18181b;
    --bg-muted: #27272a;
    --border-color: #27272a;
    --border-subtle: #1f1f23;

    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --text-dim: #52525b;

    --accent-primary: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-subtle: #172554;
    --accent-border: #1e3a8a;

    --badge-bg: #1c1c20;
    --badge-text: #a1a1aa;

    --code-bg: #18181b;
    --code-border: #27272a;
    --code-color: #f4f4f5;

    --danger-bg: #450a0a;
    --danger-text: #f87171;
    --danger-border: #7f1d1d;

    --success-bg: #052e16;
    --success-text: #4ade80;
    --success-border: #14532d;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
  }
}

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

html {
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

a.text-link {
  color: var(--accent-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}
a.text-link:hover {
  color: var(--accent-hover);
}

/* App Container */
.app-container {
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
  flex: 1;
}

.app-container.wide {
  max-width: var(--max-wide-width);
}

/* Header & Minimal Nav */
.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}

.site-brand {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-brand .brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--accent-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-subtle {
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-subtle:hover {
  color: var(--text-primary);
  background-color: var(--bg-subtle);
  border-color: var(--border-color);
}

.btn-primary {
  font-size: 0.875rem;
  font-weight: 500;
  color: #ffffff;
  background-color: var(--accent-primary);
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  transition: background-color 0.15s ease;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
}

.btn-danger {
  font-size: 0.875rem;
  color: var(--danger-text);
  background-color: var(--danger-bg);
  border: 1px solid var(--danger-border);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Search Bar Component */
.search-wrapper {
  margin-bottom: 2.5rem;
  position: relative;
}

.search-input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 1rem;
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  padding: 0.85rem 1rem 0.85rem 2.85rem;
  font-size: 1rem;
  font-family: inherit;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.search-badge {
  position: absolute;
  right: 0.85rem;
  font-size: 0.75rem;
  font-weight: 500;
  background-color: var(--badge-bg);
  color: var(--badge-text);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  pointer-events: none;
}

/* Post List Component */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.post-item {
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border-subtle);
  transition: transform 0.15s ease;
}

.post-item:last-child {
  border-bottom: none;
}

.post-item:hover .post-item-title {
  color: var(--accent-primary);
}

.post-item-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}

.post-item-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  transition: color 0.15s ease;
}

.post-item-date {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.post-item-excerpt {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 0.6rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-item-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.tag-pill {
  font-size: 0.75rem;
  background-color: var(--badge-bg);
  color: var(--badge-text);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
}

.score-badge {
  font-size: 0.75rem;
  font-weight: 600;
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  border: 1px solid var(--accent-border);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
}

/* Reader View */
.article-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.article-title {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.article-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.article-meta-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.article-actions-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.article-cover {
  width: 100%;
  max-height: 480px;
  object-fit: cover;
  border-radius: var(--radius-md);
  margin-bottom: 2.5rem;
}

/* Markdown Typography Content */
.prose {
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--text-primary);
}

.prose p {
  margin-bottom: 1.5rem;
}

.prose h1, .prose h2, .prose h3, .prose h4 {
  color: var(--text-primary);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 2rem;
  margin-bottom: 0.85rem;
  line-height: 1.3;
}

.prose h1 { font-size: 1.75rem; }
.prose h2 { font-size: 1.45rem; }
.prose h3 { font-size: 1.25rem; }

.prose ul, .prose ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
}

.prose li {
  margin-bottom: 0.4rem;
}

.prose blockquote {
  border-left: 3px solid var(--accent-primary);
  padding-left: 1.25rem;
  margin: 1.5rem 0;
  color: var(--text-secondary);
  font-style: italic;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background-color: var(--code-bg);
  border: 1px solid var(--code-border);
  color: var(--code-color);
  padding: 0.15em 0.35em;
  border-radius: 4px;
}

.prose pre {
  background-color: var(--code-bg);
  border: 1px solid var(--code-border);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 1.5rem 0;
  position: relative;
}

.prose pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.6;
}

.code-copy-btn {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.code-copy-btn:hover {
  color: var(--text-primary);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9375rem;
}

.prose th, .prose td {
  border: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  text-align: left;
}

.prose th {
  background-color: var(--bg-subtle);
  font-weight: 600;
}

/* Media Cards in Article */
.media-embed-card {
  margin: 2rem 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
}

.media-embed-card img,
.media-embed-card video {
  width: 100%;
  display: block;
  max-height: 520px;
  object-fit: contain;
  background-color: #000000;
}

.media-embed-toolbar {
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-subtle);
  border-top: 1px solid var(--border-color);
  font-size: 0.8125rem;
}

.media-embed-actions {
  display: flex;
  gap: 0.5rem;
}

/* Responsive Embeds (YouTube / Glomble) */
.video-responsive-wrap {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  border-radius: var(--radius-md);
  margin: 2rem 0;
  border: 1px solid var(--border-color);
  background: #000;
}

.video-responsive-wrap iframe,
.video-responsive-wrap video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Article Sharing Drawer & Modal */
.share-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

.share-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.share-button-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 1rem;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  padding: 1.75rem;
  transform: translateY(12px);
  transition: transform 0.2s ease;
}

.modal-backdrop.open .modal-card {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 700;
}

.modal-body {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Forms & Clean Inputs */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  color: var(--text-primary);
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 0.9375rem;
  font-family: inherit;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

/* Pagination */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-subtle);
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast-msg {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: toastIn 0.2s ease forwards;
}

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

/* Comments Section & Badges */
.comments-section {
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

.comments-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.comments-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
}

.comment-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease;
}

.comment-box:focus-within {
  border-color: var(--accent-primary);
}

.comment-identity-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.comment-identity-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.identity-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.identity-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.badge {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  line-height: 1.2;
}

.badge-author {
  background-color: rgba(234, 179, 8, 0.12);
  color: #eab308;
  border: 1px solid rgba(234, 179, 8, 0.35);
}

.badge-writer {
  background-color: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.badge-anon {
  background-color: rgba(161, 161, 170, 0.12);
  color: #a1a1aa;
  border: 1px solid rgba(161, 161, 170, 0.25);
}

.comment-textarea-wrapper {
  margin-bottom: 0.75rem;
}

.comment-textarea {
  width: 100%;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.75rem 0.875rem;
  font-size: 0.9375rem;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.comment-textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

.comment-submit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.comment-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.comments-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.comment-item {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease;
  animation: fadeIn 0.25s ease forwards;
}

.comment-item:hover {
  border-color: var(--border-subtle);
}

.comment-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.comment-author-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.comment-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9375rem;
  flex-shrink: 0;
  user-select: none;
}

.comment-author-meta {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.comment-author-name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.comment-author-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.comment-time-row {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.comment-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.comment-edited-tag {
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-style: italic;
}

.comment-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.comment-body {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-primary);
  word-break: break-word;
}

.comment-edit-form {
  margin-top: 0.5rem;
}

.comment-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.comment-turnstile-container {
  margin: 0.85rem 0 0.5rem;
  width: 100%;
  display: flex;
}

.comment-turnstile-container .cf-turnstile,
.comment-turnstile-container iframe {
  width: 100% !important;
  max-width: 100%;
}

.hide-action {
  display: none !important;
}

.empty-comments-card {
  text-align: center;
  padding: 3rem 1.5rem;
  background-color: var(--bg-surface);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.btn-xs {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
}

.btn-icon {
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  line-height: 1;
}

.btn-icon:hover {
  color: var(--danger-text);
  background-color: var(--danger-subtle);
}

/* Site Footer */
.site-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.site-footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.site-footer-links {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.footer-link {
  color: var(--text-muted);
  transition: color 0.15s ease;
}

.footer-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .app-container {
    padding: 1.5rem 1rem 3rem;
  }
  .article-title {
    font-size: 1.75rem;
  }
  .header-bar {
    margin-bottom: 1.75rem;
  }
  .search-wrapper {
    margin-bottom: 1.75rem;
  }
  .site-footer-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
}

