/* ==========================================================================
   TOEFL Material Library - Modern Responsive Stylesheet
   ========================================================================== */

:root {
  /* Default Light Theme */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-surface-subtle: #f1f5f9;
  --bg-sidebar: #ffffff;
  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --accent-primary: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-subtle: #eff6ff;
  --accent-border: #bfdbfe;

  --badge-bg: #e0f2fe;
  --badge-text: #0369a1;

  --summary-bg: #f8fafc;
  --summary-border: #3b82f6;
  --summary-text: #1e293b;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);

  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-serif: "Source Serif 4", Georgia, Cambria, "Times New Roman", Times, serif;

  --font-size-base: 16px;
  --header-height: 64px;
  --sidebar-width: 330px;
}

[data-theme="dark"] {
  --bg-app: #090d16;
  --bg-surface: #111827;
  --bg-surface-elevated: #1e293b;
  --bg-surface-subtle: #1a2234;
  --bg-sidebar: #0d1322;
  --border-color: #1f293d;
  --border-subtle: #161e31;

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-inverse: #090d16;

  --accent-primary: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-subtle: #172554;
  --accent-border: #1e3a8a;

  --badge-bg: #1e293b;
  --badge-text: #38bdf8;

  --summary-bg: #131d31;
  --summary-border: #60a5fa;
  --summary-text: #e2e8f0;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
}

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

html {
  font-size: var(--font-size-base);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
}

/* App Layout */
.app-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
}

.brand-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.25rem;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-center {
  flex: 1;
  max-width: 540px;
  margin: 0 1.5rem;
}

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  height: 40px;
  padding: 0 2.4rem 0 2.5rem;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: all 0.2s ease;
}

.search-bar input:focus {
  border-color: var(--accent-primary);
  background-color: var(--bg-surface);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.clear-search {
  position: absolute;
  right: 0.85rem;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
  line-height: 1;
}

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

.font-controls {
  display: flex;
  align-items: center;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 2px;
}

.text-ctrl-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.text-ctrl-btn:hover {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

.theme-toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.45rem 0.85rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
  background-color: var(--accent-subtle);
  border-color: var(--accent-border);
}

.theme-icon-container {
  display: flex;
  align-items: center;
  justify-content: center;
}

.sun-icon {
  display: block;
}

.moon-icon {
  display: none;
}

[data-theme="dark"] .sun-icon {
  display: none;
}

[data-theme="dark"] .moon-icon {
  display: block;
  color: #38bdf8;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Main Layout Structure */
.main-wrapper {
  display: flex;
  flex: 1;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
}

/* Sidebar Navigation */
.app-sidebar {
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 90;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.25s ease;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-stats {
  padding: 0 1.25rem 0.85rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.5rem 2rem;
}

.sidebar-nav::-webkit-scrollbar {
  width: 5px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

/* Category Tree Accordion */
.nav-category {
  margin-bottom: 0.5rem;
  border-radius: 8px;
  overflow: hidden;
}

.nav-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

.nav-category-header:hover {
  background-color: var(--bg-surface-subtle);
}

.nav-category-header.active {
  color: var(--accent-primary);
}

.cat-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  background-color: var(--badge-bg);
  color: var(--badge-text);
  border-radius: 4px;
  flex-shrink: 0;
}

.cat-arrow {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
  color: var(--text-muted);
  flex-shrink: 0;
}

.nav-category.expanded .cat-arrow {
  transform: rotate(90deg);
}

.nav-topic-list {
  display: none;
  padding: 0.25rem 0 0.25rem 0.75rem;
  list-style: none;
}

.nav-category.expanded .nav-topic-list {
  display: block;
}

.nav-topic-item {
  margin: 0.15rem 0;
}

.nav-topic-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.83rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.15s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-topic-link:hover {
  background-color: var(--bg-surface-subtle);
  color: var(--text-primary);
}

.nav-topic-link.active {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  font-weight: 600;
}

.topic-code-badge {
  font-size: 0.72rem;
  font-family: monospace;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  background-color: var(--border-color);
  color: var(--text-secondary);
  border-radius: 4px;
  flex-shrink: 0;
}

/* Content Area */
.app-content {
  flex: 1;
  min-width: 0;
  padding: 2rem 2.5rem 5rem;
  max-width: 1060px;
  margin: 0 auto;
}

/* Banner */
.content-banner {
  background: linear-gradient(135deg, var(--bg-surface), var(--bg-surface-subtle));
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 2rem 2.25rem;
  margin-bottom: 2.5rem;
  box-shadow: var(--shadow-sm);
}

.banner-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.65rem;
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  border-radius: 20px;
  margin-bottom: 0.75rem;
}

.banner-title {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}

.banner-desc {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 1.25rem;
}

.banner-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.meta-tag {
  font-size: 0.78rem;
  font-weight: 600;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
}

/* Categories & Topics View */
.category-section {
  margin-bottom: 4rem;
  scroll-margin-top: calc(var(--header-height) + 1.5rem);
}

.category-header-banner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.75rem;
  margin-bottom: 2rem;
}

.cat-heading {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
}

.cat-num-pill {
  font-size: 0.9rem;
  font-weight: 700;
  background: var(--accent-primary);
  color: #ffffff;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
}

.cat-title-text {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.cat-page-badge {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Topic Card */
.topic-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 1.75rem;
  margin-bottom: 2.25rem;
  box-shadow: var(--shadow-sm);
  scroll-margin-top: calc(var(--header-height) + 1.5rem);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.topic-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent-border);
}

.topic-meta-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px dashed var(--border-color);
}

