/* IELTS 资料预览 - 精致 UI */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&family=Noto+Sans+SC:wght@400;500;600;700&display=swap');

:root {
  /* 主色 - 深邃靛蓝 */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-glow: rgba(79, 70, 229, 0.25);

  /* 背景层级 */
  --bg-base: #0f0f12;
  --bg-surface: #18181c;
  --bg-elevated: #222228;
  --bg-card: #1c1c22;

  /* 边框 */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);

  /* 文字 */
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;

  /* 语义色 */
  --accent-listening: #06b6d4;
  --accent-reading: #8b5cf6;
  --accent-writing: #f59e0b;
  --accent-speaking: #ec4899;

  /* 动效 */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-fast: 0.15s var(--ease-out-expo);
  --transition-smooth: 0.25s var(--ease-out-expo);
  --transition-spring: 0.4s var(--ease-spring);

  /* 圆角 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* 阴影 */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'DM Sans', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ========== Header ========== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-elevated) 100%);
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
  z-index: 100;
}

.app-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  opacity: 0.5;
}

.app-header-left {
  flex: 1;
  min-width: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.app-header p {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* 推荐学习平台下拉 */
.learning-dropdown-wrap {
  position: relative;
}

.learning-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-smooth);
}

.learning-dropdown-trigger:hover {
  color: var(--text-primary);
  background: var(--bg-card);
  border-color: var(--primary);
}

.learning-dropdown-trigger svg {
  transition: transform var(--transition-fast);
}

.learning-dropdown-wrap.open .learning-dropdown-trigger svg {
  transform: rotate(180deg);
}

.learning-dropdown-panel-wrap {

  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 320px;
  max-width: 420px;
  max-height: 70vh;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition-smooth);
  z-index: 9999;
  overflow: hidden;
}

.learning-dropdown-panel-wrap.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.learning-dropdown-panel {
  max-height: 70vh;
  overflow-y: auto;
  padding: 0.75rem;
}

.learning-dropdown-panel::-webkit-scrollbar {
  width: 6px;
}

.learning-dropdown-panel::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}

.learning-dropdown-group {
  margin-bottom: 1rem;
}

.learning-dropdown-group:last-child {
  margin-bottom: 0;
}

.learning-dropdown-cat {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
  padding-bottom: 0.25rem;
}

.learning-dropdown-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.learning-dropdown-list li {
  margin-bottom: 0.15rem;
}

.learning-dropdown-list a {
  display: block;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.learning-dropdown-list a:hover {
  color: var(--primary);
  background: rgba(79, 70, 229, 0.12);
}

.learning-link-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-left: 0.35rem;
}

.app-header-github {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--transition-smooth);
}

.app-header-github:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

/* ========== Main Layout ========== */
.app-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ========== Sidebar ========== */
.sidebar {
  width: 300px;
  min-width: 260px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ========== Nav ========== */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card);
}

.nav-items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1;
}

.nav-item {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition-smooth);
}

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

.nav-item.active {
  color: var(--primary-light);
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 20px var(--primary-glow);
}

/* Tips trigger */
.tips-trigger-wrap {
  position: relative;
  flex-shrink: 0;
}

.tips-trigger {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-smooth);
}

.tips-trigger:hover {
  background: var(--primary);
  color: var(--primary-light);
}

/* Tips tooltip */
.tips-tooltip {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(320px, calc(100vw - 2rem));
  max-height: 360px;
  padding: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition-smooth);
  z-index: 100;
  overflow: hidden;
}

.tips-tooltip.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.tips-tooltip-inner {
  padding: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-height: 340px;
  overflow-y: auto;
}

.tips-tooltip-inner h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.tips-tooltip-inner .tips-logic {
  margin: 0 0 0.75rem;
  font-style: italic;
  color: var(--text-muted);
}

.tips-tooltip-inner ul {
  margin: 0.5rem 0;
  padding-left: 1.2rem;
}

.tips-tooltip-inner li {
  margin-bottom: 0.3rem;
}

.tips-tooltip-inner .pitfalls {
  margin-top: 0.75rem;
  color: #f87171;
}

.nav {
  position: relative;
}

/* ========== File List ========== */
#file-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

#file-list-wrap::-webkit-scrollbar {
  width: 6px;
}

#file-list-wrap::-webkit-scrollbar-track {
  background: transparent;
}

#file-list-wrap::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}

#file-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#file-list .file-item {
  margin-bottom: 0.2rem;
}

#file-list a {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

#file-list a:hover {
  background: var(--bg-elevated);
  color: var(--primary);
}

.file-group {
  margin-bottom: 1.25rem;
}

.file-group h4 {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.file-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.file-group li {
  margin-bottom: 0.15rem;
}

.empty, .error {
  color: var(--text-muted);
  padding: 1.5rem;
}

.error {
  color: #f87171;
}

/* ========== Content / Preview ========== */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

#preview {
  flex: 1;
  overflow: auto;
  padding: 1.5rem 2rem;
}

#preview::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

#preview::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 4px;
}

.preview-placeholder {
  color: var(--text-muted);
  text-align: center;
  padding: 4rem 2rem;
  font-size: 0.95rem;
}

.preview-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 400px;
  animation: fadeIn 0.3s var(--ease-out-expo);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 1.25rem;
}

.preview-title {
  flex-shrink: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-pdf-warning {
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.preview-content {
  flex: 1;
  min-height: 0;
}

/* Preview types */
.preview-container {
  width: 100%;
  height: 100%;
  min-height: 400px;
}

.preview-pdf-iframe, .preview-html {
  width: 100%;
  height: 80vh;
  min-height: 500px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

/* PDF.js 画布预览 */
.pdf-viewer {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.pdf-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pdf-btn:hover:not(:disabled) {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-light);
}

.pdf-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pdf-page-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.pdf-page-input {
  width: 3.5rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.9rem;
  text-align: center;
}

.pdf-canvas-wrap {
  overflow: auto;
  max-height: 80vh;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.pdf-canvas-wrap canvas {
  display: block;
  margin: 0 auto;
  box-shadow: var(--shadow-md);
}

.preview-audio {
  width: 100%;
  max-width: 520px;
  margin: 1rem 0;
  border-radius: var(--radius-md);
}

.preview-image {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.preview-loading, .preview-error {
  padding: 2.5rem;
  text-align: center;
  color: var(--text-muted);
}

.preview-loading-pdf {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  gap: 1rem;
}

.preview-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-default);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: preview-spin 0.8s linear infinite;
}

.preview-loading-text {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
}

.preview-loading-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.preview-loading-pdf-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem;
  min-height: 200px;
}

.preview-loading-pdf-inline .preview-loading-spinner {
  width: 28px;
  height: 28px;
  border-width: 2px;
}

@keyframes preview-spin {
  to { transform: rotate(360deg); }
}

.preview-error {
  color: #f87171;
}

.preview-fallback {
  display: inline-block;
  padding: 1rem 1.5rem;
  color: var(--primary);
  background: rgba(79, 70, 229, 0.15);
  border-radius: var(--radius-sm);
}

/* Markdown body */
.markdown-body {
  line-height: 1.7;
  color: var(--text-secondary);
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  margin-top: 1.75rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

.markdown-body pre, .markdown-body code {
  background: var(--bg-elevated);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.88em;
  color: var(--text-primary);
}

.markdown-body pre {
  padding: 1rem;
  overflow-x: auto;
}
