* { box-sizing: border-box; }

:root {
  --ink: #050505;
  --green: #32f65c;
  --sky: #73c8ff;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
  font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
}

button { font: inherit; }
[hidden] { display: none !important; }

.intro, .game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100svh;
  overflow: hidden;
}

.intro {
  --poster-height: min(96svh, calc((100vw - 27rem) / .56265));
  --poster-width: calc(var(--poster-height) * .56265);
  display: grid;
  grid-template-columns: minmax(13.5rem, 1fr) var(--poster-width) minmax(13.5rem, 1fr);
  align-items: center;
  background-color: #64bbed;
  background-image: radial-gradient(circle at 15% 18%, rgb(255 255 255 / 18%) 0 4px, transparent 5px), radial-gradient(circle at 82% 72%, rgb(19 84 115 / 12%) 0 3px, transparent 4px), linear-gradient(#83d2fa, #4ca5d7);
  background-size: 54px 54px, 43px 43px, auto;
}

.comic {
  grid-column: 2;
  display: block;
  width: var(--poster-width);
  height: var(--poster-height);
  object-fit: contain;
  border: clamp(3px, 0.35vw, 6px) solid #050505;
  box-shadow: 0 0 0 4px rgb(255 255 255 / 72%), 0 18px 45px rgb(0 31 55 / 34%);
  z-index: 2;
}

.ranking-panel {
  grid-column: 2;
  position: relative;
  z-index: 2;
  width: var(--poster-width);
  height: var(--poster-height);
  padding: clamp(1.1rem, 2.4vw, 2.4rem);
  overflow: auto;
  border: clamp(3px, .35vw, 6px) solid #050505;
  background-color: #f7e8c8;
  background-image: repeating-linear-gradient(0deg, transparent 0 16px, rgb(115 74 34 / 6%) 17px 18px);
  box-shadow: 0 0 0 4px rgb(255 255 255 / 72%), 0 18px 45px rgb(0 31 55 / 34%);
}
.ranking-top { position: relative; padding-bottom: 1rem; text-align: center; border-bottom: 5px solid #17100d; }
.ranking-top p { margin: 0; color: #16823d; font: 900 clamp(.65rem,1vw,.95rem)/1 Arial,sans-serif; letter-spacing: .2em; }
.ranking-top h1 { margin: .2rem 0 0; font-size: clamp(2.4rem,6vw,5.6rem); line-height: .85; }
.ranking-top button { position: absolute; top: -.45rem; right: -.2rem; width: 2.5rem; height: 2.5rem; border: 3px solid #17100d; background: #ef4545; box-shadow: 3px 3px 0 #17100d; cursor: pointer; font-size: 1.8rem; line-height: 1; }
.rank-columns { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(.8rem,2vw,1.6rem); padding-top: 1.2rem; }
.rank-columns-single { grid-template-columns: minmax(0, 1fr); max-width: 30rem; margin-inline: auto; }
.rank-columns article { min-width: 0; padding: .85rem; border: 4px solid #17100d; background: rgb(255 255 255 / 46%); box-shadow: 5px 5px 0 #17100d; }
.rank-columns h2 { min-height: 2em; margin: 0 0 .75rem; color: #c52b35; font-size: clamp(1rem,2.2vw,1.8rem); line-height: .9; text-align: center; }
.rank-columns ol { margin: 0; padding: 0; list-style: none; font: 900 clamp(.72rem,1.4vw,1.05rem)/1.25 Arial,sans-serif; }
.rank-columns li { display: flex; justify-content: space-between; gap: .5rem; padding: .48rem .2rem; border-bottom: 2px dashed rgb(23 16 13 / 35%); }
.rank-columns li strong { color: #16823d; }
.rank-columns .rank-empty { justify-content: center; color: #776b5c; }

.side-menu {
  position: relative;
  z-index: 3;
  display: flex;
  min-width: 0;
  height: 96svh;
  padding: clamp(1rem, 2vw, 2.1rem);
  flex-direction: column;
  justify-content: center;
  gap: clamp(.8rem, 1.5vh, 1.25rem);
  overflow: hidden;
  color: #16100d;
  background-color: #f7e8c8;
  background-image: repeating-linear-gradient(0deg, transparent 0 13px, rgb(115 74 34 / 4%) 14px 15px);
  border: 5px solid #15100d;
  box-shadow: 10px 12px 0 rgb(18 12 8 / 72%);
}

.menu-left { margin: 0 clamp(.6rem, 1.3vw, 1.4rem) 0 clamp(.6rem, 1.5vw, 1.8rem); transform: rotate(-.45deg); }
.menu-right { margin: 0 clamp(.6rem, 1.5vw, 1.8rem) 0 clamp(.6rem, 1.3vw, 1.4rem); transform: rotate(.45deg); }

.side-menu::before,
.side-menu::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 10px;
  background: repeating-linear-gradient(90deg, #ef3c38 0 28px, #ffda34 28px 56px, #26d657 56px 84px, #309cea 84px 112px);
}
.side-menu::before { top: 0; }
.side-menu::after { bottom: 0; }

.menu-heading { margin-bottom: .35rem; text-align: left; }
.menu-heading p { margin: 0 0 .3rem; color: #c62a2f; font: 900 clamp(.75rem, 1vw, 1rem)/1 Arial, sans-serif; letter-spacing: .16em; }
.menu-heading h2 { margin: 0; font-size: clamp(1.6rem, 2.45vw, 3.05rem); line-height: .86; letter-spacing: .015em; }
.menu-heading-right p { color: #12853b; }

.mini-feather { position: absolute; top: 1.25rem; right: 1.25rem; color: #f3c91f; font-size: 1.35rem; text-shadow: 2px 2px 0 #17100c; transform: rotate(25deg); }

.menu-button {
  display: flex;
  width: 100%;
  min-height: clamp(4.8rem, 10vh, 6.2rem);
  padding: .75rem clamp(.65rem, 1.2vw, 1.1rem);
  align-items: center;
  gap: clamp(.65rem, 1vw, 1rem);
  border: 4px solid #17100d;
  border-radius: 14px 7px 13px 8px;
  color: #17100d;
  background: #fff8e8;
  box-shadow: 6px 6px 0 #17100d;
  text-align: left;
  font-size: clamp(1rem, 1.45vw, 1.55rem);
  line-height: .88;
  letter-spacing: .02em;
  text-decoration: none;
}
.menu-button small { display: block; margin-bottom: .32rem; font: 900 .65em/1 Arial, sans-serif; letter-spacing: .16em; }
.menu-button-play { background: linear-gradient(145deg, #58ff70, #19d24c); cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, filter .12s ease; }
.menu-button-play:hover { transform: translate(-2px, -3px) rotate(.5deg); box-shadow: 9px 10px 0 #17100d; filter: saturate(1.12); }
.menu-button-play:active { transform: translate(5px, 5px); box-shadow: 1px 1px 0 #17100d; }
.menu-button-play:focus-visible { outline: 5px solid #fff; outline-offset: 4px; }
.menu-button-rank { background: linear-gradient(145deg,#ffe45d,#f1b52e); cursor: pointer; transition: transform .12s ease,box-shadow .12s ease; }
.menu-button-rank:hover { transform: translate(-2px,-3px) rotate(-.5deg); box-shadow: 9px 10px 0 #17100d; }
.menu-button-rank > span:first-child { font-size: 2rem; }
.menu-play-icon { width: 0; height: 0; flex: 0 0 auto; border-top: .85rem solid transparent; border-bottom: .85rem solid transparent; border-left: 1.3rem solid #17100d; filter: drop-shadow(2px 2px 0 rgb(255 255 255 / 50%)); }
.menu-locked { opacity: .62; background: #d7cfbd; box-shadow: 4px 4px 0 #17100d; }
.menu-locked > span:first-child { display: grid; width: 2.2rem; height: 2.2rem; flex: 0 0 auto; place-items: center; border: 3px solid #17100d; border-radius: 50%; background: #efe6d3; font-size: 1.5rem; }
.menu-tip { margin-top: auto; padding: .8rem; border: 3px dashed #17100d; background: rgb(255 255 255 / 45%); font: 800 clamp(.72rem, 1vw, .95rem)/1.45 Arial, sans-serif; text-align: center; }

.run-title {
  position: absolute;
  z-index: 8;
  top: max(1.1rem, env(safe-area-inset-top));
  left: 50%;
  width: min(92vw, 44rem);
  margin: 0;
  transform: translate(-50%, -1rem) rotate(-1deg);
  opacity: 0;
  color: #fff;
  font-size: clamp(1.35rem, 3.5vw, 3.35rem);
  line-height: 0.88;
  letter-spacing: 0.025em;
  text-align: center;
  text-shadow: 4px 4px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
  pointer-events: none;
}

.run-title.show { animation: run-title 3.15s both; }

@keyframes run-title {
  0% { opacity: 0; transform: translate(-50%, -1.25rem) scale(.78) rotate(-2deg); }
  12%, 72% { opacity: 1; transform: translate(-50%, 0) scale(1) rotate(-1deg); }
  100% { opacity: 0; transform: translate(-50%, -1.1rem) scale(1.06) rotate(1deg); }
}

.play {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  gap: clamp(0.45rem, 1vw, 0.8rem);
  min-width: clamp(5.7rem, 10vw, 8.5rem);
  min-height: clamp(3.1rem, 5.2vw, 4.4rem);
  padding: 0.5rem 0.9rem;
  justify-content: center;
  transform: translate(-50%, -50%) rotate(-2deg);
  border: clamp(4px, 0.55vw, 8px) solid var(--ink);
  border-radius: 0.45rem;
  color: var(--ink);
  background: var(--green);
  box-shadow: clamp(4px, 0.55vw, 7px) clamp(4px, 0.55vw, 7px) 0 var(--ink), 0 0 22px rgb(61 255 100 / 70%);
  cursor: pointer;
  font-size: clamp(1.15rem, 2.1vw, 1.85rem);
  letter-spacing: 0.04em;
}

.play:hover { transform: translate(-50%, -52%) rotate(1deg) scale(1.04); }
.play:active { transform: translate(calc(-50% + 7px), calc(-50% + 7px)); box-shadow: 3px 3px 0 var(--ink); }
.play:focus-visible, .sound:focus-visible, .gameover button:focus-visible { outline: 5px solid #fff; outline-offset: 4px; }

.play-triangle {
  width: 0;
  height: 0;
  border-top: 0.55em solid transparent;
  border-bottom: 0.55em solid transparent;
  border-left: 0.85em solid var(--ink);
}

.game { background: var(--sky); }
.game[hidden], .gameover[hidden] { display: none; }

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 3;
  top: max(1rem, env(safe-area-inset-top));
  left: max(1rem, env(safe-area-inset-left));
  right: max(5.25rem, calc(env(safe-area-inset-right) + 4.25rem));
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  color: #fff;
  font-size: clamp(1.4rem, 4vw, 3.2rem);
  letter-spacing: 0.05em;
  text-shadow: 4px 4px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
}

.game.cinematic .hud,
.game.cinematic .help { opacity: 0; }

.game .hud,
.game .help { transition: opacity .35s ease; }

.money-count { display: flex; align-items: center; gap: 0.35rem; }
.money-count img { width: 1.35em; height: 1.35em; object-fit: contain; image-rendering: pixelated; }

.help {
  position: absolute;
  z-index: 3;
  bottom: max(0.7rem, env(safe-area-inset-bottom));
  left: 50%;
  width: min(92vw, 36rem);
  transform: translateX(-50%);
  color: #fff;
  font-family: Arial, sans-serif;
  font-size: clamp(0.78rem, 2vw, 1rem);
  font-weight: 800;
  text-align: center;
  text-shadow: 2px 2px 0 #000;
  pointer-events: none;
  opacity: 0.9;
}

.sound {
  position: fixed;
  z-index: 20;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  display: grid;
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  place-items: center;
  border: 3px solid #000;
  border-radius: 999px;
  background: rgb(255 255 255 / 88%);
  box-shadow: 4px 4px 0 #000;
  cursor: pointer;
  font-size: 1.4rem;
}

.game + audio + .sound { bottom: auto; top: max(1rem, env(safe-area-inset-top)); }
.sound:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #000; }

.gameover {
  position: absolute;
  z-index: 10;
  top: 50%;
  left: 50%;
  width: min(88vw, 30rem);
  padding: 2rem;
  transform: translate(-50%, -50%) rotate(-1deg);
  border: 7px solid #000;
  background: #fff;
  box-shadow: 12px 12px 0 #000;
  text-align: center;
}

.gameover p { margin: 0 0 0.4rem; font-size: clamp(2.5rem, 8vw, 5rem); line-height: 0.9; }
.gameover strong { display: block; margin-bottom: 1.3rem; font-size: 1.25rem; }
.gameover button { border: 4px solid #000; background: var(--green); padding: 0.65rem 1.3rem; box-shadow: 5px 5px 0 #000; cursor: pointer; font-size: 1.5rem; }

@media (max-width: 600px) {
  .play { min-width: 5.5rem; min-height: 3rem; }
  .help { bottom: 0.45rem; }
}

@media (max-width: 900px) {
  .intro { --poster-height: min(100svh, calc(100vw / .56265)); --poster-width: calc(var(--poster-height) * .56265); display: grid; grid-template-columns: 1fr; place-items: center; }
  .comic { grid-column: 1; grid-row: 1; }
  .ranking-panel { grid-column: 1; grid-row: 1; width: min(100vw,100svh); height: min(100vw,100svh); }
  .side-menu { position: absolute; height: auto; padding: .65rem; border-width: 3px; box-shadow: 5px 5px 0 #17100d; transform: none; }
  .menu-left { right: .7rem; bottom: .8rem; left: .7rem; margin: 0; }
  .menu-right, .menu-heading, .menu-locked { display: none; }
  .menu-button { min-height: 3.8rem; padding: .55rem .8rem; justify-content: center; font-size: 1.05rem; text-align: center; }
  .menu-button small { display: inline; margin: 0 .4rem 0 0; }
}

@media (max-width: 560px) {
  .rank-columns { grid-template-columns: 1fr; }
  .rank-columns article { padding: .55rem; }
  .rank-columns h2 { min-height: 0; }
}
