@import url("../fonts/fonts.css");
@import url("./themes/default.css");
@import url("./themes/terminal.css");
@import url("./themes/ocean.css");
@import url("./themes/ember.css");

:root {
  --font-body-default: "Helvetica Neue", "Iosevka Nerd Font", "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-code-default: "DepartureMono", "GohuFont11", "JetBrainsMono Nerd Font", "Iosevka Nerd Font", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --max-width: 1024px;
  --font-tamzen: "Tamzen", sans-serif;
  --font-gohu: "GohuFont11", sans-serif;
  --font-departure: "DepartureMono", sans-serif;
  --font-libre: "LibreBaskerville", serif;
  --font-body: var(--font-body-default);
  --font-code: var(--font-code-default);
  --font-ui: var(--font-tamzen);
  --font-display: var(--font-departure);
  --font-hero: var(--font-libre);
  --font-title: "Helvetica Neue", var(--font-tamzen);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --radius-xs: 2px;
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 6px;
  --radius-pill: 999px;
  --line-thin: 1px;
  --line-thick: 2px;
}

html[data-theme-mode="light"] {
  color-scheme: light;
}

html[data-theme-mode="dark"] {
  color-scheme: dark;
}

html[data-theme-mode="light"] {
  --bg: #ffffff;
  --bg-muted: #f6f8fa;
  --bg-elevated: #ffffff;
  --bg-trans: rgba(255, 255, 255, 0.95);
  --text: #1f2328;
  --text-muted: #59636e;
  --text-very-muted: #c5c6c7;
  --border: #d0d7de;
  --border-strong: #b7bec8;
  --link: #0969da;
  --link-hover: #0a58b6;
  --code-bg: #f6f8fa;
  --shell-gradient: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  --header-bg: rgba(255, 255, 255, 0.85);
  --header-border: var(--border);
  --panel-bg: var(--bg-elevated);
  --panel-muted-bg: #f5f7fb;
  --profile-bg: rgba(242, 246, 252, 0.65);
  --focus-ring: rgba(9, 105, 218, 0.28);
  --hero-overlay-start: rgba(2, 24, 48, 0.28);
  --hero-overlay-mid: rgba(22, 68, 26, 0.2);
  --hero-overlay-end: rgba(6, 9, 14, 0.12);
  --selection-bg: rgba(9, 105, 218, 0.2);
  --selection-text: #10223a;
}

