:root {
  --ink: #1b1b1f;
  --ink-soft: #6b6870;
  --paper: #fbf8f3;
  --line: rgba(27, 27, 31, 0.12);
  --pill: rgba(255, 255, 255, 0.86);
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;   /* lives are played by holding a finger down: no iOS callout on a long press */
  overscroll-behavior: none;
}

#c {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  outline: none;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.28) 100%);
  opacity: 0;
  transition: opacity 1.2s ease;
  z-index: 2;
}
#vignette.on { opacity: 1; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}
#clock {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--pill);
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-variant-numeric: tabular-nums;
  transition: opacity 0.6s ease, transform 0.6s ease;
}
/* min-width: the widest reading ("48.8" is 2.13em in Fraunces, which has no tabular figures), so the pill never jitters */
#clock-time { font-family: var(--serif); font-weight: 600; font-size: 20px; min-width: 2.15em; text-align: right; }
.clock-label { font-size: 12px; color: var(--ink-soft); letter-spacing: 0.02em; }
#hud.fade #clock { opacity: 0; transform: translateY(-8px); }

/* Per-life counter pill (crumbs, good boys, …): the clock's look, top-left; centred under the clock on
   narrow screens. A life adds `<div class="hud-pill"><span class="num">0</span><span class="label">…</span></div>`
   to the body, toggles `.on`, and removes it on dispose. */
.hud-pill {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  z-index: 5;
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 8px 15px;
  border-radius: 999px;
  background: var(--pill);
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.hud-pill.on { opacity: 1; transform: none; }
.hud-pill .num { display: inline-block; font-family: var(--serif); font-weight: 600; font-size: clamp(17px, 4.4vw, 20px); text-align: right; }
.hud-pill .label { font-size: 12px; color: var(--ink-soft); letter-spacing: 0.02em; }
@media (max-width: 560px) {
  .hud-pill { top: calc(max(16px, env(safe-area-inset-top)) + 46px); left: 50%; padding: 5px 12px; transform: translate(-50%, -8px); }
  .hud-pill.on { transform: translate(-50%, 0); }
}

#hint {
  position: fixed;
  left: 50%;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 16px));
  transform: translate(-50%, 10px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--pill);
  box-shadow: 0 2px 14px rgba(0,0,0,0.1);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  z-index: 6;
}
#hint.show { opacity: 1; transform: translate(-50%, 0); }
#hint kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  margin: 0 2px;
  border-radius: 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  background: #fff;
  font-family: var(--sans);
  font-size: 13px;
  text-align: center;
}

#say {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translate(-50%, 6px);
  width: min(680px, calc(100vw - 32px));
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(20px, 3.4vw, 30px);
  line-height: 1.3;
  color: #fff;
  /* a tight dark edge plus a soft halo, so white narration still reads if it lands on a pale wall */
  text-shadow: 0 1px 2px rgba(0,0,0,0.45), 0 0 10px rgba(0,0,0,0.3), 0 1px 22px rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.9s ease, transform 0.9s ease;
  z-index: 6;
}
#say.show { opacity: 1; transform: translate(-50%, 0); }
#say.dark { color: var(--ink); text-shadow: 0 1px 14px rgba(255,255,255,0.7); }

#mute {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--pill);
  color: var(--ink);
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 20;
}
#mute .off { display: none; }
#mute.muted .on { display: none; }
#mute.muted .off { display: block; }

#white {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 1;
  pointer-events: none;
  z-index: 10;
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  text-align: center;
  z-index: 12;
  overflow-y: auto;
}

.logo {
  font-family: var(--serif);
  font-weight: 600;
  font-variation-settings: "SOFT" 100, "opsz" 144;
  font-size: clamp(84px, 18vw, 168px);
  letter-spacing: -0.035em;
  line-height: 0.9;
  margin: 0;
}
.logo.small { font-size: clamp(48px, 10vw, 72px); margin: 14px 0 18px; }
/* logo.svg: the wordmark plus a black cat whose tail curls into a 9. The alt text keeps the heading named "Fate". */
.logo img {
  display: block;
  margin: 0 auto;
  width: min(380px, 82vw, 52vh);   /* 52vh keeps it under a third of the height on short screens (aspect 1.65) */
  height: auto;
  -webkit-user-drag: none;
}
.logo.small img { width: min(168px, 40vw); }

