/* ── Color tokens (light / dark) ─────────────────────────── */
:root {
  --bg: #fff;
  --bg-grid: #e8e4e0;
  --color-teal: #024454;
  --color-red: #d84d50;
  --color-beige: #e4d0b9;
  --color-tan: #c19280;
  --color-blue: #5c82a7;
  --color-sage: #6f8a81;
  --color-peach: #fdc296;
  --color-gray: #606060;
  --color-orange: #ffb55c;
  --color-darkgray: #231f20;
  --color-cream: #fcf8f5;
  --card-bg: rgba(255, 255, 255, 0.5);

  --font-serif: "ER", "ER-fallback", Georgia, serif;
  --cover-w: 30%;
  --title-size: 1.8rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1816;
    --bg-grid: #252320;
    --color-teal: #4a9bae;
    --color-red: #e87b7d;
    --color-beige: #8a7566;
    --color-tan: #9a7768;
    --color-blue: #7a9dbd;
    --color-sage: #8ba89d;
    --color-peach: #c9956d;
    --color-gray: #a0a0a0;
    --color-orange: #d9a066;
    --color-darkgray: #e8e4e0;
    --color-cream: #2a2624;
    --card-bg: rgba(26, 24, 22, 0.92);
  }
}

@media screen and (max-width: 600px) {
  :root {
    --cover-w: 100%;
    --title-size: 1.4rem;
  }
}

/* ── Fonts ───────────────────────────────────────────────── */
@font-face {
  font-family: "ER";
  src: url("/css/er-bi.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "ER-fallback";
  src: local("Georgia");
  size-adjust: 98%;
  ascent-override: 90%;
  descent-override: 20%;
}

/* ── Base ────────────────────────────────────────────────── */
html {
  width: 100%;
  padding: 0;
}

body {
  margin: 0;
  overflow-x: hidden;
  text-align: center;
  color: var(--color-darkgray);
  background-color: var(--bg);
  font:
    400 100% Avenir,
    Helvetica,
    "Arial Unicode MS",
    Arial,
    sans-serif;
  text-rendering: optimizeLegibility;
  text-wrap: pretty;
  font-size: 120%;
}

h1,
h2,
h3,
h4,
h5 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-synthesis: none;
}

/* ── Links ───────────────────────────────────────────────── */
a:link,
a:visited {
  text-decoration: none;
  color: var(--color-blue);
}
a:hover {
  background: transparent;
  text-decoration: underline;
}
a:active {
  font-weight: bold;
  color: #99ff00;
  background: transparent;
}

/* ══════════════════════════════════════════════════════════
   ARTICLE / POST layout
   ══════════════════════════════════════════════════════════ */
body.article {
  width: 100%;
  background-color: var(--bg);
}

body.article #main {
  margin: auto;
  max-width: 800px;
  background-color: var(--color-cream);
  text-align: left;
}

body.article.has-toc #main {
  max-width: 1100px;
}

#content,
footer {
  text-align: left;
  width: 100%;
  box-sizing: border-box;
  padding: 1em;
  max-width: 800px;
}

#content div:not(#header):not(.post-meta) {
  padding: 1em;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
}

#content img {
  max-width: 100%;
  height: auto;
  display: block;
}

#content table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}
#content td,
#content th {
  padding: 0.5em;
  vertical-align: top;
  overflow: hidden;
  border: none;
  font-weight: normal;
  text-align: left;
}

/* ── Syntax highlighting ─────────────────────────────────── */
.highlight {
  background: var(--bg);
  padding: 0.5em 1em;
  position: relative;
}
.highlight .copy-btn {
  position: absolute;
  top: 0.4em;
  right: 0.4em;
  background: var(--color-cream);
  border: 1px solid var(--color-beige);
  color: var(--color-gray);
  font-size: 0.75em;
  padding: 0.2em 0.5em;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}
.highlight:hover .copy-btn {
  opacity: 1;
}
.highlight .copy-btn:hover {
  background: var(--color-beige);
}
.highlight .c,
.highlight .c1,
.highlight .cm {
  color: var(--color-sage);
  font-style: italic;
}
.highlight .k,
.highlight .kd,
.highlight .kn,
.highlight .kr {
  color: var(--color-teal);
  font-weight: bold;
}
.highlight .s,
.highlight .s1,
.highlight .s2 {
  color: var(--color-orange);
}
.highlight .mi,
.highlight .mf,
.highlight .mh {
  color: var(--color-red);
}
.highlight .nb,
.highlight .nf {
  color: var(--color-blue);
}
.highlight .nx {
  color: var(--color-darkgray);
}

/* ── TOC ─────────────────────────────────────────────────── */
.toc-wrapper {
  position: sticky;
  top: 0;
  float: right;
  width: 250px;
  padding: 1em 1em 2em;
  margin-left: 2em;
  margin-right: calc(-250px - 2em);
  font-size: 70%;
  font-weight: 400;
  max-height: 100vh;
  overflow-y: auto;
  scrollbar-width: none;
}
.toc-wrapper::-webkit-scrollbar {
  display: none;
}
.toc-wrapper > summary {
  margin-top: 0;
  font-size: 120%;
  font-weight: 500;
  margin-bottom: 0.5em;
  font-family: var(--font-serif);
  list-style: none;
  display: block;
  pointer-events: none;
  cursor: default;
}
.toc-wrapper > summary::-webkit-details-marker {
  display: none;
}
.toc-wrapper ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}
.toc-wrapper li {
  margin: 0.5em 0;
  line-height: 1.4;
}
.toc-wrapper li ul li {
  padding-left: 10px;
}

