:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --radius: 14px;
  --shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.06);
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #1e293b;
  --surface-2: #0f172a;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-soft: rgba(99, 102, 241, 0.16);
  --shadow: 0 4px 24px -2px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  transition: background 0.2s, color 0.2s;
}

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

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
  gap: 16px;
}

.logo {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
  cursor: pointer;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--surface-2);
  color: var(--text);
}
.btn:hover { opacity: 0.92; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: rgba(16, 185, 129, 0.14); color: var(--success); }
.btn-donate { background: linear-gradient(135deg, #f59e0b, #ea580c); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; border-radius: 8px; }
.btn-liked { background: rgba(239, 68, 68, 0.14); color: #ef4444; border-color: rgba(239, 68, 68, 0.3); }

/* Hero */
.hero {
  margin: 28px 0 36px;
  padding: 40px 32px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.hero h1 { font-size: 2rem; font-weight: 800; line-height: 1.2; margin-bottom: 10px; }
.hero p { opacity: 0.9; max-width: 580px; font-size: 1.05rem; margin-bottom: 20px; }

/* Sections & Grids */
.section { margin-bottom: 44px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.section-title { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }

.grid-works {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.grid-authors {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* Work Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.card:hover { transform: translateY(-3px); }

.work-cover {
  height: 190px;
  background: linear-gradient(135deg, #312e81, #4f46e5);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.85);
  font-weight: 700;
  font-size: 1.1rem;
  text-align: center;
  padding: 16px;
  background-size: cover;
  background-position: center;
  cursor: pointer;
}

.rating-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 3px 9px;
  border-radius: 7px;
  font-size: 0.76rem;
  font-weight: 800;
  color: #fff;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(4px);
}
.rating-G { background: #10b981; }
.rating-PG { background: #3b82f6; }
.rating-R { background: #f59e0b; }
.rating-NC-17 { background: #ef4444; }
.rating-NC-21 { background: #991b1b; }

.card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 8px;
}

.work-genre {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.work-title {
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.3;
  cursor: pointer;
}
.work-title:hover { color: var(--primary); }

.work-author {
  font-size: 0.86rem;
  color: var(--text-muted);
  cursor: pointer;
}
.work-author:hover { text-decoration: underline; }

.work-excerpt {
  font-size: 0.86rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.card-footer {
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Author Card */
.author-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: transform 0.15s;
}
.author-card:hover { transform: translateY(-2px); border-color: var(--primary); }

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

/* Forms & Inputs */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.tab {
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
}
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Reader Mode */
.reader-box {
  max-width: 780px;
  margin: 0 auto;
  padding: 36px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  line-height: 1.85;
  font-size: 18px;
}
.reader-box.sepia {
  background: #f4ecd8;
  color: #3b2f2f;
  border-color: #e2d5b5;
}
.reader-content p {
  margin-bottom: 1.15em;
  text-indent: 1.5em;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  max-width: 460px;
  width: 100%;
  padding: 26px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 200;
  display: none;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 700; color: var(--text-muted); }

@media (max-width: 640px) {
  .hero { padding: 28px 20px; }
  .hero h1 { font-size: 1.5rem; }
  .reader-box { padding: 20px; }
}
