/* Layout: full-bleed canvas world; HUD pinned to the corners; overlays centred over the game. */
:root {
  --night: #0b0f26;
  --panel: rgba(11, 15, 38, 0.82);
  --ink: #eef1ff;
  --muted: #a9b0d6;
  --star: #ffd23f;
  --go: #52e07a;
  --warn: #ffab3d;
  --display: "Press Start 2P", "Courier New", monospace;
  --body: "VT323", "Courier New", monospace;
  color-scheme: dark;
}

[hidden] { display: none !important; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  margin: 0;
  background: var(--night);
  color: var(--ink);
  font-family: var(--body);
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.hud {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}
.hud-block { display: grid; gap: 6px; }
.alt {
  font-family: var(--display);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  text-shadow: 2px 2px 0 var(--night);
}
.layer {
  font-size: 20px;
  color: var(--muted);
  text-shadow: 2px 2px 0 var(--night);
}
.stars {
  transform-origin: right center;
  font-family: var(--display);
  font-size: 14px;
  color: var(--star);
  text-align: right;
  text-shadow: 2px 2px 0 var(--night);
  font-variant-numeric: tabular-nums;
}
.toggles { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.stars.pop { animation: starpop 0.35s ease-out; }
@keyframes starpop { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
.hud button {
  pointer-events: auto;
  justify-self: end;
  font-family: var(--display);
  font-size: 9px;
  letter-spacing: 0.05em;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--muted);
  padding: 6px 8px;
  cursor: pointer;
}
.hud button:focus-visible, .overlay button:focus-visible, .pad button:focus-visible {
  outline: 3px solid var(--star);
  outline-offset: 2px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  transform: translateX(-50%);
  max-width: min(440px, calc(100% - 32px));
  padding: 8px 14px;
  background: var(--panel);
  border: 2px solid var(--star);
  font-size: 22px;
  line-height: 1.1;
  text-align: center;
  text-wrap: balance;
  pointer-events: none;
  transition: opacity 0.4s;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  /* Centred when it fits; when it's taller than the screen it starts at the
     top and scrolls (centring would push its top out of reach) */
  place-items: start center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(11, 15, 38, 0.45);
}
.overlay > .card { margin-block: auto; }
.card {
  max-width: 460px;
  width: 100%;
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.5);
  padding: 22px 22px 20px;
  display: grid;
  gap: 14px;
}
.card h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(16px, 5vw, 24px);
  line-height: 1.35;
  text-wrap: balance;
}
.card h1 span { color: var(--star); }
.card p { margin: 0; font-size: 22px; line-height: 1.15; color: var(--ink); }
.card .keys { color: var(--muted); }
.card kbd {
  font-family: var(--display);
  font-size: 10px;
  padding: 2px 5px;
  border: 2px solid var(--muted);
  color: var(--ink);
}
.card .go { color: var(--go); }
.card button {
  justify-self: start;
  font-family: var(--display);
  font-size: 13px;
  padding: 12px 16px;
  color: var(--night);
  background: var(--star);
  border: 0;
  box-shadow: 4px 4px 0 var(--ink);
  cursor: pointer;
}
.card button:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }

.pad {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  display: none;
  justify-content: space-between;
  gap: 12px;
}
.pad button {
  width: 72px;
  height: 72px;
  font-family: var(--display);
  font-size: 18px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--muted);
  touch-action: none;
}
.hud button[aria-pressed="false"] { color: var(--muted); border-style: dashed; }
.pad button.on { border-color: var(--star); color: var(--star); }
/* Intro and menu entrance */
body.intro .hud, body.intro .toast { opacity: 0; pointer-events: none; }
.hud { transition: opacity 0.6s; }
.overlay.fade-in { animation: fadein 0.8s ease-out both; }
.overlay.fade-in .card { animation: cardin 0.8s cubic-bezier(0.3, 1.4, 0.5, 1) both; }
@keyframes fadein { from { opacity: 0; } }
@keyframes cardin { from { transform: translateY(40px) scale(0.96); } }
/* Stars streaming past behind the menu card */
#title .card { position: relative; overflow: hidden; isolation: isolate; }
#title .card::before {
  content: ""; position: absolute; inset: -50%; z-index: -1; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.8) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 60% 70%, rgba(190,230,255,0.8) 50%, transparent 51%),
    radial-gradient(1px 1px at 80% 10%, rgba(255,255,255,0.6) 50%, transparent 51%),
    radial-gradient(2px 2px at 30% 85%, rgba(255,230,160,0.7) 50%, transparent 51%),
    radial-gradient(1px 1px at 45% 45%, rgba(255,255,255,0.7) 50%, transparent 51%);
  background-size: 180px 180px, 260px 260px, 140px 140px, 320px 320px, 210px 210px;
  animation: starrush 6s linear infinite;
}
@keyframes starrush { to { background-position: -180px 180px, -260px 260px, -140px 140px, -320px 320px, -210px 210px; } }

