/* =========================================================================
   Talouden perusteet — static rebuild, v2 (visual refresh)
   Reading room / archive ledger direction, lightened: v1's two-row solid
   pine-green header read heavy, so it's now a single slim bar with a gilt
   hairline instead of a block of dark color. The palette, type system, and
   footnote/table handling stay — that part was already working.
   ========================================================================= */

:root {
  --ink:        #17211C;
  --ink-soft:   #46524B;
  --paper:      #FAF9F4;
  --paper-dim:  #F1EFE4;
  --spine:      #1F3A34;
  --spine-ink:  #0F211D;
  --gilt:       #B7862C;
  --gilt-soft:  #D9C08C;
  --rule:       #DAD5C4;
  --focus:      #2B6CB0;

  --font-display: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-body:    "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-ui:      "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;

  --measure: 68ch;
  --radius: 4px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--spine); color: var(--paper); padding: 0.75em 1.25em;
  font-family: var(--font-ui);
}
.skip-link:focus { left: 0; }

a { color: var(--spine); text-decoration-thickness: 1px; text-underline-offset: 0.15em; }
a:hover { color: var(--gilt); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Header / nav — single slim bar, not a block ---------- */

.site-header {
  background: var(--spine);
  color: var(--paper);
  border-bottom: 2px solid var(--gilt);
}
.site-header__bar {
  max-width: 1180px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 1.25rem;
}
.site-header__brand {
  color: var(--paper); text-decoration: none;
  font-family: var(--font-display); font-weight: 600; font-size: 1.2rem;
  letter-spacing: 0.01em;
}
.site-header__brand:hover { color: var(--gilt-soft); }

.nav-toggle {
  display: none;
  flex-direction: column; justify-content: center; gap: 4px;
  width: 38px; height: 32px;
  background: transparent; border: 1px solid rgba(250,249,244,0.3); border-radius: var(--radius);
  cursor: pointer;
}
.nav-toggle span { display: block; height: 2px; background: var(--paper); border-radius: 1px; }

.primary-nav ul {
  max-width: 1180px; margin: 0 auto; padding: 0 1.25rem 0.55rem;
  list-style: none; display: flex; gap: 1.6rem; flex-wrap: wrap;
  font-family: var(--font-ui); font-size: 0.86rem; font-weight: 500;
}
.primary-nav > ul > li { position: relative; padding: 0.15rem 0; }
.primary-nav a { color: var(--paper); text-decoration: none; opacity: 0.82; }
.primary-nav a:hover { opacity: 1; color: var(--gilt-soft); }

.primary-nav .sub-menu {
  display: none;
  position: absolute; left: 0; top: 100%; z-index: 20;
  flex-direction: column; gap: 0; min-width: 320px;
  background: var(--spine-ink); border: 1px solid rgba(250,249,244,0.15);
  padding: 0.4rem 0; box-shadow: 0 12px 24px rgba(0,0,0,0.25); margin-top: 0.4rem;
}
.primary-nav li.has-children:hover .sub-menu,
.primary-nav li.has-children:focus-within .sub-menu { display: flex; }
.primary-nav .sub-menu li { padding: 0; }
.primary-nav .sub-menu a { display: block; padding: 0.55rem 1rem; opacity: 0.85; }
.primary-nav .sub-menu a:hover { background: rgba(255,255,255,0.06); opacity: 1; }

@media (max-width: 780px) {
  .nav-toggle { display: flex; }
  .primary-nav { display: none; }
  .primary-nav.is-open { display: block; }
  .primary-nav ul { flex-direction: column; gap: 0; padding: 0.35rem 1.25rem 0.9rem; }
  .primary-nav .sub-menu { position: static; display: flex; box-shadow: none; border: none; min-width: 0; padding-left: 0.75rem; margin: 0; }
}

/* --- Fix Navigation Hover Gap --- */
/* Creates an invisible "bridge" so the mouse doesn't fall off when moving to the submenu */
.primary-nav .has-children {
    position: relative;
}
.primary-nav .has-children > a::after {
    content: '';
    position: absolute;
    bottom: -15px; 
    left: 0;
    width: 100%;
    height: 15px;
}

/* ---------- Breadcrumb ---------- */

.breadcrumb {
  max-width: 1180px; margin: 0 auto; padding: 0.9rem 1.25rem 0;
  font-family: var(--font-ui); font-size: 0.82rem; color: var(--ink-soft);
}
.breadcrumb a { color: var(--ink-soft); text-decoration: none; }
.breadcrumb a:hover { color: var(--gilt); }
.breadcrumb__sep { margin: 0 0.5em; color: var(--rule); }

/* ---------- Layout / book TOC sidebar ---------- */

.layout {
  max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem;
  display: grid; grid-template-columns: 1fr; gap: 2rem;
}
@media (min-width: 960px) {
  .layout:has(.book-toc) { grid-template-columns: 240px minmax(0, 1fr); align-items: start; }
}

.book-toc { font-family: var(--font-ui); font-size: 0.88rem; }
.book-toc__toggle {
  width: 100%; text-align: left; cursor: pointer;
  background: var(--paper-dim); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 0.7rem 0.9rem; font: inherit; font-weight: 500; color: var(--spine);
}
.book-toc__panel { display: none; padding-top: 0.75rem; }
.book-toc__panel.is-open { display: block; }
.book-toc__title { margin: 0 0 0.5rem; font-family: var(--font-display); font-weight: 600; color: var(--ink); font-size: 0.95rem; }
.book-toc ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--rule); }
.book-toc a { display: block; padding: 0.4rem 0.75rem; margin-left: -2px; border-left: 2px solid transparent; color: var(--ink-soft); text-decoration: none; line-height: 1.35; }
.book-toc a:hover { color: var(--spine); border-left-color: var(--gilt-soft); }
.book-toc li.is-current > a { color: var(--spine); font-weight: 600; border-left-color: var(--gilt); }