html[data-theme-mode="dark"] {
  --bg: #0d1117;
  --bg-muted: #151b23;
  --bg-elevated: #111926;
  --bg-trans: rgba(13, 17, 23, 0.95);
  --text: #e6edf3;
  --text-muted: #9198a1;
  --border: #30363d;
  --border-strong: #4a5360;
  --link: #58a6ff;
  --link-hover: #8ec8ff;
  --code-bg: #161b22;
  --shell-gradient: linear-gradient(180deg, #0d1117 0%, #0b131d 100%);
  --header-bg: rgba(13, 17, 23, 0.86);
  --header-border: #2c3847;
  --panel-bg: #101722;
  --panel-muted-bg: #182131;
  --profile-bg: rgba(19, 27, 39, 0.82);
  --focus-ring: rgba(88, 166, 255, 0.35);
  --hero-overlay-start: rgba(1, 26, 41, 0.42);
  --hero-overlay-mid: rgba(31, 56, 14, 0.32);
  --hero-overlay-end: rgba(6, 8, 11, 0.26);
  --selection-bg: rgba(88, 166, 255, 0.25);
  --selection-text: #e6edf3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--shell-gradient);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--link);
}

a:hover {
  color: var(--link-hover);
}

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

.site-header {
  margin: 0 auto;
  padding: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: var(--line-thin) solid var(--header-border);
  background: var(--header-bg);
  backdrop-filter: blur(5px);
}

.theme-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.theme-scheme-menu {
  position: relative;
}

.site-header-brand {
  display: flex;
  align-items: baseline;
  gap: var(--space-4);
  min-width: 0;
}

.site-title {
  font-family: var(--font-ui);
  font-size: clamp(0.95rem, 0.65rem + 1.25vw, 2rem);
  color: var(--text);
  text-decoration: none;
  text-transform: uppercase;
  font-weight: 400;
}

.site-nav-link {
  font-family: var(--font-ui);
  color: var(--text-muted);
  text-decoration: none;
  text-transform: uppercase;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}

.site-nav-link:hover {
  color: var(--text);
  text-decoration: underline;
}

.theme-select-wrap {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  display: none;
  z-index: 40;
}

.theme-select-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.theme-select {
  background: var(--panel-muted-bg);
  color: var(--text);
  border: 0;
  border-radius: var(--radius-xs);
  height: 2.2rem;
  min-width: 7rem;
  padding: 0 0.45rem;
  font-size: 0.8rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.theme-controls[data-scheme-open="true"] .theme-select-wrap {
  display: inline-flex;
}

.theme-icon-button {
  background: var(--panel-muted-bg);
  color: var(--text);
  border: 0;
  border-radius: var(--radius-xs);
  width: 2.2rem;
  height: 2.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.theme-select:focus-visible,
.theme-icon-button:focus-visible,
.theme-button:focus-visible,
.back-to-top:focus-visible,
.post-toc-link:focus-visible,
.post-list-link:focus-visible,
.site-footer-links a:focus-visible,
.site-nav-link:focus-visible {
  outline: var(--line-thin) solid transparent;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.layout {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-4);
  display: grid;
  grid-template-columns: minmax(200px, 250px) minmax(0, 1fr);
  grid-template-areas:
    "intro posts"
    "reader reader";
  gap: var(--space-8);
  min-width: 0;
}

.layout>* {
  min-width: 0;
}

.intro {
  grid-area: intro;
}

.posts-section {
  grid-area: posts;
}

.reader-section {
  grid-area: reader;
}

aside.profile-card {
  border: 0;
  /* border-radius: var(--radius-sm); */
  padding: var(--space-4);
  background: var(--profile-bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

img.profile-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  opacity: 0.9;
  border: 0;
  border-radius: 57% 32% 52% 18% / 28% 49% 31% 42%;
  filter: brightness(0.7) saturate(0.4);
  transition: all 0.3s ease-out;
}

html[data-theme-mode="dark"] img.profile-image {
  filter: brightness(0.7) saturate(0.4);
}

html[data-theme-mode="light"] img.profile-image {
  filter: brightness(1.3) saturate(0.6);
}

.profile-name {
  font-family: var(--font-tamzen);
  margin: 0.8rem 0 0.3rem;
  font-size: 1.1rem;
  text-transform: capitalize;
}

.profile-bio {
  font-family: var(--font-gohu);
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;

}

.site-footer-links {
  max-width: var(--max-width);
  margin: 2.2rem auto 1rem;
  padding: 0 var(--space-4);
  display: flex;
  justify-content: center;
  gap: 0.85rem;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-transform: lowercase;
  opacity: 0.75;
}

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

.site-footer-links a:hover {
  color: var(--text);
  text-decoration: underline;
}

.posts-section h2,
.reader-section h2 {
  margin: 0 0 var(--space-3);
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  gap: var(--space-4);
  display: flex;
  flex-direction: column;
}

.post-list-item {
  border-top: 0;
  border-bottom: var(--line-thin) solid var(--border);
}

.post-list-link {
  display: block;
  padding: var(--space-4);
  padding-bottom: 0;
  color: inherit;
  text-decoration: none;
  background: transparent;
}

.post-list-link[aria-current="true"] {
  background: transparent;
  border-bottom-color: var(--border-strong);
}

.post-title {
  font-family: var(--font-title);
  margin: 0;
  font-size: 1.7rem;
  text-transform: lowercase;
  font-weight: 900;
  line-height: 1;
}

.post-meta {
  color: var(--text-very-muted);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.meta-icon {
  text-transform: lowercase;
}

.meta-label {
  font-family: var(--font-title);
}

.post-summary {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
}

.post-navigation {
  margin-top: 1.4rem;
  padding-top: var(--space-4);
  border-top: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  justify-content: space-between;
}

.related-posts {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 0;
}

.related-posts h2 {
  margin: 0 0 0.65rem;
  font-size: 1rem;
}

.related-posts ul {
  margin: 0;
  padding-left: 1.2rem;
}

.related-posts li {
  margin: 0.2rem 0;
  font-size: 0.9rem;
  list-style-type: disclosure-closed;
}

.post-nav-link {
  display: inline-flex;
  align-items: center;
  color: var(--link);
  text-decoration: none;
  font-size: 0.8rem;
}

.post-nav-link:hover {
  text-decoration: underline;
}

.post-nav-next {
  margin-left: auto;
}

.post-nav-icon-end {
  margin-left: 0.2rem;
  margin-right: 0;
}

.post-article {
  border-radius: var(--radius-sm);
  overflow: visible;
  background: var(--panel-bg);
  border: 0;
}

.post-content {
  padding: var(--space-4) 2rem;
}

.post-body-layout.has-sidebar {
  display: grid;
  grid-template-columns: minmax(180px, 230px) minmax(0, 1fr);
  gap: 0.9rem;
  align-items: start;
  overflow: visible;
}

.post-toc {
  position: sticky;
  top: 0.9rem;
  align-self: start;
  max-height: calc(100vh - 1.8rem);
  overflow: auto;
  border: 0;
  border-radius: var(--radius-xs);
  background: var(--panel-muted-bg);
  padding: 0.7rem;
}

.post-toc-title {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
}

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

.post-toc-item {
  margin: 0;
}

.post-toc-link {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--link);
  cursor: pointer;
  padding: 0.2rem 0;
  font-size: 0.82rem;
}

.post-toc-level-3 .post-toc-link {
  padding-left: 0.65rem;
}

.post-toc-level-4 .post-toc-link {
  padding-left: 1.1rem;
}

.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  scroll-margin-top: 1rem;
}

.post-title code {
  background-color: #ffffff33;
  border-radius: 0.2rem;
  border: 1px solid #ddd;
  font-size: 0.7em;
  padding: 0.1rem 0.2rem 0.2rem;
  margin: 0rem 0.3rem 0rem 0rem;
  font-family: 'DepartureMono';
  line-height: 1.3;
  background-size: 280%;
  display: inline-flex;
}

h1.post-title-main {
  padding: 2rem;
  padding-bottom: 0;
  line-height: 0.9;
  font-size: 3.1rem;
}

h1.post-title-main code {
  background: #00000033;
  line-height: 1;
  padding: 0.4rem 0.5rem 0.7rem 0.5rem;
  margin: 0 0.7rem 0.3rem 0rem;
  font-family: 'DepartureMono';
  font-size: 1em;
  display: inline-flex;
  opacity: 1;
  border-radius: 3px;
  text-shadow: 0px 0px 10px #ccccee;
}


h1.post-title-main code {
  background: #e02222;
  line-height: 1;
  padding: 0rem 0.5rem 0.6rem 0.5rem;
  margin: 0px 0.7rem 0.3rem 0rem;
  font-family: 'DepartureMono';
  font-size: 1em;
  display: inline-flex;
  opacity: 1;
  border-radius: 3px;
  text-shadow: -18px -18px 0.5rem #ccccee;
  mix-blend-mode: hard-light;
  border-radius: 3.6rem 5rem 0rem 0.9rem;
}

.markdown-body h1.post-title-main {
  margin: 0;
  margin-bottom: 1rem;
  font-size: 2.2rem;
}

.post-hero {
  position: relative;
  width: 100%;
  min-height: 280px;
  background: var(--panel-muted-bg);
}

.post-hero-image {
  width: 100%;
  height: 100%;
  min-height: 280px;
  max-height: 420px;
  object-fit: cover;
  display: block;
  /* filter: blur(5px); */
}

.post-hero-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  padding: 1rem;
  background: linear-gradient(to top, var(--hero-overlay-start), var(--hero-overlay-mid), var(--hero-overlay-end));
  filter: blur(0.5px);
  text-shadow: #066933cc 0px 0px 2px, rgba(0, 0, 0, 0.8) 0px 1px 1px;
}

.post-hero-title {
  margin: 0;
  font-family: var(--font-hero);
  font-weight: 900;
  color: #fffef7;
  font-size: clamp(2rem, 4vw, 4.2rem);
  line-height: 1.2;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  line-height: 1.25;
  margin-top: 1.4em;
  margin-bottom: 0.5em;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote {
  margin: 0.8em 0;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.4rem;
}

article .markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

.embed {
  margin: var(--space-4) 0;
  border: 0;
  border-radius: var(--radius-xs);
  overflow: hidden;
  background: var(--panel-muted-bg);
}

.embed iframe {
  width: 100%;
  border: 0;
  display: block;
}

.embed-youtube iframe {
  aspect-ratio: 16 / 9;
}

.embed-twitter iframe {
  min-height: 540px;
}

.embed-codesandbox iframe {
  min-height: 480px;
}

.markdown-body pre,
.markdown-body code {
  font-family: var(--font-code);
}

.markdown-body code {
  background: var(--code-bg);
  border: 0;
  border-radius: var(--radius-xs);
  padding: 0.12rem 0.35rem;
  font-size: 0.92em;
}

.markdown-body pre {
  position: relative;
  background: var(--code-bg);
  border: 0;
  border-radius: var(--radius-xs);
  padding: 0.9rem;
  overflow-x: auto;
  line-height: 1.45;
}

.markdown-body pre code {
  border: 0;
  background: transparent;
  padding: 0;
}

.code-copy-button {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  width: 1.8rem;
  height: 1.8rem;
  border: 0;
  border-radius: var(--radius-xs);
  background: var(--panel-muted-bg);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.code-copy-button:hover {
  color: var(--text);
}

.code-copy-button[data-copied="true"] {
  color: var(--link);
}

.markdown-body blockquote {
  margin-left: 0;
  padding-left: 1rem;
  border-left: var(--line-thick) solid var(--border-strong);
  color: var(--text-muted);
}

.token.keyword {
  color: #cf222e;
}

.token.string {
  color: #0a7f2e;
}

.token.number {
  color: #8250df;
}

.token.comment {
  color: #6e7781;
}

.token.tag {
  color: #116329;
}

.token.attr {
  color: #953800;
}

.token.var {
  color: #1a7f37;
}

html[data-theme-mode="dark"] .token.keyword {
  color: #ff7b72;
}

html[data-theme-mode="dark"] .token.string {
  color: #a5d6ff;
}

html[data-theme-mode="dark"] .token.number {
  color: #d2a8ff;
}

html[data-theme-mode="dark"] .token.comment {
  color: #8b949e;
}

html[data-theme-mode="dark"] .token.tag {
  color: #7ee787;
}

html[data-theme-mode="dark"] .token.attr {
  color: #ffa657;
}

html[data-theme-mode="dark"] .token.var {
  color: #79c0ff;
}

.theme-button {
  background: var(--panel-muted-bg);
  color: var(--text);
  border: 0;
  border-radius: var(--radius-xs);
  width: 2.2rem;
  height: 2.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.back-to-top {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  background: var(--panel-muted-bg);
  color: var(--text);
  border: 0;
  border-radius: var(--radius-xs);
  padding: 0.38rem 0.7rem;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.back-to-top:not([hidden]) {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

@media (max-width: 640px) {

  .site-header {
    display: inline-flex;
    padding: 0.5rem 1rem;
    width: 100vw;
    background: var(--bg-elevated);
    position: relative;
    z-index: 2;
  }

  .theme-controls {
    gap: 0.35rem;
  }

  .site-header-brand {
    gap: 0.5rem;
  }

  .site-nav-link {
    font-size: 0.78rem;
  }

  .theme-select-wrap {
    top: calc(100% + 0.2rem);
    right: -0.2rem;
  }

  .theme-select {
    min-width: 5.1rem;
    width: 5.1rem;
    font-size: 0.72rem;
    height: 2rem;
  }

  main.layout {
    padding: 0.5rem;
    max-width: 100%;
    overflow: visible;
    grid-template-columns: 1fr;
    grid-template-areas:
      "intro"
      "posts"
      "reader";
    gap: 0.5rem;
    background: var(--shell-gradient)
  }


  aside .profile-name {
    font-size: 0.95rem;
    line-height: 1;
    margin: 0;
    position: relative;
    z-index: 1;
  }

  .profile-bio {
    display: none;
  }

  aside img.profile-image {
    height: 100px;
    opacity: 0.0;
    /* hide image on mobile because safari */
    overflow: visible;
    z-index: 1;
    position: relative;
    padding-bottom: 1rem;
  }

  aside.profile-card {
    padding: 0.7rem;
    background-image: url(/images/kkar.png);
    background-position: center;
    background-size: cover;
    filter: brightness(1.2) opacity(0.7);
    margin-top: -2rem;
  }

  .post-article {
    max-width: 100%;
    overflow: hidden;
    border: none;
  }

  .post-body-layout.has-sidebar {
    display: block;
  }

  .post-toc {
    position: static;
    margin: 0.7rem;
  }

  .post-hero {
    min-height: 180px;
    max-height: 240px;
  }

  .post-hero-image {
    min-height: 180px;
    max-height: 240px;
    width: 100%;
  }

  .post-hero-overlay {
    padding: 0.75rem;
  }

  .post-hero-title {
    font-size: clamp(1.4rem, 6vw, 2rem);
    line-height: 1.1;
  }

  .post-content {
    padding: 0.75rem;
    max-width: 100%;
    overflow-x: hidden;
  }

  h1.post-title-main {
    font-size: 2rem;
    word-break: break-word;
    padding: 0 0.5rem;
    margin-top: 0;
    padding-top: 0;
  }

  .post-meta {
    display: none;
  }

  .post-navigation {
    flex-direction: column;
    gap: 0.6rem;
  }

  .post-nav-next {
    margin-left: 0;
    align-self: flex-end;
  }

  .post-list {
    border: 0;
    position: relative;
    z-index: 1;
    background: var(--bg-trans);
  }

  .markdown-body pre {
    padding: 0.65rem;
    font-size: 0.82em;
    max-width: 100%;
  }

  .markdown-body code {
    font-size: 0.84em;
    word-break: break-word;
  }

  .post-title {
    font-size: 1.1rem;
  }

  .post-list-link {
    padding: 0.7rem 0.75rem;
  }

  .post-summary {
    font-size: 0.9rem;
  }

  .site-footer-links {
    margin-top: 1.4rem;
    gap: 0.6rem;
    font-size: 0.66rem;
    padding: 0 var(--space-2);
  }

  .back-to-top {
    right: 0.65rem;
    bottom: 0.65rem;
    padding: 0.35rem 0.6rem;
  }

  /* aside overflow visible adjustments for mobile */
  section.intro,
  aside,
  aside.img {
    overflow: visible;
  }
}