:root {
  --bg: #F4EFE3;        /* ivory */
  --window: #FFFDF8;
  --ink: #1F1D1A;
  --muted: #69645B;
  --rule: #E6DFCF;
  --accent: #8A2B3A;
  --mark: #F3E2B5;
  --shadow: 0 1px 2px rgb(60 45 20 / 0.06), 0 18px 50px -12px rgb(60 45 20 / 0.22);
  --serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Window ---------- */

.window {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--window);
}

/* ---------- Banner ---------- */

.banner {
  position: relative;
  display: flex;
  align-items: flex-end;
  /* Same shape as the photo (1664 x 693), so the whole picture is shown at every width.
     If you change to a photo with another shape, put its width / height here. */
  aspect-ratio: 1664 / 693;
  padding: 1.25rem;
  background: #B9C9A0 url("assets/banner.jpg") center / cover no-repeat;
  color: #fff;
}

/* Darker tone at the bottom so the text reads on a bright photo */
.banner::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgb(0 0 0 / 0) 62%, rgb(0 0 0 / 0.38) 100%);
}

.banner-text { position: relative; }

.name {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.6rem;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 12px rgb(0 0 0 / 0.3);
}

.tag {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  opacity: 0.95;
  text-shadow: 0 1px 8px rgb(0 0 0 / 0.3);
}

/* ---------- Tab bar ---------- */

.tabs {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 0.25rem;
  padding: 0 0.75rem;
  border-bottom: 1px solid var(--rule);
  background: var(--window);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs a {
  position: relative;
  flex: none;
  padding: 0.85rem 0.6rem;
  color: var(--muted);
  font-size: 0.925rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
}

.tabs a:hover,
.tabs a[aria-current="page"] { color: var(--ink); }

.tabs a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 0.6rem;
  right: 0.6rem;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
}

/* ---------- Content ---------- */

.content {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1.75rem 1.25rem 1.5rem;
}

main { margin-bottom: 3rem; }

.panel { scroll-margin-top: 4rem; }

/* Mobile: sections are shown as a simple list, one below the other */
.panel + .panel {
  margin-top: 2.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}

.panel > :last-child { margin-bottom: 0; }

.title {
  max-width: 20ch;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.85rem, 6vw, 2.5rem);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.015em;
}

.lede {
  max-width: 36rem;
  margin: 1.1rem 0 0;
  font-size: 1.1rem;
  line-height: 1.6;
}

.note {
  max-width: 36rem;
  margin: 1.75rem 0 0;
  padding-left: 1rem;
  border-left: 3px solid var(--accent);
}

.note h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
}

.note p { margin: 0; }
.note .owner { margin-top: 0.75rem; color: var(--muted); font-size: 0.95rem; }

