:root {
  --puu: #3B2A1E;
  --puu2: #7A5230;
  --vaalea: #C89B63;
  --koivu: #EEDCB4;
  --taivas: #8ECBE3;
  --jarvi: #2F7FA6;
  --metsa: #3F7A3A;
  --ruoho: #7CB342;
  --aurinko: #F5C542;
  --oranssi: #E8862A;
  --punainen: #C1440E;
  --teksti: #FFF6E5;
  --pimea: #201812;
  --varjo: 0 8px 0 rgba(32, 24, 18, .28), 0 18px 40px rgba(32, 24, 18, .35);
  --fontti: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #17120e;
  color: var(--teksti);
  font-family: var(--fontti);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: block;
  overflow: hidden;
}

button, a { font-family: var(--fontti); }

#palkki {
  position: relative;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 56px;
  padding: 0 max(14px, env(safe-area-inset-left));
  background: linear-gradient(180deg, #2b1f16, #201812);
  border-bottom: 3px solid #7a5230;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .35);
}

.takaisin {
  color: var(--koivu);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 246, 229, .08);
  border: 1px solid rgba(238, 220, 180, .2);
  white-space: nowrap;
}

.takaisin:active { transform: translateY(1px); }

.merkki {
  color: var(--vaalea);
  font-weight: 800;
  letter-spacing: .08em;
  font-size: 13px;
  text-transform: uppercase;
}

#peli {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--pimea);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Jaettu ☰ leijuu pelin päällä; pelaaja voi raahata sitä vapaasti. */
#sg-kulma,
#sg-valikko-nappi {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#sg-kulma {
  cursor: grab;
}

#sg-kulma:active,
#sg-kulma button:active {
  cursor: grabbing;
}

#sg-kulma button {
  cursor: grab;
}

#sg-kulma button:hover {
  filter: brightness(1.08);
}

.ruutu {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
}

.ruutu.on { display: block; }

.tausta, .tarina-tausta, .hubi-tausta, .loppu-tausta {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transform: scale(1.02);
}

.tausta::after, .loppu-tausta::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(32, 24, 18, .22), rgba(32, 24, 18, .58));
}

/* ---------------- lataus ---------------- */

#ruutu-lataus { background: radial-gradient(circle at 50% 30%, #38533a, #17120e 70%); }

.lataus-kortti {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.lataus-hevonen { font-size: 64px; animation: keinu 1.6s ease-in-out infinite; }
.lataus-kortti h1 { margin: 0; font-size: clamp(28px, 4vw, 52px); letter-spacing: .02em; }
.lataus-kortti p { margin: 0; color: var(--koivu); opacity: .85; }

.lataus-palkki {
  width: min(320px, 60%);
  height: 12px;
  margin-top: 12px;
  border-radius: 999px;
  background: rgba(255, 246, 229, .16);
  overflow: hidden;
}

.lataus-palkki i {
  display: block;
  width: 40%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--oranssi), var(--aurinko));
  animation: lataus 1.4s ease-in-out infinite;
}

@keyframes keinu { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
@keyframes lataus { 0% { transform: translateX(-110%); } 100% { transform: translateX(350%); } }

/* ---------------- valikko ---------------- */

#ruutu-valikko .tausta {
  background-image: url("assets/bg/academy.webp");
  filter: saturate(1.05);
}

.valikko-sisalto {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3% 6%;
  background: radial-gradient(circle at 50% 45%, rgba(32, 24, 18, .08), rgba(32, 24, 18, .55));
}

#valikko-logo {
  width: clamp(84px, 11vw, 150px);
  height: auto;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .4));
  animation: leijuu 4s ease-in-out infinite;
}

@keyframes leijuu { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-7px) rotate(1deg); } }

.pieni-otsikko {
  margin: 6px 0 0;
  color: var(--aurinko);
  font-weight: 800;
  font-size: clamp(9px, .9vw, 13px);
  letter-spacing: .32em;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(32, 24, 18, .5);
}

