:root {
  --ink: #111111;
  --quiet: #3f3f3f;
  --faint: #5c5c5c;
  --line: #e6e6e6;
  --paper: #f4f0e7;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='900'%3E%3Cfilter id='p' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.011' numOctaves='5' seed='7' stitchTiles='stitch'/%3E%3CfeDiffuseLighting lighting-color='%23fffcf4' surfaceScale='2.2' diffuseConstant='1.05'%3E%3CfeDistantLight azimuth='40' elevation='62'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E");
  --header: 4.75rem;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: auto; }

body {
  margin: 0;
  background: var(--paper) var(--grain) center / 900px 900px repeat fixed;
  color: var(--ink);
  font-family: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 17px;
  font-weight: 400;
  line-height: 1.5;
  text-rendering: geometricPrecision;
}

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

a {
  color: inherit;
  text-underline-offset: 3px;
}

a:focus-visible,
button:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 3px;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--paper);
  color: var(--ink);
  padding: 0.4rem 0.6rem;
  z-index: 20;
}

.skip:focus { top: 0.6rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 2rem;
  padding: 1.2rem 2.5rem 0.9rem;
  position: sticky;
  top: 0;
  background: var(--paper) var(--grain) center / 900px 900px repeat fixed;
  z-index: 6;
}

h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}

h1 a { text-decoration: none; }

.side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem 1.15rem;
}

.nav a {
  color: var(--faint);
  text-decoration: none;
  font-size: 0.82rem;
}

.nav-games {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.1rem 0.6rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
}
.nav-games:hover { background: transparent; color: var(--ink); }
.nav a[aria-current="page"] {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.mail {
  font-size: 0.82rem;
  color: var(--ink);
}

.stage {
  position: relative;
  height: min(46vh, 460px);
  min-height: 300px;
  background: transparent;
  overflow: hidden;
  cursor: pointer;
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.labels button {
  position: absolute;
  left: 0;
  top: 0;
  margin: 0;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  transition: opacity 0.2s;
}

.labels button:hover { background: var(--ink); color: var(--paper); }

.fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--faint);
}

.fallback[hidden] { display: none; }

.hint {
  margin: 0;
  padding: 0.7rem 2.5rem 0;
  font-size: 0.78rem;
  color: var(--faint);
}

#memo { padding-bottom: 4.5rem; }

article {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  gap: 2.5rem 4.5rem;
  padding: 1.6rem 2.5rem 1rem;
  max-width: 1120px;
  align-items: start;
}

html.js article { display: none; }

html.js article.is-current { display: grid; }

.display {
  margin: 0;
  max-width: 14em;
  font-size: clamp(1.7rem, 3.15vw, 2.65rem);
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 1.18;
  text-wrap: pretty;
}

.pairs {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  gap: 2.4rem 4.5rem;
  align-items: start;
}

.linkline { margin-top: 0.45rem; }

.body p {
  margin: 0;
  max-width: 42ch;
  color: var(--quiet);
}

.locus { margin-top: 1.1rem; }

.locus p + p:not(.name) { margin-top: 0.65rem; }

.locus .name {
  margin: 0 0 0.15rem;
  color: var(--ink);
  font-style: italic;
}

.scores {
  grid-column: 1 / -1;
  margin: 0.15rem 0 0;
  max-width: 38rem;
  display: grid;
  gap: 0.95rem;
}

.scores div {
  display: grid;
  grid-template-columns: minmax(0, 13rem) minmax(0, 1fr);
  gap: 0.4rem 1.5rem;
  align-items: baseline;
}

@media (max-width: 760px) {
  .scores div { grid-template-columns: minmax(0, 1fr); }
}

.scores dt,
.scores dd { margin: 0; }

.scores dt {
  color: var(--ink);
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  letter-spacing: -0.03em;
}

.scores dd {
  color: var(--quiet);
  text-align: left;
  overflow-wrap: anywhere;
}

