:root {
  --bg: hsl(210, 33%, 98%);
  --surface: hsl(0, 0%, 100%);
  --surface-hover: hsl(210, 18%, 96%);
  --border: hsl(240, 6%, 88%);
  --text: hsl(240, 10%, 10%);
  --text-secondary: hsl(240, 4%, 38%);
  --text-muted: hsl(240, 3%, 52%);
  --primary: hsl(200, 29%, 42%);
  --primary-hover: hsl(200, 32%, 35%);
  --primary-light: hsl(200, 28%, 93%);
  --success: hsl(152, 56%, 34%);
  --success-light: hsl(152, 45%, 94%);
  --warning: hsl(32, 85%, 44%);
  --warning-light: hsl(45, 90%, 96%);
  --danger: hsl(0, 72%, 50%);
  --danger-light: hsl(0, 80%, 97%);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'Source Sans 3', 'Noto Sans SC', system-ui, sans-serif;
}

html.dark {
  color-scheme: dark;
  --bg: hsl(240, 21%, 6%);
  --surface: hsl(240, 10%, 9%);
  --surface-hover: hsl(240, 8%, 12%);
  --border: hsl(240, 4%, 20%);
  --text: hsl(0, 0%, 96%);
  --text-secondary: hsl(240, 5%, 72%);
  --text-muted: hsl(240, 4%, 58%);
  --primary: hsl(195, 70%, 72%);
  --primary-hover: hsl(195, 75%, 78%);
  --primary-light: hsl(195, 30%, 16%);
  --success: hsl(152, 50%, 52%);
  --success-light: hsl(152, 30%, 14%);
  --warning: hsl(38, 80%, 58%);
  --warning-light: hsl(38, 40%, 14%);
  --danger: hsl(0, 65%, 62%);
  --danger-light: hsl(0, 40%, 14%);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

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

html {
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
  position: relative;
  isolation: isolate;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background: url('../assets/background.jpg') center / cover no-repeat;
  transform: scale(1.04);
  filter: blur(6px);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

html.dark body::after {
  background: color-mix(in srgb, var(--bg) 84%, transparent);
}

html.immersive body::before {
  transform: none;
  filter: none;
}

html.immersive body::after {
  display: none;
}

html.immersive .paper-card,
html.immersive .form-card,
html.immersive .reader-panel,
html.immersive .stat-card,
html.immersive .modal-content,
html.immersive .folder-tile {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

html.immersive .paper-card,
html.immersive .folder-tile {
  background: color-mix(in srgb, hsl(220 15% 10%) 48%, transparent);
  border-color: rgba(255, 255, 255, 0.16);
}

html.immersive .current-folder-label,
html.immersive .paper-title,
html.immersive .paper-meta,
html.immersive .paper-summary,
html.immersive .reader-title,
html.immersive .reader-meta,
html.immersive .folder-tile-name,
html.immersive .folder-tile-count {
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

html.immersive .paper-meta,
html.immersive .paper-summary,
html.immersive .reader-meta,
html.immersive .folder-tile-count {
  color: rgba(255, 255, 255, 0.88);
}

html.immersive .panel-header {
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.container-wide {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Header */
.header {
  background: transparent;
  border-bottom: none;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: none;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, backdrop-filter 0.2s;
}

.header.header--scrolled {
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}

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

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

.logo h1 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

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

.nav {
  display: flex;
  gap: 0.25rem;
  background: transparent;
  padding: 0.25rem;
  border-radius: var(--radius);
}

.nav-btn {
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-btn:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.nav-btn.active {
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Main */
.main {
  flex: 1;
  padding: 2rem 1.25rem 3rem;
}

.main.main-reader {
  max-width: 1280px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: viewFadeIn 0.32s ease forwards;
}

@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(0.75rem); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .view.active {
    animation: none;
  }
}

/* Bookmark wall — full page when browsing folders */
.bookmark-section {
  min-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2.5rem 0 3rem;
}

.bookmark-section.hidden {
  display: none !important;
}

.bookmark-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 1.25rem;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  padding: 0 1rem;
}

.folder-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 1rem;
  width: 100%;
}

.folder-tile-wrap {
  position: relative;
}

.folder-tile-wrap.is-new {
  animation: folderTilePop 0.45s ease;
}

@keyframes folderTilePop {
  0% { transform: scale(0.98); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.folder-tile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  width: 100%;
  min-height: 5.5rem;
  padding: 1.75rem 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s, background 0.2s;
}

.folder-tile:hover {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.folder-tile-wrap.active .folder-tile {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.folder-tile-name {
  font-size: 1.3125rem;
  font-weight: 600;
  line-height: 1.35;
}

.folder-tile-count {
  flex-shrink: 0;
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.folder-tile-actions {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.folder-tile-wrap:hover .folder-tile-actions,
.folder-tile-wrap:focus-within .folder-tile-actions {
  opacity: 1;
}

.folder-tile-action {
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1;
}

.folder-tile-action:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.folder-tile-action.danger:hover {
  color: var(--danger);
}

.folder-empty {
  width: 100%;
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 3rem 1rem;
}

.papers-panel.hidden {
  display: none !important;
}

.papers-panel {
  animation: viewFadeIn 0.32s ease forwards;
}

.subcategory-panel {
  animation: viewFadeIn 0.32s ease forwards;
}

.subcategory-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1.25rem;
}

.papers-panel-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.papers-panel-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
}

.current-folder-label {
  flex: 1;
  min-width: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.4;
}

.modal-sm .modal-content {
  max-width: 420px;
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 0.625rem 0.875rem 0.625rem 2.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

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

.filter-group {
  display: flex;
  gap: 0.5rem;
}

.filter-group select {
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--surface);
  cursor: pointer;
}

/* Paper list */
.paper-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.paper-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.paper-card:hover {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.paper-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.paper-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}

.paper-meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.paper-summary {
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.paper-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.75rem;
}

.tag {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary);
}

.status-badge {
  flex-shrink: 0;
  padding: 0.2rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}

.status-finished {
  background: var(--success-light);
  color: var(--success);
}

.status-reading {
  background: var(--warning-light);
  color: var(--warning);
}

.status-to-read {
  background: var(--bg);
  color: var(--text-muted);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.empty-state h3 {
  font-size: 1.125rem;
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

/* Form */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-sm);
}

.form-card h2 {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
}

.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.form-group {
  flex: 1;
  min-width: 140px;
  margin-bottom: 1rem;
}

.form-group.flex-2 {
  flex: 2;
  min-width: 240px;
}

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

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

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

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

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

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

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

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

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

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

.stats-section {
  margin-bottom: 2rem;
}

.stats-section h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-cloud .tag {
  cursor: default;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

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

.paper-card-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.pdf-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary);
}

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

.pdf-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.pdf-actions .file-hint {
  margin-top: 0;
}

.pdf-page-range-wrap {
  margin-top: 0.75rem;
}

.pdf-page-range-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

.pdf-page-range {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.pdf-page-range input[type="number"] {
  width: 4.5rem;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--surface);
}

.pdf-page-range input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.ai-status-loading { color: var(--primary); }
.ai-status-error { color: var(--danger); }
.ai-status-success { color: var(--success); }

.settings-form {
  max-width: 480px;
}

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

.settings-form .form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

.settings-form .form-group input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--surface);
}

.settings-form .form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
}

/* Reader */
#view-reader.view.active {
  width: 100%;
}

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

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

.reader-title {
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 0.375rem;
}

.reader-meta {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}

.reader-layout {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  align-items: stretch;
}

.reader-panel {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.panel-header h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

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

.panel-header-actions .btn-sm {
  text-decoration: none;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.pdf-viewer-wrap {
  position: relative;
  height: min(82vh, 920px);
  min-height: 560px;
  background: #525659;
}

.pdf-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.pdf-frame.hidden {
  display: none;
}

.pdf-unavailable {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: var(--bg);
}

.pdf-unavailable span {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.reader-notes-content,
.reader-knowledge-content {
  padding: 1rem 1.25rem 1.5rem;
  overflow: visible;
}

.knowledge-point-card {
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border);
}

.knowledge-point-card:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.knowledge-point-card:first-child {
  padding-top: 0;
}

.kp-term {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.kp-explanation {
  font-size: 0.875rem;
  line-height: 1.65;
  color: var(--text-secondary);
  white-space: pre-wrap;
  margin-bottom: 0.375rem;
}

.kp-read-link {
  font-size: 0.8125rem;
  color: var(--primary);
  word-break: break-all;
}

.form-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.375rem;
}

.form-group-header label {
  margin-bottom: 0;
}

.kp-form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.knowledge-points-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.knowledge-point-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.75rem;
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.knowledge-point-row .kp-row-term {
  grid-column: 1 / -1;
}

.knowledge-point-row .kp-row-link {
  grid-column: 1 / -1;
}

.knowledge-point-row .kp-row-explanation {
  grid-column: 1 / -1;
  min-height: 4rem;
  resize: vertical;
}

.knowledge-point-row-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.illustrations-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.illustration-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.illustration-row-main {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.illustration-row .illustration-title {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--surface);
}

.illustration-preview-wrap {
  margin-top: 0.25rem;
}

.illustration-preview {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  object-fit: contain;
  background: #fff;
}

.illustration-row-actions {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.5rem;
}

/* Long-image export sheet (off-screen capture) */
.paper-export-root {
  position: fixed;
  left: -10000px;
  top: 0;
  z-index: -1;
  pointer-events: none;
}

.paper-export-sheet {
  width: 900px;
  background: #ffffff;
  color: #1e293b;
  font-family: 'Source Sans 3', 'Noto Sans SC', sans-serif;
  line-height: 1.6;
}

.paper-export-header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 2rem 2rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.paper-export-brand {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #64748b;
  letter-spacing: 0.02em;
  margin: 0;
}

.paper-export-title-block {
  display: block;
  overflow: visible;
}

.paper-export-title {
  display: block;
  font-size: 1.625rem;
  font-weight: 700;
  line-height: 1.55;
  margin: 0;
  padding: 0;
  color: #0f172a;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

.paper-export-authors {
  display: block;
  font-size: 0.9375rem;
  color: #475569;
  line-height: 1.55;
  margin: 0;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

.paper-export-meta {
  display: block;
  font-size: 0.875rem;
  color: #64748b;
  line-height: 1.5;
  margin: 0;
}

.paper-export-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
}

.paper-export-badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.75rem;
  font-weight: 600;
}

.paper-export-badge-muted {
  background: #f1f5f9;
  color: #475569;
}

.paper-export-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.paper-export-tag {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-size: 0.75rem;
  color: #475569;
}

.paper-export-section {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid #e2e8f0;
}

.paper-export-section-muted {
  background: #f8fafc;
}

.paper-export-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: #334155;
  margin: 0 0 1rem;
}

.paper-export-pdf {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.paper-export-prose .note-block {
  margin-bottom: 1rem;
}

.paper-export-prose .note-block h4 {
  font-size: 0.8125rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 0.375rem;
}

.paper-export-prose .note-block p,
.paper-export-prose .note-block a {
  font-size: 0.9375rem;
  line-height: 1.7;
  color: #334155;
  margin: 0;
  word-break: break-word;
}

.paper-export-prose .note-block a {
  color: #2563eb;
}

.paper-export-empty,
.paper-export-knowledge .note-empty {
  font-size: 0.875rem;
  color: #94a3b8;
  margin: 0;
}

.paper-export-illustration-gallery {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.paper-export-illustration {
  margin: 0;
}

.paper-export-illustration img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.paper-export-illustration-caption {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: #64748b;
  text-align: center;
}

.paper-export-knowledge .knowledge-point-card {
  padding: 0.875rem 0;
  border-bottom: 1px solid #e2e8f0;
}

.paper-export-knowledge .knowledge-point-card:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.paper-export-knowledge .kp-term {
  font-size: 0.9375rem;
  font-weight: 700;
  color: #0f172a;
  margin: 0 0 0.375rem;
}

.paper-export-knowledge .kp-explanation {
  font-size: 0.875rem;
  line-height: 1.65;
  color: #475569;
  margin: 0 0 0.375rem;
  white-space: pre-wrap;
}

.paper-export-knowledge .kp-read-link {
  font-size: 0.8125rem;
  color: #2563eb;
  word-break: break-all;
}

.paper-export-footer {
  padding: 1rem 2rem 1.5rem;
  font-size: 0.75rem;
  color: #94a3b8;
  text-align: right;
}

.reader-illustrations-content {
  padding: 1rem 1.25rem 1.25rem;
}

.illustration-gallery {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.illustration-figure {
  margin: 0;
}

.illustration-figure img {
  display: block;
  width: 100%;
  max-height: 560px;
  object-fit: contain;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
}

.illustration-caption {
  margin-top: 0.375rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

@media (max-width: 1200px) {
  .reader-layout {
    gap: 1rem;
  }

  .pdf-viewer-wrap {
    height: min(75vh, 780px);
    min-height: 420px;
  }
}

.note-block {
  margin-bottom: 1.25rem;
}

.note-block h4 {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.5rem;
}

.note-block p {
  font-size: 0.9375rem;
  white-space: pre-wrap;
  line-height: 1.7;
}

.note-block a {
  color: var(--primary);
  word-break: break-all;
}

.note-empty {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Prose (reader notes) */
.prose-content {
  font-size: 0.9375rem;
  line-height: 1.75;
  color: var(--text-secondary);
}

.prose-content a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--text-muted) 70%, transparent);
  text-underline-offset: 2px;
  border-radius: 4px;
  padding: 0.125rem 0.25rem;
  margin: -0.125rem -0.25rem;
  transition: color 0.2s, background 0.2s, text-decoration-color 0.2s;
  word-break: break-all;
}

.prose-content a:hover {
  background: var(--text);
  color: var(--bg);
  text-decoration: none;
}

.prose-content .note-block h4 {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.prose-content .note-block p {
  color: var(--text-secondary);
}

/* Theme toggle */
.theme-toggle {
  min-width: 2.5rem;
  padding-inline: 0.625rem !important;
}

.theme-icon {
  display: none;
  line-height: 1;
}

html:not(.dark):not(.immersive) .theme-icon-light {
  display: inline-block;
}

html.dark .theme-icon-dark {
  display: inline-block;
}

html.immersive .theme-icon-immersive {
  display: inline-block;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-muted) 45%, transparent);
  border-radius: 999px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 960px) {
  .pdf-viewer-wrap {
    min-height: 360px;
    height: 60vh;
  }
}

/* Modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 640px;
  width: calc(100% - 2rem);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  position: relative;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2rem;
  height: 2rem;
  border: none;
  background: var(--bg);
  border-radius: 50%;
  font-size: 1.25rem;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

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

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  padding-right: 2rem;
}

.modal-meta {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.modal-section {
  margin-top: 1.25rem;
}

.modal-section h4 {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.modal-section p {
  font-size: 0.9375rem;
  white-space: pre-wrap;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.modal-link {
  color: var(--primary);
  text-decoration: none;
  word-break: break-all;
}

.modal-link:hover {
  text-decoration: underline;
}

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

.footer a {
  color: var(--primary);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.modal-sm {
  max-width: 400px;
}

.login-hint {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}

.login-error {
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--danger);
}

.nav-btn.admin-active {
  background: var(--success-light);
  color: var(--success);
}

.nav-btn.guest-active {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 2.25rem;
}

.account-info {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.hint code {
  font-size: 0.8125rem;
  background: var(--bg);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
}

@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .nav {
    justify-content: center;
  }

  .form-card {
    padding: 1.25rem;
  }

  .modal-content {
    padding: 1.25rem;
  }
}