.valikko-sisalto h1 {
  margin: 2px 0 0;
  font-size: clamp(34px, 6.4vw, 86px);
  line-height: .92;
  letter-spacing: -.02em;
  color: #fff8e8;
  text-shadow:
    0 3px 0 #7a5230,
    0 7px 0 #3b2a1e,
    0 14px 30px rgba(0, 0, 0, .45);
  transform: skew(-3deg);
}

.alaotsikko {
  margin: 8px 0 0;
  font-size: clamp(15px, 2vw, 26px);
  font-weight: 800;
  color: var(--aurinko);
  letter-spacing: .16em;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(32, 24, 18, .45);
}

.esittely {
  margin: clamp(10px, 1.6vh, 20px) 0 0;
  max-width: 640px;
  font-size: clamp(12px, 1.25vw, 17px);
  line-height: 1.5;
  color: #f4e6cf;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .55);
}

.valikko-napit {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: clamp(14px, 2.4vh, 28px);
}

.iso-nappi {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 14px 30px;
  border: 3px solid #2a1a0e;
  border-radius: 16px;
  background: linear-gradient(180deg, #f5c542, #e8862a);
  color: #2a1a0e;
  font-size: clamp(15px, 1.3vw, 19px);
  font-weight: 900;
  letter-spacing: .02em;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 5px 0 #9c5516, 0 12px 24px rgba(0, 0, 0, .3);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
}

.iso-nappi:active { transform: translateY(3px); box-shadow: 0 2px 0 #9c5516, 0 5px 12px rgba(0, 0, 0, .3); }
.iso-nappi:hover { filter: brightness(1.05); }
.iso-nappi:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.iso-nappi.toissijainen {
  background: linear-gradient(180deg, #fff6e5, #e8d4b0);
  color: #3b2a1e;
  box-shadow: 0 5px 0 #a88a60, 0 12px 24px rgba(0, 0, 0, .25);
}

.pieni {
  margin: clamp(10px, 1.8vh, 18px) 0 0;
  color: #d8c5a5;
  font-size: clamp(10px, .95vw, 12px);
}

.kaanny-kehote { display: none; }
.kaanny-globaali { display: none; }

/* ---------------- tarina ---------------- */

#ruutu-tarina { background: var(--pimea); }

.tarina-tausta {
  transition: background-image .3s ease, filter .3s ease;
  filter: saturate(1.04);
}

#ruutu-tarina::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg, rgba(20, 14, 10, .05) 20%, rgba(20, 14, 10, .42) 100%);
  pointer-events: none;
}

.tarina-hahmo {
  position: absolute;
  bottom: 6%;
  width: 56%;
  height: 94%;
  pointer-events: none;
  z-index: 2;
  transition: opacity .25s ease, transform .35s cubic-bezier(.2, .9, .25, 1);
}

.tarina-hahmo.vasen { left: -2%; }
.tarina-hahmo.oikea { right: -2%; }

.tarina-hahmo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 18px 26px rgba(0, 0, 0, .45));
  transform: scale(1.02);
}

.tarina-hahmo.piilossa { opacity: 0; transform: translateY(16px) scale(.98); }
.tarina-hahmo.vasen.piilossa { transform: translateX(-24px); }
.tarina-hahmo.oikea.piilossa { transform: translateX(24px); }

