/*
Theme Name: David Cruz
Theme URI: https://david-cruz.org
Author: David Cruz
Description: Fast, accessible, trilingual academic theme for david-cruz.org. Custom post types for publications, books, press and courses.
Version: 2.1.1
Requires at least: 6.4
Tested up to: 6.9
Requires PHP: 7.4
License: GNU General Public License v2 or later
Text Domain: davidcruz
*/

/* ---------- Tokens ----------
   Layout: full-width photographic hero (black, bleeds into the B&W portrait), then a 1120px editorial column.
   Top bar: name left, menu + language switch right. Footer: academic profile links.
*/
:root {
  --paper: #FAFAF7;
  --paper-2: #F0F0EB;
  --ink: #15181E;
  --ink-2: #3B3F47;
  --meta: #6E727A;
  --rule: #DADBD5;
  --marine: #1B4F6B;
  --marine-2: #123A50;
  --black: #0B0C0E;
  --focus: #C8962E;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --measure: 68ch;
  --wrap: 1120px;
  --gutter: clamp(20px, 4vw, 48px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121418; --paper-2: #1A1D23; --ink: #ECECE7; --ink-2: #C6C8C2; --meta: #969AA2;
    --rule: #2D3139; --marine: #86B9CE; --marine-2: #A9CFDF; --focus: #E3B85C; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #121418; --paper-2: #1A1D23; --ink: #ECECE7; --ink-2: #C6C8C2; --meta: #969AA2;
  --rule: #2D3139; --marine: #86B9CE; --marine-2: #A9CFDF; --focus: #E3B85C; color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition: none !important; animation: none !important; } }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--serif); font-size: 1.125rem; line-height: 1.6; font-optical-sizing: auto; }
img { max-width: 100%; height: auto; display: block; }
a { color: var(--marine); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--marine-2); }
a:focus-visible, button:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 2px; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 500; line-height: 1.15; margin: 0 0 0.5em; letter-spacing: -0.005em; text-wrap: balance; }
h1 { font-size: clamp(2.2rem, 4.5vw, 3.2rem); }
h2 { font-size: clamp(1.55rem, 2.6vw, 2rem); margin-top: 2.4em; }
h3 { font-size: 1.3rem; margin-top: 1.6em; }
p { margin: 0 0 1.1em; max-width: var(--measure); }
ul, ol { padding-left: 1.2em; max-width: var(--measure); }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }
blockquote { margin: 1.5rem 0; padding-left: 1.2rem; border-left: 2px solid var(--marine); font-style: italic; color: var(--ink-2); }
.meta, .pub-meta, .topbar, .crumb, .pill, .year, time, table, .btn, .pub-links, .outlet, .term, .code, .kicker, .lang-switch { font-family: var(--sans); font-size: 0.9rem; line-height: 1.45; }
.meta { color: var(--meta); }
.wrap { width: min(var(--wrap), 100%); margin-inline: auto; padding-inline: var(--gutter); }
.screen-reader-text { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(1px,1px,1px,1px); white-space: nowrap; }

