/* ============================================
   Socratic Prep — BitDevs-native dark theme
   ============================================ */

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

:root {
  --bg: #0d1117;
  --bg-subtle: #161b22;
  --border: #21262d;
  --border-accent: #f0883e;
  --text: #c9d1d9;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #f0883e;
  --accent-dim: rgba(240, 136, 62, 0.15);
  --red: #f85149;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --transition: 0.2s ease;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* --- Container --- */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* --- Header --- */
.site-header {
  margin-bottom: 1.5rem;
}

.site-title {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.site-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* --- Controls (seminar select + search) --- */
.controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.seminar-select {
  flex: 0 0 auto;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
  appearance: auto;
}

.seminar-select:focus {
  border-bottom-color: var(--accent);
}

.search-input {
  flex: 1;
  padding: 0.4rem 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-bottom-color: var(--accent);
}

/* --- Dividers --- */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

/* --- Category Sections --- */
.category-section {
  margin-bottom: 1.5rem;
}

.category-header {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

/* --- Topic Items --- */
.topic-item {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.35rem 0;
  cursor: pointer;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.4;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
  transition: color var(--transition);
}

.topic-item:hover {
  color: var(--accent);
}

.topic-item.active {
  color: var(--accent);
}

.topic-title {
  flex: 1;
}

.topic-link-icon {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: color var(--transition);
}

.topic-item:hover .topic-link-icon {
  color: var(--accent);
}

/* --- Expanded Topic (Explainer Inline) --- */
.topic-expanded {
  border-left: 2px solid var(--accent);
  padding-left: 1rem;
  margin: 0.5rem 0 1rem 0;
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.25s ease;
}

.topic-expanded.collapsing {
  max-height: 0 !important;
  opacity: 0;
}

/* --- Explainer Content --- */
.explainer-card {
  padding: 0;
}

.explainer-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.explainer-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.difficulty-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  text-transform: lowercase;
  white-space: nowrap;
  flex-shrink: 0;
}

.difficulty-badge[data-level="beginner"] {
  background: rgba(63, 185, 80, 0.15);
  color: #3fb950;
}

.difficulty-badge[data-level="intermediate"] {
  background: var(--accent-dim);
  color: var(--accent);
}

.difficulty-badge[data-level="advanced"] {
  background: rgba(248, 81, 73, 0.15);
  color: var(--red);
}

/* --- TLDR --- */
.explainer-tldr {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

/* --- Section headings --- */
.explainer-section h3,
.explainer-diagram h3,
.explainer-connections h3 {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.explainer-section {
  margin-bottom: 1rem;
}

.explainer-section p {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.6;
}

/* --- Key Concepts as inline pills --- */
.concepts-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.concept-card {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: 12px;
  cursor: default;
  position: relative;
}

.concept-card h4 {
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
}

.concept-card p {
  display: none;
}

.concept-icon {
  font-size: 0.85rem;
}

/* concept tooltip on hover */
.concept-card[title]:hover {
  background: rgba(240, 136, 62, 0.25);
}

/* --- Diagram --- */
.explainer-diagram {
  margin-bottom: 1rem;
}

.explainer-diagram pre {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text);
  overflow-x: auto;
  line-height: 1.4;
  margin: 0;
}

/* --- Connections --- */
.explainer-connections {
  margin-bottom: 1rem;
}

.connection-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.connection-tag {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 10px;
  cursor: default;
}

/* --- Source link --- */
.topic-url a {
  color: var(--accent);
  font-size: 0.8rem;
}

.topic-url a:hover {
  text-decoration: underline;
}

/* --- Actions (regenerate) --- */
.explainer-actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.regenerate-btn {
  padding: 0.3rem 0.75rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.regenerate-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* --- Loading --- */
.explainer-loading {
  padding: 1.5rem 0;
  color: var(--text-secondary);
  text-align: center;
}

.explainer-loading h2 {
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.explainer-loading .topic-description {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 0.5rem;
}

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

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

/* --- Error --- */
.explainer-error .error-message {
  background: rgba(248, 81, 73, 0.08);
  border-left: 2px solid var(--red);
  padding: 0.5rem 0.75rem;
  margin: 0.75rem 0;
}

.explainer-error .error-message p {
  color: var(--red);
  font-size: 0.8rem;
}

/* --- Category tag (kept for JS compat) --- */
.category-tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: lowercase;
}

/* --- Empty state --- */
.empty-topics {
  padding: 2rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ============================================
   Chat Panel (inline under explainer)
   ============================================ */

.chat-panel {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.chat-messages {
  max-height: 300px;
  overflow-y: auto;
  padding: 0;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.chat-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0.5rem 0;
}

.chat-msg {
  margin-bottom: 0.65rem;
  padding-left: 0.75rem;
  line-height: 1.5;
}

.chat-msg .chat-role {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.1rem;
}

.chat-msg.user .chat-role {
  color: var(--accent);
}

.chat-msg.assistant .chat-role {
  color: #8b949e;
}

.chat-msg.user {
  color: var(--text);
}

.chat-msg.assistant {
  color: var(--text);
}

.chat-body {
  font-size: 0.85rem;
  line-height: 1.6;
}

.chat-body code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--bg-subtle);
  padding: 0.1em 0.3em;
}

.chat-body strong {
  font-weight: 600;
  color: var(--text);
}

/* Thinking animation */
.chat-thinking {
  color: var(--text-muted);
  font-style: italic;
  animation: chat-pulse 1.5s ease-in-out infinite;
}

@keyframes chat-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* --- Chat Input --- */
.chat-input-row {
  display: flex;
  gap: 0.5rem;
}

.chat-input {
  flex: 1;
  padding: 0.4rem 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition);
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-input:focus {
  border-bottom-color: var(--accent);
}

.chat-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-send {
  padding: 0.3rem 0.75rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.chat-send:hover:not(:disabled) {
  background: var(--accent);
  color: var(--bg);
}

.chat-send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* --- Collapsed chat (compat) --- */
.chat-panel.collapsed .chat-messages {
  display: none;
}

.chat-header {
  display: none;
}

/* --- Footer --- */
.site-footer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 1rem 0 0;
}

.site-footer a {
  color: var(--text-muted);
}

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

/* ============================================
   Diagram (SVG)
   ============================================ */

.diagram-container {
  text-align: center;
  max-width: 100%;
  overflow: visible;
  margin: 0.75rem 0;
}

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

.diagram-toggle {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  margin-bottom: 0.4rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.65rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.diagram-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.diagram-svg {
  display: flex;
  justify-content: center;
}

.diagram-ascii pre {
  text-align: left;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 640px) {
  .container {
    padding: 1.25rem 1rem;
  }

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

  .seminar-select {
    width: 100%;
  }

  .topic-expanded {
    padding-left: 0.75rem;
  }
}
