:root,
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --text: #24292e;
  --body: #3d444b;
  --muted: #6a737d;
  --rule: #e6e8eb;
  --underline: #d8dbdf;
  --link-line: #b9c0c8;
  --tile: #f0f1f3;
  --accent: #a33c2a;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161618;
  --text: #ebebec;
  --body: #c6c6c8;
  --muted: #8b8b90;
  --rule: #2c2c30;
  --underline: #3a3a3f;
  --link-line: #7d818b;
  --tile: #232326;
  --accent: #e98a72;
}

/* no explicit choice saved: follow the OS */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #161618;
    --text: #ebebec;
    --body: #c6c6c8;
    --muted: #8b8b90;
    --rule: #2c2c30;
    --underline: #3a3a3f;
    --link-line: #7d818b;
    --tile: #232326;
    --accent: #e98a72;
  }
}

/* ---- top bar: section nav, then the theme toggle --------------------- */

.topbar {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.sitenav {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.85rem;
}

.sitenav a {
  color: var(--muted);
  border-bottom: 1px solid transparent;
}

.sitenav a:hover {
  color: var(--text);
  border-bottom-color: var(--rule);
}

.theme-toggle {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bg);
  flex-shrink: 0;
}

.theme-toggle button {
  appearance: none;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  line-height: 1;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
}

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

.theme-toggle button[aria-pressed="true"] {
  background: var(--tile);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 5rem 1.5rem 8rem;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 42rem;
  margin: 0 auto;
}

.me {
  width: 116px;
  height: 116px;
  object-fit: cover;
  border-radius: 3px;
  display: block;
  margin-bottom: 1.75rem;
  background: var(--tile);
}

h1 {
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.4rem;
}

.links {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
}

.links a,
.links span {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.links a:hover {
  color: var(--text);
  border-bottom-color: var(--rule);
}

p {
  margin: 0 0 1.1rem;
}

a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--link-line);
}

a:hover {
  border-bottom-color: var(--text);
}

/* ---- collapsible sections ------------------------------------------- */

.section {
  border-top: 1px solid var(--rule);
}

.section:first-of-type {
  margin-top: 2.5rem;
}

.section:last-of-type {
  border-bottom: 1px solid var(--rule);
}

.section > h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  padding: 1.15rem 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.section > h2:hover .count,
.section > h2:hover::after {
  opacity: 0.95;
}

.section > h2::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  opacity: 0.4;
  transition: transform 0.25s ease;
}

.section.open > h2::after {
  transform: rotate(-135deg) translate(-2px, -2px);
}

.section > h2 .count {
  font-weight: 400;
  font-size: 0.82rem;
  color: var(--muted);
  margin-left: auto;
  opacity: 0.75;
}

.section > .fold {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease;
}

.section.open > .fold {
  grid-template-rows: 1fr;
}

.section > .fold > div {
  overflow: hidden;
}

/* one-line summary of what's inside, shown only while collapsed */
.section > .preview {
  color: var(--muted);
  font-size: 0.88rem;
  margin: -0.5rem 0 0;
  padding: 0 2rem 1.1rem 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition:
    opacity 0.2s ease,
    max-height 0.3s ease,
    padding 0.3s ease;
  max-height: 2rem;
  opacity: 1;
  cursor: pointer;
}

.section.open > .preview {
  max-height: 0;
  padding-bottom: 0;
  opacity: 0;
}

.section > .fold > div {
  padding-bottom: 1.5rem;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 1.25rem;
}

/* ---- entries --------------------------------------------------------- */

.entry {
  -webkit-tap-highlight-color: transparent;
  display: grid;
  grid-template-columns: 104px 1fr;
  gap: 1.25rem;
  padding: 1.1rem 0;
  border-top: 1px solid var(--rule);
  cursor: pointer;
}

.entry:last-child {
  border-bottom: 1px solid var(--rule);
}

.entry.link {
  grid-template-columns: 1fr;
}

.entry.link:hover h3 {
  text-decoration: underline;
  text-decoration-color: var(--underline);
  text-underline-offset: 3px;
}