/* ---------- Skip link ---------- */
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 100; background: var(--focus); color: #000; padding: 0.6em 1em; font-family: var(--sans); text-decoration: none; font-weight: 500; }
.skip-link:focus { left: 8px; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule); }
.topbar .wrap { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1.5rem; min-height: 64px; }
.brand { font-family: var(--serif); font-size: 1.35rem; font-weight: 500; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; white-space: nowrap; }
.brand small { display: block; font-family: var(--sans); font-size: 0.72rem; color: var(--meta); font-weight: 400; letter-spacing: 0; margin-top: -2px; }
.topbar-right { display: contents; }
.site-nav { justify-self: center; }
.lang-switch { justify-self: end; }
.site-nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 1.1rem; white-space: nowrap; }
.site-nav a { color: var(--ink-2); text-decoration: none; padding: 0.4em 0; border-bottom: 2px solid transparent; display: inline-block; font-size: 0.88rem; }
.site-nav a:hover { color: var(--ink); }
.site-nav .current-menu-item > a, .site-nav .current-menu-ancestor > a, .site-nav .current_page_item > a, .site-nav .current_page_ancestor > a, .site-nav .is-current > a { color: var(--ink); border-bottom-color: var(--ink); }
.site-nav .sub-menu { display: none; }
.lang-switch ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 0.15rem; border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; }
.lang-switch li { margin: 0; }
.lang-switch a { text-transform: uppercase; display: inline-flex; align-items: center; gap: 0.4em; padding: 0.35em 0.65em; color: var(--meta); text-decoration: none; font-size: 0.8rem; letter-spacing: 0.02em; }
.lang-switch .flag { width: 18px; height: 12.6px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,0.12); flex: none; }
.lang-switch a:not([aria-current]) .flag { opacity: 0.75; }
.lang-switch a:hover .flag { opacity: 1; }
.lang-switch .current-lang a, .lang-switch a[aria-current] { background: var(--ink); color: var(--paper); }
.lang-switch a:hover:not([aria-current]) { color: var(--ink); background: var(--paper-2); }
.nav-toggle { display: none !important; background: none; border: 1px solid var(--rule); color: var(--ink); font-family: var(--sans); font-size: 0.9rem; padding: 0.45em 0.8em; border-radius: 4px; cursor: pointer; }
@media (max-width: 1040px) {
  .topbar .wrap { grid-template-columns: 1fr auto; grid-template-areas: "brand lang" "nav nav"; row-gap: 0.2rem; padding-block: 0.6rem; }
  .brand { grid-area: brand; }
  .lang-switch { grid-area: lang; justify-self: end; }
  .site-nav { grid-area: nav; justify-self: center; }
  .site-nav ul { flex-wrap: wrap; justify-content: center; gap: 0.2rem 1rem; white-space: normal; }
}

/* ---------- Hero (home) ---------- */
.hero { background: #ECEAE4; color: var(--ink); position: relative; overflow: hidden; border-bottom: 1px solid var(--rule); }
:root[data-theme="dark"] .hero { background: #1E2227; color: #F2F1EC; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero { background: #1E2227; color: #F2F1EC; } }
.hero .wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 46%); gap: clamp(1.5rem, 4vw, 4rem); align-items: end; padding-block: 0; }
.hero-text { padding-block: clamp(2.5rem, 6vw, 5rem); }
.hero-kicker { font-family: var(--sans); font-size: 0.85rem; color: var(--meta); margin: 0 0 1rem; letter-spacing: 0.02em; }
.hero-text h1 { font-size: clamp(2.8rem, 6.5vw, 5rem); font-weight: 400; letter-spacing: -0.02em; line-height: 1.02; margin: 0 0 1rem; color: inherit; }
.hero-text .lede { font-size: clamp(1.1rem, 1.7vw, 1.35rem); line-height: 1.45; color: var(--ink-2); max-width: 34ch; margin: 0 0 1.8rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.8rem 1.4rem; align-items: center; }
.btn { display: inline-block; background: var(--ink); color: var(--paper); padding: 0.65em 1.2em; border-radius: 4px; text-decoration: none; font-weight: 500; }
.btn:hover { background: var(--marine); color: #fff; }
.btn-ghost { display: inline-block; color: inherit; text-decoration: none; border-bottom: 1px solid var(--rule); padding-bottom: 2px; }
.btn-ghost:hover { color: var(--marine); border-bottom-color: var(--marine); }
.hero-photo { margin: 0; align-self: end; position: relative; }
.hero-photo img { display: block; width: 100%; height: auto; max-height: 640px; object-fit: cover; object-position: 50% 20%; }
.hero-photo figcaption { display: none; }
@media (max-width: 760px) {
  .hero .wrap { grid-template-columns: 1fr; }
  .hero-photo { order: -1; margin-inline: calc(-1 * var(--gutter)); }
  .hero-photo img { max-height: none; aspect-ratio: 4/3; object-position: 50% 15%; }
  .hero-text { padding-top: 1.4rem; }
}

/* ---------- Home body ---------- */
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: clamp(2rem, 5vw, 4.5rem); align-items: start; padding-block: 3.5rem 2rem; }
@media (max-width: 960px) { .home-grid { grid-template-columns: 1fr; } }
.project-card { display: block; padding: 1.3rem 1.4rem; background: var(--paper-2); border-left: 3px solid var(--marine); margin: 0 0 2.2rem; text-decoration: none; color: inherit; max-width: var(--measure); }
.project-card .kicker { color: var(--meta); margin: 0 0 0.3rem; font-size: 0.8rem; }
.project-card h2 { font-size: 1.45rem; font-style: italic; font-weight: 400; margin: 0 0 0.4rem; }
.project-card p { font-size: 1rem; color: var(--ink-2); margin: 0; }
.project-card:hover h2 { text-decoration: underline; text-underline-offset: 0.15em; }
.aside h2 { font-size: 1.2rem; margin-top: 0; }
.shelf { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; list-style: none; padding: 0; margin: 0 0 2rem; max-width: none; }
.shelf img { width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 2px; box-shadow: 0 2px 6px rgba(0,0,0,0.2); }
.shelf a { display: block; }
.shelf a:hover img, .shelf a:focus-visible img { transform: translateY(-3px); transition: transform .15s ease; }
.news-list { list-style: none; padding: 0; margin: 0; max-width: var(--measure); }
.news-list li { display: grid; grid-template-columns: 6.5em minmax(0,1fr); gap: 0.8rem; padding: 0.7rem 0; border-top: 1px solid var(--rule); }
.news-list time { color: var(--meta); padding-top: 0.15em; }
.news-list a { text-decoration: none; color: var(--ink); }
.news-list a:hover { text-decoration: underline; }
.more { font-family: var(--sans); font-size: 0.9rem; }

