/* Palette: pine green as the primary accent, a warm resin amber held in
   reserve for the growth-ring signature and sparing emphasis. Light mode is
   a cool sage paper, not the cream-and-terracotta combination that's become
   the generic "AI-generated site" default — chosen because this is a
   garden of conifers ("evergreen"), not a coffee-shop menu. Dark mode is a
   green-black forest floor rather than a neutral near-black. */
:root {
  --bg: #f2f4ee;
  --fg: #1e2a20;
  --fg-muted: #5c6b5a;
  --border: #d8ddd0;
  --accent: #3f6b4a;
  --accent-warm: #a5672c;
  --accent-bg: #e3e9db;
  --code-bg: #e6e9df;
}

/* System dark preference, unless the toggle button has set an explicit
   light override (data-theme="light") saved in localStorage. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10160f;
    --fg: #e2e6da;
    --fg-muted: #8a9686;
    --border: #263124;
    --accent: #7fb894;
    --accent-warm: #d9a463;
    --accent-bg: #1a2318;
    --code-bg: #182016;
  }
}

/* Explicit dark override from the toggle button, so it wins even when the
   system preference is light. Same values as the media query above. */
:root[data-theme="dark"] {
  --bg: #10160f;
  --fg: #e2e6da;
  --fg-muted: #8a9686;
  --border: #263124;
  --accent: #7fb894;
  --accent-warm: #d9a463;
  --accent-bg: #1a2318;
  --code-bg: #182016;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: Charter, Georgia, "Hiragino Mincho ProN", "Yu Mincho", serif;
  line-height: 1.7;
}

header.site-header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-family: -apple-system, "Hiragino Sans", sans-serif;
}

header.site-header a.wordmark {
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.wordmark-mark {
  color: var(--accent);
  flex-shrink: 0;
}

header.site-header nav {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
}

header.site-header nav a {
  font-weight: 400;
  color: var(--fg-muted);
  text-decoration: none;
}

#search-box {
  margin-left: auto;
  position: relative;
  width: min(20rem, 100%);
}

#search-input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.9rem;
}

#search-results {
  position: absolute;
  top: calc(100% + 0.3rem);
  right: 0;
  width: 100%;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.15);
  display: none;
  z-index: 10;
}

#search-results.open {
  display: block;
}

#search-results a {
  display: block;
  padding: 0.5rem 0.7rem;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

#search-results a:last-child {
  border-bottom: none;
}

#search-results a:hover,
#search-results a.active {
  background: var(--accent-bg);
}

#theme-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: none;
  color: var(--fg-muted);
  cursor: pointer;
}

#theme-toggle:hover {
  color: var(--fg);
  border-color: var(--fg-muted);
}

/* The icon shown is the theme a click switches TO, not the current one:
   moon (switch to dark) while light, sun (switch to dark's opposite,
   i.e. light) once dark. Layered the same way as the color tokens above —
   system preference by default, an explicit data-theme always wins. */
#theme-toggle .icon-sun {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle .icon-moon {
    display: none;
  }
  :root:not([data-theme="light"]) #theme-toggle .icon-sun {
    display: block;
  }
}

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

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

main {
  max-width: 42rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

h1, h2, h3 {
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.01em;
}

article > h1:first-child {
  margin-top: 0;
  font-size: 1.9rem;
}

.meta {
  font-family: -apple-system, "Hiragino Sans", sans-serif;
  font-size: 0.8rem;
  color: var(--fg-muted);
  margin-top: -0.5rem;
  margin-bottom: 1.5rem;
}

a.wikilink {
  color: var(--accent);
  text-decoration-color: var(--border);
  text-underline-offset: 0.15em;
}

a.wikilink--broken {
  border-bottom: 1px dashed var(--fg-muted);
  text-decoration: none;
  color: var(--fg-muted);
}

a.tag-inline {
  color: var(--accent);
  text-decoration: none;
}

.tag-pill {
  display: inline-block;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-size: 0.78rem;
  text-decoration: none;
}

pre {
  background: var(--code-bg);
  padding: 0.8rem 1rem;
  border-radius: 0.4rem;
  overflow-x: auto;
}

code {
  background: var(--code-bg);
  padding: 0.1rem 0.3rem;
  border-radius: 0.25rem;
  font-size: 0.9em;
}

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

.backlinks {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-family: -apple-system, "Hiragino Sans", sans-serif;
}

.backlinks h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
}

.backlinks ul {
  list-style: none;
  padding: 0;
}

.backlinks li {
  margin: 0.3rem 0;
}

ul.note-list {
  list-style: none;
  padding: 0;
}

/* Grid, not flex: a title column that wraps on its own plus a date column
   pinned to the same x-position on every row, so "updated …" lines up
   regardless of how long each title is. */
ul.note-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 0 1rem;
  margin: 0.5rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

ul.note-list a {
  color: var(--fg);
  font-weight: 600;
  text-decoration: none;
}

ul.note-list .meta {
  margin: 0;
  white-space: nowrap;
}

.tag-cloud a {
  font-size: 1rem;
}

.tag-cloud .count {
  color: var(--fg-muted);
  font-size: 0.75rem;
}

.warning-banner {
  background: var(--accent-warm);
  color: #fff8ee;
  padding: 0.6rem 1.5rem;
  font-family: -apple-system, "Hiragino Sans", sans-serif;
  font-size: 0.85rem;
}
