/* ============================================
   蒙德里安教程 V4 - 全面修订
   至上主义视觉风格 + 翻页式教程
   ============================================ */

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

:root {
  --mondrian-red: #E53935;
  --mondrian-blue: #1565C0;
  --mondrian-yellow: #FDD835;
  --mondrian-black: #1A1A1A;
  --mondrian-white: #FAFAFA;
  --mondrian-gray: #F5F5F5;
  --mondrian-dark-gray: #333;
  --mondrian-light-gray: #E0E0E0;
  --mondrian-green: #2E7D32;
  --mondrian-green-bg: #E8F5E9;
  --mondrian-green-border: #A5D6A7;
  --card-bg: #FFFFFF;
  --code-bg: #263238;
  --code-text: #EEFFFF;
  --border-width: 3px;
  --thick-border: 5px;
  --font-display: 'Oswald', sans-serif;
  --font-body: 'Noto Serif SC', serif;
  --font-mono: 'JetBrains Mono', monospace;
  --page-max-width: 780px;
  --transition-speed: 0.4s;
}

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

body {
  font-family: var(--font-body);
  background: var(--mondrian-white);
  color: var(--mondrian-black);
  line-height: 1.8;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* --- Typography --- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

h1 { font-size: 2.4rem; margin-bottom: 0.6em; }
h2 { font-size: 1.8rem; margin-bottom: 0.5em; }
h3 { font-size: 1.3rem; margin-bottom: 0.4em; }

p {
  margin-bottom: 1em;
  font-size: 1.05rem;
}

strong {
  color: var(--mondrian-red);
  font-weight: 700;
}

em {
  font-style: normal;
  background: linear-gradient(to top, var(--mondrian-yellow) 40%, transparent 40%);
  padding: 0 2px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  background: var(--mondrian-gray);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--mondrian-light-gray);
}

/* --- Progress Bar --- */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 4px;
  background: var(--mondrian-red);
  transition: width 0.3s ease;
  z-index: 9999;
}

/* --- Page Counter --- */
.page-counter {
  position: fixed;
  bottom: 20px;
  right: 24px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: #999;
  z-index: 1000;
  background: rgba(255,255,255,0.9);
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--mondrian-light-gray);
}

/* --- Navigation Buttons --- */
.nav-buttons {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 1000;
}

.nav-btn {
  width: 48px;
  height: 48px;
  border: var(--border-width) solid var(--mondrian-black);
  background: var(--card-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 1.2rem;
}

.nav-btn:hover {
  background: var(--mondrian-yellow);
  transform: scale(1.05);
}

.nav-btn:active {
  transform: scale(0.95);
}

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

.nav-btn:disabled:hover {
  background: var(--card-bg);
  transform: none;
}

/* --- TOC Toggle --- */
.toc-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 44px;
  height: 44px;
  border: var(--border-width) solid var(--mondrian-black);
  background: var(--card-bg);
  cursor: pointer;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.2s;
}

.toc-toggle:hover {
  background: var(--mondrian-yellow);
}

.toc-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--mondrian-black);
  transition: all 0.3s;
}

.toc-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(4px, 4px);
}

.toc-toggle.active span:nth-child(2) {
  opacity: 0;
}

.toc-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(4px, -4px);
}

/* --- TOC Panel --- */
.toc-panel {
  position: fixed;
  top: 0;
  left: -320px;
  width: 320px;
  height: 100vh;
  background: var(--card-bg);
  border-right: var(--thick-border) solid var(--mondrian-black);
  z-index: 1500;
  overflow-y: auto;
  transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 80px 24px 40px;
}

.toc-panel.open {
  left: 0;
}

.toc-panel h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--mondrian-black);
}

.toc-list {
  list-style: none;
}

.toc-list li {
  margin-bottom: 4px;
}

.toc-list a {
  display: block;
  padding: 8px 12px;
  text-decoration: none;
  color: var(--mondrian-dark-gray);
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: all 0.2s;
  border-radius: 0 4px 4px 0;
}

.toc-list a:hover {
  background: var(--mondrian-gray);
  border-left-color: var(--mondrian-blue);
}

.toc-list a.active {
  background: #E3F2FD;
  border-left-color: var(--mondrian-blue);
  font-weight: 600;
  color: var(--mondrian-blue);
}

.toc-list .toc-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

.toc-tag.cognitive {
  background: #FFF3E0;
  color: #E65100;
  border: 1px solid #FFB74D;
}

.toc-tag.practice {
  background: #E8F5E9;
  color: #2E7D32;
  border: 1px solid #A5D6A7;
}

/* --- TOC Overlay --- */
.toc-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.3);
  z-index: 1400;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.toc-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

/* --- Pages Container --- */
.pages-container {
  width: 100%;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* --- Single Page --- */
.page {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 24px 80px;
  opacity: 0;
  transform: translateX(60px);
  transition: all var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  overflow-y: auto;
}

.page.active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: all;
}

