:root {
  --bg: #0a0a0a;
  --bg-elevated: #141414;
  --bg-card: #1a1a1a;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --text-muted: #9a9a9a;
  --accent: #119f86;
  --accent-hover: #0e8a74;
  --accent-dim: rgba(17, 159, 134, 0.15);
  --danger: #e85d5d;
  --font-serif: "Libre Baskerville", "Georgia", serif;
  --font-sans: "Inter", system-ui, -apple-system, sans-serif;
  --radius: 8px;
  --max-width: 1100px;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  overflow-x: hidden;
}

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

a:hover {
  color: var(--accent-hover);
}

img {
  max-width: 100%;
}

/* Nav */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-nav .logo {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.site-nav .logo span {
  color: var(--accent);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-links a {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--text);
}

.nav-badge {
  position: relative;
}

.nav-badge .count {
  position: absolute;
  top: -6px;
  right: -10px;
  background: var(--accent);
  color: #000;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle-bar {
  display: block;
  width: 18px;
  height: 2px;
  margin: 0 auto;
  background: var(--text);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

.site-nav.is-open .nav-toggle-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.site-nav.is-open .nav-toggle-bar:nth-child(2) {
  opacity: 0;
}

.site-nav.is-open .nav-toggle-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

@keyframes menuDropIn {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Layout */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.container-narrow {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

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

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 0.5rem;
}

.btn-ghost:hover {
  color: var(--text);
}

.btn-google {
  background: #fff;
  color: #333;
  border: 1px solid #ddd;
  width: 100%;
  gap: 0.65rem;
}

.btn-google:hover {
  background: #f5f5f5;
  color: #333;
}

.btn-google .google-icon {
  flex-shrink: 0;
}

/* Forms */
.auth-card {
  max-width: 420px;
  margin: 3rem auto;
  padding: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.auth-card h1 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  margin: 0 0 0.5rem;
}

.auth-card .subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: none;
}

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

.form-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Stylish remember-me toggle */
.remember-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  margin: 0.25rem 0 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}

.remember-toggle:hover {
  border-color: #3a3a3a;
  background: var(--bg-elevated);
}

.remember-toggle:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.remember-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.remember-toggle-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.remember-toggle-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

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

.remember-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.2s;
}

.remember-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s;
}

.remember-toggle input:checked + .remember-switch {
  background: var(--accent);
}

.remember-toggle input:checked + .remember-switch::after {
  transform: translateX(20px);
}

/* Paper attachments */
.attachment-panel {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.attachment-title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  margin: 0 0 1rem;
}

.attachment-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.attachment-icon {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.5rem 0.65rem;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 4px;
}