.thumb {
  width: 104px;
  height: 72px;
  border-radius: 3px;
  object-fit: cover;
  background: var(--tile);
  display: block;
}

/* logos and wordmarks: fit inside the tile rather than filling it */
.thumb.contain {
  object-fit: contain;
  padding: 10px;
}

.head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.entry h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.15rem;
  line-height: 1.4;
  flex: 1;
}

.year {
  color: var(--muted);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.meta {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0;
}

.venue {
  font-style: italic;
}

/* small pills next to an entry title: placements, star counts */
.badge,
.stars {
  align-items: center;
  gap: 0.25rem;
  font-size: 0.78rem;
  line-height: 1;
  color: var(--muted);
  background: var(--tile);
  border-radius: 999px;
  padding: 0.25rem 0.5rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-flex;
}

/* the star count stays hidden until the API answers */
.stars {
  display: none;
}

.stars[data-count] {
  display: inline-flex;
}

.badge svg,
.stars svg {
  width: 11px;
  height: 11px;
  fill: currentColor;
}

/* my own name in an author list */
.meta strong {
  color: var(--accent);
  font-weight: 600;
}

/* competition placements */
.badge.place {
  color: var(--accent);
}

.body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.28s ease;
}

.entry.open .body {
  grid-template-rows: 1fr;
}

.body > div {
  overflow: hidden;
}

.body p {
  font-size: 0.92rem;
  color: var(--body);
  margin: 0.65rem 0 0;
}

.body .actions {
  margin-top: 0.55rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.88rem;
}

/* categories revealed under the Notes entry */
.cats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.7rem 0 0;
  font-size: 0.88rem;
}

.unwritten {
  color: var(--muted);
  border-bottom: 1px dotted var(--underline);
  cursor: default;
}

/* ---- post pages ------------------------------------------------------ */

.post-nav {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0 0 2.5rem;
}

.post-nav a {
  color: var(--muted);
  border-bottom: none;
}

.post-nav a:hover {
  color: var(--text);
}

article h1 {
  margin-bottom: 0.25rem;
}

article .date {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 2.5rem;
}

article h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 2.5rem 0 0.75rem;
}

article h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 2rem 0 0.5rem;
}

article img {
  max-width: 100%;
  height: auto;
  border-radius: 3px;
  margin: 1.5rem 0;
}

article blockquote {
  margin: 1.5rem 0;
  padding-left: 1rem;
  border-left: 2px solid var(--rule);
  color: var(--body);
}

article code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--tile);
  border-radius: 3px;
  padding: 0.1rem 0.25rem;
}

article pre {
  background: var(--tile);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
}

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

article table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5rem 0;
  font-size: 0.94rem;
}

article th,
article td {
  border-bottom: 1px solid var(--rule);
  padding: 0.5rem 0.75rem 0.5rem 0;
  text-align: left;
}

article hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2.5rem 0;
}

@media (max-width: 620px) {
  body {
    padding: 1.25rem 1.15rem 4rem;
  }

  .topbar {
    position: static;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    margin-bottom: 1.75rem;
  }

  .sitenav {
    gap: 0.9rem;
  }

  .me {
    width: 84px;
    height: 84px;
    margin-bottom: 1.25rem;
  }

  h1 {
    font-size: 1.45rem;
  }

  .links {
    gap: 0.75rem 1rem;
    margin-bottom: 1.5rem;
  }

  .entry {
    grid-template-columns: 64px 1fr;
    gap: 0.9rem;
  }

  .thumb {
    width: 64px;
    height: 46px;
  }

  .head {
    flex-wrap: wrap;
    gap: 0 0.6rem;
  }

  .entry h3 {
    flex: 1 1 100%;
    font-size: 0.97rem;
  }

  .section > .preview {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    max-height: 3.2rem;
  }

  article table {
    display: block;
    overflow-x: auto;
  }

  article pre {
    padding: 0.75rem;
    font-size: 0.85rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .body,
  .section > .fold,
  .section > h2::before {
    transition: none;
  }
}