@media (min-width: 960px) {
  .book-toc { position: sticky; top: 1.5rem; max-height: calc(100vh - 3rem); overflow-y: auto; }
  .book-toc__toggle { display: none; }
  .book-toc__panel { display: block; padding-top: 0; }
}

/* ---------- Reading column ---------- */

.reading-column { min-width: 0; }
.entry-header { margin-bottom: 1.75rem; }
.entry-header__eyebrow {
  font-family: var(--font-ui); font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--gilt); margin: 0 0 0.4rem;
}
.entry-header h1 {
  font-family: var(--font-display); font-weight: 600;
  font-size: clamp(1.7rem, 1.3rem + 1.6vw, 2.5rem);
  line-height: 1.15; margin: 0 0 0.4rem; color: var(--ink); max-width: var(--measure);
}
.entry-header__meta { font-family: var(--font-ui); font-size: 0.82rem; color: var(--ink-soft); margin: 0; }

.entry-content { max-width: var(--measure); }
.entry-content p { margin: 0 0 1.25em; }
.entry-content h2 {
  font-family: var(--font-display); font-weight: 600; color: var(--ink);
  font-size: 1.5rem; margin: 2rem 0 0.75em; padding-top: 0.25em; border-top: 1px solid var(--rule);
}
.entry-content h3 { font-family: var(--font-display); font-weight: 600; color: var(--ink); font-size: 1.2rem; margin: 1.75rem 0 0.6em; }
.entry-content ul, .entry-content ol { margin: 0 0 1.25em; padding-left: 1.4em; }
.entry-content li { margin-bottom: 0.4em; }
.entry-content blockquote { margin: 1.5em 0; padding: 0.2em 1.25em; border-left: 3px solid var(--gilt-soft); color: var(--ink-soft); font-style: italic; }
.entry-content img { max-width: 100%; height: auto; border-radius: var(--radius); }
.entry-content figure { margin: 1.5em 0; }
.entry-content figcaption { font-family: var(--font-ui); font-size: 0.8rem; color: var(--ink-soft); margin-top: 0.4em; }
.entry-content hr { border: none; border-top: 1px solid var(--rule); margin: 2.5em 0; }

/* Legacy WP layout tables (book listings etc.) overflow horizontally on
   phones if left alone. Fixed by wrapping in a scrollable div at extract
   time (extract.py: wrap_tables) rather than forcing display:block on the
   <table> itself, which strips its accessible table semantics in some
   browser/AT combinations. */
.entry-content .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 0 1.5em; }
.entry-content table { max-width: 100%; border-collapse: collapse; font-size: 0.95rem; margin: 0; }
.entry-content td, .entry-content th { padding: 0.5em 0.75em; vertical-align: top; }
.entry-content small { color: var(--ink-soft); }

.entry-content sup { color: var(--gilt); font-weight: 600; }
.entry-content sup a { color: inherit; text-decoration: none; }
.entry-content ol[start], .entry-content .footnotes, .entry-content .footnotes-area {
  font-family: var(--font-ui); font-size: 0.88rem; color: var(--ink-soft);
  border-top: 1px solid var(--rule); padding-top: 1.25em; margin-top: 2em;
}

/* ---------- WordPress column shortcodes (tg-one-third etc.) ----------
   entry-content is captured verbatim, so whatever grid classes a page's
   original shortcodes emitted are still there; we just need to give them
   a responsive definition. Covers the Accelerate theme's own grid
   classes and is intentionally generic (float-based markup, no wrapper
   assumptions) so it degrades safely if a class isn't actually present. */
