/* mikaelcromsjo.com, design v2: warm paper, serif headings, one colour per facet
   (green = Awakened Warrior, ochre = Political Figure, blue = IT Consultant).
   The previous design is kept at /v/1/. */
:root {
  color-scheme: light dark;
  --paper: #f6f2e9;
  --card: #fcfaf5;
  --ink: #1d1b18;
  --muted: #625c51;
  --line: #dcd4c3;
  --warrior: #2b684c;
  --politics: #9a560a;
  --it: #294b8c;
  --accent: var(--ink);
  --shadow: 0 10px 30px rgba(60, 45, 20, 0.10);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141311;
    --card: #1d1b18;
    --ink: #efe9dd;
    --muted: #a69f91;
    --line: #36322b;
    --warrior: #86c9a6;
    --politics: #e3aa55;
    --it: #96b6ee;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}
/* one accent per facet: on <body> for the subpages, on a section or box on the home page */
.t-warrior { --accent: var(--warrior); }
.t-politics { --accent: var(--politics); }
.t-it { --accent: var(--it); }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.65;
}
/* the three facet colours as a stripe across the top of every page */
body::before {
  content: "";
  display: block;
  height: 5px;
  background: linear-gradient(90deg, var(--warrior) 0 33.33%, var(--politics) 33.33% 66.66%, var(--it) 66.66%);
}
.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2.5rem) 5rem;
}
img { max-width: 100%; }
p { margin: 0 0 1rem; }
a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; text-wrap: balance; }
h1 {
  font-size: clamp(2.6rem, 7vw, 4.75rem);
  line-height: 1.03;
  letter-spacing: -0.02em;
  margin: 0;
}
h1 em { color: var(--muted); font-weight: 400; }
h3 { font-size: 1.2rem; line-height: 1.25; margin: 0 0 0.4rem; }
h3 a { color: inherit; }
h3 a:hover { color: var(--accent); }
.tagline {
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.25rem);
  line-height: 1.45;
  max-width: 46ch;
}

/* --- top navigation --- */
.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 2rem;
  padding: 1.2rem 0;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}
.nav-links { display: flex; flex-wrap: wrap; gap: 0.4rem 1.6rem; }
.nav-links a {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  padding-bottom: 0.2rem;
  border-bottom: 2px solid transparent;
}
.nav-links a:hover { color: var(--ink); }
.nav-links a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* --- home page: name, tagline, the three image boxes --- */
.home-hero {
  display: flex;
  flex-direction: column;
  padding: clamp(2rem, 6vw, 4.5rem) 0 clamp(2rem, 5vw, 4rem);
}
.home-hero h1 { font-size: clamp(2.6rem, 7.4vw, 5.5rem); }
.home-hero .tagline { order: 1; margin: 1.2rem 0 2.5rem; }
.highlights {
  order: 2;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(0.75rem, 2vw, 1.5rem);
}
.highlight {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.2s, border-color 0.2s;
}
.highlight:hover { transform: translateY(-4px); border-color: var(--accent); }
.highlight img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}
.hl-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.1rem 1.25rem 1.2rem;
  border-top: 4px solid var(--accent);
}
.highlight q {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.05rem, 1.7vw, 1.3rem);
  line-height: 1.35;
  quotes: none;
}
.hl-label {
  margin-top: auto;
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

/* --- sections: heading in the left column, content in the right --- */
section {
  display: grid;
  grid-template-columns: minmax(0, 15rem) minmax(0, 1fr);
  gap: 1.25rem 3rem;
  padding: clamp(2rem, 5vw, 3.5rem) 0;
  border-top: 1px solid var(--line);
}
section[id] { scroll-margin-top: 1rem; }
section > h2 {
  position: sticky;
  top: 1.5rem;
  align-self: start;
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
}
section > h2::before {
  content: "";
  display: block;
  width: 2.5rem;
  height: 4px;
  margin-bottom: 1rem;
  background: var(--accent);
}
h2 a { color: inherit; text-decoration: none; }
h2 a:hover { color: var(--accent); }
.section-body > p { max-width: 64ch; }

/* --- link pills --- */
.links { display: flex; flex-wrap: wrap; gap: 0.55rem; margin-top: 1.2rem; }
.section-body > .links:first-child { margin-top: 0; }
.links a {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.42rem 1rem;
  font-size: 0.9rem;
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.links a:hover { border-color: var(--accent); color: var(--accent); }
.links a.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--paper);
  font-weight: 600;
}
.links a.primary:hover { color: var(--paper); opacity: 0.88; }

