/* MasterThaiBook — Cosmic Observatory
   Deep space aesthetic: infinite knowledge as stars in the void.
   Strategy: Drenched dark field, warm gold knowledge-light, nebula accents */

:root {
  /* Space field — deep violet-black */
  --space-void: oklch(0.12 0.03 280);
  --space-deep: oklch(0.16 0.04 280);
  --space-surface: oklch(0.20 0.04 280);
  --space-elevated: oklch(0.24 0.05 280);

  /* Knowledge light — warm amber/gold */
  --star-gold: oklch(0.82 0.16 80);
  --star-gold-dim: oklch(0.65 0.12 80);
  --star-glow: oklch(0.82 0.16 80 / 0.4);

  /* Nebula accents (shifted from original palette for dark legibility) */
  --nebula-violet: oklch(0.68 0.20 290);
  --nebula-violet-glow: oklch(0.68 0.20 290 / 0.3);
  --nebula-teal: oklch(0.72 0.14 195);
  --nebula-teal-glow: oklch(0.72 0.14 195 / 0.3);
  --nebula-rose: oklch(0.72 0.16 10);
  --nebula-rose-glow: oklch(0.72 0.16 10 / 0.3);
  --nebula-amber: oklch(0.75 0.14 65);
  --nebula-amber-glow: oklch(0.75 0.14 65 / 0.3);
  --nebula-mint: oklch(0.75 0.14 160);
  --nebula-mint-glow: oklch(0.75 0.14 160 / 0.3);

  /* Ink on dark */
  --ink-primary: oklch(0.93 0.01 280);
  --ink-secondary: oklch(0.72 0.02 280);
  --ink-muted: oklch(0.55 0.02 280);
  --ink-faint: oklch(0.38 0.02 280);

  /* Borders on dark */
  --border-subtle: oklch(0.28 0.03 280);
  --border-glow: oklch(0.40 0.06 280);

  /* Mascot — adapted for dark */
  --mascot-body: var(--nebula-violet);
  --mascot-belly: oklch(0.88 0.03 280);
  --mascot-wing: oklch(0.50 0.18 290);
  --mascot-accent: var(--star-gold);
  --mascot-hp: oklch(0.90 0.02 280);
  --mascot-book: var(--star-gold);

  /* Radii — softer than cartoon, still rounded */
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --radius-pill: 100px;

  /* Motion */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --duration-slow: 600ms;
  --duration-drift: 20s;
}

/* PaperMod overrides — force dark regardless of toggle */
:root,
.dark {
  --theme: var(--space-void);
  --entry: var(--space-surface);
  --primary: var(--star-gold);
  --secondary: var(--ink-secondary);
  --tertiary: var(--space-elevated);
  --content: var(--ink-primary);
  --hljs-bg: var(--space-deep);
  --code-bg: var(--space-deep);
  --border: var(--border-subtle);
  --gap: 24px;
}

body {
  background: var(--space-void);
  color: var(--ink-primary);
  font-family: 'Satoshi', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Typography — lighter weight for dark backgrounds */
h1, .post-title {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  text-wrap: balance;
  font-size: clamp(1.8rem, 4vw + 1rem, 3.2rem);
  color: var(--ink-primary);
}

h2 {
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: clamp(1.4rem, 3vw + 0.5rem, 2.2rem);
  text-wrap: balance;
  color: var(--ink-primary);
}

h3 {
  font-weight: 600;
  font-size: clamp(1.1rem, 2vw + 0.5rem, 1.6rem);
  color: var(--ink-primary);
}

p, li, .post-content {
  line-height: 1.85;
  max-width: 65ch;
  text-wrap: pretty;
  color: var(--ink-secondary);
}

/* Links — gold knowledge light */
a {
  color: var(--star-gold);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out-expo),
              text-shadow var(--duration-fast) var(--ease-out-expo);
}

a:hover {
  color: oklch(0.90 0.14 80);
  text-shadow: 0 0 12px var(--star-glow);
}

/* Header — dark glass nav */
.nav {
  background: oklch(0.12 0.03 280 / 0.85);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

header.header {
  background: transparent;
}

.logo a {
  font-weight: 700;
  color: var(--star-gold);
  font-size: 1.15rem;
  text-shadow: 0 0 20px var(--star-glow);
}

#menu a {
  font-weight: 600;
  color: var(--ink-secondary);
  border-radius: var(--radius-pill);
  padding: 0.4rem 1rem;
  transition: all var(--duration-fast) var(--ease-out-expo);
}