.page.exit-left {
  opacity: 0;
  transform: translateX(-60px);
}

.page.exit-right {
  opacity: 0;
  transform: translateX(60px);
}

.page-inner {
  max-width: var(--page-max-width);
  width: 100%;
}

/* --- Mondrian Decorative Elements --- */
.mondrian-border-top {
  border-top: var(--thick-border) solid var(--mondrian-black);
}

.mondrian-accent {
  display: inline-block;
  width: 40px;
  height: 8px;
  background: var(--mondrian-red);
  margin-bottom: 16px;
}

.mondrian-accent.blue { background: var(--mondrian-blue); }
.mondrian-accent.yellow { background: var(--mondrian-yellow); }

/* --- Cover Page --- */
.cover-page .page-inner {
  text-align: center;
}

.cover-title {
  font-size: 3rem;
  font-family: var(--font-display);
  margin-bottom: 0.3em;
  position: relative;
}

.cover-subtitle {
  font-size: 1.2rem;
  color: #666;
  margin-bottom: 2em;
  font-weight: 400;
}

.cover-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  max-width: 400px;
  margin: 0 auto 2em;
  aspect-ratio: 4/3;
  border: 3px solid var(--mondrian-black);
}

.cover-grid div {
  background: var(--mondrian-white);
}

.cover-grid .red { background: var(--mondrian-red); }
.cover-grid .blue { background: var(--mondrian-blue); }
.cover-grid .yellow { background: var(--mondrian-yellow); }
.cover-grid .black { background: var(--mondrian-black); }

.cover-meta {
  font-size: 0.9rem;
  color: #999;
  font-family: var(--font-mono);
}

/* --- Section Headers --- */
.section-header {
  padding: 20px 0;
  margin-bottom: 24px;
  border-left: var(--thick-border) solid var(--mondrian-red);
  padding-left: 20px;
}

.section-header.blue-accent {
  border-left-color: var(--mondrian-blue);
}

.section-header.yellow-accent {
  border-left-color: var(--mondrian-yellow);
}

.section-header.green-accent {
  border-left-color: var(--mondrian-green);
}

/* --- Content Cards --- */
.content-card {
  background: var(--card-bg);
  border: var(--border-width) solid var(--mondrian-black);
  padding: 28px;
  margin-bottom: 20px;
  position: relative;
}

.content-card::before {
  content: '';
  position: absolute;
  top: -3px;
  right: -3px;
  width: 24px;
  height: 24px;
  background: var(--mondrian-yellow);
  border: var(--border-width) solid var(--mondrian-black);
}

.content-card.red-corner::before { background: var(--mondrian-red); }
.content-card.blue-corner::before { background: var(--mondrian-blue); }
.content-card.no-corner::before { display: none; }

/* --- Prompt Cards (Copyable) --- */
.prompt-card {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 20px;
  padding-top: 44px;
  border-radius: 0;
  border: var(--border-width) solid var(--mondrian-black);
  margin: 16px 0;
  position: relative;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.7;
  word-break: break-all;
}

.prompt-card code {
  display: block;
  background: none;
  border: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
  font-size: inherit;
  white-space: pre-wrap;
  word-break: break-all;
}

.prompt-card .copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.2s;
}

.prompt-card .copy-btn:hover {
  background: rgba(255,255,255,0.25);
}

.prompt-card .copy-btn.copied {
  background: var(--mondrian-green);
  border-color: var(--mondrian-green);
}

.prompt-label {
  position: absolute;
  top: 12px;
  left: 20px;
  display: inline-block;
  background: var(--mondrian-blue);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 2px 8px;
  letter-spacing: 0.05em;
}

/* --- Result Hint (Green Box) --- */
.result-hint {
  background: var(--mondrian-green-bg);
  border: 2px solid var(--mondrian-green-border);
  border-left: 5px solid var(--mondrian-green);
  padding: 16px 20px;
  margin: 16px 0;
  font-size: 0.95rem;
}

.result-hint::before {
  content: '✓ 你应该看到';
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--mondrian-green);
  margin-bottom: 6px;
  font-size: 0.9rem;
}

/* --- Metaphor Box --- */
.metaphor-box {
  background: #FFF8E1;
  border: 2px solid #FFD54F;
  border-left: 5px solid var(--mondrian-yellow);
  padding: 16px 20px;
  margin: 16px 0;
  font-size: 0.95rem;
}

.metaphor-box::before {
  content: '💡 生活化类比';
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  color: #F57F17;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

/* --- Quote Block --- */
.quote-block {
  border-left: 4px solid var(--mondrian-blue);
  padding: 12px 20px;
  margin: 16px 0;
  background: #F8F9FA;
  font-style: italic;
  color: #555;
}

/* --- SVG Illustrations --- */
.illustration {
  margin: 24px 0;
  text-align: center;
}

.illustration svg {
  max-width: 100%;
  height: auto;
}

/* --- Lists --- */
.styled-list {
  list-style: none;
  padding-left: 0;
}

.styled-list li {
  padding: 8px 0 8px 24px;
  position: relative;
  font-size: 1rem;
}

.styled-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 16px;
  width: 12px;
  height: 12px;
  background: var(--mondrian-red);
}