@media (max-width: 760px) {
  :root { --header: 5.6rem; }
  .top {
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.7rem 1.15rem 0.6rem;
  }
  .top .brand { width: 100%; justify-content: space-between; gap: 0.6rem; }
  .side { align-items: flex-start; width: 100%; }
  .side .mail { display: none; }
  .nav {
    width: 100%;
    justify-content: flex-start;
    align-items: center;
    gap: 0.3rem 0.8rem;
  }
  .nav a { font-size: 0.84rem; }
  .nav-games { margin-left: auto; font-size: 0.8rem; }
  .view-switch button { font-size: 0.78rem; padding: 0.25rem 0.7rem; }
  h1 { font-size: 0.9rem; }

  .stage {
    height: 220px;
    min-height: 220px;
  }

  .hint { padding-left: 1.15rem; padding-right: 1.15rem; }

  article,
  html.js article.is-current {
    grid-template-columns: 1fr;
    gap: 1.15rem;
    padding: 1.35rem 1.15rem 0.5rem;
  }

  .display { max-width: 16em; }

  .pairs { grid-template-columns: 1fr; gap: 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  .stage { cursor: auto; }
}

.sheet {
  margin: auto;
  padding: 0;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  width: min(40rem, calc(100% - 2rem));
  max-height: min(34rem, calc(100% - 2rem));
  overflow: auto;
}

.sheet::backdrop { background: rgba(244, 240, 231, 0.84); }

.sheet-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.9rem;
  background: var(--ink);
  color: var(--paper);
}

.sheet-bar p {
  margin: 0;
  font-size: 0.95rem;
}

.sheet-bar button {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sheet-body { padding: 1.1rem 1.15rem 1.25rem; }

.sheet-name {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
}

.sheet-kicker {
  margin: 1rem 0 0.4rem;
  font-style: italic;
}

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

.sheet li {
  margin: 0.28rem 0;
  padding-left: 0.85rem;
  position: relative;
}

.sheet li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.45em;
  width: 0.38rem;
  height: 0.38rem;
  background: var(--ink);
}

.sheet-papers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin-top: 1.15rem;
}

.sheet-papers section {
  margin: 0;
  padding: 0.7rem 0.75rem 0.8rem;
  border: 1px solid var(--ink);
}

.sheet-papers h2 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: -0.03em;
}

.sheet-papers p {
  margin: 0;
  color: var(--quiet);
  font-size: 0.82rem;
  max-width: 36ch;
}

@media (max-width: 640px) {
  .sheet-papers { grid-template-columns: 1fr; }
}

@media print {
  .sheet { display: none; }

  .stage,
  .hint,
  .nav { display: none; }

  article,
  html.js article {
    display: grid !important;
    break-inside: avoid;
  }
}

.walk-in {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  display: none;
  font: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  z-index: 3;
}
.stage.in-room:not(.is-walking) .walk-in { display: block; }
.walkpad {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  display: none;
  grid-template-columns: repeat(3, 2.4rem);
  grid-template-rows: repeat(2, 2.4rem);
  gap: 0.3rem;
  z-index: 3;
}
.stage.is-walking .walkpad { display: grid; }
.walkpad button {
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  touch-action: none;
  user-select: none;
}
.walkpad button[data-key="arrowup"] { grid-column: 2; grid-row: 1; }
.walkpad button[data-key="arrowleft"] { grid-column: 1; grid-row: 2; }
.walkpad button[data-key="arrowdown"] { grid-column: 2; grid-row: 2; }
.walkpad button[data-key="arrowright"] { grid-column: 3; grid-row: 2; }
.walkpad button[data-leave] { grid-column: 3; grid-row: 1; }
.stage.is-walking { cursor: grab; }


.toast {
  position: fixed;
  left: 50%;
  bottom: 1.4rem;
  transform: translate(-50%, 0.6rem);
  margin: 0;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.82rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 30;
  max-width: calc(100% - 2rem);
}

.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.keys {
  margin: 0 0 1.2rem;
  display: grid;
  gap: 0.35rem;
}

.keys div {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 1rem;
}

.keys dt { margin: 0; color: var(--ink); }
.keys dd { margin: 0; color: var(--quiet); }

