/*
  Foundations shared by every style.
  Each style sheet (style1.css, style2.css, style3.css) sets the design tokens below for its own
  :root[data-style="..."] and lays out the sections however it likes.
*/

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 96px; }
body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--f-sans);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
/* Floated legends sit inside their fieldset instead of on its top border. */
legend { float: left; width: 100%; padding: 0; }
legend + * { clear: both; }
:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip-link {
  position: fixed; left: 1rem; top: -4rem; z-index: 200;
  padding: .7rem 1.1rem;
  background: var(--c-ink); color: var(--c-bg);
  text-decoration: none;
}
.skip-link:focus { top: calc(1rem + env(safe-area-inset-top, 0px)); }

.wrap {
  width: 100%;
  max-width: var(--wrap, 1240px);
  margin-inline: auto;
  padding-inline: max(var(--gutter, 1.25rem), env(safe-area-inset-left, 0px));
}

/* Bits of markup that belong to one style only: data-only="style1" (space-separate several). */
:root[data-style="style1"] [data-only]:not([data-only~="style1"]),
:root[data-style="style2"] [data-only]:not([data-only~="style2"]),
:root[data-style="style3"] [data-only]:not([data-only~="style3"]) { display: none !important; }

/* Elements that keep their identity when the style changes (or between pages), so they glide
   from one layout to the other. Headings get theirs inline in the templates. */
.site-header { view-transition-name: site-header; }
.brand { view-transition-name: brand; }
.hero-art img { view-transition-name: tom-portrait; }
.settings-btn { view-transition-name: settings-btn; }
.contents-nav { view-transition-name: contents-nav; }
.book { view-transition-name: book-cover; }
.settings-panel { view-transition-name: settings-panel; }
/* Keep the settings button and open panel above everything else mid-transition
   (otherwise named elements like Tom's photo are drawn over them). */
::view-transition-group(settings-btn),
::view-transition-group(settings-panel) { z-index: 10; }
/* ...and keep the panel solid: the new panel fades in over the old one, not through it. */
::view-transition-old(settings-panel) { animation: none; }
::view-transition-new(settings-panel) { animation: .25s ease both vt-fade-in; mix-blend-mode: normal; }
::view-transition-old(settings-panel), ::view-transition-new(settings-panel) { height: 100%; }

/* ---------- Floating settings button + panel (positioning only) ---------- */
.settings {
  position: fixed; z-index: 60;
  right: calc(1rem + env(safe-area-inset-right, 0px));
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}
.settings-btn { display: grid; place-items: center; cursor: pointer; }
.settings-hint { position: absolute; right: 100%; bottom: 70%; margin: 0; white-space: nowrap; pointer-events: none; }
.settings-panel {
  position: fixed; inset: auto;
  right: calc(1rem + env(safe-area-inset-right, 0px));
  bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px));
  width: min(20rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 7rem);
  overflow: auto;
  margin: 0;
}
/* Browsers without the popover attribute: site.js toggles [hidden] instead. */
.no-popover .settings-panel:not([hidden]) { display: block; }
.style-option { position: relative; display: flex; align-items: center; cursor: pointer; }
.style-option input { position: absolute; opacity: 0; pointer-events: none; }
.style-option.is-soon { cursor: not-allowed; }
.swatches { display: inline-flex; }
.swatches i { display: block; width: 1rem; height: 1rem; border-radius: 50%; }
.size-options { display: flex; }
.size-options button { cursor: pointer; }
.size-options [data-size="100"] { font-size: .95rem; }
.size-options [data-size="112.5"] { font-size: 1.15rem; }
.size-options [data-size="125"] { font-size: 1.38rem; }

/* ---------- Search dialog (structure only) ---------- */
.search-dialog {
  width: min(40rem, calc(100vw - 2rem));
  max-height: min(36rem, calc(100dvh - 4rem));
  margin: max(8vh, 1rem) auto auto;
  padding: 0;
  overflow: hidden;
}
.search-dialog[open] { display: flex; flex-direction: column; }
.search-head { display: flex; align-items: center; gap: .75rem; flex: none; }
.search-head input { flex: 1; min-width: 0; border: 0; background: none; outline: none; }
.search-head input::-webkit-search-cancel-button { display: none; }
.search-results { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.search-results a { display: block; text-decoration: none; }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }

  /* Sections drift up as they scroll into view (site.js adds .reveal-ready). */
  [data-reveal] { transition: opacity .9s ease, transform .9s cubic-bezier(.2, .7, .2, 1); }
  .reveal-ready [data-reveal]:not(.is-visible) { opacity: 0; transform: translateY(22px); }

  /* Page-to-page and style-to-style transitions. Elements that share a
     view-transition-name (like a project title) glide between positions. */
  @view-transition { navigation: auto; }
  ::view-transition-group(*) { animation-duration: .6s; animation-timing-function: cubic-bezier(.2, .7, .2, 1); }
  ::view-transition-old(root) { animation: .35s ease both vt-fade-out; }
  ::view-transition-new(root) { animation: .5s ease .1s both vt-fade-in; }
  /* The contents side menu (style 2) slides in and out when switching to or from that style */
  ::view-transition-new(contents-nav):only-child { animation: .55s cubic-bezier(.2, .7, .2, 1) both vt-slide-in; }
  ::view-transition-old(contents-nav):only-child { animation: .35s ease both vt-slide-out; }
}
@keyframes vt-slide-in { from { transform: translateX(-100%); } }
@keyframes vt-slide-out { to { transform: translateX(-100%); } }
@keyframes vt-fade-out { to { opacity: 0; } }
@keyframes vt-fade-in { from { opacity: 0; } }