.dialogi-laatikko {
  position: absolute;
  z-index: 5;
  left: 4%;
  right: 4%;
  bottom: calc(2% + env(safe-area-inset-bottom, 0px));
  min-height: 0;
  max-height: 32%;
  padding: clamp(10px, 1.2vw, 18px) clamp(14px, 1.8vw, 26px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 3px solid #2a1a0e;
  border-radius: 18px;
  background:
    radial-gradient(circle at 12% 15%, rgba(255, 255, 255, .32), transparent 34%),
    linear-gradient(180deg, rgba(255, 248, 232, .74), rgba(238, 220, 180, .70));
  color: #2a1a0e;
  box-shadow: var(--varjo);
  cursor: pointer;
}

.dialogi-nimi {
  display: inline-block;
  align-self: flex-start;
  margin: 0 0 4px 2px;
  padding: 5px 16px 6px;
  border: 3px solid #2a1a0e;
  border-radius: 10px;
  background: linear-gradient(180deg, #4f7a3a, #2f5d46);
  color: #fff8e8;
  font-weight: 900;
  font-size: clamp(13px, 1.3vw, 17px);
  letter-spacing: .03em;
  box-shadow: 0 4px 0 rgba(32, 24, 18, .3);
}

.dialogi-nimi.tyhja { visibility: hidden; }

.dialogi-teksti {
  margin: 6px 0 4px;
  min-height: 2.8em;
  font-size: clamp(14px, 1.4vw, 19px);
  line-height: 1.35;
  font-weight: 600;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
}

.dialogi-vihje {
  position: static;
  align-self: flex-end;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
  color: #7a5230;
  opacity: .8;
  animation: vinkki 1.6s ease-in-out infinite;
  flex: 0 0 auto;
}

@keyframes vinkki { 0%, 100% { opacity: .35; transform: translateY(0); } 50% { opacity: .9; transform: translateY(-2px); } }

.jatka-nappi {
  position: static;
  align-self: flex-end;
  margin-top: 6px;
  flex: 0 0 auto;
  min-height: 44px;
  padding: 10px 18px;
  border: 3px solid #2a1a0e;
  border-radius: 12px;
  background: linear-gradient(180deg, #f5c542, #e8862a);
  color: #2a1a0e;
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 #9c5516;
}

.jatka-nappi span { display: inline-block; transition: transform .15s ease; }
.jatka-nappi:hover span { transform: translateX(3px); }
.jatka-nappi:active { transform: translateY(2px); box-shadow: 0 2px 0 #9c5516; }

.dialogi-valinnat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 8px;
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.dialogi-valinnat:empty { display: none; }

.dialogi-valinnat button {
  min-height: 46px;
  padding: 10px 16px;
  border: 2px solid #2a1a0e;
  border-radius: 12px;
  background: #fffaf0;
  color: #2a1a0e;
  font-size: clamp(12px, 1.25vw, 16px);
  font-weight: 800;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 3px 0 #c8a878;
}

.dialogi-valinnat button:hover { background: #fff2c8; }
.dialogi-valinnat button:active { transform: translateY(2px); box-shadow: 0 1px 0 #c8a878; }

/* ---------------- hubi ---------------- */

#ruutu-hubi { background: var(--pimea); }

.hubi-tausta {
  background-image: url("assets/bg/academy.webp");
  filter: blur(1px) saturate(.9) brightness(.62);
}

.hubi-sisalto {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(12px, 2vw, 26px) clamp(14px, 3vw, 42px);
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(20, 14, 10, .25), rgba(20, 14, 10, .65));
}

.hubi-yläosa {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.paiva-merkki {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(245, 197, 66, .18);
  border: 1px solid rgba(245, 197, 66, .5);
  color: var(--aurinko);
  font-weight: 900;
  font-size: 11px;
  letter-spacing: .14em;
}

.hubi-otsikko-ryhmä h2 {
  margin: 8px 0 2px;
  font-size: clamp(22px, 3vw, 38px);
  color: #fff8e8;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .45);
}

#hubi-kuvaus { margin: 0; color: #e6d3b2; font-size: clamp(11px, 1.1vw, 14px); }

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(58px, 1fr));
  gap: 7px;
  padding: 9px 11px;
  border-radius: 14px;
  background: rgba(32, 24, 18, .62);
  border: 1px solid rgba(238, 220, 180, .22);
  backdrop-filter: blur(4px);
}

.stat {
  min-width: 0;
}

.stat-rivi {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  font-size: 10px;
  font-weight: 800;
  color: #e8d6b8;
}

.stat-rivi b { font-size: 11px; }

.stat-palkki {
  height: 7px;
  margin-top: 3px;
  border-radius: 999px;
  background: rgba(255, 246, 229, .16);
  overflow: hidden;
}

.stat-palkki i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  transition: width .4s ease;
}

.kortit {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(10px, 1.6vw, 22px);
  margin-top: clamp(14px, 2.6vh, 30px);
}

.kortti-valmennus {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 190px;
  padding: 16px;
  border: 3px solid #2a1a0e;
  border-radius: 18px;
  background: linear-gradient(165deg, #fff8e8, #e8d2ac);
  color: #2a1a0e;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(32, 24, 18, .45), 0 16px 30px rgba(0, 0, 0, .25);
  transition: transform .12s ease, box-shadow .12s ease;
  overflow: hidden;
}

.kortti-valmennus::after {
  content: "";
  position: absolute;
  right: -30px;
  top: -30px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--kortti-vari, var(--oranssi));
  opacity: .16;
}

.kortti-valmennus:hover { transform: translateY(-3px); box-shadow: 0 9px 0 rgba(32, 24, 18, .45), 0 20px 34px rgba(0, 0, 0, .3); }
.kortti-valmennus:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(32, 24, 18, .45), 0 8px 16px rgba(0, 0, 0, .25); }

.kortti-valmennus img {
  width: clamp(46px, 6vw, 74px);
  height: clamp(46px, 6vw, 74px);
  object-fit: contain;
  margin-bottom: 2px;
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, .2));
}