@media screen and (max-width: 1100px) {
  .toc-wrapper {
    position: static;
    float: none;
    width: auto;
    margin: 0 0 1.5em 0;
    padding: 0.75em 1em;
    max-height: none;
    overflow-y: visible;
    border: 1px solid var(--color-beige);
    border-radius: 4px;
  }
  .toc-wrapper > summary {
    pointer-events: auto;
    cursor: pointer;
    margin-bottom: 0;
  }
  .toc-wrapper[open] > summary {
    margin-bottom: 0.5em;
  }
}

/* ── Post meta / header ──────────────────────────────────── */
.post-meta {
  font-size: 85%;
  color: var(--color-gray);
  display: flex;
  gap: 1.5em;
  margin-bottom: 0.5em;
}
.post-meta a {
  color: var(--color-gray);
}
.post-meta a:hover {
  text-decoration: underline;
}

h1.post-title {
  font-size: 2rem;
  font-weight: 500;
  margin: 0.15em 0 0.2em;
  line-height: 1.15;
}

.post-description {
  font-size: 95%;
  color: var(--color-gray);
  margin: 0 0 1em;
}

.post-ext-link {
  display: inline-block;
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--color-teal) !important;
  border: 1px solid var(--color-teal);
  padding: 0.3em 0.8em;
  border-radius: 6px;
  margin-bottom: 1.5em;
}
.post-ext-link:hover {
  background: var(--color-teal);
  color: white !important;
  text-decoration: none !important;
}

.post-media {
  display: flex;
  flex-direction: column;
  gap: 1em;
  margin-top: 1em;
}
.post-media img,
.post-media video {
  width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
}

@media screen and (max-width: 510px) {
  body.article #main {
    padding: 0;
    margin: 0;
  }
  a:not(h1 a):not(h2 a):not(h3 a) {
    word-break: break-all;
  }
}

/* ══════════════════════════════════════════════════════════
HOME layout
   ══════════════════════════════════════════════════════════ */

body.home #main {
  background-color: var(--color-cream);

  display: flex;
  flex-direction: column;
  gap: 3em;
  padding: 1em 2em 4em;
  max-width: 800px;
  margin: 0 auto;
  text-align: left;
}

/* ── Portfolio card ──────────────────────────────────────── */
.wide-item {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 1.5em;
  max-height: 300px;
  background-color: var(--card-bg);
  border-radius: 16px;
  overflow: hidden;
}

.item-cover {
  flex: 0 0 var(--cover-w);
  aspect-ratio: 1/1;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}
.item-cover video.cover-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.item-cover video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 8px;
}

.item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2em;
  overflow: hidden;
  padding: 0.5em;
}

.wide-item h2,
.item-link {
  font-family: var(--font-serif);
  font-weight: 500;
  font-synthesis: none;
}
.wide-item h2 {
  font-size: var(--title-size);
  margin: 0;
  line-height: 1.1;
  word-break: normal;
  overflow-wrap: break-word;
}
.wide-item h2 a {
  text-decoration: none;
}
.wide-item h2 a:hover {
  text-decoration: underline;
}

.item-desc {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  font-size: 88%;
}
.item-desc p {
  margin: 0;
}
.item-desc p + p {
  margin-top: 0.5em;
}
.item-desc a {
  color: var(--color-blue);
}

.item-link {
  font-size: 100%;
  color: var(--color-teal);
  display: block;
  margin-bottom: 0.4em;
  text-decoration: none;
}
.item-link:hover {
  text-decoration: underline;
}

.item-date {
  font-size: 82%;
  color: var(--color-gray);
  display: block;
  margin-top: 0.4em;
}

/* ── Thumbnail strip ─────────────────────────────────────── */
.item-thumbs {
  display: flex;
  flex-wrap: nowrap;
  flex-shrink: 0;
  gap: 4px;
}
.item-thumbs .thumb {
  flex: 1 1 0;
  min-width: 0;
  max-width: 100px;
  aspect-ratio: 1/1;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: 5px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.item-thumbs .thumb:hover {
  opacity: 0.75;
}
.item-thumbs .thumb.active {
  outline: 2px solid var(--color-teal);
  outline-offset: -2px;
}
.item-thumbs .thumb-video {
  flex: 1 1 0;
  min-width: 0;
  aspect-ratio: 1/1;
  max-width: 100px;
  border-radius: 5px;
  overflow: hidden;
  cursor: pointer;
  transition: opacity 0.15s;
}
.item-thumbs .thumb-video:hover {
  opacity: 0.75;
}
.item-thumbs .thumb-video.active {
  outline: 2px solid var(--color-teal);
  outline-offset: -2px;
}
.item-thumbs .thumb-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  max-width: 100px;
}

/* ── Article items (no image) ────────────────────────────── */
.wide-item.article-item {
  min-height: 0;
  padding-top: 0.25em;
}
.wide-item.article-item .item-content {
  flex: 1 1 100%;
}
.wide-item.article-item h2 {
  font-size: calc(var(--title-size) * 0.75);
}

#copyright {
  text-align: center;
  color: var(--color-gray);
  font-size: 85%;
  margin-top: 1em;
}

@media screen and (max-width: 600px) {
  .wide-item {
    flex-direction: column;
    gap: 0.75em;
    max-height: none;
    border-radius: 0.5em;
    padding: 0.5em;
  }
  .item-content {
    display: contents;
  }
  .wide-item h2 {
    order: 1;
  }
  .item-desc {
    order: 2;
  }
  .item-cover {
    order: 3;
    flex: none;
    width: 100%;
    border-radius: 0;
  }
  .item-thumbs {
    order: 4;
  }

  body.home #main {
    padding: 0.1em;
  }
}
