@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&family=Noto+Sans+Mono:wght@400;700&family=Noto+Serif:wght@400;700&family=Noto+Sans:wght@400;700&display=swap');

/* Krokodeilaki Font */
@font-face {
  font-family: 'Krokodeilaki';
  src: url('/files/fonts/krokodeilaki/Krokodeilaki.woff2') format('woff2'),
    url('/files/fonts/krokodeilaki/Krokodeilaki.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* Avant-Garde Glagolitic Font */
@font-face {
  font-family: 'Avant-Glagolitic';
  src: url('/files/fonts/avant-garde%20glagolitic/Avant-Glagolitic.woff2') format('woff2'),
    url('/files/fonts/avant-garde%20glagolitic/Avant-Glagolitic-v1.0.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --sidebar: 240px;
  --gutter: 40px;
  --content: 620px;
  --notes: 220px;
  --max-width: 1440px;

  --font-main: 'Noto Sans Mono', monospace;
  --font-heading: 'Noto Sans Mono', monospace;
  /* --font-heading: 'Montserrat', sans-serif; */
  --font-serif: 'Noto Serif', serif;
  --font-sans: 'Noto Sans', sans-serif;

  /* --- Color Constants --- */
  --white: #fafafa;
  --black: #222;

  /* --- Semantic Colors - Light Theme (Default) --- */
  --color-text: var(--black);
  --color-text-muted: #666;
  --color-bg: var(--white);
  --color-bg-alt: #f0f0f0;
  --color-border: #e6e6e6;
  --color-overlay: rgba(34, 34, 34, 0.1);
  --color-lightbox-bg: rgba(250, 250, 250, 0.95);
}

/* Manual Dark Theme Override */
[data-theme="dark"] {
  --color-text: var(--white);
  --color-text-muted: #999;
  --color-bg: var(--black);
  --color-bg-alt: #2a2a2a;
  --color-border: #444;
  --color-overlay: rgba(250, 250, 250, 0.2);
  --color-lightbox-bg: rgba(0, 0, 0, 0.95);
}

/* Respect System Preference if no manual choice is made */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-text: var(--white);
    --color-text-muted: #999;
    --color-bg: var(--black);
    --color-bg-alt: #2a2a2a;
    --color-border: #444;
    --color-overlay: rgba(250, 250, 250, 0.2);
    --color-lightbox-bg: rgba(0, 0, 0, 0.95);
  }
}

/* --- Language Switching Logic --- */
/* Hide content with a specific lang attribute if it doesn't match the document lang */
html[lang="en"] [lang]:not([lang="en"]),
html[lang="ru"] [lang]:not([lang="ru"]) {
  display: none !important;
}

/* Language Switcher Styles */
.lang-switcher {
  margin-top: 1rem;
  margin-bottom: 2rem;
  display: flex;
  gap: 0.5rem;
}

.lang-btn {
  background: none;
  border: none;
  color: inherit;
  font-family: var(--font-main);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
  opacity: 0.5;
  text-decoration: none;
}

.lang-btn.is-active {
  opacity: 1;
  font-weight: bold;
  text-decoration: underline;
}

.lang-btn:hover {
  opacity: 1;
}



body {
  background-color: var(--color-bg);
  color: var(--color-text);
  margin: 0;
}

/* --- Typography & Elements --- */
a {
  color: inherit;
  text-decoration: underline;
}

a:hover {
  text-decoration: none;
}

p {
  margin-bottom: 1rem;
  line-height: 1.6;
}

/* Utilities */
.hidden {
  display: none;
}

/* --- General Styles --- */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  font-family: var(--font-main);
  display: grid;
  grid-template-columns: var(--sidebar) var(--gutter) var(--content) var(--gutter) var(--notes) 1fr;
  grid-template-areas: "sidebar . content . notes extra";
  padding-top: 40px;
  padding-bottom: 60px;
}

.nav-icon {
  display: block;
  margin-bottom: 2rem;
  height: 124px;
}

.nav-icon img {
  height: 100%;
  object-fit: contain;
}

.sidebar {
  grid-area: sidebar;
}

.content {
  grid-area: content;
}

.notes {
  grid-area: notes;
}