.entry-content .tg-columns { display: flex; flex-wrap: wrap; gap: 1.5rem; margin: 0 0 1.5em; }
.entry-content [class*="tg-one-half"]   { flex: 1 1 100%; }
.entry-content [class*="tg-one-third"]  { flex: 1 1 100%; }
.entry-content [class*="tg-two-third"]  { flex: 1 1 100%; }
.entry-content [class*="tg-one-fourth"] { flex: 1 1 100%; }
.entry-content [class*="tg-three-fourth"] { flex: 1 1 100%; }
@media (min-width: 640px) {
  .entry-content [class*="tg-one-half"]     { flex-basis: calc(50% - 0.75rem); }
  .entry-content [class*="tg-one-third"]    { flex-basis: calc(33.333% - 1rem); }
  .entry-content [class*="tg-two-third"]    { flex-basis: calc(66.666% - 0.75rem); }
  .entry-content [class*="tg-one-fourth"]   { flex-basis: calc(25% - 1.125rem); }
  .entry-content [class*="tg-three-fourth"] { flex-basis: calc(75% - 0.5rem); }
}

/* ---------- Book card grid ----------
   Used on the homepage and /kirjoja/ listing. This is the one place a
   generic class is *added* rather than only styling what's inherited,
   because a plain link list of nine books was the flattest, least "wow"
   part of the original design. */
.book-grid {
  /* Increased from 160px to 240px so it naturally forms a beautiful 3-column or 4-column grid */
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 2rem; margin: 1.75rem 0 2.5rem; max-width: none;
  list-style: none; padding: 0;
}
.book-card { display: block; text-decoration: none; color: inherit; }
.book-card__cover {
  position: relative;
  aspect-ratio: 2 / 3; /* This forces every box to be perfectly uniform */
  border-radius: var(--radius); 
  overflow: hidden;
  transition: transform 0.18s ease;
  background-color: var(--paper-dim); /* Adds a soft background for transparent covers */
}
.book-card__cover img { 
  position: relative; 
  width: 100%; 
  height: 100%; 
  object-fit: cover; /* Fills the 2:3 aspect ratio completely for unified grid heights */
  padding: 0;
  padding: 0.5rem; /* Gives breathing room inside the uniform box */
  display: block; 
}
.book-card:hover .book-card__cover { transform: translateY(-3px); box-shadow: 0 10px 20px rgba(23,33,28,0.16); }
.book-card__title {
  display: block; margin-top: 0.6rem; font-family: var(--font-display); font-weight: 600;
  font-size: 0.95rem; line-height: 1.3; color: var(--ink);
}
.book-card:hover .book-card__title { color: var(--spine); }
.book-card__author { display: block; margin-top: 0.15rem; font-family: var(--font-ui); font-size: 0.78rem; color: var(--ink-soft); }

@media (prefers-reduced-motion: reduce) { .book-card__cover { transition: none; } }

/* Unified Bookstore Buttons */
.store-links-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--rule);
}
.store-badge {
    display: inline-block;
    transition: transform 0.15s ease;
}
.store-badge:hover {
    transform: translateY(-2px);
}
.store-badge img {
    height: 26px; /* Forces all store logos to be the exact same height */
    width: auto;
    display: block;
    margin: 0;
}

/* Style for text-based Gumroad buttons so they match the image badges */
.gumroad-btn-styled {
    background: var(--spine);
    color: var(--paper);
    padding: 0 12px;
    border-radius: 4px;
    font-weight: 600;
    text-decoration: none;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    height: 26px;
    white-space: nowrap;
}
.gumroad-btn-styled:hover {
    background: var(--gilt);
    color: var(--paper);
}

/* --- High-Res Standardized Book Covers --- */
.standard-book-cover {
    float: right; /* Aligns the book to the right, letting text wrap on the left */
    width: 240px; /* Perfect, uniform size for every book */
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12); /* Adds a subtle, professional shadow */
    margin: 0 0 1.5rem 2rem; /* Pushes text cleanly away from the image */
}

/* On mobile phones, center the image instead of floating it */
@media (max-width: 650px) {
    .standard-book-cover {
        float: none;
        display: block;
        margin: 0 auto 2rem auto;
    }
}

/* ---------- Search page (Pagefind) ---------- */

.search-page #search {
  --pagefind-ui-primary: var(--spine);
  --pagefind-ui-text: var(--ink);
  --pagefind-ui-background: var(--paper);
  --pagefind-ui-border: var(--rule);
  --pagefind-ui-tag: var(--paper-dim);
  --pagefind-ui-font: var(--font-ui);
  max-width: var(--measure); margin-top: 1rem;
}

/* ---------- Footer ---------- */

.site-footer { background: var(--paper-dim); border-top: 1px solid var(--rule); margin-top: 2rem; }
.site-footer__inner {
  max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.75rem;
  font-family: var(--font-ui); font-size: 0.82rem; color: var(--ink-soft);
}
.back-to-top { color: var(--ink-soft); text-decoration: none; }
.back-to-top:hover { color: var(--gilt); }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
@media print {
  .site-header, .breadcrumb, .book-toc, .site-footer, .nav-toggle { display: none !important; }
  body { background: #fff; }
}