#menu a:hover,
#menu .active {
  color: var(--star-gold);
  background: oklch(0.82 0.16 80 / 0.08);
}

/* Posts / entries — space cards */
.post-entry {
  background: var(--space-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  transition: transform var(--duration-normal) var(--ease-out-quint),
              border-color var(--duration-fast) var(--ease-out-expo),
              box-shadow var(--duration-normal) var(--ease-out-expo);
}

.post-entry:hover {
  transform: translateY(-3px);
  border-color: var(--border-glow);
  box-shadow: 0 8px 40px oklch(0.68 0.20 290 / 0.08),
              0 0 1px oklch(0.68 0.20 290 / 0.2);
}

.post-entry:active {
  transform: scale(0.99);
}

.first-entry {
  border: 1px solid oklch(0.82 0.16 80 / 0.3);
  border-radius: var(--radius-xl);
  background: linear-gradient(
    135deg,
    oklch(0.20 0.06 280) 0%,
    oklch(0.18 0.04 290) 100%
  );
}

.first-entry:hover {
  box-shadow: 0 12px 48px oklch(0.82 0.16 80 / 0.1),
              0 0 1px oklch(0.82 0.16 80 / 0.3);
}

/* Entry text */
.entry-header h2 {
  color: var(--ink-primary);
}

.entry-content p {
  color: var(--ink-secondary);
}

/* Tags — nebula pills */
.post-tags a,
.terms-tags a {
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all var(--duration-fast) var(--ease-out-quint);
}

.post-tags a:nth-child(5n+1),
.terms-tags a:nth-child(5n+1) {
  background: oklch(0.68 0.20 290 / 0.15);
  color: var(--nebula-violet);
}

.post-tags a:nth-child(5n+2),
.terms-tags a:nth-child(5n+2) {
  background: oklch(0.72 0.14 195 / 0.15);
  color: var(--nebula-teal);
}

.post-tags a:nth-child(5n+3),
.terms-tags a:nth-child(5n+3) {
  background: oklch(0.72 0.16 10 / 0.15);
  color: var(--nebula-rose);
}

.post-tags a:nth-child(5n+4),
.terms-tags a:nth-child(5n+4) {
  background: oklch(0.75 0.14 65 / 0.15);
  color: var(--nebula-amber);
}

.post-tags a:nth-child(5n+5),
.terms-tags a:nth-child(5n+5) {
  background: oklch(0.75 0.14 160 / 0.15);
  color: var(--nebula-mint);
}

.post-tags a:hover,
.terms-tags a:hover {
  transform: scale(1.05);
  box-shadow: 0 0 16px oklch(0.7 0.15 280 / 0.2);
}

/* Audio player — deep space */
.audio-player {
  background: var(--space-deep);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  margin: 1.5rem 0;
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.03);
}

.audio-player-play-btn {
  background: var(--star-gold);
  color: var(--space-void);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  box-shadow: 0 0 24px var(--star-glow),
              0 4px 12px oklch(0 0 0 / 0.4);
  transition: transform var(--duration-fast) var(--ease-out-quint),
              box-shadow var(--duration-fast) var(--ease-out-expo);
}

.audio-player-play-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 0 36px var(--star-glow),
              0 6px 16px oklch(0 0 0 / 0.5);
}

.audio-player-play-btn:active {
  transform: scale(0.96);
}

.audio-player-progress-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--space-elevated);
}

.audio-player-progress-filled {
  background: var(--star-gold);
  border-radius: 3px;
  box-shadow: 0 0 8px var(--star-glow);
}

.audio-player-speed-btn {
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.35rem 0.75rem;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--ink-muted);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out-quint);
}

.audio-player-speed-btn:hover {
  border-color: var(--star-gold);
  color: var(--star-gold);
}

.audio-player-speed-btn.active {
  background: var(--star-gold);
  color: var(--space-void);
  border-color: var(--star-gold);
  box-shadow: 0 0 12px var(--star-glow);
}