.attachment-info {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.attachment-info span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

.attachment-preview {
  width: 100%;
  height: 520px;
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.attachment-txt-preview {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.attachment-status {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: -0.25rem 0 1rem;
}

.attachment-picker {
  cursor: pointer;
}

/* Flash */
.flash-messages {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.5rem 1.5rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.flash.success {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--text);
}

.flash.error {
  background: rgba(232, 93, 93, 0.1);
  border: 1px solid var(--danger);
}

.flash.info {
  background: var(--bg-card);
  border: 1px solid var(--border);
}

/* Feed cards */
.feed-grid {
  display: grid;
  gap: 1.5rem;
}

.paper-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  transition: border-color 0.15s;
}

.paper-card:hover {
  border-color: #3a3a3a;
}

.paper-card h2 {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  margin: 0 0 0.5rem;
}

.paper-card h2 a {
  color: var(--text);
}

.paper-card h2 a:hover {
  color: var(--accent);
}

.paper-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.paper-meta .author-link {
  color: var(--text);
  font-weight: 500;
}

.paper-excerpt {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.paper-stats {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Paper detail */
.paper-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.paper-header h1 {
  font-family: var(--font-serif);
  font-size: 2.25rem;
  line-height: 1.2;
  margin: 0 0 1rem;
}

.paper-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.paper-actions .liked {
  border-color: var(--accent);
  color: var(--accent);
}

.markdown-body {
  font-size: 1.05rem;
  line-height: 1.75;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  font-family: var(--font-serif);
  margin-top: 1.5em;
}

.markdown-body pre {
  background: var(--bg);
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
}

.markdown-body code {
  background: var(--bg);
  padding: 0.15em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  margin-left: 0;
  padding-left: 1rem;
  color: var(--text-muted);
}

/* Comments */
.comments-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.comment {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.comment-author {
  font-weight: 600;
  font-size: 0.9rem;
}

.comment-time {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-left: 0.5rem;
}

/* Dashboard */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  font-family: var(--font-serif);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

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

.stats-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.stats-table tr:hover td {
  background: var(--bg-elevated);
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}

/* Landing placeholder */
.landing-hero {
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
}

.landing-hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.5rem, 6vw, 4rem);
  margin: 0 0 1rem;
  max-width: 14ch;
  line-height: 1.1;
}

.landing-hero p {
  color: var(--text-muted);
  font-size: 1.15rem;
  max-width: 42ch;
  margin-bottom: 2rem;
}

.landing-cta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-header h1 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  margin: 0;
}

.notification-item {
  display: block;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.notification-item.unread {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
}

.notification-item:hover {
  background: var(--bg-elevated);
}

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

/* Editor */
.editor-toolbar-extra {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.EasyMDEContainer .CodeMirror {
  background: var(--bg) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
  min-height: 320px;
}

.EasyMDEContainer .editor-toolbar {
  background: var(--bg-card) !important;
  border-color: var(--border) !important;
}

.EasyMDEContainer .editor-toolbar button {
  color: var(--text-muted) !important;
}

.EasyMDEContainer .editor-toolbar button:hover {
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
}

.editor-preview {
  background: var(--bg-card);
  padding: 1rem;
  border-radius: var(--radius);
  margin-top: 1rem;
}

/* Desktop: always keep the original horizontal nav */
@media (min-width: 641px) {
  .nav-toggle {
    display: none !important;
  }

  .site-nav .nav-links {
    display: flex !important;
    flex-direction: row;
    align-items: center;
    width: auto;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
  }

  .site-nav {
    flex-wrap: nowrap;
  }
}

@media (max-width: 640px) {
  .site-nav {
    position: sticky;
    flex-wrap: nowrap;
    padding: 0.75rem 1rem;
    gap: 0;
  }

  .nav-toggle {
    display: flex;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: calc(100% + 0.35rem);
    right: 1rem;
    left: auto;
    bottom: auto;
    flex-direction: column;
    align-items: stretch;
    width: min(260px, calc(100vw - 2rem));
    gap: 0.15rem;
    margin: 0;
    padding: 0.4rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
    overflow-y: auto;
    max-height: calc(100vh - 4rem);
    z-index: 101;
    -webkit-overflow-scrolling: touch;
    transform-origin: top right;
  }

  .site-nav.is-open .nav-links {
    display: flex;
    animation: menuDropIn 0.22s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  .nav-links li {
    width: 100%;
  }

  .nav-links a {
    display: block;
    padding: 0.75rem 0.85rem;
    font-size: 0.95rem;
    border-bottom: none;
    border-radius: 6px;
    transition: background 0.2s ease;
  }

  .nav-links a:hover,
  .nav-links a.active {
    background: var(--bg-elevated);
  }

  .nav-badge .count {
    position: static;
    display: inline-flex;
    margin-left: 0.5rem;
    vertical-align: middle;
  }

  .container,
  .container-narrow {
    padding: 1.25rem 1rem;
  }

  .auth-card {
    margin: 1.5rem auto;
    padding: 1.5rem 1.25rem;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .page-header .btn {
    width: 100%;
  }

  .paper-header h1 {
    font-size: 1.75rem;
  }

  .paper-actions .btn {
    flex: 1 1 100%;
  }

  .attachment-card {
    flex-direction: column;
    align-items: stretch;
  }

  .attachment-actions {
    width: 100%;
  }

  .attachment-actions .btn {
    flex: 1;
  }

  .attachment-preview {
    height: min(520px, 60vh);
  }

  .editor-toolbar-extra {
    flex-wrap: wrap;
  }

  .editor-toolbar-extra .btn {
    flex: 1 1 auto;
    min-width: calc(50% - 0.25rem);
  }

  .EasyMDEContainer .editor-toolbar {
    flex-wrap: wrap;
  }

  .stats-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .stat-card {
    padding: 1rem;
  }

  .stat-card .value {
    font-size: 1.5rem;
  }

  .stats-table {
    font-size: 0.8rem;
    min-width: 520px;
  }

  .stats-table th,
  .stats-table td {
    padding: 0.55rem 0.65rem;
  }

  .paper-card {
    padding: 1.15rem;
  }

  .flash-messages {
    padding: 0.5rem 1rem;
  }
}

@media (max-width: 480px) {
  .stats-row {
    grid-template-columns: 1fr;
  }
}