.extra {
  grid-area: extra;
}

img {
  max-width: 100%;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-sans);
  color: var(--color-text);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

.nav-group-toggle,
.nav-group-link {
  font-family: var(--font-sans);
  color: var(--color-text);
}

h1 {
  margin-top: 0;
  font-weight: 700;
  font-size: 3rem;
}

h2 {
  font-weight: 700;
  font-size: 2rem;
}

h3 {
  font-weight: 700;
  font-size: 1.5rem;
}

h4 {
  font-weight: 400;
  font-size: 1.2rem;
}

.serif {
  font-family: var(--font-serif);
}

figcaption {
  font-size: 0.8rem;
  margin-bottom: 2rem;
}

figure blockquote {
  margin-left: 0;
  margin-right: 0;
}

/* --- Navigation --- */
.nav-group-header {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
}

.nav-group-link {
  display: inline;
  padding: 0.6rem 0;
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 700;
}

.nav-group-link:hover {
  text-decoration: underline;
  text-decoration-color: currentColor;
}

.nav-group-link.is-active {
  font-style: italic;
}

.nav-group-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.6rem 0 0.6rem 0.15rem;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
}

.nav-group-toggle:hover {
  opacity: 0.7;
}

.nav-toggle-icon {
  display: inline-block;
  width: 0.95em;
  height: 0.95em;
  fill: currentColor;
  transform: translateY(0.03em);
}



.nav-item a {
  color: var(--color-text);
  text-decoration: none;
  padding: 0.2rem 0;
  display: inline-block;
}

.nav-item a:hover {
  text-decoration: underline;
  text-decoration-color: currentColor;
}

.nav-item a.is-active {
  font-style: italic;
  /* font-weight: 700; */
}

.nav-group-list {
  display: none;
  list-style: none;
  padding-left: 0;
  margin-top: 0;
}

.nav-item {
  padding-left: 10px;
}

.nav-group.is-open .nav-group-list {
  display: block;
}

.telegram-icon {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  vertical-align: baseline;
  opacity: 0.7;
}

/* Icon List - displays favicons instead of bullets */
.icon-list {
  list-style: none;
  padding-left: 0;
}

.icon-list li {
  padding-left: 1.5em;
  margin-bottom: 0.5rem;
  position: relative;
}

.icon-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.2em;
  width: 1em;
  height: 1em;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* Favicon for each domain */
.icon-list li:has(a[href*="patreon.com"])::before {
  background-image: url('https://www.patreon.com/favicon.ico');
}

.icon-list li:has(a[href*="boosty.to"])::before {
  background-image: url('https://boosty.to/favicon.ico');
}

.icon-list li:has(a[href*="instagram.com"])::before {
  background-image: url('https://upload.wikimedia.org/wikipedia/commons/9/95/Instagram_logo_2022.svg');
}

.icon-list li:has(a[href*="spotify.com"])::before {
  background-image: url('https://open.spotify.com/favicon.ico');
}

/* Platform Specific Icons */
.icon-list li.icon-apple::before {
  content: '';
  top: 0.1em;
  /* Slight adjustment for character alignment */
}

.icon-list li.icon-windows::before {
  background-image: url('https://upload.wikimedia.org/wikipedia/commons/7/7e/Font_Awesome_5_brands_windows.svg');
}


/* --- Notes (Tufte Style) --- */
.notes-list {
  /* Kept for backward compatibility if needed, but mostly empty now */
  position: relative;
  list-style: none;
  padding: 0;
}

.note-wrapper {
  position: relative;
}

.note-ref {
  vertical-align: super;
  font-size: 0.7em;
  font-weight: bold;
  color: var(--color-text-muted);
  margin-left: 0.1em;
}

.note {
  /* Hidden by default until JS places it */
  display: none;
}

.note.is-placed {
  /* Mobile First styles */
  display: block;
  margin-top: 0.5rem;
  margin-bottom: 2rem;
  padding-left: 2rem;
  position: relative;

  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--color-text-muted);
}

