/*
 * Color themes. The <html> element carries data-theme="<id>" (the visitor's
 * choice, or the default set in src/themes.ts); each theme picker option
 * carries its own data-theme so it previews itself. Every text color here
 * meets WCAG AA contrast (4.5:1) against the backgrounds it's used on.
 */
:root,
[data-theme="classic"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #1f2430;
  --heading: #1f2430;
  --muted: #5b6475;
  --accent: #2456d6;
  --accent-soft: #edf2fd;
  --border: #e3e6ec;
  color-scheme: light;
}

[data-theme="ocean"] {
  --bg: #f3f8fb;
  --surface: #e6f1f7;
  --text: #12293a;
  --heading: #0b3954;
  --muted: #4a6475;
  --accent: #0a6789;
  --accent-soft: #d3e9f3;
  --border: #cddfe9;
  color-scheme: light;
}

[data-theme="forest"] {
  --bg: #f4f7f2;
  --surface: #e7efe2;
  --text: #1d2a1f;
  --heading: #1f4d2b;
  --muted: #556658;
  --accent: #2b6e33;
  --accent-soft: #d8e8d3;
  --border: #d1ddcc;
  color-scheme: light;
}

[data-theme="sand"] {
  --bg: #fbf7f0;
  --surface: #f2e8d8;
  --text: #2f2419;
  --heading: #5a3a1e;
  --muted: #6d5c4a;
  --accent: #9c4420;
  --accent-soft: #f5e4d9;
  --border: #e4d8c5;
  color-scheme: light;
}

[data-theme="lavender"] {
  --bg: #f7f5fc;
  --surface: #ebe6f7;
  --text: #272040;
  --heading: #3d2a7a;
  --muted: #625a7b;
  --accent: #6038d0;
  --accent-soft: #e2d9f8;
  --border: #dbd3ee;
  color-scheme: light;
}

[data-theme="rose"] {
  --bg: #fdf6f7;
  --surface: #f7e4e9;
  --text: #2e1c22;
  --heading: #7a2140;
  --muted: #72565d;
  --accent: #b3164f;
  --accent-soft: #f8d9e3;
  --border: #ecd3da;
  color-scheme: light;
}

[data-theme="midnight"] {
  --bg: #0f172a;
  --surface: #131d35;
  --text: #e2e8f0;
  --heading: #f8fafc;
  --muted: #a0aec0;
  --accent: #7cc4fa;
  --accent-soft: #1e3a5f;
  --border: #26344f;
  color-scheme: dark;
}

[data-theme="charcoal"] {
  --bg: #1c1c1e;
  --surface: #252527;
  --text: #ececec;
  --heading: #ffffff;
  --muted: #a6a6ab;
  --accent: #f5b942;
  --accent-soft: #3b3222;
  --border: #36363a;
  color-scheme: dark;
}

[data-theme="dusk"] {
  --bg: #1e1626;
  --surface: #271d31;
  --text: #ede6f3;
  --heading: #ffffff;
  --muted: #b8aac7;
  --accent: #f2a9cd;
  --accent-soft: #432d4d;
  --border: #3c2d48;
  color-scheme: dark;
}

:root {
  --content-width: 46rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  line-height: 1.65;
  background: var(--bg);
}

a {
  color: var(--accent);
}

/* Navbar */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-header-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 64rem;
  margin: 0 auto;
  padding: 0.6rem 1rem;
}

.site-nav {
  flex: 1;
  min-width: 0;
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-nav a {
  display: block;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}

.site-nav a:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.site-nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
}

/* Theme picker: a button that pops out a 3×3 grid of themes. */
.theme-picker {
  position: relative;
  flex: none;
}

.theme-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.theme-button::-webkit-details-marker {
  display: none;
}

.theme-button:hover,
.theme-picker[open] > .theme-button {
  background: var(--accent-soft);
}

.theme-button:focus-visible,
.theme-option:focus-visible,
.site-nav a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Tiles redefine --accent for their preview, so their focus ring uses the page's accent instead. */
.theme-option:focus-visible {
  outline-color: var(--page-accent);
}

