/* ── CSS Custom Properties ── */
:root {
  --font-size: 18px;
  --font-family: Georgia, 'Times New Roman', serif;
  --line-height: 1.7;
  --bg-color: #ffffff;
  --text-color: #1a1a1a;
  --text-secondary: #555;
  --border-color: #e0e0e0;
  --card-bg: #ffffff;
  --card-hover: #f8f8f8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --toolbar-bg: #ffffff;
  --input-bg: #f5f5f5;
  --highlight-yellow: #fff3a3;
  --highlight-green: #b5e8b5;
  --highlight-blue: #b3d4fc;
  --highlight-pink: #f8b4c8;
  --highlight-purple: #d4b5f0;
}

/* ── Theme: Sepia ── */
body.theme-sepia {
  --bg-color: #f4ecd8;
  --text-color: #433422;
  --text-secondary: #6b5b4a;
  --border-color: #d4c9b0;
  --card-bg: #f4ecd8;
  --card-hover: #ede4cc;
  --toolbar-bg: #f4ecd8;
  --input-bg: #ebe2cd;
}

/* ── Theme: Dark ── */
body.theme-dark {
  --bg-color: #1a1a1a;
  --text-color: #d4d4d4;
  --text-secondary: #999;
  --border-color: #333;
  --card-bg: #242424;
  --card-hover: #2a2a2a;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --toolbar-bg: #242424;
  --input-bg: #2a2a2a;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  color: var(--text-color);
  background: var(--bg-color);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
}

/* ── Login ── */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 24px;
  text-align: center;
  font-weight: 600;
}

.login-card input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background: var(--input-bg);
  color: var(--text-color);
  margin-bottom: 16px;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.login-card .btn-primary {
  width: 100%;
}

.login-error {
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 12px;
  text-align: center;
}

/* ── Buttons ── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  transition: background 0.15s;
}

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  transition: background 0.15s;
  font-size: 18px;
}

.btn-icon:hover {
  background: var(--card-hover);
}

/* ── Article List ── */
.list-container {
  max-width: 700px;
  margin: 0 auto;
  padding: 20px;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.list-header h1 {
  font-size: 22px;
  font-weight: 600;
}

.list-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Filter Tabs ── */
.filter-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
}

.filter-tab {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-tab:hover {
  color: var(--text-color);
}

.filter-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Search ── */
.search-bar {
  margin-bottom: 16px;
}

.search-bar input {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 15px;
  background: var(--input-bg);
  color: var(--text-color);
}

.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Article Card ── */
.article-card {
  display: block;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.1s;
  text-decoration: none;
  color: inherit;
}

.article-card:hover {
  text-decoration: none;
}

.article-card-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 4px;
  color: var(--text-color);
}

.article-card-meta {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.article-card-meta .sep {
  opacity: 0.4;
}

.article-card-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.article-card-content {
  flex: 1;
  min-width: 0;
}

.article-card-excerpt {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article-card-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.favorite-btn {
  font-size: 18px;
  padding: 4px;
  transition: transform 0.15s;
}

.favorite-btn:hover {
  transform: scale(1.2);
}

.favorite-btn.active {
  color: #f59e0b;
}

.article-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.article-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text-secondary);
}

/* ── Load More ── */
.load-more {
  text-align: center;
  padding: 20px;
}

.load-more button {
  padding: 10px 24px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.load-more button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 15px;
}

/* ── Reader View ── */
.reader-container {
  max-width: 650px;
  margin: 0 auto;
  padding: 20px 24px 100px;
}

/* ── Reader Toolbar ── */
.reader-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
}

.reader-toolbar-left,
.reader-toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Reader Header ── */
.reader-header {
  margin-bottom: 32px;
  padding-top: 16px;
}

.reader-header h1 {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 12px;
}

.reader-meta {
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.reader-meta a {
  color: var(--accent);
}

.reader-meta .sep {
  opacity: 0.4;
}

/* ── Reader Content ── */
.reader-content {
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--text-color);
}

.reader-content p {
  margin-bottom: 1.2em;
}

.reader-content h1,
.reader-content h2,
.reader-content h3,
.reader-content h4,
.reader-content h5,
.reader-content h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  line-height: 1.3;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.reader-content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 16px 0;
}

.reader-content pre {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 16px 0;
  font-size: 0.875em;
  line-height: 1.5;
}

.reader-content code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.9em;
}

.reader-content p code,
.reader-content li code {
  background: var(--input-bg);
  padding: 2px 6px;
  border-radius: 4px;
}