/* Strip of photos (home, teaching) */
.photo-strip { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 0.6rem; list-style: none; padding: 0; margin: 0; max-width: none; }
.photo-strip li { margin: 0; position: relative; }
.photo-strip img { width: 100%; height: 100%; aspect-ratio: 4/3; object-fit: cover; object-position: 50% 30%; border-radius: 3px; }
.photo-strip li:first-child img { aspect-ratio: auto; }
.photo-strip figcaption, .photo-strip .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 1.6rem 0.8rem 0.6rem; font-family: var(--sans); font-size: 0.78rem; color: #fff; background: linear-gradient(180deg, transparent, rgba(0,0,0,0.65)); border-radius: 0 0 3px 3px; }
@media (max-width: 640px) { .photo-strip { grid-template-columns: 1fr 1fr; } .photo-strip li:first-child { grid-column: 1 / 3; } }
.band { background: var(--paper-2); padding-block: 2.5rem; margin-block: 1rem 0; }
.band h2 { margin-top: 0; font-size: 1.4rem; }

/* ---------- Page header ---------- */
.page { padding-block: 2.6rem 5rem; }
.page-head { padding-block: 2.6rem 0; }
.page-head h1 { margin-bottom: 0.3em; }
.page-head .lede { color: var(--ink-2); font-size: 1.15rem; margin-bottom: 0; }
.page-cover { margin: 0 0 2.5rem; position: relative; }
.page-cover img { width: 100%; aspect-ratio: 21/8; object-fit: cover; border-radius: 4px; }
.page-cover figcaption { position: absolute; right: 0.8rem; bottom: 0.6rem; font-family: var(--sans); font-size: 0.72rem; color: #fff; background: rgba(0,0,0,0.45); padding: 0.15em 0.5em; border-radius: 2px; }
@media (max-width: 640px) { .page-cover img { aspect-ratio: 16/10; } }

/* ---------- Bibliography ---------- */
.bib { list-style: none; margin: 0 0 2rem; padding: 0; max-width: none; }
.bib li { display: grid; grid-template-columns: 5em minmax(0,1fr) auto; gap: 1.2rem; padding: 1rem 0; border-top: 1px solid var(--rule); }
.bib li:last-child { border-bottom: 1px solid var(--rule); }
.bib .year { color: var(--meta); padding-top: 0.25em; }
.bib .title { font-size: 1.1rem; margin: 0 0 0.2em; max-width: 60ch; }
.pub-meta { color: var(--ink-2); margin: 0; max-width: 60ch; }
.pub-links { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin-top: 0.45rem; font-size: 0.85rem; }
.pub-links a { text-decoration: none; border-bottom: 1px solid var(--rule); }
.pub-links a:hover { border-bottom-color: var(--marine); }
.abstract { margin: 0.6rem 0 0; color: var(--ink-2); font-size: 1rem; max-width: 60ch; }
.abstract summary { cursor: pointer; font-family: var(--sans); font-size: 0.85rem; color: var(--meta); }
.pill { display: inline-block; padding: 0.1em 0.5em; border: 1px solid var(--rule); border-radius: 3px; color: var(--meta); font-size: 0.75rem; vertical-align: middle; margin-left: 0.4em; }
.bib .thumb { width: 128px; }
.bib .thumb img { width: 128px; aspect-ratio: 16/10; object-fit: cover; border-radius: 3px; }
.bib .thumb.tall img { aspect-ratio: 2/3; width: 76px; }
@media (max-width: 640px) { .bib li { grid-template-columns: 4em minmax(0,1fr); } .bib .thumb { grid-column: 2; width: auto; } .bib .thumb img { width: 100%; max-width: 240px; } .bib .thumb.tall img { width: 90px; } }

/* ---------- Books ---------- */
.books { list-style: none; padding: 0; margin: 0; display: grid; gap: 0; max-width: none; }
.book { display: grid; grid-template-columns: 180px minmax(0,1fr); gap: 1.8rem; align-items: start; padding-block: 1.8rem; border-top: 1px solid var(--rule); }
.book-cover { margin: 0; width: 100%; }
.book-cover img { width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 2px; box-shadow: 0 3px 10px rgba(0,0,0,0.22); }
.book-cover.placeholder { aspect-ratio: 2/3; background: var(--paper-2); border-radius: 2px; display: grid; place-items: center; color: var(--meta); font-family: var(--sans); font-size: 0.8rem; text-align: center; padding: 0.6rem; }
.book h3 { margin-top: 0; font-size: 1.55rem; font-style: italic; font-weight: 400; }
.book .award { color: var(--marine); font-family: var(--sans); font-size: 0.9rem; margin: 0.2rem 0 0.6rem; }
.book .press-quote { margin: 0.8rem 0 0; font-style: italic; color: var(--ink-2); max-width: 60ch; }
.book .entry-content > * { max-width: 60ch; }
@media (max-width: 600px) { .book { grid-template-columns: 120px minmax(0,1fr); gap: 1rem; } }

/* ---------- Press ---------- */
.press-group h2 { margin-top: 2rem; }
.press { list-style: none; padding: 0; margin: 0; max-width: none; }
.press li { display: grid; grid-template-columns: 7.5em minmax(0,1fr); gap: 1rem; padding: 0.8rem 0; border-top: 1px solid var(--rule); }
.press .outlet { color: var(--meta); font-size: 0.85rem; }
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.4rem; list-style: none; padding: 0; margin: 0 0 1rem; max-width: none; }
.video { aspect-ratio: 16/9; background: var(--black); border-radius: 4px; overflow: hidden; }
.video iframe { width: 100%; height: 100%; border: 0; }
.video-grid h3 { font-size: 1.05rem; margin: 0.6rem 0 0.1rem; font-family: var(--sans); font-weight: 500; }
.yt-lite { position: relative; display: block; width: 100%; height: 100%; background: #000 center/cover no-repeat; border: 0; cursor: pointer; padding: 0; }
.yt-lite::after { content: ""; position: absolute; inset: 0; margin: auto; width: 64px; height: 44px; background: rgba(27,79,107,0.92); border-radius: 10px; }
.yt-lite::before { content: ""; position: absolute; inset: 0; margin: auto; width: 0; height: 0; border-left: 18px solid #fff; border-top: 11px solid transparent; border-bottom: 11px solid transparent; z-index: 1; transform: translateX(3px); }

/* ---------- Teaching ---------- */
.courses { list-style: none; padding: 0; margin: 0 0 2rem; max-width: none; }
.courses li { display: grid; grid-template-columns: 9em minmax(0,1fr); gap: 1rem; padding: 0.75rem 0; border-top: 1px solid var(--rule); }
.courses .term { color: var(--meta); font-size: 0.85rem; padding-top: 0.2em; }
.courses .code { color: var(--meta); font-size: 0.85rem; }
.course-desc { margin: 0.3rem 0 0; font-size: 1rem; color: var(--ink-2); max-width: 60ch; }

/* ---------- Generic blocks ---------- */
.entry-content > * { max-width: var(--measure); }
.entry-content > .alignwide, .entry-content > .alignfull, .entry-content > .photo-strip, .entry-content > .bib, .entry-content > .wp-block-table { max-width: none; }
.wp-block-table table, table { border-collapse: collapse; width: 100%; }
.wp-block-table td, .wp-block-table th { border-top: 1px solid var(--rule); padding: 0.5em 0.6em 0.5em 0; text-align: left; vertical-align: top; }
.wp-block-button__link { background: var(--marine); color: #fff; font-family: var(--sans); border-radius: 4px; padding: 0.6em 1.1em; text-decoration: none; }
.wp-block-button__link:hover { background: var(--marine-2); color: #fff; }
.wp-block-image figcaption { font-family: var(--sans); font-size: 0.85rem; color: var(--meta); }
.alignleft { float: left; margin: 0.3em 1.5em 1em 0; }
.alignright { float: right; margin: 0.3em 0 1em 1.5em; }

/* ---------- Footer ---------- */
.site-footer { background: var(--black); color: #B9BBB4; margin-top: 3rem; }
.site-footer .wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2rem; padding-block: 2.4rem; align-items: start; }
.site-footer h2 { font-family: var(--serif); font-size: 1.2rem; color: #fff; margin: 0 0 0.3rem; font-weight: 500; }
.site-footer p { margin: 0 0 0.3rem; font-family: var(--sans); font-size: 0.85rem; }
.site-footer a { color: #E6E6E1; }
.site-footer a:hover { color: #fff; }
.profile-links { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.35rem; font-family: var(--sans); font-size: 0.88rem; }
.profile-links a { display: inline-flex; align-items: center; gap: 0.5rem; text-decoration: none; border-bottom: 1px solid #3A3D3A; padding-bottom: 1px; }
.profile-links a:hover { border-bottom-color: #fff; }
.profile-links svg { width: 16px; height: 16px; flex: none; }
.site-footer .legal { font-size: 0.75rem; color: #7E817C; margin-top: 1.2rem; }
@media (max-width: 640px) { .site-footer .wrap { grid-template-columns: 1fr; } }

/* ---------- Dropdown submenu (Creative Writing) ---------- */
.site-nav li { position: relative; }
.site-nav .has-sub > a::after, .site-nav .menu-item-has-children > a::after { content: ""; display: inline-block; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg) translateY(-3px); margin-left: 0.45em; }
.site-nav .sub-menu { display: none; position: absolute; top: 100%; left: -0.6rem; min-width: 190px; background: var(--paper); border: 1px solid var(--rule); border-radius: 4px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); padding: 0.4rem 0; list-style: none; margin: 0; z-index: 60; }
.site-nav li:hover > .sub-menu, .site-nav li:focus-within > .sub-menu, .site-nav li.is-open > .sub-menu { display: block; }
.site-nav .sub-menu a { display: block; padding: 0.45em 0.9em; border-bottom: 0; white-space: nowrap; }
.site-nav .sub-menu a:hover { background: var(--paper-2); }
.site-nav .sub-menu .is-current > a { font-weight: 500; color: var(--ink); }


/* ---------- Accessibility notice (first visit) ---------- */
.a11y-notice { position: fixed; left: max(16px, env(safe-area-inset-left, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); z-index: 90; width: min(380px, calc(100vw - 32px)); background: var(--paper); color: var(--ink); border: 1px solid var(--rule); border-left: 3px solid var(--marine); border-radius: 6px; box-shadow: 0 12px 32px rgba(0,0,0,0.18); padding: 1rem 1.1rem 1rem 1.2rem; font-family: var(--sans); font-size: 0.9rem; line-height: 1.45; }
.a11y-notice[hidden] { display: none; }
.a11y-notice h2 { font-family: var(--sans); font-size: 0.95rem; font-weight: 500; margin: 0 2rem 0.3rem 0; }
.a11y-notice p { margin: 0 0 0.8rem; color: var(--ink-2); max-width: none; }
.a11y-notice .a11y-actions { display: flex; gap: 1rem; align-items: center; }
.a11y-notice .btn-small { background: var(--ink); color: var(--paper); border: 0; padding: 0.45em 0.9em; border-radius: 4px; font: inherit; cursor: pointer; }
.a11y-notice .a11y-x { position: absolute; top: 0.5rem; right: 0.5rem; width: 32px; height: 32px; background: none; border: 0; color: var(--meta); font-size: 1.3rem; line-height: 1; cursor: pointer; border-radius: 4px; }
.a11y-notice .a11y-x:hover { color: var(--ink); background: var(--paper-2); }
