/* TESSELLA — museum of mathematics
   Warm plaster ground, jewel-tone tiles, Marcellus + Figtree. */

:root {
  --plaster: #f4efe8;
  --plaster-deep: #ece5d9;
  --teal: #155e63;
  --teal-deep: #0d3b3f;
  --teal-ink: #0a3134;
  --madder: #b23a48;
  --ochre: #e0a458;
  --ink: #2b2620;
  --ink-soft: #5c544a;
  --hairline: rgba(43, 38, 32, 0.16);
  --display: "Marcellus", serif;
  --body: "Figtree", system-ui, sans-serif;
  --step: cubic-bezier(0.6, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  background: var(--plaster);
  color: var(--ink);
  font-family: var(--body);
  font-weight: 400;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: var(--ochre); color: var(--teal-ink); }

.skip {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--teal); color: var(--plaster);
  padding: 0.6rem 1.2rem; font-weight: 600; text-decoration: none;
}
.skip:focus { left: 0; }

:focus-visible {
  outline: 2px solid var(--madder);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ---------- nav ---------- */
.nav {
  position: fixed; inset: 0 0 auto 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem clamp(1.2rem, 4vw, 3rem);
  transition: background 0.4s var(--step), box-shadow 0.4s var(--step), padding 0.4s var(--step);
}
.nav.scrolled {
  background: rgba(244, 239, 232, 0.92);
  backdrop-filter: blur(10px);
  box-shadow: 0 1px 0 var(--hairline);
  padding-block: 0.75rem;
}
.nav-mark {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font-family: var(--display); font-size: 1.25rem; letter-spacing: 0.14em;
  color: var(--plaster); text-decoration: none;
  transition: color 0.4s var(--step);
}
.nav.scrolled .nav-mark, .nav.inked .nav-mark { color: var(--teal-ink); }
.nav-glyph { width: 26px; height: 26px; }
.nav nav { display: flex; gap: clamp(0.9rem, 2.5vw, 2rem); align-items: center; }
.nav nav a {
  color: var(--plaster); text-decoration: none; font-size: 0.92rem; font-weight: 500;
  letter-spacing: 0.02em; transition: color 0.4s var(--step), opacity 0.2s;
}
.nav.scrolled nav a, .nav.inked nav a { color: var(--ink); }
.nav nav a:hover { opacity: 0.65; }
.nav-cta {
  border: 1px solid currentColor; border-radius: 999px;
  padding: 0.42rem 1.05rem;
}
@media (max-width: 640px) {
  .nav nav a:not(.nav-cta) { display: none; }
}

/* ---------- hero ---------- */
.hero {
  position: relative; min-height: 100svh;
  display: grid; place-items: center;
  background: var(--teal-deep);
  overflow: hidden;
}
#penrose {
  position: absolute; inset: 0; width: 100%; height: 100%;
  clip-path: circle(150% at 50% 62%);
}
#penrose.veiled { clip-path: circle(0% at 50% 62%); }
@media (prefers-reduced-motion: no-preference) {
  #penrose { transition: clip-path 2.2s var(--step); }
}
.hero-scrim {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 90% 62% at 50% 46%, rgba(10, 49, 52, 0.68) 0%, rgba(10, 49, 52, 0.32) 55%, rgba(10, 49, 52, 0) 78%);
}
.hero-copy {
  position: relative; z-index: 2; text-align: center;
  padding: 0 1.4rem; max-width: 60rem;
}
.hero-kicker {
  color: var(--ochre); font-size: 0.85rem; font-weight: 600;
  letter-spacing: 0.32em; text-transform: uppercase;
  margin-bottom: 1.6rem;
}
.hero-title {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(2.7rem, 9.2vw, 6.8rem);
  line-height: 1.04; color: var(--plaster);
  text-wrap: balance;
}
.hero-title .line { display: block; overflow: hidden; }
.hero-title .line span { display: inline-block; transform: translateY(112%); }
.hero-sub {
  margin-top: 1.8rem; color: rgba(244, 239, 232, 0.85);
  font-size: clamp(0.98rem, 1.6vw, 1.12rem); font-weight: 300;
  max-width: 44rem; margin-inline: auto;
}
.hero-scroll {
  position: absolute; bottom: 2rem; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 0.7rem;
  color: rgba(244, 239, 232, 0.65); font-size: 0.78rem; letter-spacing: 0.22em;
  text-transform: uppercase; z-index: 2;
}
.hero-scroll-line {
  width: 1px; height: 44px;
  background: linear-gradient(to bottom, var(--ochre), transparent);
}
@media (prefers-reduced-motion: no-preference) {
  .hero-scroll-line { animation: drop 2.4s var(--step) infinite; transform-origin: top; }
  @keyframes drop { 0% { transform: scaleY(0); } 45% { transform: scaleY(1); } 100% { transform: scaleY(1); opacity: 0; } }
}