/* --- home page: the four books photo, a low banner above the footer.
   The photo is taller than its box: the script in index.html slides it while the
   page scrolls, treetops first, books and moss last. Without script: the books. --- */
.books-banner {
  display: block;
  position: relative;
  aspect-ratio: 2.75 / 1;
  margin-bottom: clamp(2rem, 5vw, 3.5rem);
  overflow: hidden;
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.books-banner img {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  max-width: none;
  height: auto;
  will-change: transform;
}

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}
footer a { color: var(--muted); }
.stamp { flex: none; width: 72px; height: auto; }

/* --- subpage header: title and intro left, portrait right --- */
.sub-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 34%);
  grid-template-rows: auto auto 1fr;
  column-gap: clamp(2rem, 5vw, 4rem);
  padding: clamp(2rem, 6vw, 4.5rem) 0 clamp(2.5rem, 6vw, 4.5rem);
}
.sub-hero h1 { grid-column: 1; grid-row: 1; }
.sub-hero .tagline { grid-column: 1; grid-row: 2; margin: 1.1rem 0 1.6rem; }
.sub-hero .lede { grid-column: 1; grid-row: 3; max-width: 62ch; margin: 0; }
.portrait {
  grid-column: 2;
  grid-row: 1 / span 3;
  align-self: start;
  position: relative;
  margin: 0 14px 14px 0;
}
/* a block of the facet colour, offset behind the photo */
.portrait::before {
  content: "";
  position: absolute;
  inset: 14px -14px -14px 14px;
  border-radius: 6px;
  background: var(--accent);
}
.portrait img {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
}

/* --- service cards --- */
.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 2rem 1.75rem;
}
.service-card { border-top: 2px solid var(--accent); padding-top: 0.9rem; }
.service-card p { margin-bottom: 0; font-size: 0.95rem; color: var(--muted); }
.service-card .price {
  display: inline-block;
  margin-top: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.15rem 0.7rem;
  font-size: 0.8rem;
  color: var(--ink);
}

/* --- book cards --- */
.book-grid { display: grid; grid-template-columns: 1fr; }   /* one book per row: cover left, text right */
.book-card {
  display: flex;
  align-items: flex-start;
  gap: clamp(1rem, 3vw, 1.75rem);
  padding: 1.5rem 0;
  border-top: 1px solid var(--line);
}
.book-card:first-child { border-top: 0; padding-top: 0; }
.book-card:last-child { padding-bottom: 0; }
/* every cover gets the same box (7:10, the usual book shape) */
img.book-cover {
  flex: none;
  width: clamp(84px, 16vw, 132px);
  height: auto;
  aspect-ratio: 7 / 10;
  object-fit: cover;
  background: #1b1a24;
  border-radius: 3px;
  box-shadow: var(--shadow);
}
img.book-cover.square { object-fit: contain; }   /* square cover: letterbox, don't crop the title */
.book-card p { max-width: 62ch; font-size: 0.95rem; color: var(--muted); margin-bottom: 0.5rem; }
.book-card .links { margin-top: 0.8rem; }

/* --- book bundle offer --- */
.book-bundle {
  margin-bottom: 2rem;
  padding: 1.1rem 1.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  font-size: 0.98rem;
}
.book-bundle strong {
  display: block;
  margin-bottom: 0.3rem;
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
}
.book-bundle .links { margin-top: 0.8rem; }

/* --- article lists --- */
.item-list .item { padding: 1.1rem 0; border-top: 1px solid var(--line); }
.item-list .item:first-child { border-top: 0; padding-top: 0; }
.item-list .item:last-child { padding-bottom: 0; }
.item-list .item h3 { margin-bottom: 0.25rem; }
.item-list .item h3 a { text-decoration: none; }
.item-list .item .meta {
  margin-bottom: 0.35rem;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.item-list .item p { max-width: 62ch; margin-bottom: 0; font-size: 0.95rem; color: var(--muted); }

/* --- app cards --- */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}
.app-card {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  padding: 1.1rem 1.15rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.app-body { min-width: 0; }
.app-body .links { margin-top: 0.7rem; }
.app-icon {
  flex: none;
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);   /* same 44px box for real and drawn icons */
  object-fit: cover;
}
.app-icon-drawn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  background: var(--paper);
}
.app-icon-drawn svg { width: 24px; height: 24px; }
.app-card p { margin-bottom: 0.5rem; font-size: 0.92rem; color: var(--muted); }
.app-card .tag {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.72rem;
  color: var(--accent);
}