/* Podcast list entries */
.podcast-entry {
  background: var(--space-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
  transition: all var(--duration-normal) var(--ease-out-quint);
  display: flex;
  gap: 1rem;
  align-items: start;
}

.podcast-entry:hover {
  border-color: var(--border-glow);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px oklch(0 0 0 / 0.3);
}

.podcast-entry:active {
  transform: scale(0.99);
}

.podcast-play-icon {
  background: var(--nebula-violet);
  color: white;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 20px var(--nebula-violet-glow);
  transition: all var(--duration-fast) var(--ease-out-quint);
}

.podcast-play-icon:hover {
  transform: scale(1.1);
  box-shadow: 0 0 32px var(--nebula-violet-glow);
}

.podcast-entry:nth-child(5n+2) .podcast-play-icon {
  background: var(--nebula-teal);
  box-shadow: 0 0 20px var(--nebula-teal-glow);
}

.podcast-entry:nth-child(5n+3) .podcast-play-icon {
  background: var(--nebula-rose);
  box-shadow: 0 0 20px var(--nebula-rose-glow);
}

.podcast-entry:nth-child(5n+4) .podcast-play-icon {
  background: var(--nebula-amber);
  box-shadow: 0 0 20px var(--nebula-amber-glow);
}

.podcast-entry:nth-child(5n+5) .podcast-play-icon {
  background: var(--nebula-mint);
  box-shadow: 0 0 20px var(--nebula-mint-glow);
}

/* RSS button */
.podcast-rss-link {
  background: transparent;
  color: var(--star-gold);
  border: 1px solid oklch(0.82 0.16 80 / 0.3);
  border-radius: var(--radius-pill);
  font-weight: 600;
  padding: 0.65rem 1.3rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--duration-fast) var(--ease-out-quint);
  text-decoration: none;
}

.podcast-rss-link:hover {
  background: oklch(0.82 0.16 80 / 0.08);
  border-color: var(--star-gold);
  box-shadow: 0 0 20px var(--star-glow);
  color: var(--star-gold);
}

/* Latest episode hero — deep space glow */
.latest-episode {
  background: var(--space-deep);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 2rem;
  margin: 2rem 0;
  position: relative;
  overflow: hidden;
}

.latest-episode::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 50%, oklch(0.68 0.20 290 / 0.06) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 30%, oklch(0.72 0.14 195 / 0.04) 0%, transparent 50%);
  pointer-events: none;
}

.latest-episode-header h2 {
  color: var(--star-gold);
  margin: 0;
  font-size: 1.4rem;
}

.latest-episode-title a {
  color: var(--ink-primary);
}

.latest-episode-title a:hover {
  color: var(--star-gold);
}

.latest-episode-link {
  color: var(--star-gold);
  font-weight: 600;
}

/* Badges */
.badge-new {
  display: inline-block;
  background: var(--nebula-teal);
  color: var(--space-void);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  box-shadow: 0 0 12px var(--nebula-teal-glow);
}

.badge-popular {
  display: inline-block;
  background: var(--nebula-rose);
  color: white;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  box-shadow: 0 0 12px var(--nebula-rose-glow);
}

.badge-duration {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: oklch(0.75 0.14 65 / 0.1);
  color: var(--nebula-amber);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-pill);
}

/* Search */
#search-input {
  background: var(--space-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  color: var(--ink-primary);
  font-size: 1.1rem;
  padding: 1rem 1.5rem;
  transition: border-color var(--duration-fast) var(--ease-out-expo),
              box-shadow var(--duration-fast) var(--ease-out-expo);
}

#search-input:focus {
  border-color: var(--star-gold);
  box-shadow: 0 0 0 3px oklch(0.82 0.16 80 / 0.1),
              0 0 20px oklch(0.82 0.16 80 / 0.05);
  outline: none;
}

.search-result {
  background: var(--space-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease-out-quint);
}

.search-result:hover {
  border-color: var(--border-glow);
  transform: translateY(-1px);
}

.highlight {
  background: oklch(0.82 0.16 80 / 0.15);
  color: var(--star-gold);
  border-radius: 4px;
  padding: 0.1rem 0.3rem;
  font-weight: 600;
}

/* Homepage title */
.home-info .entry-hint-parent {
  font-size: clamp(2rem, 5vw + 0.5rem, 3rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--star-gold);
}

/* Pagination */
.paginav {
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.paginav a {
  background: var(--space-surface);
  transition: all var(--duration-fast) var(--ease-out-expo);
  padding: 1rem;
  color: var(--ink-secondary);
}

.paginav a:hover {
  background: var(--space-elevated);
  color: var(--star-gold);
}

/* Footer */
footer.footer {
  border-top: 1px solid var(--border-subtle);
  color: var(--ink-muted);
}

/* Selection */
::selection {
  background: oklch(0.82 0.16 80 / 0.25);
  color: var(--ink-primary);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--space-void);
}