/* ---------- re-tiling dividers ---------- */
.tile-divider { line-height: 0; background: var(--plaster); }
.tile-divider svg { width: 100%; height: clamp(76px, 12vw, 130px); display: block; }

/* ---------- manifesto ---------- */
.manifesto {
  padding: clamp(5rem, 12vw, 9.5rem) clamp(1.4rem, 6vw, 4rem) clamp(4rem, 9vw, 7rem);
  max-width: 62rem; margin: 0 auto;
}
.manifesto-text {
  font-family: var(--display);
  font-size: clamp(1.45rem, 3.4vw, 2.35rem);
  line-height: 1.42; color: var(--ink-soft);
  text-wrap: pretty;
}
.manifesto-text em { font-style: normal; color: var(--madder); }
.manifesto-text .w.lit { color: var(--teal-ink); }
.manifesto-text .w { transition: color 0.35s linear; }
.stat-strip {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem; margin-top: clamp(3rem, 6vw, 5rem);
  border-top: 1px solid var(--hairline); padding-top: 2.2rem;
}
.stat-strip dt {
  font-size: 0.76rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: 0.35rem;
}
.stat-strip dd { font-family: var(--display); font-size: clamp(1.5rem, 3vw, 2.2rem); color: var(--teal); }
@media (max-width: 720px) { .stat-strip { grid-template-columns: repeat(2, 1fr); } }

/* ---------- chapter heads ---------- */
.chapter-head { max-width: 74rem; margin: 0 auto; padding: 0 clamp(1.4rem, 5vw, 3rem); }
.chapter-index {
  color: var(--madder); font-size: 0.82rem; font-weight: 600;
  letter-spacing: 0.28em; text-transform: uppercase; margin-bottom: 1rem;
}
.chapter-title {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(2rem, 5.6vw, 3.9rem); line-height: 1.08; color: var(--teal-ink);
}
.chapter-sub {
  margin-top: 1.3rem; max-width: 40rem; color: var(--ink-soft); font-size: 1.02rem;
}

/* ---------- galleries mosaic ---------- */
.galleries { padding: clamp(4rem, 9vw, 7.5rem) 0 clamp(5rem, 10vw, 8rem); }
.mosaic {
  max-width: 74rem; margin: clamp(2.5rem, 6vw, 4.5rem) auto 0;
  padding: 0 clamp(1.4rem, 5vw, 3rem);
  display: grid; grid-template-columns: repeat(6, 1fr); gap: clamp(1rem, 2.2vw, 1.6rem);
}
.card { grid-column: span 2; }
.card-wide { grid-column: span 4; }
.card {
  background: #fbf8f2;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform 0.5s var(--step), box-shadow 0.5s var(--step);
}
@media (hover: hover) {
  .card:hover { transform: translateY(-5px); box-shadow: 0 18px 44px -22px rgba(13, 59, 63, 0.4); }
  .card:hover .card-art svg { transform: scale(1.045); }
}
.card-art {
  aspect-ratio: 16 / 9; background: var(--plaster-deep);
  border-bottom: 1px solid var(--hairline);
  overflow: hidden; display: grid; place-items: center;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}
.card-art svg { width: 100%; height: 100%; display: block; transition: transform 1.2s var(--step); }
.card-body { padding: clamp(1.2rem, 2.4vw, 1.8rem); display: flex; flex-direction: column; gap: 0.7rem; flex: 1; }
.card-no {
  color: var(--ochre); font-weight: 600; font-size: 0.78rem;
  letter-spacing: 0.24em; text-transform: uppercase;
}
.card h3 { font-family: var(--display); font-weight: 400; font-size: clamp(1.4rem, 2.4vw, 1.85rem); color: var(--teal-ink); }
.card p { color: var(--ink-soft); font-size: 0.96rem; }
.card p em { font-style: italic; }
.card-meta {
  margin-top: auto; padding-top: 0.9rem;
  font-size: 0.8rem !important; letter-spacing: 0.06em; color: var(--teal) !important;
  border-top: 1px dashed var(--hairline);
}
@media (max-width: 900px) {
  .card, .card-wide { grid-column: span 6; }
  .card-art { aspect-ratio: 2 / 1; }
}