.topic-badges {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.topic-badge-id {
  font-size: 0.82rem;
  font-family: monospace;
  font-weight: 700;
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--accent-border);
}

.topic-badge-page {
  font-size: 0.78rem;
  color: var(--text-muted);
  background-color: var(--bg-surface-subtle);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

/* Question Prompts */
.topic-question-box {
  background-color: var(--bg-surface-subtle);
  border-radius: 10px;
  padding: 1.15rem 1.35rem;
  margin-bottom: 1.5rem;
  border-left: 4px solid var(--accent-primary);
}

.prompt-en {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  color: var(--text-primary);
  line-height: 1.65;
  font-weight: 500;
  margin-bottom: 0.65rem;
}

.prompt-zh {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Arguments Section */
.arguments-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.argument-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.35rem;
  transition: all 0.2s ease;
}

.argument-card:hover {
  border-color: var(--accent-border);
}

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

.argument-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
}

.arg-num-tag {
  font-size: 0.8rem;
  font-weight: 700;
  background-color: var(--bg-surface-subtle);
  color: var(--accent-primary);
  border: 1px solid var(--border-color);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  flex-shrink: 0;
}

.arg-title-text {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.4;
}

.copy-arg-btn {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.copy-arg-btn:hover {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  border-color: var(--accent-border);
}

/* Paragraph Summary Callout (段落大意) */
.argument-summary-box {
  background-color: var(--summary-bg);
  border-left: 3.5px solid var(--summary-border);
  padding: 0.75rem 1rem;
  border-radius: 0 8px 8px 0;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--summary-text);
  line-height: 1.55;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.summary-label {
  font-weight: 700;
  color: var(--accent-primary);
  white-space: nowrap;
  font-size: 0.85rem;
}

/* English Body Paragraphs */
.argument-body {
  font-family: var(--font-serif);
  font-size: 1.02rem;
  color: var(--text-primary);
  line-height: 1.8;
}

.argument-body p {
  margin-bottom: 0.95rem;
  text-align: justify;
}

.argument-body p:last-child {
  margin-bottom: 0;
}

/* Search Panel */
.search-results-panel {
  background-color: var(--bg-surface);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 2.5rem;
  box-shadow: var(--shadow-md);
}

.search-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--accent-primary);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
}

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

.search-item {
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  margin-bottom: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.search-item:hover {
  background-color: var(--bg-surface-subtle);
  border-color: var(--accent-primary);
}

.search-item-meta {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.search-item-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}

.search-item-snippet {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.highlight {
  background-color: #fef08a;
  color: #854d0e;
  padding: 0 0.2rem;
  border-radius: 3px;
  font-weight: 600;
}

[data-theme="dark"] .highlight {
  background-color: #854d0e;
  color: #fef08a;
}

/* Floating Back to Top Button */
.floating-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 80;
}

.floating-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

.floating-btn:hover {
  background-color: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
  transform: translateY(-3px);
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: #0f172a;
  color: #ffffff;
  padding: 0.75rem 1.5rem;
  border-radius: 30px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
}

[data-theme="dark"] .toast {
  background-color: #f8fafc;
  color: #0f172a;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Footer */
.app-footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.footer-sub {
  font-size: 0.78rem;
  margin-top: 0.35rem;
  color: var(--text-muted);
  opacity: 0.8;
}

.hidden {
  display: none !important;
}

/* Responsive Media Queries */
.mobile-only {
  display: none !important;
}

@media (max-width: 960px) {
  .mobile-only {
    display: flex !important;
  }
  .desktop-only {
    display: none !important;
  }

  .app-header {
    padding: 0 1rem;
  }

  .header-center {
    margin: 0 0.75rem;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    z-index: 1000;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .app-sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .sidebar-backdrop.active {
    opacity: 1;
    pointer-events: auto;
  }

  .app-content {
    padding: 1.25rem 1rem 4rem;
  }

  .content-banner {
    padding: 1.5rem 1.25rem;
    margin-bottom: 2rem;
  }

  .banner-title {
    font-size: 1.45rem;
  }

  .topic-card {
    padding: 1.25rem;
  }

  .argument-card {
    padding: 1rem;
  }

  .argument-header {
    flex-direction: column;
    gap: 0.5rem;
  }

  .floating-btn {
    bottom: 1.25rem;
    right: 1.25rem;
  }
}
