/* Perceived Contrast Study.
 *
 * The page chrome follows earendil.com (warm paper, Departure Mono for UI,
 * PlantinNow italics for display). Trial screens deliberately do NOT: they
 * are plain neutral greys with no texture, tint, shadow, radius or hover,
 * identical in light and dark mode, so nothing but the stimuli varies.
 */

@font-face {
  font-family: 'Departure Mono';
  src: url('/fonts/DepartureMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'PlantinNow';
  src: url('/fonts/PlantinNowVariable-Upright.woff2') format('woff2');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'PlantinNow';
  src: url('/fonts/PlantinNowVariable-Italic.woff2') format('woff2');
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
}
/* Text trials use Inter 600 at 24px. JS waits for this face before any
   text trial is shown, so a fallback font never appears as a stimulus. */
@font-face {
  font-family: 'Inter Stimulus';
  src: url('/fonts/Inter-600.woff2') format('woff2');
  font-weight: 600;
  font-display: block;
}

:root {
  color-scheme: light dark;
  --mono: 'Departure Mono', 'SFMono-Regular', ui-monospace, monospace;
  --serif: 'PlantinNow', 'Plantin MT Pro', Georgia, serif;
  --paper: #faf9f6;
  --ink: #353431;
  --muted: rgba(25, 24, 22, 0.6);
  --faint: rgba(25, 24, 22, 0.35);
  --line: rgba(39, 37, 34, 0.18);
  --bar: rgba(25, 24, 22, 0.14);
  --star: url('/cursor-dark.svg');
  --text-sm: 0.8125rem;
  --text-ui: 0.9375rem;
  --text-reading: clamp(1.125rem, 1.05rem + 0.375vw, 1.25rem);
  --text-hero: clamp(1.75rem, 1.2rem + 2vw, 2.75rem);
  --ease: cubic-bezier(0.333333, 0, 0.666667, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #2e2d2b;
    --ink: #fff;
    --muted: rgba(240, 240, 240, 0.6);
    --faint: rgba(240, 240, 240, 0.3);
    --line: rgba(244, 242, 238, 0.18);
    --bar: rgba(240, 240, 240, 0.16);
    --star: url('/cursor-light.svg');
  }
}

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

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: var(--text-ui);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body.is-stage { background: rgb(118, 118, 118); overflow: hidden; }
body.is-blackout { background: #000; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

a { color: inherit; }

kbd {
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--faint);
}

@media (pointer: coarse) {
  kbd { display: none; }
}

[hidden] { display: none !important; }

/* --- Page screens --------------------------------------------------------- */

.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: max(48px, 8vh) clamp(24px, 6vw, 75px);
  animation: page-in 600ms var(--ease) both;
}

@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.surface {
  width: min(100%, 640px);
  margin: 0 auto;
}

.emblem {
  display: block;
  width: 22px;
  height: 40px;
  margin-bottom: 32px;
  fill: currentColor;
  opacity: 0.9;
}

.title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: var(--text-hero);
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin-bottom: 0.7em;
  text-wrap: balance;
}

.lede {
  font-family: var(--serif);
  font-size: var(--text-reading);
  line-height: 1.55;
  margin-bottom: 0.9em;
  text-wrap: pretty;
}

.fine {
  color: var(--muted);
  font-size: var(--text-sm);
  margin-top: 1.6em;
}

.step {
  color: var(--muted);
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 1.2em;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 36px;
  margin-top: 2em;
}

/* Text actions in the earendil.com style: uppercase mono with a dotted
   underline and the spinning star on hover. */