.reader-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  margin: 16px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.reader-content ul,
.reader-content ol {
  padding-left: 24px;
  margin-bottom: 1.2em;
}

.reader-content li {
  margin-bottom: 0.4em;
}

.reader-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.reader-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.95em;
}

.reader-content th,
.reader-content td {
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  text-align: left;
}

.reader-content th {
  background: var(--input-bg);
  font-weight: 600;
}

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

/* ── Bottom Bar ── */
.reader-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--toolbar-bg);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
}

.reader-bottom-bar .btn-icon {
  width: 44px;
  height: 44px;
  font-size: 20px;
}

.reader-bottom-bar .btn-icon.active {
  color: var(--accent);
}

.reader-bottom-bar .btn-icon.danger:hover {
  color: var(--danger);
}

/* ── Font Controls Panel ── */
.font-panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
}

.font-panel {
  position: fixed;
  top: 52px;
  right: 16px;
  z-index: 201;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  width: 280px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.font-panel-section {
  margin-bottom: 16px;
}

.font-panel-section:last-child {
  margin-bottom: 0;
}

.font-panel-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.font-size-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.font-size-control button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.font-size-control button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.font-size-control .size-value {
  font-size: 14px;
  font-weight: 500;
}

.font-options {
  display: flex;
  gap: 4px;
}

.font-option {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  transition: all 0.15s;
}

.font-option:hover {
  border-color: var(--accent);
}

.font-option.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.theme-options {
  display: flex;
  gap: 8px;
}

.theme-option {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  transition: all 0.15s;
}

.theme-option:hover {
  transform: scale(1.1);
}

.theme-option.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.theme-option.light { background: #ffffff; }
.theme-option.sepia { background: #f4ecd8; }
.theme-option.dark { background: #1a1a1a; }

/* ── Highlight Styles ── */
mark[data-highlight] {
  cursor: pointer;
  border-radius: 2px;
  padding: 1px 0;
  transition: filter 0.15s;
}

mark[data-highlight]:hover {
  filter: brightness(0.92);
}

mark[data-color="yellow"] { background: var(--highlight-yellow); }
mark[data-color="green"] { background: var(--highlight-green); }
mark[data-color="blue"] { background: var(--highlight-blue); }
mark[data-color="pink"] { background: var(--highlight-pink); }
mark[data-color="purple"] { background: var(--highlight-purple); }

.highlight-note-icon {
  display: inline-block;
  font-size: 12px;
  vertical-align: super;
  cursor: pointer;
  margin-left: 2px;
  opacity: 0.7;
}

.highlight-note-icon:hover {
  opacity: 1;
}

/* ── Highlight Popover ── */
.highlight-popover {
  position: fixed;
  z-index: 300;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.highlight-colors {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.highlight-color-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: all 0.15s;
}

.highlight-color-btn:hover {
  transform: scale(1.15);
}

.highlight-color-btn.active {
  border-color: var(--text-color);
}

.highlight-color-btn.yellow { background: var(--highlight-yellow); }
.highlight-color-btn.green { background: var(--highlight-green); }
.highlight-color-btn.blue { background: var(--highlight-blue); }
.highlight-color-btn.pink { background: var(--highlight-pink); }
.highlight-color-btn.purple { background: var(--highlight-purple); }

.highlight-popover-actions {
  display: flex;
  gap: 4px;
  justify-content: center;
  border-top: 1px solid var(--border-color);
  padding-top: 6px;
}

.highlight-popover-actions button {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 6px;
  transition: background 0.15s;
}

.highlight-popover-actions button:hover {
  background: var(--card-hover);
}

.highlight-popover-actions button.danger {
  color: var(--danger);
}

.highlight-note-input {
  width: 220px;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 13px;
  background: var(--input-bg);
  color: var(--text-color);
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

.highlight-note-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Scroll end marker (for IntersectionObserver) ── */
.reader-end-marker {
  height: 1px;
}

/* ── Loading / Spinner ── */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .list-container {
    padding: 16px;
  }

  .reader-container {
    padding: 16px 16px 100px;
  }

  .reader-header h1 {
    font-size: 24px;
  }

  .font-panel {
    right: 8px;
    left: 8px;
    width: auto;
  }

  .login-card {
    padding: 28px 24px;
  }
}

@media (max-width: 480px) {
  .list-container {
    padding: 12px;
  }

  .reader-container {
    padding: 12px 12px 100px;
  }

  .reader-header h1 {
    font-size: 22px;
  }

  .article-card-title {
    font-size: 16px;
  }

  .filter-tab {
    padding: 8px 12px;
    font-size: 13px;
  }
}
