/* =====================================================
   仙境圖書館 - 全站樣式
   ===================================================== */

/* CSS Variables */
:root {
  /* 深色主題 (預設) */
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #252542;
  --bg-hover: #2d2d4a;

  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b80;

  --accent: #7c3aed;
  --accent-light: #a78bfa;
  --accent-dark: #5b21b6;

  --border: #3d3d5c;
  --shadow: rgba(0, 0, 0, 0.4);

  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;

  --font-sans: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-serif: "Noto Serif TC", "PMingLiU", serif;

  --transition: 0.2s ease;
  --radius: 8px;
  --radius-lg: 12px;
}

/* 淺色主題 */
[data-theme="light"] {
  --bg-primary: #f8f8fc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f0f0f8;

  --text-primary: #1a1a2e;
  --text-secondary: #4a4a60;
  --text-muted: #8888a0;

  --border: #e0e0f0;
  --shadow: rgba(0, 0, 0, 0.1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

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

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

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

input,
textarea {
  font-family: inherit;
  font-size: inherit;
}

/* =====================================================
   Layout
   ===================================================== */

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

/* Header */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  font-size: 1.8rem;
}

.nav {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-link {
  color: var(--text-secondary);
  font-weight: 500;
  padding: 8px 0;
  position: relative;
}

.nav-link:hover,
.nav-link.active {
  color: var(--text-primary);
}

.nav-link.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}

/* Theme Toggle */
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: background var(--transition);
}

.theme-toggle:hover {
  background: var(--bg-hover);
}

/* Main */
.main {
  padding: 40px 0;
  min-height: calc(100vh - 140px);
}

/* Footer */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 24px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* =====================================================
   Components
   ===================================================== */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-weight: 500;
  transition: all var(--transition);
}

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

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px var(--shadow);
}

.card-cover {
  aspect-ratio: 3 / 4;
  background: var(--bg-secondary);
  overflow: hidden;
}

.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-body {
  padding: 16px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-author {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.card-meta {
  display: flex;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Tags */
.tag {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg-hover);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.tag-primary {
  background: var(--accent);
  color: white;
}

/* Search */
.search-box {
  position: relative;
  max-width: 400px;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  transition: border-color var(--transition);
}

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

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

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* Grid */
.grid {
  display: grid;
  gap: 24px;
}

.grid-novels {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.grid-chapters {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* =====================================================
   Pages - Home
   ===================================================== */

.hero {
  text-align: center;
  padding: 60px 20px;
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-card));
  border-radius: var(--radius-lg);
  margin-bottom: 40px;
}

.hero-title {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-desc {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 24px;
}

.section {
  margin-bottom: 48px;
}

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

.section-title {
  font-size: 1.5rem;
  font-weight: 600;
}

/* =====================================================
   Pages - Novel Detail
   ===================================================== */

.novel-header {
  display: flex;
  gap: 32px;
  margin-bottom: 40px;
}

.novel-cover {
  width: 240px;
  flex-shrink: 0;
  aspect-ratio: 3 / 4;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.novel-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.novel-info {
  flex: 1;
}

.novel-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.novel-author {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.novel-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.novel-stats {
  display: flex;
  gap: 24px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.novel-summary {
  color: var(--text-secondary);
  line-height: 1.8;
}

.novel-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

/* Chapter List */
.chapter-list {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.chapter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

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

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

.chapter-title {
  font-weight: 500;
}

.chapter-date {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* =====================================================
   Pages - Reader
   ===================================================== */

.reader {
  max-width: 800px;
  margin: 0 auto;
}

.reader-header {
  text-align: center;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.reader-novel-title {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.reader-chapter-title {
  font-size: 1.8rem;
  font-weight: 600;
}

.reader-content {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  line-height: 2;
  color: var(--text-primary);
}

.reader-content p {
  text-indent: 2em;
  margin-bottom: 1.5em;
}

.reader-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.reader-nav-btn {
  flex: 1;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  transition: all var(--transition);
}

.reader-nav-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.reader-nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.reader-nav-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Reader Settings */
.reader-settings {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reader-settings .btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  box-shadow: 0 4px 12px var(--shadow);
}

.reader-settings .btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* =====================================================
   Pages - Bookshelf
   ===================================================== */

.bookshelf-empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-secondary);
}

.bookshelf-empty-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* =====================================================
   Pages - Admin
   ===================================================== */

.admin-container {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  min-height: calc(100vh - 140px);
}

.admin-sidebar {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px;
  height: fit-content;
  position: sticky;
  top: 100px;
}

.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  transition: all var(--transition);
  margin-bottom: 4px;
}

.admin-nav-item:hover,
.admin-nav-item.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.admin-content {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 24px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.admin-title {
  font-size: 1.5rem;
  font-weight: 600;
}

/* Form */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  transition: border-color var(--transition);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-textarea {
  min-height: 150px;
  resize: vertical;
}

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
}

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

.table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

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

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9);
  transition: transform var(--transition);
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px var(--shadow);
  animation: slideUp 0.3s ease;
}

.toast-success {
  border-color: var(--success);
}

.toast-error {
  border-color: var(--error);
}

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

/* =====================================================
   Utilities
   ===================================================== */

.hidden {
  display: none !important;
}

.loading {
  opacity: 0.6;
  pointer-events: none;
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-card) 25%,
    var(--bg-hover) 50%,
    var(--bg-card) 75%
  );
  background-size: 200% 100%;
  animation: skeleton 1.5s infinite;
  border-radius: var(--radius);
}

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

/* =====================================================
   Responsive
   ===================================================== */

@media (max-width: 768px) {
  .header-inner {
    flex-wrap: wrap;
  }

  .nav {
    order: 3;
    width: 100%;
    justify-content: center;
    padding-top: 12px;
  }

  .hero-title {
    font-size: 1.8rem;
  }

  .novel-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .novel-cover {
    width: 180px;
  }

  .novel-tags,
  .novel-stats {
    justify-content: center;
  }

  .novel-actions {
    justify-content: center;
  }

  .admin-container {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: static;
  }

  .reader-settings {
    bottom: 16px;
    right: 16px;
  }
}