/* --- chat widget (shared across all pages) --- */
#chat-toggle {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1000;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 999px;
  padding: 0.75rem 1.2rem;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
#chat-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 5rem;
  z-index: 1000;
  width: min(360px, calc(100vw - 2.5rem));
  height: min(500px, calc(100vh - 8rem));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
#chat-panel.open { display: flex; }
#chat-header {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#chat-header span.sub { font-family: var(--sans); font-weight: 400; color: var(--muted); font-size: 0.8rem; }
#chat-close { background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; }
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.chat-msg { font-size: 0.92rem; line-height: 1.45; white-space: pre-wrap; }
.chat-msg.user { align-self: flex-end; background: var(--ink); color: var(--paper); padding: 0.5rem 0.75rem; border-radius: 10px 10px 2px 10px; max-width: 85%; }
.chat-msg.bot { align-self: flex-start; max-width: 90%; }
.chat-sources { font-size: 0.72rem; color: var(--muted); margin-top: 0.3rem; display: flex; flex-direction: column; gap: 0.15rem; }
.chat-sources a { color: var(--muted); }
#chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem;
  border-top: 1px solid var(--line);
}
#chat-input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--paper);
  color: var(--ink);
  resize: none;
}
#chat-send {
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 8px;
  padding: 0 0.9rem;
  cursor: pointer;
  font-family: inherit;
}
#chat-send:disabled { opacity: 0.5; cursor: default; }

/* --- narrow screens --- */
@media (max-width: 800px) {
  section { grid-template-columns: 1fr; }
  section > h2 { position: static; }
}
@media (max-width: 600px) {
  body { font-size: 1rem; }
  .wrap { padding-bottom: 5.5rem; }   /* room for the chat button under the footer */
  .site-nav { padding: 0.8rem 0; }
  .nav-links { gap: 0.3rem 1rem; }
  .nav-links a { font-size: 0.7rem; letter-spacing: 0.05em; }

  /* home: the name, then the three image + quote boxes fill the rest of the first screen */
  .home .site-nav { display: none; }
  .home-hero { padding: 0 0 1.5rem; }
  .home-hero h1 {
    height: 3.25rem;
    line-height: 3.25rem;
    font-size: min(2rem, 7vw);
    white-space: nowrap;
  }
  .highlights {
    order: 0;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
    height: calc(100vh - 3.25rem - 5px - 0.75rem);
    height: calc(100svh - 3.25rem - 5px - 0.75rem);
    min-height: 26rem;
  }
  .highlight { flex-direction: row; box-shadow: none; }
  .highlight:hover { transform: none; }
  .highlight img { flex: none; width: 42%; height: 100%; aspect-ratio: auto; }
  .hl-text {
    justify-content: center;
    gap: 0.6rem;
    min-width: 0;
    padding: 0.6rem 0.9rem;
    border-top: 0;
    border-left: 4px solid var(--accent);
  }
  .highlight q { font-size: min(1.1rem, 4.4vw); line-height: 1.3; }
  .hl-label { margin-top: 0; font-size: 0.68rem; }
  .home-hero .tagline { order: 1; margin: 1.5rem 0 0; }

  /* subpages: title, tagline, photo, intro */
  .sub-hero { grid-template-columns: 1fr; grid-template-rows: none; }
  .sub-hero h1, .sub-hero .tagline, .sub-hero .lede, .portrait { grid-column: 1; grid-row: auto; }
  .sub-hero .tagline { margin: 0.8rem 0 1.5rem; }
  .portrait { margin: 0 12px 2.2rem 0; }
  .portrait::before { inset: 12px -12px -12px 12px; }

  /* zoom in so the four books fill the width */
  .books-banner { aspect-ratio: 1.95 / 1; }
  .books-banner img { left: -20%; width: 140%; }
  .stamp { width: 40px; }

  #chat-toggle { right: 0.75rem; bottom: 0.75rem; padding: 0.6rem 1rem; font-size: 0.88rem; }
  #chat-panel { right: 0.75rem; bottom: 4rem; width: calc(100vw - 1.5rem); }
}