.styled-list li:nth-child(2)::before { background: var(--mondrian-blue); }
.styled-list li:nth-child(3)::before { background: var(--mondrian-yellow); }
.styled-list li:nth-child(4)::before { background: var(--mondrian-red); }
.styled-list li:nth-child(5)::before { background: var(--mondrian-blue); }

/* --- Numbered Steps --- */
.step-list {
  counter-reset: step-counter;
  list-style: none;
  padding-left: 0;
}

.step-list li {
  counter-increment: step-counter;
  padding: 12px 0 12px 50px;
  position: relative;
  margin-bottom: 8px;
}

.step-list li::before {
  content: counter(step-counter);
  position: absolute;
  left: 0;
  top: 10px;
  width: 36px;
  height: 36px;
  background: var(--mondrian-black);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Inline SVG Diagram Containers --- */
.diagram-container {
  margin: 20px 0;
  padding: 16px;
  border: 2px solid var(--mondrian-light-gray);
  background: #fff;
  text-align: center;
}

.diagram-container svg {
  max-width: 100%;
  height: auto;
}

/* --- Swipe Hint (mobile only) --- */
.swipe-hint-mobile {
  display: none;
  margin-top: 32px;
  padding: 20px 0;
}

.swipe-hint-mobile .swipe-hand {
  animation: swipeLeftRight 2.5s ease-in-out infinite;
  transform-origin: center;
}

@keyframes swipeLeftRight {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-20px); }
  50% { transform: translateX(0); }
  75% { transform: translateX(20px); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .swipe-hint-mobile {
    display: block;
  }
  :root {
    --page-max-width: 100%;
  }
  
  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.4rem; }
  
  .cover-title { font-size: 2.2rem; }
  .cover-subtitle { font-size: 1rem; }
  
  .page {
    padding: 50px 16px 90px;
    align-items: flex-start;
  }
  
  .content-card {
    padding: 20px;
  }
  
  .prompt-card {
    padding: 16px;
    padding-top: 40px;
    font-size: 0.8rem;
  }

  .prompt-label {
    top: 10px;
    left: 16px;
  }

  .prompt-card .copy-btn {
    top: 8px;
    right: 8px;
  }
  
  .nav-buttons {
    bottom: 16px;
  }
  
  .nav-btn {
    width: 44px;
    height: 44px;
  }
  
  .page-counter {
    bottom: 16px;
    right: 16px;
    font-size: 0.75rem;
  }
  
  .toc-panel {
    width: 280px;
  }
  
  .cover-grid {
    max-width: 280px;
  }
  
  .section-header {
    padding-left: 14px;
  }
}

@media (max-width: 480px) {
  h1 { font-size: 1.5rem; }
  .cover-title { font-size: 1.8rem; }
  
  .content-card::before {
    width: 16px;
    height: 16px;
  }
}

/* --- Animations --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page.active .page-inner > * {
  animation: fadeInUp 0.5s ease forwards;
}

.page.active .page-inner > *:nth-child(2) { animation-delay: 0.1s; }
.page.active .page-inner > *:nth-child(3) { animation-delay: 0.15s; }
.page.active .page-inner > *:nth-child(4) { animation-delay: 0.2s; }
.page.active .page-inner > *:nth-child(5) { animation-delay: 0.25s; }

/* --- Touch Hint --- */
.touch-hint {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: #aaa;
  font-family: var(--font-mono);
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
}

.touch-hint.visible {
  opacity: 1;
}

/* --- Keyboard Shortcut Hint --- */
.keyboard-hint {
  position: fixed;
  top: 16px;
  right: 16px;
  font-size: 0.75rem;
  color: #bbb;
  font-family: var(--font-mono);
  z-index: 100;
}

.keyboard-hint kbd {
  display: inline-block;
  padding: 2px 6px;
  background: var(--mondrian-gray);
  border: 1px solid var(--mondrian-light-gray);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

/* --- Special: Final Page --- */
.final-page {
  text-align: center;
}

.final-page h1 {
  font-size: 2.6rem;
}

/* --- Utility --- */
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.text-center { text-align: center; }
.text-muted { color: #888; font-size: 0.9rem; }
.text-small { font-size: 0.85rem; }

/* --- Swipe indicator --- */
.swipe-indicator {
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  .swipe-indicator {
    display: block;
    text-align: center;
    font-size: 0.8rem;
    color: #bbb;
    margin-top: 16px;
    font-family: var(--font-mono);
  }
  
  .keyboard-hint {
    display: none;
  }
}