/* ---------- studio ---------- */
.studio {
  background: linear-gradient(var(--plaster-deep), var(--plaster));
  border-block: 1px solid var(--hairline);
  padding: clamp(4.5rem, 9vw, 7.5rem) 0;
}
.studio-frame {
  max-width: 46rem; margin: clamp(2.5rem, 5vw, 4rem) auto 0;
  padding: 0 clamp(1.4rem, 5vw, 3rem);
}
.studio-tools {
  display: flex; flex-wrap: wrap; gap: 1rem 1.8rem; align-items: center;
  margin-bottom: 1.1rem;
}
.tool-group { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }
.tool-label {
  font-size: 0.76rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-soft); margin-right: 0.2rem;
}
.sym-btn, .tool-btn {
  font: 500 0.9rem var(--body); color: var(--teal-ink);
  background: transparent; border: 1px solid var(--hairline);
  border-radius: 999px; padding: 0.4rem 0.85rem; cursor: pointer;
  transition: background 0.25s, color 0.25s, border-color 0.25s;
  min-height: 40px;
}
.sym-btn { min-width: 40px; }
.sym-btn:hover, .tool-btn:hover { border-color: var(--teal); }
.sym-btn.is-active { background: var(--teal); color: var(--plaster); border-color: var(--teal); }
#mirror-btn[aria-pressed="true"] { background: var(--teal-ink); color: var(--plaster); border-color: var(--teal-ink); }
.ink-btn {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  background: var(--ink); /* each button sets --ink inline */
  border: 2px solid var(--plaster);
  box-shadow: 0 0 0 1px var(--hairline);
  min-width: 30px; padding: 0;
}
.ink-btn.is-active { box-shadow: 0 0 0 2px var(--teal-ink); }
.studio-canvas-wrap {
  aspect-ratio: 1; border: 1px solid var(--hairline); border-radius: 4px;
  background: #fbf8f2; overflow: hidden;
  box-shadow: 0 24px 60px -34px rgba(13, 59, 63, 0.35);
}
#studio-canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.studio-note { margin-top: 0.9rem; font-size: 0.85rem; color: var(--ink-soft); text-align: center; }

/* ---------- visit ---------- */
.visit { padding: clamp(4.5rem, 9vw, 8rem) 0; }
.visit-today { margin-top: 1.2rem; color: var(--madder); font-weight: 500; font-size: 1rem; }
.visit-grid {
  max-width: 74rem; margin: clamp(2.5rem, 5vw, 4rem) auto 0;
  padding: 0 clamp(1.4rem, 5vw, 3rem);
  display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(1.6rem, 4vw, 3.5rem);
}
.visit-col h3 {
  font-family: var(--display); font-weight: 400; font-size: 1.35rem;
  color: var(--teal-ink); margin-bottom: 1.1rem;
  padding-bottom: 0.7rem; border-bottom: 2px solid var(--ochre);
}
.visit-list { list-style: none; }
.visit-list li {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.55rem 0; border-bottom: 1px solid var(--hairline);
  font-size: 0.95rem;
}
.visit-list li span:last-child { color: var(--teal); font-weight: 500; text-align: right; }
.visit-fine { margin-top: 1rem; font-size: 0.87rem; color: var(--ink-soft); }
.visit-addr { font-style: normal; font-size: 0.95rem; line-height: 1.7; color: var(--ink); }
@media (max-width: 860px) { .visit-grid { grid-template-columns: 1fr; } }