.tagline {
  font-family: var(--serif);
  font-size: clamp(18px, 2.6vw, 22px);
  color: var(--ink-soft);
  margin: 14px 0 30px;
  text-wrap: balance; /* no lone "well." on a narrow phone */
}

.btn {
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 14px 34px;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04), 0 6px 20px rgba(0,0,0,0.07);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 1px 0 rgba(0,0,0,0.04), 0 10px 26px rgba(0,0,0,0.1); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.btn.ghost { background: transparent; box-shadow: none; }

.fineprint { margin-top: 22px; font-size: 13px; color: var(--ink-soft); }
.fineprint a { color: inherit; }

#title { background: transparent; }
#title .title-inner { transform: translateY(-6vh); }
#title.leaving { animation: fadeout 0.8s ease forwards; }

/* death card */
#card { background: #fff; }
.card-inner { max-width: 620px; width: 100%; }   /* wide enough that "You lived 29 seconds." stays on one line */
.card-life {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 18px;
}
.card-lived {
  font-family: var(--serif);
  font-weight: 600;
  font-variation-settings: "SOFT" 100;
  font-size: clamp(36px, 7vw, 56px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.card-as {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(20px, 3.6vw, 26px);
  color: var(--ink-soft);
  margin-top: 10px;
}
.card-cause {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  margin: 30px 0 4px;
  padding: 14px 24px;
  border-radius: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  font-size: 18px;
  font-weight: 500;
  text-wrap: balance;
}
.card-cause .label { font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft); }
.card-fact {
  font-size: 16px;
  line-height: 1.55;
  color: #3d3b42;
  margin: 22px auto 34px;
  max-width: 440px;
  text-wrap: pretty;   /* no one-word last line */
}
#card .card-inner > * { opacity: 0; transform: translateY(8px); }
#card.show .card-inner > * { animation: rise 0.7s ease forwards; }
#card.show .card-inner > *:nth-child(2) { animation-delay: 0.15s; }
#card.show .card-inner > *:nth-child(3) { animation-delay: 0.5s; }
#card.show .card-inner > *:nth-child(4) { animation-delay: 1.1s; }
#card.show .card-inner > *:nth-child(5) { animation-delay: 1.6s; }
#card.show .card-inner > *:nth-child(6) { animation-delay: 2.3s; }
#card.leaving { animation: fadeout 0.6s ease forwards; }

/* end screen */
#end { background: #fff; }
.end-inner { max-width: 560px; width: 100%; }
.end-kicker { font-family: var(--serif); font-style: italic; font-size: 20px; color: var(--ink-soft); margin: 0; }
.end-sum { font-size: 17px; line-height: 1.5; margin: 0 auto 22px; max-width: 460px; }
.end-list {
  list-style: none;
  padding: 0;
  margin: 0 auto 30px;
  max-width: 460px;
  text-align: left;
  border-top: 1px solid var(--line);
}
.end-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.end-list .who { font-weight: 600; }
.end-list .how { grid-column: 1 / 2; color: var(--ink-soft); font-size: 13px; }
.end-list .time { grid-row: 1 / 3; grid-column: 2; align-self: center; font-family: var(--serif); font-weight: 600; font-variant-numeric: tabular-nums; }
.end-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
/* Wide but short windows (a 1280×800 laptop): one line per life, so "Live again" isn't below the fold. */
@media (min-width: 640px) and (max-height: 940px) {
  .end-list { max-width: 560px; }
  .end-list li { grid-template-columns: 11.5em 1fr auto; align-items: baseline; padding: 8px 2px; }
  .end-list .how { grid-column: 2; grid-row: 1; }
  .end-list .time { grid-column: 3; grid-row: 1; }
  .end-sum { margin-bottom: 16px; }
  .end-list { margin-bottom: 22px; }
}
@media (min-width: 640px) and (max-height: 720px) {
  .logo.small { margin: 6px 0 10px; }
  .logo.small img { width: 124px; }
  #end .fineprint { margin-top: 12px; }
}
/* 960×600 and shorter: tighter still, so the buttons aren't cut off at the bottom */
@media (min-width: 640px) and (max-height: 640px) {
  #end { padding-top: 14px; padding-bottom: 14px; }
  .end-kicker { font-size: 18px; }
  .logo.small { margin: 4px 0 6px; }
  .logo.small img { width: 104px; }
  .end-sum { margin-bottom: 10px; }
  .end-list { margin-bottom: 14px; }
  .end-list li { padding: 5px 2px; }
  #end .fineprint { margin-top: 6px; }
}
#end .end-inner > * { opacity: 0; transform: translateY(8px); }
#end.show .end-inner > * { animation: rise 0.9s ease forwards; }
#end.show .end-inner > *:nth-child(2) { animation-delay: 1.4s; }
#end.show .end-inner > *:nth-child(3) { animation-delay: 2.2s; }
#end.show .end-inner > *:nth-child(4) { animation-delay: 2.8s; }
#end.show .end-inner > *:nth-child(5) { animation-delay: 3.9s; }
#end.show .end-inner > *:nth-child(6) { animation-delay: 4.3s; }
/* the lives come in one by one, like a roll call (ui.js sets --i on each row) */
#end .end-list li { opacity: 0; transform: translateY(6px); }
#end.show .end-list li { animation: rise 0.6s ease forwards; animation-delay: calc(2.8s + var(--i, 0) * 0.11s); }

@keyframes rise { to { opacity: 1; transform: none; } }
@keyframes fadeout { to { opacity: 0; } }

@media (max-width: 520px) {
  #clock { padding: 6px 13px; }
  #clock-time { font-size: 17px; }
  .clock-label { font-size: 11px; }
  /* long hints wrap onto a second line instead of being cut off with an ellipsis */
  #hint { font-size: 14px; white-space: normal; text-align: center; line-height: 1.5; border-radius: 20px; text-wrap: balance; width: max-content; }
  .card-cause { font-size: 16px; }
  .card-fact { font-size: 15px; }
  #end { padding-top: max(64px, calc(env(safe-area-inset-top) + 56px)); }   /* clear the mute button when the list overflows */
  /* compact, so "Live again" fits on a 390×844 phone without scrolling */
  .end-kicker { font-size: 17px; }
  .logo.small { margin: 8px 0 10px; }
  .logo.small img { width: 120px; }
  .end-sum { font-size: 15px; margin-bottom: 14px; }
  .end-list { margin-bottom: 16px; }
  .end-list li { padding: 6px 2px; font-size: 14px; }
  .end-list .how { font-size: 12px; }
  #end .fineprint { margin-top: 8px; }
}
/* short phones (375×667): tighter rows and a smaller logo, so the whole list and "Live again" fit without scrolling */
@media (max-width: 520px) and (max-height: 760px) {
  #end { padding-top: max(58px, calc(env(safe-area-inset-top) + 50px)); padding-bottom: 12px; }
  .end-kicker { font-size: 16px; }
  .logo.small { margin: 2px 0 6px; }
  .logo.small img { width: 96px; }
  .end-sum { font-size: 14px; line-height: 1.4; margin-bottom: 10px; }
  .end-list { margin-bottom: 12px; }
  .end-list li { padding: 3px 2px 4px; gap: 0 12px; line-height: 1.25; }
  .end-buttons .btn { padding: 11px 28px; font-size: 16px; }
  #end .fineprint { margin: 6px 0 0; }
}

/* short landscape windows: lift the title block so the fine print clears the nest */
@media (max-height: 720px) and (min-aspect-ratio: 1/1) {
  #title .title-inner { transform: translateY(-10vh); }
}
/* short phones (an iPhone SE is 320×568): a smaller logo and tighter spacing, so the fine print clears the eggs */
@media (max-height: 640px) and (max-aspect-ratio: 1/1) {
  #title .title-inner { transform: translateY(-12vh); }
  #title .logo img { width: min(240px, 70vw); }
  #title .tagline { margin: 10px 0 20px; }
  #title .fineprint { margin-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  #card.show .card-inner > *, #end.show .end-inner > *, #end.show .end-list li { animation-duration: 0.01s; }
}
