:root {
  --bg: #f5f0e2;
  --ink: #1f1d1a;
  --muted: rgba(31, 29, 26, 0.82);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  color-scheme: light;
}
:root.night {
  --bg: #2a3350;
  --ink: #ece7db;
  --muted: rgba(236, 231, 219, 0.85);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}
body {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: color 1.5s;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}
#scene { background: #f3eee1; }
#light {
  position: fixed;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
}
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.page {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(1.25rem, env(safe-area-inset-top)) clamp(1.25rem, 7vw, 6rem) max(clamp(2rem, 10vh, 6rem), env(safe-area-inset-bottom));
}

.mark {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.mark svg { width: 3.5rem; height: 3.5rem; overflow: visible; }
.mark .ink { stroke: currentColor; stroke-width: 1.5; }
.mark .ink { transition: opacity 0.5s; }
.mark.is-signing .ink { opacity: 0.22; }
.mark.is-fading .ink { opacity: 1; }
.mark .trace { fill: currentColor; stroke: none; }
.mark.is-fading .trace { opacity: 0; transition: opacity 0.7s ease-out; }

.hero { max-width: 34rem; text-shadow: 0 0 0.5em var(--bg), 0 0 1.4em var(--bg); }
h1 {
  font-size: clamp(2rem, 4.6vw, 3.4rem);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.hero p {
  margin-top: 1.25rem;
  color: var(--muted);
  text-wrap: pretty;
}

.hero .credit {
  margin-top: 3rem;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: color-mix(in srgb, var(--ink) 62%, transparent);
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: currentColor;
  transition: color 0.45s ease, text-decoration-color 0.45s ease;
}
/* The painter's name brightens to full ink: darker by day, whiter by night. */
a.person:hover, a.person:focus-visible, a.person.is-carded { color: var(--ink); }
a.person:focus-visible { outline: none; }

/* The card is a small canvas on a beige mount: the same paper by day and by night. */
.card {
  position: fixed;
  z-index: 10;
  width: min(20rem, calc(100vw - 2rem));
  overflow: hidden;
  border-radius: 6px;
  color: #1f1d1a;
  background-color: #f2ebda;
  background-image:
    url("data:image/svg+xml,%3Csvg viewBox='0 0 240 240' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.27 0 0 0 0 0.15 0 0 0 0.9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.11'/%3E%3C/svg%3E");
  box-shadow: 0 1px 2px rgba(20, 16, 10, 0.12), 0 14px 34px -10px rgba(20, 16, 10, 0.35);
  visibility: hidden;
  opacity: 0;
  transform: translateY(4px) scale(0.98);
  transform-origin: 1.5rem 100%;
  transition: opacity 0.14s ease-in, transform 0.14s ease-in, visibility 0s 0.14s;
}
.card[data-side="below"] { transform-origin: 1.5rem 0; transform: translateY(-4px) scale(0.98); }
.card.is-open {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity 0.2s ease-out, transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
}

.card-painting {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1200 / 1005;
  object-fit: cover;
  object-position: 60% 55%;
}
.card-body { padding: 0.85rem 1rem 1rem; }
.card-body p { margin: 0; }
.card-name { font-size: 1.15rem; line-height: 1.25; }
.card-meta { margin-top: 0.15rem !important; font-size: 0.78rem; letter-spacing: 0.02em; opacity: 0.68; }
.card-text { margin-top: 0.55rem !important; font-size: 0.9rem; line-height: 1.5; }
.card-hint { margin-top: 0.7rem !important; font-size: 0.78rem; letter-spacing: 0.02em; }
.card-hint a { opacity: 0.62; transition: opacity 0.35s ease; }
.card-hint a:hover, .card-hint a:focus-visible { opacity: 1; outline: none; }

/* ---------- languages ---------- */
:root:lang(zh) body { font-family: var(--serif), "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif; }
:root:lang(ar) body { font-family: var(--serif), "Geeza Pro", "Noto Naskh Arabic", "Amiri", "Traditional Arabic", serif; }
/* Spaced letters break the joins of Arabic script and look loose in Chinese. */
:root:lang(ar) *, :root:lang(zh) h1 { letter-spacing: 0 !important; }
:root:lang(ar) h1 { line-height: 1.3; }
html[data-pending] .hero, html[data-pending] .card { visibility: hidden; }

/* The switcher sits beside the mark, on the bare side of the page, so no word ever sits on paint. */
.top {
  display: flex;
  align-items: center;
  gap: clamp(1.25rem, 4vw, 2.75rem);
}
.top .mark { align-self: auto; }
.langs { display: flex; align-items: center; gap: 0.15rem; }
.langs button {
  font: inherit;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  padding: 0.4rem 0.45rem;
  border: 0;
  background: none;
  color: color-mix(in srgb, var(--ink) 55%, transparent);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.3em;
  transition: color 0.35s ease, text-decoration-color 0.35s ease;
}
.langs button[lang="zh-Hans"] { font-family: var(--serif), "Songti SC", "Noto Serif CJK SC", serif; }
.langs button[lang="ar"] { font-family: var(--serif), "Geeza Pro", "Noto Naskh Arabic", serif; letter-spacing: 0; }
.langs button:hover, .langs button:focus-visible { color: var(--ink); outline: none; }
.langs button[aria-pressed="true"] { color: var(--ink); text-decoration-color: currentColor; cursor: default; }

@media (max-height: 520px) {
  .hero { max-width: min(34rem, 46vw); }
  h1 { font-size: clamp(1.6rem, 3.6vw, 2.4rem); }
  .hero p { margin-top: 0.75rem; font-size: 1rem; }
  .hero .credit { margin-top: 1.5rem; font-size: 0.72rem; }
  .card { width: min(32rem, calc(100vw - 2rem)); }
  .card-painting { aspect-ratio: 4.2 / 1; object-fit: cover; object-position: 60% 55%; }
  .card-body { padding: 0.7rem 1rem 0.8rem; }
  .card-text { font-size: 0.82rem; }
}

@media (prefers-reduced-motion: reduce) {
  body, .mark .ink, .langs button { transition: none; }
  a, .card, .card.is-open { transition: none; }
  .card, .card[data-side="below"] { transform: none; }
}