::-webkit-scrollbar-thumb {
  background: var(--border-glow);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--star-gold-dim);
}

/* Mascot animations */
@keyframes wave-wing {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(8deg); }
}

@keyframes float-note {
  0%, 100% { transform: translateY(0) rotate(0); opacity: 1; }
  50% { transform: translateY(-5px) rotate(3deg); opacity: 0.7; }
}

.mascot-wing-wave {
  transform-origin: 24px 70px;
  animation: wave-wing 2s var(--ease-out-expo) infinite;
}

.mascot-note-1 {
  animation: float-note 3s ease-in-out infinite;
}

.mascot-note-2 {
  animation: float-note 3s ease-in-out infinite 0.7s;
}

.mascot-confetti {
  animation: float-note 2.5s ease-in-out infinite;
}

.mascot-confetti:nth-child(2) { animation-delay: 0.4s; }
.mascot-confetti:nth-child(3) { animation-delay: 0.8s; }
.mascot-confetti:nth-child(4) { animation-delay: 1.2s; }

/* Mobile */
@media (max-width: 768px) {
  .post-entry:hover,
  .podcast-entry:hover {
    transform: none;
    box-shadow: none;
  }

  .post-entry:active,
  .podcast-entry:active {
    transform: scale(0.98);
  }

  .audio-player-play-btn {
    width: 48px;
    height: 48px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Page load */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.main {
  animation: fade-up var(--duration-slow) var(--ease-out-expo) both;
}

@media (prefers-reduced-motion: reduce) {
  .main { animation: none; }
}

/* Knowledge Graph — cosmic starfield */
.kg-section {
  padding: 1.5rem 0 2.5rem;
}

.kg-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.kg-title {
  margin: 0;
  font-size: 1.4rem;
  color: var(--star-gold);
  font-weight: 700;
}

.kg-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.kg-search-wrap {
  margin-bottom: 1.25rem;
}

.kg-search {
  width: 100%;
  padding: 0.75rem 1.2rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-size: 1rem;
  font-family: inherit;
  background: var(--space-surface);
  color: var(--ink-primary);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out-expo),
              box-shadow var(--duration-fast) var(--ease-out-expo);
}

.kg-search:focus {
  border-color: var(--star-gold);
  box-shadow: 0 0 0 3px oklch(0.82 0.16 80 / 0.1),
              0 0 16px oklch(0.82 0.16 80 / 0.05);
}

.kg-search::placeholder {
  color: var(--ink-muted);
}

.kg-canvas-wrap {
  border-radius: var(--radius-lg);
  background: var(--space-deep);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  position: relative;
}

#kg-canvas {
  display: block;
  width: 100%;
}

.kg-results {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--space-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.kg-results h3 {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  color: var(--ink-muted);
  font-weight: 600;
}

.kg-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink-primary);
  transition: background var(--duration-fast) var(--ease-out-expo);
}

.kg-result-item:hover {
  background: oklch(0.82 0.16 80 / 0.06);
}

.kg-result-title {
  font-weight: 600;
  font-size: 0.92rem;
}

.kg-result-date {
  font-size: 0.78rem;
  color: var(--ink-muted);
}

/* Starfield background (homepage only via .home class or body positioning) */
.kg-canvas-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(1px 1px at 20% 30%, oklch(0.95 0 0 / 0.4), transparent),
    radial-gradient(1px 1px at 60% 15%, oklch(0.95 0 0 / 0.3), transparent),
    radial-gradient(1px 1px at 85% 55%, oklch(0.95 0 0 / 0.35), transparent),
    radial-gradient(1.5px 1.5px at 45% 80%, oklch(0.95 0 0 / 0.25), transparent),
    radial-gradient(1px 1px at 10% 70%, oklch(0.95 0 0 / 0.3), transparent);
}

/* Active Learners widget */
.active-learners {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.75rem 0;
  margin: 0.5rem 0 1rem;
}

.active-learners-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--nebula-teal);
  box-shadow: 0 0 8px var(--nebula-teal-glow);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

.active-learners-text {
  font-size: 0.85rem;
  color: var(--ink-muted);
  font-weight: 500;
}

#active-count {
  color: var(--nebula-teal);
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  .active-learners-dot { animation: none; }
}
