/* ==========================================================================
   NotesSite — Kunj.dev Design System & Eye-Comfort Themes
   ========================================================================== */

:root,
[data-theme="paper"] {
  /* Typography */
  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* Kunj.dev Default Paper Theme */
  --bg-canvas: #F3F0E8;
  --bg-surface: #F3F0E8;
  --bg-sidebar: #EBE7DD;
  --bg-card: rgba(255, 255, 255, 0.65);
  --bg-hover: rgba(10, 10, 10, 0.05);

  --text-ink: #0A0A0A;
  --text-muted: #6B6760;
  --text-faint: #9E998F;

  /* Signature Ember Accent */
  --color-accent: #FF4D1F;
  --color-accent-hover: #E03F14;
  --color-accent-light: rgba(255, 77, 31, 0.12);
  --color-accent-border: rgba(255, 77, 31, 0.35);

  --border-hairline: rgba(10, 10, 10, 0.12);
  --border-subtle: rgba(10, 10, 10, 0.06);
  --grid-line: rgba(10, 10, 10, 0.06);

  --selection-bg: #FF4D1F;
  --selection-text: #F3F0E8;

  /* Callouts */
  --callout-note-border: #FF4D1F;
  --callout-note-bg: rgba(255, 77, 31, 0.06);
  --callout-warning-border: #D97706;
  --callout-warning-bg: rgba(217, 119, 6, 0.08);
  --callout-tip-border: #10B981;
  --callout-tip-bg: rgba(16, 185, 129, 0.08);
  --callout-caution-border: #DC2626;
  --callout-caution-bg: rgba(220, 38, 38, 0.08);

  /* Layout */
  --sidebar-width: 290px;
  --toc-width: 230px;
  --content-max-width: 70ch;
  --header-height: 60px;
}

/* Onyx Dark Theme */
[data-theme="dark"] {
  --bg-canvas: #0A0A0A;
  --bg-surface: #0A0A0A;
  --bg-sidebar: #111111;
  --bg-card: #141414;
  --bg-hover: rgba(237, 233, 225, 0.06);

  --text-ink: #EDE9E1;
  --text-muted: #8A857C;
  --text-faint: #5C5851;

  --color-accent: #FF4D1F;
  --color-accent-hover: #FF663E;
  --color-accent-light: rgba(255, 77, 31, 0.15);
  --color-accent-border: rgba(255, 77, 31, 0.4);

  --border-hairline: rgba(237, 233, 225, 0.12);
  --border-subtle: rgba(237, 233, 225, 0.05);
  --grid-line: rgba(237, 233, 225, 0.05);

  --selection-bg: #FF4D1F;
  --selection-text: #0A0A0A;

  --callout-note-border: #FF4D1F;
  --callout-note-bg: rgba(255, 77, 31, 0.08);
  --callout-warning-border: #F59E0B;
  --callout-warning-bg: rgba(245, 158, 11, 0.1);
  --callout-tip-border: #34D399;
  --callout-tip-bg: rgba(52, 211, 153, 0.1);
  --callout-caution-border: #F87171;
  --callout-caution-bg: rgba(248, 113, 113, 0.1);
}

/* Sepia Warm Library Theme (Low eye-strain for readers) */
[data-theme="sepia"] {
  --bg-canvas: #F7EFE2;
  --bg-surface: #F7EFE2;
  --bg-sidebar: #EDE3D2;
  --bg-card: rgba(255, 252, 245, 0.75);
  --bg-hover: rgba(44, 34, 24, 0.06);

  --text-ink: #2C2218;
  --text-muted: #7D6B5A;
  --text-faint: #A69481;

  --color-accent: #C25E2E;
  --color-accent-hover: #AA4F24;
  --color-accent-light: rgba(194, 94, 46, 0.12);
  --color-accent-border: rgba(194, 94, 46, 0.35);

  --border-hairline: rgba(44, 34, 24, 0.12);
  --border-subtle: rgba(44, 34, 24, 0.06);
  --grid-line: rgba(44, 34, 24, 0.05);

  --selection-bg: #C25E2E;
  --selection-text: #F7EFE2;

  --callout-note-border: #C25E2E;
  --callout-note-bg: rgba(194, 94, 46, 0.08);
  --callout-warning-border: #B45309;
  --callout-warning-bg: rgba(180, 83, 9, 0.08);
  --callout-tip-border: #047857;
  --callout-tip-bg: rgba(4, 120, 87, 0.08);
  --callout-caution-border: #B91C1C;
  --callout-caution-bg: rgba(185, 28, 28, 0.08);
}

/* Calm Sage Theme (Soft botanical green, pleasant for eye relaxation) */
[data-theme="sage"] {
  --bg-canvas: #EEF3ED;
  --bg-surface: #EEF3ED;
  --bg-sidebar: #E2EAE1;
  --bg-card: rgba(255, 255, 255, 0.75);
  --bg-hover: rgba(20, 34, 25, 0.06);

  --text-ink: #142219;
  --text-muted: #5D7266;
  --text-faint: #8B9E93;

  --color-accent: #237A57;
  --color-accent-hover: #1B6547;
  --color-accent-light: rgba(35, 122, 87, 0.12);
  --color-accent-border: rgba(35, 122, 87, 0.35);

  --border-hairline: rgba(20, 34, 25, 0.12);
  --border-subtle: rgba(20, 34, 25, 0.06);
  --grid-line: rgba(20, 34, 25, 0.05);

  --selection-bg: #237A57;
  --selection-text: #EEF3ED;

  --callout-note-border: #237A57;
  --callout-note-bg: rgba(35, 122, 87, 0.08);
  --callout-warning-border: #C05621;
  --callout-warning-bg: rgba(192, 86, 33, 0.08);
  --callout-tip-border: #2F855A;
  --callout-tip-bg: rgba(47, 133, 90, 0.08);
  --callout-caution-border: #C53030;
  --callout-caution-bg: rgba(197, 48, 48, 0.08);
}