.kortti-valmennus h3 {
  margin: 0;
  font-size: clamp(14px, 1.5vw, 21px);
  line-height: 1.1;
}

.kortti-valmennus p {
  margin: 2px 0 0;
  font-size: clamp(10px, 1vw, 13px);
  line-height: 1.35;
  color: #5c4228;
}

.kortti-stat {
  display: inline-block;
  margin-top: auto;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--kortti-vari, var(--oranssi));
  color: #fff8e8;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .1em;
}

.hubi-vinkki {
  margin: auto 0 0;
  padding-top: 10px;
  color: #cdb795;
  font-size: clamp(10px, 1vw, 12px);
  font-style: italic;
}

/* ---------------- rytmipeli ---------------- */

#ruutu-rytmi { background: #17120e; }

#rytmi-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.rytmi-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(20, 14, 10, .78), transparent);
  pointer-events: none;
}

.rytmi-hud .pieni-nappi { pointer-events: auto; margin-left: auto; }

.rytmi-vinkki {
  position: absolute;
  left: 50%;
  top: clamp(62px, 8.5vh, 88px);
  transform: translateX(-50%);
  max-width: 84%;
  margin: 0;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(32, 24, 18, .55);
  color: #fff6e5;
  font-size: clamp(10px, 1vw, 13px);
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.rytmi-otsikko { display: flex; flex-direction: column; }
.rytmi-otsikko span { font-weight: 900; font-size: clamp(14px, 1.5vw, 20px); }
.rytmi-otsikko small { color: var(--aurinko); font-weight: 800; font-size: 9px; letter-spacing: .18em; }

.rytmi-pisteet, .rytmi-combo { display: flex; flex-direction: column; align-items: center; margin-left: auto; }
.rytmi-combo { margin-left: 0; }
.rytmi-pisteet b, .rytmi-combo b { font-size: clamp(18px, 2.2vw, 30px); line-height: 1; }
.rytmi-pisteet span, .rytmi-combo span { font-size: 9px; color: #d8c5a5; letter-spacing: .1em; text-transform: uppercase; }

.pieni-nappi {
  min-height: 40px;
  padding: 7px 13px;
  border: 2px solid rgba(255, 246, 229, .35);
  border-radius: 10px;
  background: rgba(32, 24, 18, .55);
  color: #fff6e5;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}

.rytmi-napit {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 3%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.rytmi-nappi {
  min-height: 62px;
  border: 3px solid #2a1a0e;
  border-radius: 14px;
  background: rgba(255, 246, 229, .12);
  color: rgba(255, 246, 229, .75);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: .1em;
  cursor: pointer;
  backdrop-filter: blur(3px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .15);
  transition: background .08s ease, transform .08s ease;
}

.rytmi-nappi.pohjassa, .rytmi-nappi:active {
  background: var(--aurinko);
  color: #2a1a0e;
  transform: translateY(2px);
}

.tulos-paneeli {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, 84%);
  padding: 24px 30px 26px;
  border: 3px solid #2a1a0e;
  border-radius: 22px;
  background: linear-gradient(180deg, #fff8e8, #eedcb4);
  color: #2a1a0e;
  text-align: center;
  box-shadow: 0 10px 0 rgba(32, 24, 18, .4), 0 30px 60px rgba(0, 0, 0, .45);
  z-index: 10;
  animation: paneeli .28s cubic-bezier(.2, 1.3, .4, 1);
}

@keyframes paneeli { from { opacity: 0; transform: translate(-50%, -44%) scale(.94); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

.tulos-arvosana {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 76px;
  margin-top: -52px;
  border: 4px solid #2a1a0e;
  border-radius: 50%;
  background: linear-gradient(180deg, #f5c542, #e8862a);
  color: #2a1a0e;
  font-size: 40px;
  font-weight: 900;
  box-shadow: 0 6px 0 #9c5516;
}

.tulos-paneeli h3 { margin: 6px 0 4px; font-size: clamp(20px, 2.4vw, 30px); }
.tulos-paneeli p { margin: 0; color: #5c4228; font-size: clamp(12px, 1.2vw, 15px); }

.tulos-rivit {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin: 16px 0 20px;
  font-size: 12px;
  color: #5c4228;
}

.tulos-rivit b { display: block; font-size: 20px; color: #2a1a0e; }

/* ---------------- 3D-juoksu ---------------- */

#ruutu-juoksu { background: #8ecbe3; }

#juoksu-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.juoksu-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(20, 14, 10, .72), transparent);
  pointer-events: none;
}

.hud-lohko {
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(32, 24, 18, .55);
  border: 1px solid rgba(255, 246, 229, .16);
  backdrop-filter: blur(4px);
  min-width: 120px;
}

.hud-keskiosa { flex: 1; max-width: 380px; }
.hud-oikea { margin-left: auto; min-width: 190px; }

.hud-otsikko { display: block; color: var(--aurinko); font-weight: 900; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; }
.hud-rivi { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; color: #e8d6b8; margin-top: 3px; }
.hud-rivi b { color: #fff8e8; font-size: 13px; }
.hud-palkki { height: 8px; margin-top: 4px; border-radius: 999px; background: rgba(255, 246, 229, .18); overflow: hidden; }
.hud-palkki i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #f5c542, #e8862a); border-radius: inherit; }
.boost .hud-palkki i { background: linear-gradient(90deg, #8ecbe3, #2fb6a6); }

.juoksu-laskenta {
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  font-size: clamp(64px, 10vw, 140px);
  font-weight: 900;
  color: #fff8e8;
  text-shadow: 0 6px 0 #7a5230, 0 18px 40px rgba(0, 0, 0, .5);
  pointer-events: none;
  opacity: 0;
}

.juoksu-laskenta.näkyy { animation: laskenta .9s ease-out; }

@keyframes laskenta { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.7); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(.8); } }

.juoksu-ohjaimet {
  position: absolute;
  left: 3%;
  right: 3%;
  bottom: 4%;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
}

.juoksu-ohjaimet .ohjain-nappi {
  pointer-events: auto;
  width: clamp(56px, 7vw, 82px);
  height: clamp(56px, 7vw, 82px);
  border: 3px solid rgba(42, 26, 14, .85);
  border-radius: 50%;
  background: rgba(255, 246, 229, .82);
  color: #2a1a0e;
  font-size: clamp(20px, 2.4vw, 30px);
  font-weight: 900;
  box-shadow: 0 6px 0 rgba(32, 24, 18, .45), 0 12px 24px rgba(0, 0, 0, .25);
  backdrop-filter: blur(3px);
  cursor: pointer;
  touch-action: none;
}

.juoksu-ohjaimet .ohjain-nappi:active, .juoksu-ohjaimet .ohjain-nappi.pohjassa {
  transform: translateY(3px);
  background: var(--aurinko);
  box-shadow: 0 2px 0 rgba(32, 24, 18, .45);
}

.ohjain-hyppy { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); }
.ohjain-hyppy:active { transform: translate(-50%, 3px); }
.ohjain-boost { margin-left: auto; background: rgba(47, 182, 166, .85) !important; }

.juoksu-vihje {
  position: absolute;
  left: 50%;
  bottom: 2%;
  transform: translateX(-50%);
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(32, 24, 18, .55);
  color: #f4e6cf;
  font-size: clamp(9px, .9vw, 11px);
  white-space: nowrap;
  pointer-events: none;
}

/* ---------------- loppu ---------------- */

.loppu-tausta {
  background-image: url("assets/ending.webp");
  filter: saturate(1.08);
}

.loppu-sisalto {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4% 8%;
  background: linear-gradient(180deg, rgba(20, 14, 10, .18), rgba(20, 14, 10, .78));
}

.loppu-sisalto h1 {
  margin: 2px 0 6px;
  font-size: clamp(30px, 5vw, 66px);
  color: #fff8e8;
  text-shadow: 0 4px 0 #7a5230, 0 14px 30px rgba(0, 0, 0, .5);
}

.loppu-teksti {
  margin: 0;
  max-width: 760px;
  font-size: clamp(12px, 1.3vw, 17px);
  line-height: 1.5;
  color: #f4e6cf;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .6);
  white-space: pre-line;
}

.loppu-tilastot {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 16px 0 22px;
}

.loppu-tilasto {
  min-width: 92px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(32, 24, 18, .58);
  border: 1px solid rgba(238, 220, 180, .25);
  backdrop-filter: blur(4px);
}

.loppu-tilasto span { display: block; font-size: 9px; letter-spacing: .12em; text-transform: uppercase; color: #d8c5a5; }
.loppu-tilasto b { font-size: 20px; color: #fff8e8; }

.loppu-napit { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.ilmoitus {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 200;
  max-width: 90vw;
  padding: 12px 20px;
  border: 2px solid #2a1a0e;
  border-radius: 12px;
  background: #fff8e8;
  color: #2a1a0e;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

/* ---------------- pystysuunta ---------------- */

@media (orientation: portrait) {
  .kaanny-globaali {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10%;
    background: rgba(20, 14, 10, .95);
    text-align: center;
  }
  .kaanny-globaali span { font-size: 52px; animation: keinu 1.6s ease-in-out infinite; }
  .kaanny-globaali strong { font-size: 20px; }
  .kaanny-globaali small { color: #cdb795; }
  .kaanny-kehote {
    position: absolute;
    inset: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10%;
    background: rgba(20, 14, 10, .92);
    text-align: center;
  }
  .kaanny-kehote span { font-size: 52px; animation: keinu 1.6s ease-in-out infinite; }
  .kaanny-kehote strong { font-size: 20px; }
  .kaanny-kehote small { color: #cdb795; }
}

@media (max-height: 560px) {
  .hubi-sisalto { padding: 8px 16px; }
  .kortti-valmennus { min-height: 150px; padding: 10px 12px; }
  .kortti-valmennus img { width: 42px; height: 42px; }
  .hubi-vinkki { display: none; }
  .dialogi-laatikko { max-height: 44%; }
  .dialogi-teksti { font-size: 14px; }
  .dialogi-vihje { display: none; }
  .tarina-hahmo { height: 90%; width: 50%; }
  .juoksu-vihje { display: none; }
}

@media (max-width: 760px) {
  .merkki { display: none; }
  .stats { grid-template-columns: repeat(5, minmax(46px, 1fr)); gap: 4px; padding: 6px 7px; }
  .stat-rivi { font-size: 8px; }
  .stat-rivi b { font-size: 9px; }
  .kortti-valmennus p { display: none; }
  .hubi-otsikko-ryhmä h2 { font-size: 20px; }
  .kortit { gap: 8px; }
}
