:root {
  color-scheme: light;
  --bg: #f7f4ec;
  --fg: #2c2b28;
  --muted: #6a675c;
  --link: #036a96;
  --accent: #5b4a8a;
  --code: #ebe6dc;
  --pre: #f0ebe2;
  --scrollbar: #c8c2b4;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #282a36;
  --fg: #f8f8f2;
  --muted: #a8adc4;
  --link: #8be9fd;
  --accent: #bd93f9;
  --code: #44475a;
  --pre: #21222c;
  --scrollbar: #44475a;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  overflow: hidden;
  color: var(--fg);
  background: var(--bg);
  font: 400 1.05rem/1.75 "Source Sans 3", "Segoe UI", sans-serif;
  letter-spacing: 0.01em;
}

.shell {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 2rem 1.75rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

@media (min-width: 75rem) {
  .shell { width: 90%; }
}

.page {
  display: flex;
  flex-flow: row nowrap;
  justify-content: flex-start;
  align-items: stretch;
  gap: 3rem;
  flex: 1 1 auto;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  flex: 0 0 15rem;
  width: 15rem;
  max-width: 15rem;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.sidebar::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.sidebar-backdrop { display: none; }

.portrait {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100% - 19rem);
  align-self: flex-start;
  object-fit: contain;
  object-position: center top;
}

.sidebar .name,
.sidebar .description,
.sidebar .role,
.sidebar .where,
.sidelinks {
  flex-shrink: 0;
}

.sidebar .name {
  margin: 0.9rem 0 0.15rem;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar .description,
.sidebar .role,
.sidebar .where {
  margin: 0.15rem 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.sidelinks {
  list-style: none;
  padding: 0;
  margin: 0.9rem 0 0;
}

.sidelinks li { margin: 0.2rem 0; }

nav {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 2rem;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}

main {
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
  min-width: 0;
  min-height: 0;
  font-size: 1.08rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 2.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

/* Narrow, but not a tall portrait frame: sidebar stays an off-canvas drawer. */
@media (max-width: 700px) and (min-aspect-ratio: 3/4) {
  body { overflow-x: hidden; overflow-y: auto; }

  .shell {
    height: auto;
    display: block;
    padding-bottom: 4rem;
  }

  .page { display: block; }

  main { overflow: visible; padding-bottom: 0; }

  .sidebar {
    position: fixed;
    z-index: 30;
    top: 0;
    left: 0;
    bottom: 0;
    flex: none;
    width: min(18rem, 86vw);
    max-width: 86vw;
    height: auto;
    margin: 0;
    padding: 1.25rem 1.25rem 2rem;
    background: var(--bg);
    overflow: auto;
    transform: translateX(-110%);
    transition: transform 0.22s ease;
  }

  .sidebar.is-open { transform: translateX(0); }

  .sidebar-backdrop.is-open {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.45);
  }
}

/* Much taller than wide: read the page, then the sidebar follows. */
@media (max-aspect-ratio: 3/4) {
  body { overflow-x: hidden; overflow-y: auto; }

  .shell {
    height: auto;
    display: block;
    padding-bottom: 4rem;
  }

  .page {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    min-height: 0;
  }

  main {
    order: 1;
    overflow: visible;
    padding-bottom: 0;
  }

  .sidebar,
  .sidebar.is-open {
    order: 2;
    position: static;
    z-index: auto;
    top: auto;
    left: auto;
    bottom: auto;
    flex: none;
    align-self: start;
    width: min(15rem, 100%);
    max-width: 15rem;
    height: auto;
    max-height: none;
    margin: 2.75rem 0 0;
    padding: 1.75rem 0 0;
    background: transparent;
    border-top: 1px solid var(--code);
    overflow: visible;
    transform: none;
  }

  .sidebar-backdrop,
  .sidebar-backdrop.is-open { display: none; }
}

nav a { color: var(--muted); text-decoration: none; }
nav a.active { color: var(--fg); }
nav a:hover { color: var(--link); }

.theme-toggle {
  margin-left: auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.theme-toggle:hover { color: var(--link); }

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

h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.3;
}

h1 { font-size: 1.5em; margin: 0 0 0.75rem; }
h2 { font-size: 1.2em; margin: 2rem 0 0.5rem; }
h3 { font-size: 1.08em; margin: 1.5rem 0 0.4rem; }

p { margin: 0.8rem 0; }

.meta, time { color: var(--muted); }
.meta { margin-top: 0; }

ul.posts {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0 0;
}

ul.posts li { margin: 0 0 2.75rem; }
ul.posts time { display: block; font-size: 0.8em; }
ul.posts .item-title {
  display: block;
  font-size: 1.2em;
  line-height: 1.3;
  margin: 0.15rem 0 0.1rem;
}
ul.posts .desc { display: block; color: var(--muted); }
ul.posts .tags { display: block; color: var(--accent); font-size: 0.9em; }
.meta .tags { color: var(--accent); }

blockquote {
  margin: 1.25rem 0;
  padding-left: 1rem;
  border-left: 2px solid var(--accent);
}

code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.88em;
  background: var(--code);
  padding: 0.1em 0.3em;
}

pre {
  max-width: 100%;
  overflow-x: auto;
  padding: 0.9rem 1rem;
  background: var(--pre);
}

pre code {
  background: none;
  padding: 0;
}

img, video { max-width: 100%; height: auto; }

article:has(.demo) {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.demo {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  min-height: 24rem;
  border: 0;
}

hr {
  border: 0;
  border-top: 1px solid var(--code);
  margin: 2rem 0;
}

::selection {
  background: var(--code);
  color: var(--fg);
}
