:root {
  --ink: #161311;
  --paper: #f4efe6;
  --muted: #5e584f;
  --line: rgba(22, 19, 17, 0.12);
  --red: #c4161c;
  --red-deep: #8d1016;
  --card: rgba(255, 252, 247, 0.9);
  --shadow: 0 18px 40px rgba(8, 6, 10, 0.22);
  --radius: 18px;
  --display: "Syne", sans-serif;
  --poster: "Bebas Neue", "Syne", sans-serif;
  --body: "Outfit", "Manrope", sans-serif;
  --serif: "Newsreader", Georgia, serif;
  --pad: clamp(1.25rem, 4vw, 2.5rem);
  --max: 1120px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.05rem;
  line-height: 1.55;
  background: #09070b;
  overflow-x: hidden;
}
main { flex: 1; display: flex; flex-direction: column; position: relative; z-index: 1; }
.world {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
body[data-theme="home"] { background: #0b0610; color: #f7f1ea; }
body[data-theme="problem"] { background: #050308; color: #f3e6d8; }
body[data-theme="mason"] { background: #2a0810; color: #1a0b08; }
body[data-theme="daniels"] { background: #14061f; color: #f7f4ff; }
body[data-theme="tws"] { background: #1a0610; color: #fff6f4; }
body[data-theme="tapes"] { background: #0b1018; color: #f6f1ea; }
body[data-theme="part"] { background: #120806; color: #f8f1e8; }
body[data-theme="zort"] { background: #1a0e08; color: #fff6ea; }
body[data-theme="yeo"] { background: #2a1608; color: #2a1208; }
body[data-theme="games"],
body[data-theme="stack"],
body[data-theme="beat"],
body[data-theme="willis"] { background: #0c0a12; color: #f6f1ea; }
body[data-theme="account"],
body[data-theme="admin"],
body[data-theme="legal"] { background: #0d0b10; color: #f4efe6; }

img { max-width: 100%; display: block; }
a { color: inherit; }
button, a, input, select { font: inherit; }
:focus-visible { outline: 2px solid #ffd166; outline-offset: 3px; }
.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: white;
  color: var(--ink);
  padding: 0.4rem 0.7rem;
  z-index: 40;
}
.skip:focus { top: 0.6rem; }

.cursor {
  position: fixed;
  left: 0;
  top: 0;
  width: 56px;
  height: 56px;
  margin: -6px 0 0 -6px;
  pointer-events: none;
  z-index: 50;
  display: none;
}
.cursor img { width: 56px; height: 56px; object-fit: contain; }
@media (pointer: fine) {
  body, a, button, input, select { cursor: none; }
  .cursor { display: block; }
}

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 4.25rem;
  padding: 0.75rem var(--pad);
  background: rgba(10, 8, 12, 0.72);
  border-bottom: 1px solid rgba(255, 241, 224, 0.12);
  backdrop-filter: blur(16px);
  color: #f6f1ea;
}
.brand {
  font-family: var(--display);
  font-weight: 800;
  text-decoration: none;
  letter-spacing: -0.03em;
  white-space: nowrap;
}
nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  margin-left: auto;
}
nav a {
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 700;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
nav a:hover { background: rgba(255, 209, 102, 0.12); transform: translateY(-1px); }
nav a[aria-current="page"] { background: #ffd166; color: #1a1208; }
.menu { display: none; }

.page:not([hidden]) {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2.5rem 0 3rem;
  animation: pageIn 0.55s ease;
}
.wrap { width: min(var(--max), calc(100% - var(--pad) * 2)); margin: 0 auto; }
.narrow { max-width: 44rem; }
.kicker {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #ffd166;
}
h1, h2 { font-family: var(--display); font-weight: 800; letter-spacing: -0.04em; line-height: 1.02; }
h1 { margin: 0 0 0.6rem; font-size: clamp(2.6rem, 6vw, 5rem); max-width: 16ch; text-wrap: balance; }
h2 { margin: 0 0 0.45rem; font-size: 1.3rem; }
.lead, .zort p, .chart-notes { max-width: 40rem; text-wrap: pretty; }
.scream {
  font-family: var(--poster);
  font-size: clamp(1.8rem, 5vw, 3.4rem);
  letter-spacing: 0.04em;
  color: #ff4d4d;
  text-shadow: 0 0 24px rgba(255, 40, 40, 0.45);
}
.problem-page h1, .problem-page .lead { color: #fff4e6; text-shadow: 0 6px 28px rgba(0,0,0,0.85); }
.home-page { position: relative; overflow: hidden; }
.home-bg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
.home-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(90deg, rgba(8, 12, 20, 0.86) 0%, rgba(8, 12, 20, 0.4) 46%, rgba(8, 12, 20, 0.06) 74%);
}
.home-page .wrap { position: relative; z-index: 2; }
.home-page .card { background: rgba(255, 248, 240, 0.94); color: var(--ink); }
.home-page .card p { color: #4e473f; }
.zort p { margin: 0.8rem 0; font-size: 1.12rem; }
.zort { max-width: 46rem; }
.zort .sub { margin: 0.4rem 0 1rem; font-family: var(--display); font-size: clamp(1.3rem, 3vw, 2rem); }
.chart-notes { margin: 0.8rem 0 0; padding-left: 1.1rem; color: #f4e8ff; font-size: 0.95rem; }
.chart-notes li + li { margin-top: 0.25rem; }
.plotline, .tick, .note-label, .axis-name { font-family: Manrope, sans-serif; }
.tick { font-size: 11px; fill: #d8c8f4; }
.note-label { font-size: 12px; font-weight: 700; fill: #ffd166; }
.axis-name { font-size: 12px; fill: #d8c8f4; }
.plotline { stroke: rgba(255, 255, 255, 0.16); }
.axis { stroke: #f6f1ea; }
.chart-scroll { overflow-x: auto; }
.chart-scroll svg { min-width: 920px; height: auto; }

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem; }
.btn, .menu, .auth-form button, .tape-close, .tape-chrome button, .cam-map button, .willis-controls button, .admin-list button {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0.7rem 1.2rem;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #ff3b3f 0%, #c4161c 48%, #8d1016 100%);
  color: white;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-decoration: none;
  box-shadow: 0 10px 0 #5a0b10, 0 16px 28px rgba(196, 22, 28, 0.32);
  transform: translateY(0);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.2s ease;
}
.btn::after, .menu::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 -40%;
  width: 28%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.28), transparent);
  transform: skewX(-18deg);
  animation: shine 3.4s ease-in-out infinite;
}
.btn:hover, nav a:hover, .tape:hover, .brand:hover { filter: brightness(1.08); }
.btn:active { box-shadow: 0 4px 0 #5a0b10; }
.btn, nav a, .tape, .brand { transition: transform 0.08s linear, filter 0.2s ease, background 0.2s ease; }
.btn-ghost, .menu {
  background: rgba(255, 248, 240, 0.08);
  color: inherit;
  border: 1px solid rgba(255, 248, 240, 0.28);
  box-shadow: 0 8px 0 rgba(0,0,0,0.25);
}
.btn-ghost::after { opacity: 0.4; }
.home-copy .btn-ghost { color: #fff8f2; }

.panel, .chart, .card, .memorial, .stack-panel, .end-card, .prompt-card, .greet-card {
  background: var(--card);
  border: 1px solid rgba(255, 248, 240, 0.16);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
.grid.four { grid-template-columns: repeat(4, 1fr); }
.card {
  padding: 1.35rem;
  min-height: 11rem;
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}
.card a { text-decoration: none; display: block; height: 100%; }
.card:hover { transform: translateY(-6px) rotate(-0.4deg); box-shadow: 0 22px 40px rgba(0,0,0,0.28); }
.card p { margin: 0; color: var(--muted); }

.hero, .split {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 2rem;
  align-items: center;
  margin-bottom: 2rem;
}
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.8rem; }
.steps li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.8rem;
  align-items: center;
  padding: 1rem 1.1rem;
  background: rgba(255, 248, 240, 0.92);
  border-radius: var(--radius);
  color: #161311;
}
.steps span { font-family: var(--display); color: var(--red); font-size: 1.3rem; }
.steps p { margin: 0; }
.line { margin: 0.4rem 0; font-family: var(--display); font-size: clamp(1.4rem, 3vw, 2rem); }
.line.dim { color: #ffe3f2; font-family: var(--body); font-size: 1.2rem; font-weight: 600; }
.chart { padding: 1.25rem; background: rgba(255, 248, 255, 0.12); color: #f7f4ff; }
.chart figcaption { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.5rem; }
.chart strong { font-family: var(--display); font-size: 2rem; color: #ffd166; }
.col {
  fill: #ff4d6d;
  transform-box: fill-box;
  transform-origin: bottom;
  transform: scaleY(0.2);
  animation: grow 0.8s ease forwards;
}

.film-layout { display: grid; gap: 1.25rem; justify-items: start; }
.screen {
  position: relative;
  width: min(920px, 100%);
  aspect-ratio: 16 / 9;
  border: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 18px;
  background: #081018;
  box-shadow: var(--shadow);
}
.screen canvas, #cliff-canvas { width: 100%; height: 100%; display: block; background: #081018; }
.screen.is-idle #cliff-canvas { filter: grayscale(0.7) brightness(0.42) contrast(1.15); }
.arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  margin: -28px 0 0 -18px;
  border-style: solid;
  border-width: 28px 0 28px 46px;
  border-color: transparent transparent transparent rgba(255, 255, 255, 0.92);
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.35));
}
.screen:not(.is-idle) .arrow { display: none; }

.tape-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.tape {
  text-align: left;
  background: linear-gradient(180deg, rgba(255,248,240,0.98), rgba(255,236,214,0.94));
  color: #161311;
  border: 0;
  border-radius: 16px;
  padding: 1.3rem;
  min-height: 10rem;
  box-shadow: var(--shadow);
  transition: transform 0.22s ease;
}
.tape:hover { transform: translateY(-6px) rotate(-0.3deg); }
.tape span { display: block; color: #c4161c; font-weight: 800; letter-spacing: 0.14em; }
.tape strong { display: block; font-family: var(--display); font-size: 1.5rem; margin: 0.4rem 0; }
.tape em { font-style: normal; color: #5e564c; display: block; margin-bottom: 0.8rem; }

.tape-player {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(4, 5, 8, 0.92);
  display: grid;
  place-items: center;
  padding: 1.2rem;
}
.tape-player[hidden] { display: none; }
.tape-stage {
  position: relative;
  width: min(1100px, 100%);
  aspect-ratio: 3 / 2;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,0.55);
}
.tape-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}
.tape-chrome {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.8rem 0.75rem;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,0.78));
  color: #f6f1ea;
}
.tape-chrome button {
  min-height: 2.4rem;
  min-width: 4.6rem;
  padding: 0.35rem 0.8rem;
  box-shadow: 0 4px 0 #5a0b10;
}
.tape-chrome input[type="range"] { flex: 1; accent-color: #ffd166; }
.tape-chrome span { font-variant-numeric: tabular-nums; font-size: 0.85rem; min-width: 6.4rem; }
.tape-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  min-height: 2.4rem;
}

.leave-title { font-family: var(--display); font-size: clamp(2rem, 5vw, 3.4rem); margin: 1.6rem 0 0.3rem; }
.leave-count { font-variant-numeric: tabular-nums; font-size: clamp(1.5rem, 4vw, 2.4rem); }

.stack-wrap { width: min(560px, calc(100% - var(--pad) * 2)); }
.stack-panel { background: #11141a; color: #f6f1ea; padding: 1rem 1rem 0.85rem; }
.stack-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.stack-head h1 { font-size: clamp(1.6rem, 4vw, 2rem); max-width: none; margin: 0; }
.stack-head p, .stack-scores p, .stack-help, .stack-float { margin: 0; }
.stack-scores { text-align: right; font-size: 0.92rem; }
.stack-float { min-height: 1.3rem; margin-top: 0.45rem; text-align: center; color: #ffd166; }
.stack-stage {
  position: relative;
  overflow: hidden;
  width: min(100%, calc(70vh * 480 / 680));
  margin-inline: auto;
  touch-action: none;
  border-radius: 14px;
  background: #0d1624;
}
.stack-stage canvas { width: 100%; height: auto; display: block; touch-action: none; }
.stack-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  background: rgba(8, 10, 16, 0.55);
  padding: 1rem;
}
.stack-overlay .ready { font-family: var(--display); font-size: 2rem; margin: 0 0 0.75rem; }
.stack-overlay .mark { margin: 0 0 0.2rem; letter-spacing: 0.08em; font-size: 0.8rem; font-weight: 700; }
.stack-help { margin-top: 0.65rem; font-size: 0.85rem; text-align: center; color: #c8c0b4; }
.board {
  list-style: none;
  margin: 0.8rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.25rem;
}
.board li {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0.5rem;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  font-size: 0.9rem;
}

.game-shell canvas { width: min(960px, 100%); height: auto; background: #111; border-radius: 12px; display: block; }
.arcade { display: grid; gap: 0.7rem; }
.hud-row { display: flex; flex-wrap: wrap; gap: 0.7rem 1.2rem; align-items: center; }
.health { height: 10px; background: #2a1c22; border-radius: 99px; overflow: hidden; min-width: 8rem; }
.health span { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ff4d6d, #ffd166); }
.cam-map, .willis-controls { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.cam-map button, .willis-controls button, .admin-list button {
  min-height: 2.3rem;
  padding: 0.3rem 0.7rem;
  box-shadow: 0 4px 0 #5a0b10;
}
.end-card, .prompt-card { padding: 1.2rem; color: #161311; }
.gain-box { position: relative; min-height: 1.4rem; }
.gain {
  margin: 0;
  font-weight: 800;
  color: #ffd166;
  animation: gain 0.75s ease forwards;
}
@keyframes gain { to { transform: translateY(-22px); opacity: 0; } }

.memorial { max-width: 40rem; margin: 4vh auto; padding: 3rem 2rem; text-align: left; color: #2a1208; }
.memorial h1 { font-family: var(--serif); font-weight: 500; }
.memorial p { font-family: var(--serif); font-size: 1.45rem; margin: 0.7rem 0; }
.dear { font-style: italic; }

.auth-form { display: grid; gap: 0.75rem; margin-top: 1rem; }
.auth-form label, .search { display: grid; gap: 0.3rem; font-weight: 700; font-size: 0.9rem; }
.auth-form input, .search input {
  min-height: 2.8rem;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  border: 1px solid rgba(255,248,240,0.2);
  background: rgba(8,8,12,0.45);
  color: inherit;
}
.err { color: #ff8a8a; min-height: 1.2rem; margin: 0; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.admin-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; }
.admin-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: center;
  padding: 0.55rem 0.7rem;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
}

.greet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(4, 4, 8, 0.72);
  backdrop-filter: blur(10px);
}
.greet[hidden] { display: none; }
.greet-card {
  width: min(28rem, 100%);
  padding: 1.6rem 1.4rem 1.3rem;
  color: #161311;
}
.greet-card h2 { font-size: 2rem; }
.greet-card .kicker { color: #c4161c; }
.greet-card .btn-ghost { color: #161311; border-color: rgba(22,19,17,0.2); width: 100%; margin-top: 0.7rem; }

footer {
  position: relative;
  z-index: 1;
  background: #0a0809;
  color: #c8c0b4;
  text-align: center;
  padding: 0.85rem 1rem 1rem;
}
footer p { margin: 0 auto; max-width: 36rem; font-size: 0.78rem; line-height: 1.45; }
.cookie-bar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: center;
  padding: 0.7rem 1rem;
  background: #14110f;
  color: #f4efe6;
}
.cookie-bar[hidden] { display: none; }
.legal h2 { margin-top: 1.1rem; font-size: 1.15rem; }
.legal p { margin: 0.3rem 0 0; max-width: 40rem; }

.rise { animation: rise 0.6s ease both; }
.grid .rise:nth-child(2) { animation-delay: 0.06s; }
.grid .rise:nth-child(3) { animation-delay: 0.12s; }
.grid .rise:nth-child(4) { animation-delay: 0.18s; }

@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes pageIn { from { opacity: 0; filter: blur(6px); } to { opacity: 1; filter: none; } }
@keyframes grow { from { transform: scaleY(0.15); } to { transform: scaleY(1); } }
@keyframes shine {
  0%, 55% { left: -40%; }
  80%, 100% { left: 130%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 1024px) {
  .grid.four, .admin-grid { grid-template-columns: 1fr 1fr; }
  .hero, .split { grid-template-columns: 1fr; }
}
.tws-page { padding: 0; justify-content: stretch; }
#tws-burst { width: min(1100px, calc(100% - 2rem)); height: min(74vh, 760px); margin: 1rem auto; display: block; border-radius: 18px; background: #1a0610; }
@media (max-width: 768px) {
  nav { flex-wrap: wrap; }
  nav a { padding: 0.45rem 0.4rem; font-size: 0.95rem; }
  .bar { flex-wrap: wrap; }
  .tape-stage { aspect-ratio: 3 / 2; }
  .tape-chrome { flex-wrap: wrap; }
}
@media (max-width: 480px) {
  .grid.four, .admin-grid { grid-template-columns: 1fr; }
  h1 { font-size: 2.4rem; }
  .card { min-height: 0; }
}