.panel-title {
  margin: 0 0 1.25rem;
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

/* ---------- Topic search ---------- */

.search {
  position: relative;
  max-width: 28rem;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.search-icon {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  width: 1rem;
  height: 1rem;
  z-index: 2;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-input,
.search-ghost {
  font: inherit;
  letter-spacing: normal;
}

.search-input {
  position: relative;
  width: 100%;
  margin: 0;
  padding: 0.65rem 0.9rem 0.65rem 2.4rem;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}

.search-input::placeholder { color: var(--muted); opacity: 0.8; }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-input:focus { border-color: var(--muted); }
.search-input:focus-visible { outline-offset: -1px; }

/* Autocomplete suggestion shown in grey behind the typed text */
.search-ghost {
  position: absolute;
  inset: 0;
  padding: calc(0.65rem + 1px) 0.9rem calc(0.65rem + 1px) calc(2.4rem + 1px);
  overflow: hidden;
  background: var(--window);
  color: var(--muted);
  opacity: 0.6;
  white-space: pre;
  pointer-events: none;
}

.search-typed { visibility: hidden; }

.topic-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.topic-list li { padding: 0.3rem 0; }

.topic-list a {
  font-size: 1.05rem;
  text-decoration-color: rgb(138 43 58 / 0.35);
}

.topic-list a:hover { text-decoration-color: currentColor; }

.topic-list mark {
  background: var(--mark);
  color: inherit;
}

.search-empty { margin: 0; color: var(--muted); }

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

.footer {
  max-width: 34rem;
  margin: auto auto 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.55;
  text-align: center;
}

.footer p { margin: 0; }

/* ---------- Floating reader ---------- */

.reader {
  width: min(62rem, 100vw - 1.5rem);
  height: min(78rem, 100dvh - 1.5rem);
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  background: var(--window);
  color: var(--ink);
  box-shadow: 0 2px 6px rgb(20 15 5 / 0.12), 0 40px 90px -20px rgb(20 15 5 / 0.45);
}

.reader[open] {
  display: flex;
  flex-direction: column;
  animation: reader-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.reader::backdrop {
  background: rgb(35 30 20 / 0.28);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in 0.22s ease-out;
}

@keyframes reader-in {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
}

@keyframes fade-in { from { opacity: 0; } }

html.reader-open { overflow: hidden; }

.reader-bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.25rem;
  height: 2.75rem;
  padding: 0 0.4rem 0 1.25rem;
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
}

.reader-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 0.875rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-btn {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.reader-btn:hover { background: var(--rule); color: var(--ink); }
.reader-btn svg { width: 1.1rem; height: 1.1rem; }

.reader-frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: var(--window);
}

/* ---------- Topic pages (topics/*.html) ---------- */

.article {
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
  background: var(--window);
  min-height: 100vh;
}

.article-back {
  display: inline-block;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  text-decoration: none;
}

.article-back:hover { text-decoration: underline; }

.article h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.9rem, 5vw, 2.6rem);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.015em;
}

.article-lede {
  margin: 0.9rem 0 0;
  color: var(--muted);
  font-size: 1.1rem;
}

.article h2 {
  margin: 2.25rem 0 0.6rem;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.25;
}

.article p,
.article ul { max-width: 40rem; margin: 0 0 1rem; }

.article ul { padding-left: 1.2rem; }
.article li { margin-bottom: 0.4rem; }

.article .formula {
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--bg);
  font-family: var(--serif);
  font-size: 1.1rem;
}

/* Inside the reader only the article is shown */
html.embedded body { padding: 0; background: var(--window); }
html.embedded .article { min-height: 0; padding: 2.25rem 2.5rem 3rem; max-width: 44rem; box-shadow: none; }
html.embedded .article-back { display: none; }

/* ---------- Front page ---------- */

/* No visible scrollbar (scrolling still works with wheel, touchpad and touch).
   A scrollbar that comes and goes between tabs would change the page width and make the
   window jump sideways. */
html.site { scrollbar-width: none; }
html.site::-webkit-scrollbar { display: none; }

/* Very light beige, almost white, around the window */
body.home {
  padding: 2.5rem 0.75rem;
  background: #F8F5EE;
  /* Outside the window there is nothing to select */
  -webkit-user-select: none;
  user-select: none;
}

body.home .window {
  -webkit-user-select: text;
  user-select: text;
  min-height: calc(100vh - 5rem);
  min-height: calc(100svh - 5rem);  /* small viewport: doesn't change while mobile toolbars move */
  box-shadow: 0 1px 2px rgb(70 50 20 / 0.08), 0 14px 40px -14px rgb(70 50 20 / 0.22);
}

/* ---------- Wide screens: window in the middle with tabs ---------- */

@media (min-width: 42rem) {
  /* Fixed spacing (not tied to the screen height), so nothing moves while the browser is resized */
  body,
  body.home { padding: 6rem 2rem 2.5rem; }

  /* The window grows with its content: no scrolling inside it.
     Top-aligned with a fixed minimum height so it doesn't jump between tabs. */
  .window {
    width: 100%;
    max-width: 52rem;
    margin: 0 auto;
    box-shadow: var(--shadow);
  }

  .window,
  body.home .window { min-height: 42rem; }

  .banner { padding: 1.5rem 2rem; }

  .name { font-size: 2rem; }

  .tabs {
    position: static;
    padding: 0 1.4rem;
  }

  .content { padding: 2.25rem 2rem 1.75rem; }

  /* With JavaScript, only the active tab is shown */
  .js .panel:not(.is-active) { display: none; }

  /* The disclaimer belongs to the About tab, the page that always opens first */
  .js .window:not([data-tab="about"]) .footer { display: none; }
  .js .panel + .panel { margin-top: 0; padding-top: 0; border-top: 0; }

  .topic-page { padding-top: 3rem; }
  .topic-page .article {
    min-height: 0;
    padding: 2.5rem 3rem 3rem;
    box-shadow: var(--shadow);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tabs a { transition: none; }
  .reader[open], .reader::backdrop { animation: none; }
}