.action {
  position: relative;
  padding: 6px 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: var(--text-ui);
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.action.small { font-size: var(--text-sm); padding: 0; margin-left: 0.6em; }
.action::after {
  content: "";
  width: 15px;
  height: 15px;
  background: var(--star) center/contain no-repeat;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.action.small::after { display: none; }
.action:is(:hover, :focus-visible) {
  text-decoration: underline dotted;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.2em;
  outline: none;
}
.action:is(:hover, :focus-visible)::after {
  opacity: 1;
  animation: spin 1.15s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.byline {
  width: min(100%, 640px);
  margin: 64px auto 0;
  color: var(--muted);
  font-size: var(--text-sm);
}
.byline a { text-decoration: none; }
.byline a:hover { text-decoration: underline dotted; }

/* --- Choices (room light) ------------------------------------------------- */

.choices {
  list-style: none;
  margin-top: 1.8em;
  border-top: 1px dotted var(--line);
}
.choice {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0;
  border-bottom: 1px dotted var(--line);
  text-align: left;
  transition: padding 0.25s var(--ease);
}
.choice em {
  font-family: var(--serif);
  font-size: var(--text-reading);
}
.choice:is(:hover, :focus-visible) { padding-left: 10px; outline: none; }
.choice:is(:hover, :focus-visible) em {
  text-decoration: underline dotted;
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.14em;
}
.choice.is-picked em::after {
  content: "";
  display: inline-block;
  width: 15px;
  height: 15px;
  margin-left: 10px;
  background: var(--star) center/contain no-repeat;
  animation: spin 1.15s linear infinite;
  vertical-align: -2px;
}

/* --- Screen check (near-black on black) ------------------------------------ */

.blackout {
  min-height: 100vh;
  min-height: 100dvh;
  background: #000;
  color: #6b6b6b;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  animation: page-in 600ms var(--ease) both;
}
.check-wrap {
  width: min(100%, 640px);
  text-align: center;
}
.blackout .step { color: #555; }
.check-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
  color: #8a8a8a;
  margin-bottom: 40px;
}
.near-blacks {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(20px, 5vw, 44px);
  width: min(100%, 440px);
  margin: 0 auto 48px;
}
.near-blacks span {
  aspect-ratio: 1;
}
.counts {
  display: flex;
  justify-content: center;
  gap: clamp(4px, 1.5vw, 8px);
}
.counts button {
  flex: 0 1 44px;
  min-width: 0;
  height: 44px;
  border: 1px solid #2a2a2a;
  color: #8a8a8a;
  transition: border-color 0.2s, color 0.2s;
}
.counts button:is(:hover, :focus-visible) {
  border-color: #777;
  color: #ccc;
  outline: none;
}
.check-hint {
  margin-top: 28px;
  font-size: var(--text-sm);
  color: #4d4d4d;
}

/* --- Trial stage ------------------------------------------------------------
   Neutral sRGB 118 frame, 20px around the edges and between the cards. */

.stage {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: 20px 1fr;
  gap: 12px;
  padding: 16px 20px 20px;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: rgb(118, 118, 118);
  color: rgb(58, 58, 58);
  -webkit-user-select: none;
  user-select: none;
  forced-color-adjust: none;
}
.stage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  font-size: var(--text-sm);
  line-height: 20px;
  white-space: nowrap;
  overflow: hidden;
}
.question { overflow: hidden; text-overflow: ellipsis; }
.counter { font-variant-numeric: tabular-nums; }
.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  min-height: 0;
}
@media (orientation: portrait) {
  .cards { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}
.card {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: 0;
  outline: none;
  cursor: pointer;
}
.patch {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--patch, 120px);
  height: var(--patch, 120px);
  transform: translate(-50%, -50%);
}
.card .word {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Inter Stimulus', sans-serif;
  font-weight: 600;
  font-size: 24px;
  line-height: 1;
  letter-spacing: 0;
  -webkit-font-smoothing: auto;
}
.stage.is-blank .cards { visibility: hidden; }

/* --- Results ------------------------------------------------------------------ */

.results { margin-top: 2.2em; }
.result {
  padding: 22px 0 24px;
  border-top: 1px dotted var(--line);
}
.result h3 {
  font-weight: 400;
  font-size: var(--text-sm);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.6em;
}
.result-line {
  font-family: var(--serif);
  font-size: var(--text-reading);
  line-height: 1.5;
  text-wrap: pretty;
}
.result-note {
  color: var(--muted);
  font-size: var(--text-sm);
  margin-top: 0.8em;
}
.result-count { margin-top: 0.4em; }

.histogram {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  align-items: end;
  height: 72px;
  margin-top: 18px;
}
.histogram .col {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  gap: 4px;
  font-size: 0.6875rem;
  color: var(--faint);
}
.histogram .bar {
  width: 100%;
  background: var(--bar);
  min-height: 2px;
  transform-origin: bottom;
  animation: grow 900ms var(--ease) both;
}
.histogram .col.is-you { color: var(--ink); }
.histogram .col.is-you .bar { background: var(--ink); }
@keyframes grow { from { transform: scaleY(0); } }

.metrics {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: var(--text-sm);
}
.metrics th {
  font-weight: 400;
  color: var(--muted);
  text-align: left;
  padding: 0 0 6px;
}
.metrics td {
  padding: 7px 0;
  border-top: 1px dotted var(--line);
  vertical-align: middle;
}
.metrics td:first-child { width: 40%; padding-right: 12px; }
.metrics td:not(:first-child) { width: 30%; }
.metrics tr.is-top td:first-child { font-family: var(--serif); font-style: italic; font-size: 1.05em; }
.meter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 14px;
}
.meter i {
  display: block;
  flex: 1;
  height: 6px;
  background: var(--bar);
  position: relative;
}
.meter i b {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--ink);
  transform-origin: left;
  animation: grow-x 900ms var(--ease) both;
}
.meter.others i b { background: var(--faint); }
.meter span { min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; }
@keyframes grow-x { from { transform: scaleX(0); } }

@media (max-width: 520px) {
  .metrics td:first-child { width: 36%; }
  .meter { padding-right: 6px; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