.theme-menu {
  --page-accent: var(--accent);
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 20;
  width: min(21rem, calc(100vw - 2rem));
  /* The header is sticky, so on short screens the grid scrolls inside itself. */
  max-height: calc(100dvh - 7rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.2);
}

.theme-menu-title {
  margin: 0 0 0.6rem;
  color: var(--text);
  font-weight: 600;
}

.theme-menu-note {
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

/* Each option sets its own data-theme, so the variables below are that theme's colors. */
.theme-option {
  display: grid;
  gap: 0.35rem;
  padding: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  text-align: center;
  cursor: pointer;
}

.theme-option:hover {
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.18);
}

.theme-option[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.theme-option[aria-pressed="true"] .theme-name::after {
  content: " ✓";
}

.theme-swatch {
  display: block;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.theme-swatch-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 0.9rem;
  padding: 0 0.3rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.theme-swatch-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
}

.theme-swatch-text {
  display: block;
  padding: 0.25rem 0 0.35rem;
  color: var(--heading);
  font-size: 1.1rem;
  font-weight: 700;
}

.theme-name {
  white-space: nowrap;
}

/* Print dark-on-white whatever the theme, and leave the picker out. */
@media print {
  html[data-theme] {
    --bg: #ffffff;
    --surface: #ffffff;
    --text: #1f2430;
    --heading: #1f2430;
    --muted: #5b6475;
    --accent: #2456d6;
    --accent-soft: #edf2fd;
    --border: #e3e6ec;
    color-scheme: light;
  }

  .theme-picker {
    display: none;
  }
}

@media (max-width: 520px) {
  /* Icon-only button on phones; the label stays available to screen readers. */
  .theme-button-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .theme-button {
    padding: 0.4rem;
  }
}

/* Page content */
.site-main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.page-title,
.rich-text h2,
.rich-text h3 {
  color: var(--heading);
}

.page-title {
  font-size: clamp(2rem, 5vw, 2.75rem);
  line-height: 1.15;
  margin: 0 0 1.5rem;
}

/* Text modules: headings, paragraphs and lists written in the admin editor. */
.rich-text h2 {
  font-size: 1.65rem;
  line-height: 1.25;
  margin: 2.25rem 0 0.75rem;
}

.rich-text h3 {
  font-size: 1.25rem;
  line-height: 1.3;
  margin: 1.75rem 0 0.5rem;
}

.rich-text h2,
.rich-text h3,
.rich-text p,
.rich-text li {
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

/* Text sizes, fonts and alignment chosen in the editor (keep in sync with admin.css). */
.rt-size-small {
  font-size: 0.8em;
}

.rt-size-large {
  font-size: 1.4em;
  line-height: 1.35;
}

.rt-size-huge {
  font-size: 2em;
  line-height: 1.2;
}

.rt-font-arial {
  font-family: Arial, Helvetica, sans-serif;
}

.rt-font-georgia {
  font-family: Georgia, "Times New Roman", serif;
}

.rt-font-times-new-roman {
  font-family: "Times New Roman", Times, serif;
}

.rt-font-verdana {
  font-family: Verdana, Geneva, sans-serif;
}

.rt-font-courier-new {
  font-family: "Courier New", Courier, monospace;
}

.rt-align-center {
  text-align: center;
}

.rt-align-right {
  text-align: right;
}

.rt-align-justify {
  text-align: justify;
}

/* Keep a centered or right-aligned list item's bullet/number next to its text, as in the editor. */
.rich-text li.rt-align-center,
.rich-text li.rt-align-right {
  list-style-position: inside;
}

.rich-text p {
  margin: 0 0 1rem;
}

.rich-text ul,
.rich-text ol {
  margin: 0 0 1rem;
  padding-left: 1.5rem;
}

.module-image {
  margin: 1.75rem 0;
}

.module-image img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 6px;
}

.module-image figcaption {
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.page-message {
  text-align: center;
  padding-top: 3rem;
}

.page-message p {
  color: var(--muted);
}
