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

html, body {
  height: 100%;
  background: #0b0b12;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  background: #000;
  image-rendering: pixelated;
  max-width: 100vw;
  max-height: 100vh;
  aspect-ratio: 16 / 9;
  width: 100vw;
  height: auto;
}
@media (min-aspect-ratio: 16/9) {
  #game { height: 100vh; width: auto; }
}

#muteBtn {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 30;
  font-size: 22px;
  background: rgba(0,0,0,.45);
  color: #fff;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}

/* ---- touch controls ---- */
#touch {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  display: none;
}
body.touch #touch { display: block; }

#touchLeftGroup, #touchRightGroup {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  gap: 14px;
}
#touchLeftGroup { left: max(14px, env(safe-area-inset-left)); }
#touchRightGroup { right: max(14px, env(safe-area-inset-right)); }

.tbtn {
  pointer-events: auto;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.9);
  font-size: 30px;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.tbtn:active { background: rgba(255,255,255,.3); }
#btnJump { width: 88px; height: 88px; font-size: 40px; }

/* ---- overlay / cutscenes ---- */
#overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5,5,12,.88);
  padding: 12px;
}
#overlay.show { display: flex; }

.panel {
  max-width: 640px;
  width: 100%;
  max-height: 96vh;
  overflow-y: auto;
  background: linear-gradient(160deg, #15151f, #0d0d16);
  border: 2px solid var(--accent, #e8b64c);
  border-radius: 16px;
  padding: 22px 24px;
  text-align: center;
  color: #eee;
  box-shadow: 0 0 40px color-mix(in srgb, var(--accent, #e8b64c) 35%, transparent);
  animation: pop .35s ease-out;
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.panel .emblem {
  font-size: 54px;
  line-height: 1.1;
  filter: drop-shadow(0 0 14px var(--accent, #e8b64c));
}
.panel h1 {
  font-size: 26px;
  margin: 8px 0 2px;
  color: var(--accent, #e8b64c);
  letter-spacing: .5px;
}
.panel h2 {
  font-size: 14px;
  font-weight: 500;
  color: #9a9ab0;
  margin-bottom: 12px;
  font-style: italic;
}
.panel p {
  font-size: 15px;
  line-height: 1.55;
  color: #d5d5e2;
  margin: 0 auto 14px;
  max-width: 54ch;
}
.panel img.scene {
  width: 100%;
  max-height: 46vh;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.15);
  margin: 4px 0 12px;
  background: #000;
}
.panel img.portrait {
  width: 130px;
  height: 130px;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--accent, #e8b64c);
  margin-bottom: 10px;
}
.panel .stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 6px 0 16px;
}
.panel .stats span {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 15px;
}
.panel .btn {
  display: inline-block;
  background: var(--accent, #e8b64c);
  color: #10101a;
  font-weight: 700;
  font-size: 17px;
  border: none;
  border-radius: 12px;
  padding: 12px 30px;
  cursor: pointer;
  margin: 4px 6px;
}
.panel .btn:active { transform: scale(.96); }
.panel .btn:disabled { opacity: .55; cursor: default; }
.panel .btn.btn2 {
  background: transparent;
  color: var(--accent, #e8b64c);
  border: 2px solid var(--accent, #e8b64c);
  font-size: 15px;
  padding: 10px 22px;
}
.panel .hint { font-size: 12px; color: #77778c; margin-top: 12px; }

/* ---- hallituksen kuulustelu ---- */
.askRow {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  min-height: 110px;
  margin: 6px 0 4px;
}
#lannistettuBtn { transition: transform .15s ease-out; }

/* ---- voittokuvan kokosivuanimaatio ---- */
img.scene-fly {
  position: fixed;
  z-index: 900;
  margin: 0;
  max-width: none;
  max-height: none;
  object-fit: contain;
  background: #000;
  border: 0;
  border-radius: 10px;
  transition: left 3.5s ease-in-out, top 3.5s ease-in-out,
              width 3.5s ease-in-out, height 3.5s ease-in-out,
              border-radius 3.5s ease-in-out;
}
.goodnight-fly {
  position: fixed;
  z-index: 901;
  left: 50%;
  bottom: 7vh;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .9s ease;
  background: #ffd75e;
  color: #10101a;
  font-weight: 700;
  font-family: inherit;
  font-size: 17px;
  border: 0;
  border-radius: 10px;
  padding: 12px 30px;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(0,0,0,.6);
}
.goodnight-fly.show { opacity: 1; pointer-events: auto; }
.goodnight-fly:active { transform: translateX(-50%) scale(.96); }

/* ---- terveiset-lomake ---- */
.greetform {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 420px;
  margin: 0 auto 12px;
}
.greetform input, .greetform textarea {
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 10px;
  color: #eee;
  font-family: inherit;
  font-size: 15px;
  padding: 10px 12px;
  resize: none;
  -webkit-user-select: text;
  user-select: text;
}
.greetform input:focus, .greetform textarea:focus {
  outline: none;
  border-color: var(--accent, #e8b64c);
}

/* ---- scoreboard ---- */
.board { text-align: left; }
.board h2 {
  font-size: 15px;
  font-weight: 700;
  font-style: normal;
  color: var(--accent, #e8b64c);
  margin: 14px 0 8px;
  text-align: center;
}
.board .toplist {
  margin: 0 auto;
  max-width: 400px;
  padding-left: 30px;
  font-size: 15px;
  line-height: 1.7;
  color: #d5d5e2;
}
.board .toplist small { color: #9a9ab0; }
.board .greetlist {
  list-style: none;
  margin: 0 auto;
  max-width: 460px;
  font-size: 14px;
  line-height: 1.5;
  color: #d5d5e2;
  max-height: 180px;
  overflow-y: auto;
  padding: 0 6px;
}
.board .greetlist li {
  border-bottom: 1px solid rgba(255,255,255,.08);
  padding: 6px 0;
}
.board p { text-align: center; }

@media (max-height: 500px) {
  .panel { padding: 12px 16px; }
  .panel .emblem { font-size: 34px; }
  .panel h1 { font-size: 19px; }
  .panel p { font-size: 13px; }
  .panel img.scene { max-height: 34vh; }
  .panel img.portrait { width: 80px; height: 80px; }
}