.note.is-placed p {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

/* Desktop positioning */
@media (min-width: 900px) {
  .note.is-placed {
    position: absolute;
    top: 0;
    /* 
       Left position: 100% of the content width + gutter.
       The wrapper is inside .content, so 100% = width of paragraph.
    */
    left: calc(100% + var(--gutter));
    width: var(--notes);

    margin-top: 0;
    margin-bottom: 0;
    padding-left: 0;
  }
}

/* --- Blog --- */
.blog-posts {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.post-date {
  margin-top: 0.4rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.post-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.post-list li {
  margin-bottom: 0.5rem;
}

.post-list a.is-active {
  font-weight: 700;
  text-decoration: none;
}

/* --- Mobile Version --- */
/* --- Mobile Version --- */
@media (max-width: 1200px) {
  :root {
    --notes: 180px;
    --gutter: 20px;
  }
}

/* Mobile Toggle Button */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10001;
  background: none;
  border: none;
  width: 30px;
  height: 30px;
  cursor: pointer;
  flex-direction: column;
  justify-content: space-around;
  padding: 0;
}

.mobile-nav-toggle .bar {
  width: 100%;
  height: 3px;
  background-color: var(--color-text);
  transition: all 0.3s;
  transform-origin: 1px;
}

/* Hamburger to X animation */
.mobile-nav-toggle.is-active .bar:nth-child(1) {
  transform: rotate(45deg);
}

.mobile-nav-toggle.is-active .bar:nth-child(2) {
  opacity: 0;
}

.mobile-nav-toggle.is-active .bar:nth-child(3) {
  transform: rotate(-45deg);
}

@media (max-width: 900px) {
  .page {
    display: block;
    padding: 20px 20px 60px;
  }

  .mobile-nav-toggle {
    display: flex;
    /* Show only on mobile */
  }

  /* Sidebar gets repurposed as the overlay */
  .sidebar {
    display: none;
    /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    box-sizing: border-box;
    background: var(--color-bg);
    z-index: 10000;
    overflow-y: auto;
    padding: 80px 40px 150px;
    /* Space for X button and bottom safe area */
  }

  /* When open */
  body.is-mobile-nav-open {
    overflow: hidden;
    /* Prevent background scroll */
  }

  body.is-mobile-nav-open .sidebar {
    display: block;
  }

  /* Force groups open in mobile menu */
  body.is-mobile-nav-open .nav-group-list {
    display: block !important;
  }

  /* Hide toggles when groups are forced open */
  body.is-mobile-nav-open .nav-group-toggle {
    display: none;
  }

  .notes {
    margin-top: 4rem;
    padding: 20px;
  }

  .notes-list li {
    margin-bottom: 2rem;
  }
}


/* My custom classes */

.pad-up {
  margin-top: 1rem;
}

/* --- Zoomable Images --- */
img.img-zoom {
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s;
}

img.img-zoom:hover {
  opacity: 0.85;
  transform: scale(1.01);
}

img.img-zoom:focus {
  outline: 2px solid var(--color-text-muted);
  outline-offset: 2px;
}

/* --- Inline Icons --- */
.inline-icon {
  display: inline-block;
  height: 1em;
  width: auto;
  vertical-align: -0.15em;
  /* Optically align with text baseline */
  margin-right: 0.25em;
  /* Spacing between icon and text */
}

/* --- Theme Switcher --- */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10002;
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  opacity: 0.6;
  transition: opacity 0.2s, transform 0.2s;
}

.theme-toggle:hover {
  opacity: 1;
  transform: scale(1.1);
}

.theme-toggle svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Hide moon in dark theme, hide sun in light theme */
.theme-toggle .moon {
  display: block;
}

.theme-toggle .sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .sun {
  display: block;
}

/* Handle system preference visibility */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .moon {
    display: none;
  }

  :root:not([data-theme="light"]) .theme-toggle .sun {
    display: block;
  }
}

@media (max-width: 900px) {
  .theme-toggle {
    right: 70px;
    /* Leave space for hamburger menu */
  }
}

/* --- Krokodeilaki Font Class --- */
.kroko {
  font-family: 'Krokodeilaki', sans-serif;
}

/* --- Avant-Garde Glagolitic Font Class --- */
.glagolitic {
  font-family: 'Avant-Glagolitic', sans-serif;
}