/* Title logo: each letter of SUPERTRAMP takes its turn on the trampoline */
.card h1.logo span { color: inherit; }
.card h1.logo .logo-top { color: #8fd0ff; }
.card h1.logo .logo-top i { color: var(--star); }
.card h1.logo .logo-main { color: var(--star); }
.card h1.logo .logo-main span:nth-child(n+6) { color: #eef1ff; }
.card h1.logo .logo-tag { color: var(--muted); font-weight: normal; }
.card h1.logo .logo-top { font-weight: normal; }
.card .geom-word { color: #6dff7a; }
#title .card { gap: 12px; }
#title .card p { font-size: 20px; }
@media (max-width: 480px) { #title .card p { font-size: 17px; } #title .card { gap: 10px; } .logo-tag { font-size: 16px; } }
@media (pointer: coarse) { #title .card .keys { display: none; } }
.card h1.logo { display: grid; justify-items: center; gap: 8px; margin: 0 0 4px; text-align: center; }
.logo-top { font-family: var(--display); font-size: 11px; letter-spacing: 0.5em; color: #8fd0ff; padding-left: 0.5em; }
.logo-top i { font-style: normal; color: var(--star); display: inline-block; animation: twinkle 1.6s ease-in-out infinite; }
.logo-top i:last-child { animation-delay: 0.8s; }
.logo-main { position: relative; display: flex; justify-content: center; font-family: var(--display); font-size: clamp(22px, 7.4vw, 36px); line-height: 1; color: var(--star); padding-top: 66px; }
.logo-main span {
  display: inline-block;
  transform-origin: 50% 100%;
  text-shadow: 2px 2px 0 #e0433b, 4px 4px 0 #1b1530, 5px 5px 0 rgba(0, 0, 0, 0.4);
  animation: dropin 0.7s cubic-bezier(0.3, 1.6, 0.5, 1) backwards;
  animation-delay: calc(0.2s + var(--i) * 0.07s);
}
/* A letter the tramp just landed on */
.card h1.logo .logo-main span.squash { animation: squash 0.5s ease-out; color: #6dff7a; }
#logo-tramp { position: absolute; left: 0; top: 0; width: 36px; height: 48px; image-rendering: pixelated; pointer-events: none; }
.logo-tag { font-family: var(--body); font-size: 19px; color: var(--muted); }
.press-start { margin: 0; text-align: center; font-family: var(--display); font-size: 11px; letter-spacing: 0.12em; color: var(--star); animation: blink 1.1s steps(2, start) infinite; }
.press-start .ps-keys { display: inline; }
.press-start .ps-touch { display: none; }
@media (pointer: coarse) { .press-start .ps-keys { display: none; } .press-start .ps-touch { display: inline; } }
@keyframes blink { to { visibility: hidden; } }
@keyframes dropin {
  0% { transform: translateY(-80px) scale(1, 1.3); opacity: 0; }
  60% { transform: translateY(0) scale(1.25, 0.7); opacity: 1; }
  80% { transform: translateY(-6px) scale(0.95, 1.08); }
  100% { transform: translateY(0) scale(1, 1); }
}
@keyframes squash {
  0% { transform: scale(1.35, 0.6); }
  35% { transform: translateY(-8px) scale(0.9, 1.15); }
  65% { transform: translateY(0) scale(1.08, 0.92); }
  100% { transform: none; }
}
@keyframes twinkle { 0%, 100% { opacity: 1; transform: scale(1) rotate(0); } 50% { opacity: 0.35; transform: scale(0.7) rotate(45deg); } }
/* The title's small character animations stay on even with reduced motion; screen shake and speed lines are what that setting turns off. */

/* Score and multiplier (Geometry Wars style) */
.scoreline { display: flex; align-items: baseline; gap: 10px; text-shadow: 2px 2px 0 var(--night); }
.score { font-family: var(--display); font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; }
.mult { font-family: var(--display); font-size: 16px; color: #6dff7a; display: inline-block; transform-origin: left center; }
.mult.bump { animation: multbump 0.3s ease-out; }
@keyframes multbump { 0% { transform: scale(1); } 40% { transform: scale(1.5); } 100% { transform: scale(1); } }
.card .won-score { font-family: var(--display); font-size: 26px; color: var(--ink); }
.card .won-score b { font-size: 10px; font-weight: normal; color: var(--go); vertical-align: middle; }
.title-board { display: grid; gap: 6px; }
.tb-head { font-family: var(--display); font-size: 10px; letter-spacing: 0.06em; color: #6dff7a; text-transform: uppercase; }
.board-list.compact li { font-size: 19px; padding: 0 6px; }

/* Mode picker */
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.card .modes .mode {
  display: grid; gap: 6px; align-content: start; text-align: left;
  padding: 12px; min-width: 0;
  font-family: var(--body);
  color: var(--night); background: var(--star);
  box-shadow: 4px 4px 0 var(--ink);
}
.card .modes .mode.uber { color: var(--ink); background: #c7362f; }
.card .modes .mode.last { outline: 3px dashed var(--ink); outline-offset: 3px; }
.mode .mode-name { font-family: var(--display); font-size: 12px; }
.mode .mode-desc { font-size: 18px; line-height: 1.05; }
.mode .mode-best { font-size: 16px; line-height: 1.1; opacity: 0.85; }
.mode .mode-best b { font-weight: normal; text-decoration: underline; }
.card .won-mode { font-family: var(--display); font-size: 10px; letter-spacing: 0.08em; color: var(--muted); text-transform: uppercase; }
.won-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.card .won-actions .secondary { color: var(--ink); background: transparent; border: 3px solid var(--ink); box-shadow: none; }

/* Scoreboard */
.card #open-board { justify-self: start; }
.card .secondary { color: var(--ink); background: transparent; border: 3px solid var(--ink); box-shadow: none; }
.board-where { color: var(--muted); }
.tabs { display: flex; gap: 8px; }
.card .tabs .tab { font-size: 10px; padding: 8px 10px; color: var(--muted); background: transparent; border: 2px dashed var(--muted); box-shadow: none; }
.card .tabs .tab[aria-selected="true"] { color: var(--night); background: var(--star); border: 2px solid var(--star); }
.board-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; max-height: 50vh; overflow-y: auto; }
.board-list li { display: grid; grid-template-columns: 2.2em minmax(0, 1fr) auto auto; gap: 10px; align-items: baseline; font-size: 21px; padding: 2px 6px; font-variant-numeric: tabular-nums; }
.board-list li.me { background: rgba(255, 210, 63, 0.15); outline: 2px solid var(--star); }
.board-list .rank { font-family: var(--display); font-size: 10px; color: var(--star); }
.board-list .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .stars-col { color: var(--star); }
.board-list li.note { display: block; color: var(--muted); }
.post { display: grid; gap: 6px; }
.post label { font-size: 19px; color: var(--muted); }
.post-row { display: flex; gap: 8px; flex-wrap: wrap; }
.post-row input {
  -webkit-user-select: text; user-select: text; touch-action: manipulation;
  flex: 1 1 10em; min-width: 0;
  font-family: var(--body); font-size: 22px;
  color: var(--ink); background: var(--night);
  border: 2px solid var(--muted); padding: 6px 8px;
}
.post-row input:focus-visible { outline: 3px solid var(--star); outline-offset: 1px; }
.card .post-row button { padding: 8px 12px; font-size: 11px; }
.card .post-status { color: var(--go); }
.card .skip { justify-self: start; padding: 0; font-family: var(--body); font-size: 17px; color: var(--muted); background: none; border: 0; box-shadow: none; text-decoration: underline; }
.card .post .linkish { justify-self: start; padding: 0; font-family: var(--body); font-size: 18px; color: var(--muted); background: none; border: 0; box-shadow: none; text-decoration: underline; }

/* Records and medals */
.card .bests { font-size: 19px; color: var(--muted); }
.card .bests b { color: var(--star); font-weight: normal; }
.medals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.medal { display: grid; justify-items: center; align-content: start; gap: 4px; text-align: center; min-width: 0; }
.medal .disc {
  width: 34px; height: 34px;
  background: var(--medal, transparent);
  border: 3px solid var(--medal-edge, var(--muted));
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
}
.medal.none .disc { border-style: dashed; box-shadow: none; clip-path: none; border-radius: 50%; }
.medal.gold { --medal: #ffd23f; --medal-edge: #fff1a8; }
.medal.silver { --medal: #cfd6e6; --medal-edge: #ffffff; }
.medal.bronze { --medal: #d08a4a; --medal-edge: #f1b27a; }
.medal .m-label { font-family: var(--display); font-size: 9px; letter-spacing: 0.08em; color: var(--muted); text-transform: uppercase; }
.medal .m-value { font-size: 22px; font-variant-numeric: tabular-nums; }
.medal .m-value b { display: block; font-family: var(--display); font-size: 8px; font-weight: normal; color: var(--go); }
.medal .m-hint { font-size: 16px; color: var(--muted); line-height: 1; }

@media (pointer: coarse) {
  body.playing .pad { display: flex; }
  .toast { bottom: calc(env(safe-area-inset-bottom, 0px) + 104px); font-size: 19px; }
}
@media (max-width: 480px) {
  .card { padding: 18px 16px 16px; gap: 10px; }
  .card p { font-size: 19px; }
  .alt { font-size: 14px; }
  .layer { font-size: 18px; }
}

/* Short screens: phones in landscape */
@media (max-height: 500px) {
  .hud { top: calc(env(safe-area-inset-top, 0px) + 8px); left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); }
  .alt { font-size: 13px; }
  .layer { font-size: 17px; }
  .score { font-size: 15px; }
  .mult { font-size: 12px; }
  .stars { font-size: 12px; }
  .hud button { font-size: 8px; padding: 5px 6px; }
  .pad { left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(env(safe-area-inset-bottom, 0px) + 10px); }
  .pad button { width: 58px; height: 58px; font-size: 15px; }
  .toast { bottom: calc(env(safe-area-inset-bottom, 0px) + 12px) !important; max-width: min(420px, calc(100% - 260px)); font-size: 17px !important; padding: 6px 10px; }
  .overlay { place-items: start center; padding-block: 12px; }
  .card { max-width: 620px; padding: 14px 16px; gap: 8px; }
  .card h1 { font-size: 16px; }
  .logo-main { font-size: 24px; padding-top: 52px; }
  #logo-tramp { width: 27px; height: 36px; }
  .logo-tag { font-size: 16px; }
  .card p { font-size: 17px; }
  .card button { padding: 10px 14px; font-size: 11px; }
  .card .modes .mode { padding: 8px 10px; }
  .mode .mode-desc { font-size: 16px; }
}
@media (max-width: 380px) { .modes { grid-template-columns: 1fr; } }

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } .stars.pop, .mult.bump { animation: none; } }

/* Level 2: Moon to Mars or Venus */
.card button.level2 {
  display: grid;
  gap: 6px;
  text-align: left;
  color: var(--ink);
  background: linear-gradient(90deg, #c8553a, #b5523a 50%, #c9a04a);
}
.card button.level2 span { font-family: var(--body); font-size: 18px; opacity: 0.9; }
.won-actions .level2 { flex-basis: 100%; }

/* Secret: a shooting star crosses the title screen. Catch it for conspiracy mode. */
.secret-star {
  position: fixed; z-index: 30; left: 0; top: 0;
  width: 64px; height: 64px; margin: -32px 0 0 -32px; padding: 0;
  border: 0; background: transparent; cursor: pointer;
  animation: shoot 2.8s linear forwards;
}
.secret-star::before {
  content: ""; position: absolute; left: 26px; top: 26px; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 10px 4px rgba(191, 232, 255, 0.9), 0 0 24px 10px rgba(143, 208, 255, 0.4);
}
.secret-star::after {
  content: ""; position: absolute; left: -84px; top: 30px; width: 116px; height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, rgba(143, 208, 255, 0), rgba(220, 240, 255, 0.95));
  transform-origin: right center; transform: rotate(14deg);
}
@keyframes shoot {
  from { transform: translate(-60px, 9vh); }
  to { transform: translate(calc(100vw + 120px), 33vh); }
}
.conspiracy-tag {
  position: fixed; z-index: 30; left: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  font-family: var(--display); font-size: 9px; line-height: 1.6; color: #8fff6a;
  background: rgba(6, 20, 8, 0.85); border: 2px solid #8fff6a; padding: 6px 8px; cursor: pointer; text-align: left;
}
.conspiracy-tag span { display: block; font-family: var(--body); font-size: 15px; color: #c9f5b8; }
body.conspiracy .card { border-color: #8fff6a; }
body.playing .conspiracy-tag { display: none; }
/* During the level 5 run, words go up top, out of your way */
body.run .toast { bottom: calc(env(safe-area-inset-bottom, 0px) + 6px) !important; font-size: 15px !important; line-height: 1.05; max-width: min(620px, calc(100% - 24px)); padding: 4px 10px; background: rgba(11, 15, 38, 0.6); border-width: 1px; }
@media (pointer: coarse) { body.run .toast { bottom: calc(env(safe-area-inset-bottom, 0px) + 94px) !important; } }

/* Stop and record your score: only while you're playing */
#stop { border-color: #ff8a7a; color: #ffd6d0; }
body:not(.playing) #stop { display: none; }