/* ---------- schools ---------- */
.schools {
  background: var(--teal-deep); color: var(--plaster);
  padding: clamp(5rem, 10vw, 8.5rem) clamp(1.4rem, 5vw, 3rem);
  position: relative; overflow: hidden;
}
.schools::before {
  content: ""; position: absolute; inset: 0; opacity: 0.1; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='84' height='48.5' viewBox='0 0 84 48.5'%3E%3Cg fill='none' stroke='%23f4efe8' stroke-width='1'%3E%3Cpath d='M0 0 L14 8 L14 24 L0 32 L-14 24 L-14 8 Z M42 0 L56 8 L56 24 L42 32 L28 24 L28 8 Z M21 24.25 L35 32.25 L35 48.25 L21 56.25 L7 48.25 L7 32.25 Z M63 24.25 L77 32.25 L77 48.25 L63 56.25 L49 48.25 L49 32.25 Z M84 0 L98 8 L98 24 L84 32 L70 24 L70 8 Z M21 -24.25 L35 -16.25 L35 -0.25 L21 7.75 L7 -0.25 L7 -16.25 Z M63 -24.25 L77 -16.25 L77 -0.25 L63 7.75 L49 -0.25 L49 -16.25 Z'/%3E%3C/g%3E%3C/svg%3E");
}
.schools-inner { position: relative; max-width: 44rem; margin: 0 auto; text-align: center; }
.schools .chapter-index { color: var(--ochre); }
.schools-title {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(2rem, 5.4vw, 3.6rem); line-height: 1.12; color: var(--plaster);
}
.schools-accent { color: var(--ochre); }
.schools-sub { margin: 1.5rem auto 2.4rem; max-width: 37rem; color: rgba(244, 239, 232, 0.8); font-size: 1rem; }
.schools-form { display: flex; flex-direction: column; gap: 1.1rem; text-align: left; max-width: 33rem; margin: 0 auto; }
.form-row { display: flex; flex-direction: column; gap: 0.35rem; }
.form-row-split { flex-direction: row; gap: 1.1rem; }
.form-row-split > div { flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }
.schools-form label { font-size: 0.8rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ochre); }
.schools-form input, .schools-form select {
  font: 400 1rem var(--body); color: var(--plaster);
  background: rgba(244, 239, 232, 0.07);
  border: 1px solid rgba(244, 239, 232, 0.28); border-radius: 3px;
  padding: 0.75rem 0.9rem; min-height: 48px;
}
.schools-form select option { color: var(--ink); }
.schools-form input:focus-visible, .schools-form select:focus-visible { outline-color: var(--ochre); }
.schools-form input::placeholder { color: rgba(244, 239, 232, 0.4); }
.schools-submit {
  margin-top: 0.4rem; cursor: pointer;
  font: 600 1rem var(--body); letter-spacing: 0.04em;
  color: var(--teal-ink); background: var(--ochre);
  border: none; border-radius: 999px; padding: 0.95rem 1.6rem; min-height: 52px;
  transition: transform 0.3s var(--step), background 0.3s;
}
.schools-submit:hover { background: #eab36c; transform: translateY(-2px); }
.schools-confirm { margin-top: 1.4rem; color: var(--ochre); font-size: 1rem; min-height: 1.5em; }
@media (max-width: 560px) { .form-row-split { flex-direction: column; } }

/* ---------- footer ---------- */
.footer {
  padding: 2.6rem clamp(1.4rem, 5vw, 3rem);
  display: flex; flex-wrap: wrap; gap: 1rem 2.5rem; align-items: baseline; justify-content: space-between;
  border-top: 1px solid var(--hairline);
  font-size: 0.88rem; color: var(--ink-soft);
}
.footer a { color: var(--teal); text-decoration-color: rgba(21, 94, 99, 0.4); }
.footer a:hover { text-decoration-color: currentColor; }
.footer-fine { width: 100%; font-size: 0.8rem; }

/* ---------- 404 ---------- */
.notfound {
  min-height: 100svh; display: grid; place-items: center; text-align: center;
  background: var(--teal-deep); color: var(--plaster); padding: 2rem;
}
.notfound-inner { max-width: 34rem; }
.notfound h1 { font-family: var(--display); font-weight: 400; font-size: clamp(2.4rem, 8vw, 4.4rem); line-height: 1.1; }
.notfound .gap-svg { width: min(300px, 70vw); margin: 0 auto 2rem; display: block; }
.notfound p { margin: 1.4rem 0 2.2rem; color: rgba(244, 239, 232, 0.8); }
.notfound a {
  display: inline-block; color: var(--teal-ink); background: var(--ochre);
  text-decoration: none; font-weight: 600; border-radius: 999px; padding: 0.85rem 1.7rem;
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .hero-title .line span { transform: none; }
  #penrose { transition: none; }
  #penrose.veiled { clip-path: circle(150% at 50% 62%); }
  .card, .card-art svg, .schools-submit { transition: none; }
}
