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

:root {
  --bg: #fafaf8;
  --text: #1a1a1a;
  --text-secondary: #555;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --border: #e5e5e5;
  --card-bg: #fff;
  --reflect-bg: #f0f7ff;
  --reflect-border: #93c5fd;
  --annotation-bg: #fffbeb;
  --annotation-border: #f59e0b;
  --highlight: #fef08a;
  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', Georgia, serif;
  --font-sans: 'Noto Sans SC', 'Source Han Sans SC', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --max-width: 720px;
}

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

body {
  font-family: var(--font-serif);
  color: var(--text);
  background: var(--bg);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}

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

/* -- Typography -- */
h1 {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.article-meta {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

h2 {
  font-size: 1.35rem;
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  letter-spacing: -0.01em;
}

p {
  margin-bottom: 1.2rem;
  text-align: justify;
}

strong { font-weight: 600; }

/* -- Annotatable paragraphs -- */
.annotatable {
  position: relative;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.2s;
}

.annotatable:hover {
  background: rgba(37, 99, 235, 0.04);
}

.annotatable.has-annotation {
  border-left: 3px solid var(--annotation-border);
  padding-left: 1rem;
}

.annotation-indicator {
  position: absolute;
  right: -2rem;
  top: 0.2rem;
  width: 1.2rem;
  height: 1.2rem;
  background: var(--annotation-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: #fff;
  font-family: var(--font-sans);
  font-weight: 700;
  cursor: pointer;
}

.annotation-display {
  background: var(--annotation-bg);
  border: 1px solid var(--annotation-border);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
}

.annotation-display .annotation-time {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
}

/* -- Annotation modal -- */
.annotation-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}

.annotation-modal-overlay.active { display: flex; }

.annotation-modal {
  background: var(--card-bg);
  width: 100%;
  max-width: 600px;
  border-radius: 16px 16px 0 0;
  padding: 1.5rem;
  max-height: 60vh;
  overflow-y: auto;
}

.annotation-modal h3 {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.annotation-modal .context-preview {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 0.6rem;
  background: var(--bg);
  border-radius: 6px;
  margin-bottom: 1rem;
  line-height: 1.5;
  max-height: 80px;
  overflow: hidden;
}

.annotation-modal textarea {
  width: 100%;
  min-height: 100px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}

.annotation-modal textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.annotation-modal .btn-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.8rem;
  justify-content: flex-end;
}

.annotation-modal .btn-row button {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  padding: 0.5rem 1.2rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
}

.btn-save {
  background: var(--accent);
  color: #fff;
}

.btn-cancel {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border) !important;
}

.btn-delete {
  background: #fee2e2;
  color: #dc2626;
  margin-right: auto;
}

/* -- Reflection block -- */
.reflection {
  background: var(--reflect-bg);
  border-left: 3px solid var(--reflect-border);
  border-radius: 0 8px 8px 0;
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

.reflection .label {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}

/* -- Tables -- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

th {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* -- Mermaid -- */
.mermaid-container {
  margin: 1.5rem 0;
  overflow-x: auto;
  text-align: center;
}

.mermaid-container svg { max-width: 100%; }

/* -- Concept index -- */
.concept-index {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.concept-index h2 { margin-top: 0; }

/* -- Feedback section -- */
.feedback-section {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--accent);
}

.feedback-section h2 {
  margin-top: 0;
  color: var(--accent);
}

.feedback-block {
  margin-bottom: 1.5rem;
}

.feedback-block h3 {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.feedback-block .feedback-hint {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.feedback-block textarea {
  width: 100%;
  min-height: 80px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}

.feedback-block textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.feedback-submit {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 0.6rem 2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 0.5rem;
}

.feedback-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.feedback-saved {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: #16a34a;
  margin-left: 1rem;
  display: none;
}

/* -- Feedback answer reveal -- */
.feedback-block details {
  margin-top: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.feedback-block details summary {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  padding: 0.6rem 1rem;
  cursor: pointer;
  background: var(--bg);
  list-style: none;
  user-select: none;
}

.feedback-block details summary::-webkit-details-marker { display: none; }

.feedback-block details summary::before {
  content: '+ ';
  font-weight: 700;
}

.feedback-block details[open] summary::before {
  content: '- ';
}

.feedback-block details .answer {
  padding: 0.8rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--text);
  border-top: 1px solid var(--border);
}

.feedback-block details .answer p {
  margin-bottom: 0.6rem;
  text-align: left;
}

.feedback-block details .answer p:last-child {
  margin-bottom: 0;
}

.feedback-block details .answer ol,
.feedback-block details .answer ul {
  margin: 0.4rem 0 0.6rem 1.2rem;
}

.feedback-block details .answer li {
  margin-bottom: 0.3rem;
}

/* -- Key point highlight -- */
mark, .key-point {
  background: linear-gradient(180deg, transparent 50%, #fef08a 50%);
  padding: 0 2px;
  font-style: inherit;
  font-weight: inherit;
}

/* -- Separator -- */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* -- LaTeX (KaTeX) -- */
.katex-display { margin: 1.5rem 0; overflow-x: auto; }

/* -- Nav -- */
.site-nav {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 50;
}

.site-nav a {
  color: var(--text-secondary);
  text-decoration: none;
}

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

.site-nav .current {
  color: var(--text);
  font-weight: 600;
}

/* -- Mobile responsive -- */
@media (max-width: 768px) {
  html { font-size: 16px; }

  .article-container { padding: 1.2rem 1rem 3rem; }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.2rem; margin-top: 2rem; }

  .annotation-indicator { right: -1.5rem; }

  .annotation-modal {
    border-radius: 12px 12px 0 0;
    padding: 1.2rem;
  }

  table { font-size: 0.82rem; }
  th, td { padding: 0.5rem; }

  .site-nav { padding: 0.6rem 1rem; }
}

@media (max-width: 480px) {
  .article-container { padding: 1rem 0.8rem 3rem; }

  .annotation-indicator {
    position: static;
    display: inline-block;
    margin-left: 0.3rem;
    vertical-align: super;
  }
}