.term { background: #15171b; color: #e3e6ea; }
.term pre { margin: 0 0 0.8rem; font: inherit; white-space: pre-wrap; }
#term-form { display: flex; gap: 0.5rem; align-items: center; }
#term-form .prompt { color: #8fb3d9; }
#term-in {
  flex: 1;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #3a3f47;
  color: #e3e6ea;
  font: inherit;
  padding: 0.25rem 0;
  outline: none;
}
#term-in:focus { border-bottom-color: #8fb3d9; }
.stage.is-party { animation: party-tint 1.2s linear infinite; }
@keyframes party-tint {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

.arcade-menu { display: grid; gap: 0.5rem; grid-template-columns: 1fr 1fr; }
.arcade-menu button:last-child { grid-column: 1 / -1; }
@media (max-width: 640px) { .arcade-menu { grid-template-columns: 1fr; } }
.arcade-menu button {
  display: grid;
  gap: 0.15rem;
  text-align: left;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.arcade-menu button:hover { background: var(--ink); color: var(--paper); }
.arcade-menu small { font-size: 0.78rem; color: inherit; opacity: 0.75; }
.arcade-screen canvas { display: block; width: 100%; height: auto; background: #15171b; border: 1px solid var(--ink); }
.arcade-foot { display: flex; justify-content: space-between; align-items: center; margin: 0.6rem 0 0; font-size: 0.82rem; }
.arcade-foot button { border: 0; background: transparent; color: var(--ink); font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 0; }

.arcade-menu[hidden], .arcade-screen[hidden] { display: none; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.9rem 0 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0.8rem 0.3rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--ink);
  max-width: 100%;
  line-height: 1.25;
  text-decoration: none;
}
a.chip:hover { border-color: var(--ink); }
.chip img { flex: none; }
.links { margin: 0.9rem 0 0; display: flex; gap: 1.1rem; font-size: 0.9rem; }
.links a { color: var(--faint); text-decoration: underline; text-underline-offset: 4px; }
.links a:hover { color: var(--ink); }
.card > p a, .sheet-papers a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }

.chip img { width: 26px; height: 26px; border-radius: 6px; object-fit: contain; }

.chip b {
  display: inline-grid;
  place-items: center;
  min-width: 1.6rem;
  height: 1.6rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 500;
  font-size: 0.62rem;
  letter-spacing: 0;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.6rem;
  margin: 0.9rem 0 0;
}

.stat { display: grid; gap: 0.05rem; }

.stat .n {
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stat .l { font-size: 0.76rem; color: var(--faint); }

.pairs .stats, .pairs .chips { margin-top: 0.7rem; }
.scores + .chips { grid-column: 1 / -1; max-width: 38rem; margin-top: 1.4rem; }

.scores ~ .chips { grid-column: 1 / -1; max-width: 38rem; }
.scores + .chips { margin-top: 1.4rem; }
.chips + .chips { margin-top: 0.5rem; }

.lede {
  margin: 1.2rem 0 0;
  max-width: 46ch;
  color: var(--quiet);
}

.cards {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: 1.6rem 3rem;
  align-items: start;
}

.card.wide { grid-column: 1 / -1; max-width: 60ch; }

.card h3 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 400;
  letter-spacing: -0.03em;
}

.card > p { margin: 0; color: var(--quiet); max-width: 46ch; }
.card .chip { margin: 0.7rem 0 0; }
.card .linkline + .chip { margin-top: 0.5rem; }
.card .stats { margin-top: 0.7rem; }
.card .linkline { margin-top: 0.5rem; }

.scores {
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 0.6rem 3rem;
  max-width: none;
}

.scores div { grid-template-columns: minmax(0, 1fr); gap: 0.1rem; }
.scores dt { font-size: 1rem; }
.scores dd { font-size: 0.9rem; }

@media (max-width: 760px) {
  .cards { grid-template-columns: minmax(0, 1fr); }
}

.stage { height: min(42vh, 420px); }
#memo { padding-bottom: 2.5rem; }
article { padding-top: 1.2rem; }
.cards { gap: 1.2rem 2.5rem; }
.card > p { font-size: 0.9rem; line-height: 1.45; }
.card h3 { font-size: 1.05rem; }
.card .chip { margin-top: 0.5rem; padding: 0.2rem 0.65rem 0.2rem 0.3rem; font-size: 0.74rem; }
.card .chip img { width: 20px; height: 20px; }
.stat .n { font-size: 1.15rem; }
.lede, .body p { font-size: 0.92rem; }
.display { font-size: clamp(1.5rem, 2.6vw, 2.1rem); }

.stage { height: min(40vh, 400px); }
article:has(.cards) { max-width: none; }
.cards { grid-template-columns: repeat(auto-fit, minmax(15.5rem, 1fr)); gap: 1rem 2.2rem; }
.strip { grid-column: 1 / -1; margin: 0 0 0.2rem; max-width: 70ch; color: var(--quiet); font-size: 0.9rem; }
.card > p { max-width: none; }

.strip { max-width: none; }
#memo { padding-bottom: 1.2rem; }
article { padding-bottom: 0.5rem; }
@media (min-width: 1150px) {
  .cards.five { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1rem 1.8rem; }
}
@media (min-width: 1150px) and (max-height: 820px) {
  .stage { height: min(36vh, 360px); }
}

article[data-room="atrium"] { grid-template-columns: minmax(0, 0.72fr) minmax(0, 1.28fr); gap: 1.5rem 3.5rem; }
article[data-room="atrium"] .locus { columns: 1; margin-top: 0.4rem; }
article[data-room="atrium"] .locus .name { column-span: all; }
article[data-room="atrium"] .locus p { max-width: none; break-inside: avoid; }
@media (max-width: 900px) { article[data-room="atrium"] .locus { columns: 1; } }

article[data-room="atrium"] .locus p { font-size: 1.05rem; max-width: 34ch; color: var(--ink); }


/* ---------- simple (non-3D) site ---------- */
.brand { display: flex; align-items: center; gap: 1.4rem; flex-wrap: wrap; }
.view-switch { display: inline-flex; border: 1px solid var(--ink); border-radius: 999px; overflow: hidden; }
.view-switch button {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.3rem 0.85rem;
  border: 0;
  background: none;
  color: var(--faint);
  cursor: pointer;
}
.view-switch button + button { border-left: 1px solid var(--ink); }
.view-switch button:hover { color: var(--ink); }
.view-switch button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.linkish {
  font: inherit;
  font-size: 0.82rem;
  color: var(--faint);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.linkish:hover { color: var(--ink); }
.plain-only { display: none; }
html.plain .plain-only { display: block; margin: 0 0 1rem; }
html.plain .stage,
html.plain .hint,
html.plain .toast { display: none !important; }
html.plain article,
html.plain.js article { display: grid; max-width: 1120px; padding-top: 2.6rem; padding-bottom: 2.2rem; border-top: 1px solid var(--line); }
html.plain article[data-room="atrium"] { border-top: 0; padding-top: 1.6rem; }
html.plain article h2 {
  position: static; width: auto; height: auto; margin: 0 0 1.1rem; padding: 0; overflow: visible; clip: auto; white-space: normal;
  grid-column: 1 / -1;
  font-size: 0.82rem; font-weight: 400; color: var(--faint); letter-spacing: 0.02em; text-transform: lowercase;
}
html.plain article[data-room="atrium"] h2 { display: none; }
html.plain article { scroll-margin-top: var(--header); }
html.plain .nav a[aria-current="page"] { color: var(--faint); text-decoration: none; }
@media (max-width: 760px) {
  .brand { gap: 0.7rem; }
  html.plain article, html.plain.js article { padding-left: 1.15rem; padding-right: 1.15rem; }
}

/* phones: roomier tap targets, no sideways scroll, lighter grain tile */
@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  body { background-attachment: scroll; }
  .top { background-attachment: scroll; }
  .stage { height: min(44vh, 420px); min-height: 260px; }
  .walk-in { font-size: 0.9rem; padding: 0.5rem 0.9rem; }
  .walkpad button { width: 48px; height: 48px; font-size: 1.1rem; }
  .card .chip { font-size: 0.8rem; }
  .card > p { font-size: 0.95rem; }
  .links { gap: 1.3rem; }
  .arcade-menu button { padding: 0.9rem 0.9rem; }
  .sheet { max-height: calc(100% - 1rem); width: calc(100% - 1rem); }
}