/* Nord Twilight Theme (Cool slate gray) */
[data-theme="slate"] {
  --bg-canvas: #1A1D24;
  --bg-surface: #1A1D24;
  --bg-sidebar: #15181E;
  --bg-card: #222630;
  --bg-hover: rgba(229, 233, 240, 0.06);

  --text-ink: #E5E9F0;
  --text-muted: #8B949E;
  --text-faint: #5E6572;

  --color-accent: #88C0D0;
  --color-accent-hover: #72B1C4;
  --color-accent-light: rgba(136, 192, 208, 0.15);
  --color-accent-border: rgba(136, 192, 208, 0.4);

  --border-hairline: rgba(229, 233, 240, 0.12);
  --border-subtle: rgba(229, 233, 240, 0.05);
  --grid-line: rgba(229, 233, 240, 0.05);

  --selection-bg: #88C0D0;
  --selection-text: #1A1D24;

  --callout-note-border: #88C0D0;
  --callout-note-bg: rgba(136, 192, 208, 0.08);
  --callout-warning-border: #EBCB8B;
  --callout-warning-bg: rgba(235, 203, 139, 0.1);
  --callout-tip-border: #A3BE8C;
  --callout-tip-bg: rgba(163, 190, 140, 0.1);
  --callout-caution-border: #BF616A;
  --callout-caution-bg: rgba(191, 97, 106, 0.1);
}

/* ==========================================================================
   Base Reset & Global Styles
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--font-sans);
  font-size: 16px;
  background-color: var(--bg-canvas);
  color: var(--text-ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11", "kern";
  scroll-behavior: smooth;
}

/* Reader font-size modes */
[data-font-size="large"] {
  font-size: 18px;
}

/* Signature Selection Styling */
::selection {
  background: var(--selection-bg);
  color: var(--selection-text);
}

::-moz-selection {
  background: var(--selection-bg);
  color: var(--selection-text);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-canvas);
  position: relative;
  overflow-x: hidden;
}

/* Subtle Physical Paper Grain Overlay */
.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
  opacity: 0.035;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

[data-theme="dark"] .noise,
[data-theme="slate"] .noise {
  opacity: 0.05;
  mix-blend-mode: screen;
}

/* Subtle Grid Background Accents */
.grid-lines {
  background-image: linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
                    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 40px 40px;
}

/* Hairline helper */
.hairline {
  border-color: var(--border-hairline);
}

/* Accessible Skip Link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 1.5rem;
  background: var(--color-accent);
  color: var(--bg-canvas);
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  z-index: 10000;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  transition: top 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.skip-link:focus {
  top: 1rem;
  outline: 2px solid var(--text-ink);
}

/* Thin Elegant Scrollbars */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-hairline);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Focus Visible Rings */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ==========================================================================
   Header Bar (Editorial Minimalist)
   ========================================================================== */

.app-header {
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

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

.app-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--text-ink);
}

/* Pulsing Ember Dot from kunj.dev */
.brand-pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent);
  box-shadow: 0 0 0 rgba(255, 77, 31, 0.5);
  animation: emberPulse 2.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes emberPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(255, 77, 31, 0.5);
  }
  50% {
    transform: scale(1.15);
    opacity: 0.85;
    box-shadow: 0 0 8px 3px rgba(255, 77, 31, 0.35);
  }
}

.brand-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  font-weight: 400;
  color: var(--text-ink);
}

.brand-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  border-left: 1px solid var(--border-hairline);
  padding-left: 0.75rem;
  margin-left: 0.25rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Action Buttons & Pills */
.header-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 36px;
  padding: 0.35rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  border-radius: 9999px;
  border: 1px solid var(--border-hairline);
  background: transparent;
  color: var(--text-ink);
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.header-pill-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--bg-hover);
}

.theme-swatch-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-accent);
  flex-shrink: 0;
  display: inline-block;
}

.font-size-btn {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0 0.65rem;
  letter-spacing: -0.05em;
}

.font-size-btn.is-large {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* ==========================================================================
   3-Column Layout Container
   ========================================================================== */

.app-container {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width);
  min-height: calc(100vh - var(--header-height));
  width: 100%;
}

.app-sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
}

.app-main {
  background: var(--bg-surface);
  padding: 3rem 2.5rem 6rem 2.5rem;
  display: flex;
  justify-content: center;
  min-height: calc(100vh - var(--header-height));
}

.main-content-inner {
  width: 100%;
  max-width: var(--content-max-width);
  opacity: 1;
  transition: opacity 150ms ease;
}

.route-transition-out {
  opacity: 0;
}

.route-transition-in {
  opacity: 1;
}

.app-toc-rail {
  padding: 3rem 1.5rem;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  border-left: 1px solid var(--border-hairline);
}

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

/* Responsive Breakpoints */
@media (max-width: 1099px) {
  .app-container {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }
  .app-toc-rail {
    display: none;
  }
}

@media (max-width: 767px) {
  .app-container {
    grid-template-columns: 1fr;
  }
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 310px;
    z-index: 1001;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    height: 100vh;
  }
  .app-sidebar.is-open {
    transform: translateX(0);
  }
  .app-main {
    padding: 2rem 1.25rem 5rem 1.25rem;
  }
  .brand-badge {
    display: none;
  }
}
