@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/andika-regular.woff2') format('woff2');
}

@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/andika-bold.woff2') format('woff2');
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #141414;
  font-family: 'Andika', 'DejaVu Sans', 'Liberation Sans', Arial, sans-serif;
  user-select: none;
  touch-action: manipulation;
}

#main {
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#emoji-img {
  display: none;
  width: min(58vw, 58vh);
  height: min(58vw, 58vh);
  object-fit: contain;
  image-rendering: auto;
  flex-shrink: 0;
}

#name-text {
  display: none;
  color: #fff;
  font-size: max(3.0rem, min(10vw, 8rem));
  font-weight: 900;
  text-shadow: 4px 4px 0 #000;
  text-align: center;
  margin-top: 3vh;
  letter-spacing: 0.05em;
}

#letter-display {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: max(8rem, min(45vh, 22rem));
  font-weight: bold;
  text-shadow: 6px 6px 0 #000;
  line-height: 1;
}

#grid-container {
  display: none;
  gap: max(4px, min(1.5vmin, 16px));
  padding: max(8px, min(2vmin, 24px));
  flex: 1;
  width: 100%;
  max-height: 80vh;
  align-content: center;
  justify-items: center;
}

.grid-emoji {
  width: 100%;
  height: 100%;
  max-width: min(20vw, 20vh);
  max-height: min(20vw, 20vh);
  object-fit: contain;
}

.grid-letter {
  color: #fff;
  font-weight: bold;
  text-shadow: 3px 3px 0 #000;
  font-size: max(3rem, min(10vmin, 8rem));
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#grid-word {
  display: none;
  color: #fff;
  font-size: max(2.5rem, min(8vh, 5rem));
  font-weight: bold;
  text-shadow: 3px 3px 0 #000;
  text-align: center;
  padding: 1vh 0 2vh;
  letter-spacing: 0.05em;
}

#menu {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 20px 0;
  gap: max(12px, min(3vh, 28px));
  background: linear-gradient(160deg, #FDEFC7 0%, #F7D68E 55%, #F3C36E 100%);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

#menu::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.85;
  /* Muutama sävy sormihahmon omasta paletista (teal/pinkki/violetti) amberin
     rinnalle — värikkäämpi, ei enää yksisävyinen. */
  background-image:
    radial-gradient(280px 200px at 8% 12%, rgba(217,138,46,0.28), transparent),
    radial-gradient(320px 220px at 92% 22%, rgba(60,200,170,0.22), transparent),
    radial-gradient(260px 200px at 85% 78%, rgba(224,80,144,0.20), transparent),
    radial-gradient(240px 180px at 12% 82%, rgba(112,80,220,0.18), transparent),
    radial-gradient(200px 150px at 50% 48%, rgba(217,138,46,0.15), transparent);
}

#menu-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3em;
  font-size: max(2.0rem, min(6vmin, 3.6rem));
  font-weight: 900;
  color: #6b3f14;
  text-align: center;
  letter-spacing: -0.02em;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  padding: 0.5em 1.1em;
  background: #FFF6E5;
  border: 3px solid #8a5a1f;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(107,63,20,0.25);
}

#menu-title-logo {
  height: 1.25em;
  width: 1.25em;
  border-radius: 0.28em;
  flex-shrink: 0;
}

#menu-grid {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 4px 20px;
}

#menu-grid::-webkit-scrollbar {
  display: none;
}

#menu-path-canvas {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.mode-card {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  width: max(60px, min(11vw, 96px));
  z-index: 1;
  user-select: none;
}

.mode-stop {
  width: max(52px, min(10vw, 88px));
  height: max(52px, min(10vw, 88px));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease;
  flex-shrink: 0;
}

.mode-stop.available {
  background: linear-gradient(145deg, var(--card-color) 0%, var(--card-color-dark) 100%);
  border: 3px solid #6b3f14;
  box-shadow: 0 4px 10px rgba(107,63,20,0.35);
  cursor: pointer;
}

.mode-stop.available:active {
  transform: scale(0.92);
}

.mode-stop.unavailable {
  background: #E9D2A0;
  border: 3px solid #B98F52;
}

.mode-stop.unavailable .mode-card-emoji {
  opacity: 0.5;
}

.mode-card-emoji {
  font-size: max(1.3rem, min(4vmin, 2.2rem));
  line-height: 1;
  pointer-events: none;
}

/* Ensimmäinen pysäkki ("Yllätä mut") on sormihahmo itse — osa polkua muiden
   pysäkkien tapaan, mutta tarkoituksella isompi ja kermanvärisellä taustalla
   (ei kilpaile moodivärien kanssa) koska toimii samalla appsin "logona". */
.mode-card-mascot {
  width: max(78px, min(14.5vw, 130px));
}

.mode-stop.mode-stop-mascot {
  width: max(70px, min(13vw, 120px));
  height: max(70px, min(13vw, 120px));
  background: #FFF6E5;
  border: 3px solid #8a5a1f;
}

.mode-card-mascot-img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  pointer-events: none;
}

/* Kaartuva "SORMISEIKKAILU"-teksti maskotin yläpuolella, kuin pyöreä
   leima/mitali-yläkaari. */
.mode-mascot-arc-text {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 155%;
  height: 155%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  overflow: visible;
}

.mode-card-name {
  font-size: max(0.85rem, min(2.2vmin, 1.1rem));
  font-weight: 700;
  color: #6b3f14;
  text-align: center;
  letter-spacing: 0.02em;
}

.mode-card-badge {
  font-size: max(0.6rem, min(1.3vmin, 0.75rem));
  font-weight: 600;
  color: rgba(107,63,20,0.55);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#back-btn {
  position: fixed;
  top: 10px;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px;
  left: calc(10px + env(safe-area-inset-left));
  width: 44px;
  height: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s;
  z-index: 210;
  font-family: inherit;
  cursor: default;
}

#back-btn img {
  width: 24px;
  height: 24px;
  pointer-events: none;
}

#settings-update-btn {
  background: #FF6B35;
  color: #fff;
  border: none;
  border-radius: 18px;
  font-size: max(1.1rem, min(3vmin, 1.6rem));
  font-weight: 700;
  padding: max(14px, min(3vh, 24px)) max(28px, min(6vw, 48px));
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 6px 24px rgba(255,107,53,0.4);
}

#settings-update-btn:disabled {
  opacity: 0.5;
}

#settings-build {
  font-size: 0.85rem;
  color: rgba(107,63,20,0.55);
  font-family: monospace;
}

#settings-credits {
  font-size: 0.8rem;
  color: rgba(107,63,20,0.6);
  font-family: sans-serif;
}

#settings-copyright {
  font-size: 0.75rem;
  color: rgba(107,63,20,0.45);
  font-family: sans-serif;
}

#settings-credits a {
  color: rgba(107,63,20,0.85);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: min(90vw, 520px);
  background: rgba(255,255,255,0.5);
  padding: 20px;
  border-radius: 24px;
  border: 2px solid rgba(107,63,20,0.25);
}

.info-panel {
  max-width: min(90vw, 640px);
  text-align: left;
  gap: 4px;
}

.info-section {
  margin-bottom: 14px;
}

.info-section h3 {
  color: #6b3f14;
  font-size: 1.05rem;
  margin: 0 0 6px;
}

.info-section p {
  color: rgba(107,63,20,0.85);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 6px;
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  width: 100%;
}

.settings-label {
  color: #6b3f14;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: sans-serif;
}

.settings-options {
  display: flex;
  gap: 8px;
  width: 100%;
}

.settings-opt-btn {
  flex: 1;
  min-width: 0;
  background: rgba(107,63,20,0.08);
  border: 2px solid transparent;
  color: rgba(107,63,20,0.75);
  border-radius: 14px;
  padding: 12px 4px;
  /* Pitkät labelit (esim. "Helppo veto/täppäys") eivät mahtuneet kapealla
     pystysuuntaisella puhelinnäytöllä 1.1rem-koolla — skaalataan alaspäin. */
  font-size: max(0.72rem, min(1.1rem, 3.3vw));
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.settings-opt-btn.active {
  background: #FFD43B;
  color: #141414;
  box-shadow: 0 4px 16px rgba(255,212,59,0.35);
  border-color: #FFD43B;
}

#menu-settings-btn {
  /* Pinottu vasempaan alakulmaan, "?"-napin (#menu-info-btn, 60px + 8px
     marginaali joka reunalla) yläpuolelle sopivalla välillä — ei enää
     erillään oikeassa alakulmassa. */
  position: fixed;
  bottom: 88px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 0px;
  left: env(safe-area-inset-left);
  width: 60px;
  height: 60px;
  margin: 8px;
  /* Sama pallukka-tyyli kuin "?"-napilla (#menu-info-btn) yhtenäisyyden vuoksi. */
  background: rgba(107,63,20,0.12);
  border-radius: 50%;
  border: none;
  opacity: 0.55;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s ease;
}

#settings-gear-icon {
  width: 28px;
  height: 28px;
  position: relative;
  pointer-events: none;
}

#menu-info-btn {
  position: fixed;
  bottom: 0px;
  bottom: env(safe-area-inset-bottom);
  left: 0px;
  left: env(safe-area-inset-left);
  width: 60px;
  height: 60px;
  margin: 8px;
  background: rgba(107,63,20,0.12);
  border: none;
  border-radius: 50%;
  opacity: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  -webkit-tap-highlight-color: transparent;
}

/* iOS PWA standalone -tilassa (kotivalikkoon asennettuna) env(safe-area-
   inset-bottom) raportoi liian pienen arvon todelliseen kotivalikkopalkin
   tilantarpeeseen nähden — sama havainto/korjaus kuin Löytöretki-ohjelmassa. */
.ios-pwa-bottom-fix #menu-settings-btn {
  bottom: calc(88px + 3 * env(safe-area-inset-bottom, 0px));
}

.ios-pwa-bottom-fix #menu-info-btn {
  bottom: calc(3 * env(safe-area-inset-bottom, 0px));
}

.ios-pwa-bottom-fix #paint-name-text,
.ios-pwa-bottom-fix #letters-word-text {
  bottom: calc(15vh + 3 * env(safe-area-inset-bottom, 0px));
}

.ios-pwa-bottom-fix #paint-slider-container,
.ios-pwa-bottom-fix #letters-slider-container,
.ios-pwa-bottom-fix #route-slider-container,
.ios-pwa-bottom-fix #numbers-slider-container {
  bottom: calc(6vh + 3 * env(safe-area-inset-bottom, 0px));
}

#menu-info-btn img {
  width: 26px;
  height: 26px;
  pointer-events: none;
}

#menu-settings-btn.holding {
  opacity: 0.9;
}

#settings-hold-ring {
  /* Rengas on tarkoituksella ison napin (60x60) omaa laatikkoa isompi
     (negatiivinen offset joka suuntaan) — muuten sormi peittää koko renkaan
     heti kun painallus alkaa, eikä aikuinen näe edistymää ollenkaan. */
  position: absolute;
  top: -16px;
  right: -16px;
  bottom: -16px;
  left: -16px;
  transform: rotate(-90deg);
  pointer-events: none;
}

#settings-hold-ring circle {
  fill: none;
  stroke: #FFD43B;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 163.36;
  stroke-dashoffset: 163.36;
}

#menu-settings-btn.holding #settings-hold-ring circle {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset linear;
}

#paint-container {
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: none;
}

#paint-wrapper {
  position: relative;
  width: min(58vw, 58vh);
  height: min(58vw, 58vh);
  flex-shrink: 0;
}

#paint-emoji-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

#paint-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  -webkit-filter: grayscale(100%) brightness(65%) contrast(0.35);
  filter: grayscale(100%) brightness(65%) contrast(0.35);
  opacity: 0.96;
}

#paint-name-text {
  display: none;
  position: absolute;
  bottom: calc(15vh + env(safe-area-inset-bottom));
  left: 0;
  width: 100%;
  color: #fff;
  font-size: max(3.0rem, min(10vw, 8rem));
  font-weight: 900;
  text-shadow: 4px 4px 0 #000;
  text-align: center;
  letter-spacing: 0.05em;
  user-select: none;
  z-index: 100;
  pointer-events: none;
}

#paint-slider-container {
  position: absolute;
  bottom: calc(6vh + env(safe-area-inset-bottom));
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 150;
  user-select: none;
  -webkit-user-select: none;
}

#paint-slider-track {
  position: relative;
  width: min(86vw, 380px);
  min-height: 60px;
  padding: 8px 20px 8px 64px;
  background: rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

#paint-slider-text {
  color: rgba(255,255,255,0.85);
  font-size: min(1.1rem, 4vw);
  font-weight: 700;
  font-family: sans-serif;
  white-space: normal;
  text-align: center;
  pointer-events: none;
  letter-spacing: 0.02em;
}

#paint-slider-handle {
  position: absolute;
  left: 4px;
  width: 52px;
  height: 52px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  cursor: grab;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
  transition: transform 0.1s ease-out;
  touch-action: none;
}

#paint-slider-handle:active {
  cursor: grabbing;
}

.star-particle {
  position: fixed;
  font-size: max(1.5rem, min(4vmin, 3rem));
  pointer-events: none;
  z-index: 150;
  user-select: none;
  animation: explode-star 1.5s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
}

@keyframes explode-star {
  0% {
    transform: translate(-50%, -50%) scale(0.5) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1.5) rotate(720deg);
    opacity: 0;
  }
}

#letters-container {
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: none;
}

#letters-letter-wrapper {
  position: relative;
  width: min(60vw, 60vh);
  height: min(60vw, 60vh);
  flex-shrink: 0;
}

#letters-fill-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#letters-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

#letters-hint-img {
  position: absolute;
  top: 4vh;
  right: 4vw;
  width: min(15vw, 15vh);
  height: min(15vw, 15vh);
  object-fit: contain;
  transition: top 0.6s ease, right 0.6s ease, width 0.6s ease, height 0.6s ease, margin 0.6s ease;
  z-index: 50;
  pointer-events: none;
}

#letters-hint-img.solved {
  top: 50%;
  right: 50%;
  width: min(58vw, 58vh);
  height: min(58vw, 58vh);
  margin-top: calc(-1 * min(29vw, 29vh));
  margin-right: calc(-1 * min(29vw, 29vh));
}

#letters-word-text {
  display: none;
  position: absolute;
  bottom: calc(15vh + env(safe-area-inset-bottom));
  left: 0;
  width: 100%;
  color: #fff;
  font-size: max(3.0rem, min(10vw, 8rem));
  font-weight: 900;
  text-shadow: 4px 4px 0 #000;
  text-align: center;
  letter-spacing: 0.05em;
  user-select: none;
  z-index: 100;
  pointer-events: none;
}

#letters-slider-container {
  position: absolute;
  bottom: calc(6vh + env(safe-area-inset-bottom));
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 150;
  user-select: none;
  -webkit-user-select: none;
}

#letters-slider-track {
  position: relative;
  width: min(86vw, 380px);
  min-height: 60px;
  padding: 8px 20px 8px 64px;
  background: rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

#letters-slider-text {
  color: rgba(255,255,255,0.85);
  font-size: min(1.1rem, 4vw);
  font-weight: 700;
  font-family: sans-serif;
  white-space: normal;
  text-align: center;
  pointer-events: none;
  letter-spacing: 0.02em;
}

#letters-slider-handle {
  position: absolute;
  left: 4px;
  width: 52px;
  height: 52px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  cursor: grab;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
  transition: transform 0.1s ease-out;
  touch-action: none;
}

#letters-slider-handle:active {
  cursor: grabbing;
}

#route-container {
  width: 100%;
  height: 100%;
  display: none;
  position: relative;
  touch-action: none;
}

#route-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#route-coin {
  position: absolute;
  top: 0;
  left: 0;
  width: max(50px, min(10vw, 80px));
  height: max(50px, min(10vw, 80px));
  border-radius: 22%;
  pointer-events: none;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
  will-change: transform;
}

#route-success {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  pointer-events: none;
}

#route-success-img {
  width: min(50vw, 50vh);
  height: min(50vw, 50vh);
  object-fit: contain;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,0.4));
}

#route-success-hint {
  font-size: max(1.1rem, min(3vmin, 1.6rem));
  font-weight: 700;
  color: rgba(255,255,255,0.75);
  text-shadow: 2px 2px 0 #000;
}

#route-slider-container {
  position: absolute;
  bottom: calc(6vh + env(safe-area-inset-bottom));
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 150;
  user-select: none;
  -webkit-user-select: none;
}

#route-slider-track {
  position: relative;
  width: min(86vw, 380px);
  min-height: 60px;
  padding: 8px 20px 8px 64px;
  background: rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

#route-slider-text {
  color: rgba(255,255,255,0.85);
  font-size: min(1.1rem, 4vw);
  font-weight: 700;
  font-family: sans-serif;
  white-space: normal;
  text-align: center;
  pointer-events: none;
  letter-spacing: 0.02em;
}

#route-slider-handle {
  position: absolute;
  left: 4px;
  width: 52px;
  height: 52px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  cursor: grab;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
  transition: transform 0.1s ease-out;
  touch-action: none;
}

#route-slider-handle:active {
  cursor: grabbing;
}

#numbers-container {
  width: 100%;
  height: 100%;
  display: none;
  position: relative;
}

#numbers-grid-container {
  display: none;
  gap: max(4px, min(1.5vmin, 16px));
  padding: max(8px, min(2vmin, 24px));
  width: 100%;
  height: 100%;
  align-content: center;
  justify-items: center;
}

.numbers-grid-emoji {
  width: 100%;
  height: 100%;
  max-width: min(20vw, 20vh);
  max-height: min(20vw, 20vh);
  object-fit: contain;
  transition: opacity 0.15s ease, filter 0.15s ease;
}

/* "Laske sormella" -tila: jo laskettu emoji himmenee ja harmaantuu, jotta
   lapsi näkee selvästi mitä on jo laskenut. */
.numbers-grid-emoji.numbers-counted {
  opacity: 0.3;
  filter: grayscale(85%);
}

#numbers-count-text {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: max(3.5rem, min(12vw, 9rem));
  font-weight: 900;
  text-shadow: 4px 4px 0 #000, 0 0 40px rgba(0,0,0,0.7);
  text-align: center;
  letter-spacing: 0.05em;
  padding: 0 4vw;
  pointer-events: none;
}

#numbers-prompt-text {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  /* env(safe-area-inset-top) ettei teksti jää notchin/kameran alle */
  padding-top: calc(max(14px, min(3vh, 28px)) + env(safe-area-inset-top));
  text-align: center;
  color: #fff;
  font-size: max(1.3rem, min(4vmin, 2rem));
  font-weight: 700;
  text-shadow: 2px 2px 0 #000;
  letter-spacing: 0.03em;
  pointer-events: none;
  z-index: 5;
}

#numbers-slider-container {
  position: absolute;
  bottom: calc(6vh + env(safe-area-inset-bottom));
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 150;
  user-select: none;
  -webkit-user-select: none;
}

#numbers-slider-track {
  position: relative;
  width: min(86vw, 380px);
  min-height: 60px;
  padding: 8px 20px 8px 64px;
  background: rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

#numbers-slider-text {
  color: rgba(255,255,255,0.85);
  font-size: min(1.1rem, 4vw);
  font-weight: 700;
  font-family: sans-serif;
  white-space: normal;
  text-align: center;
  pointer-events: none;
  letter-spacing: 0.02em;
}

#numbers-slider-handle {
  position: absolute;
  left: 4px;
  width: 52px;
  height: 52px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  cursor: grab;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
  transition: transform 0.1s ease-out;
  touch-action: none;
}

#numbers-slider-handle:active {
  cursor: grabbing;
}

/* Piano-moodi: 2 oktaavin kosketin (specs/024-piano-laulut.md) */
#piano-container {
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: max(16px, min(3vh, 32px));
  touch-action: none;
  position: relative;
}

#piano-settings-btn {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(10px + env(safe-area-inset-right, 0px));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  z-index: 20;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s ease;
}

#piano-settings-btn.holding {
  opacity: 0.9;
}

#piano-settings-hold-ring {
  position: absolute;
  top: -14px;
  right: -14px;
  bottom: -14px;
  left: -14px;
  transform: rotate(-90deg);
  pointer-events: none;
}

#piano-settings-hold-ring circle {
  fill: none;
  stroke: #FFD43B;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 163.36;
  stroke-dashoffset: 163.36;
}

#piano-settings-btn.holding #piano-settings-hold-ring circle {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset linear;
}

#piano-settings-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  z-index: 30;
}

#piano-settings-title {
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
  text-shadow: 2px 2px 0 #000;
}

#piano-settings-close-btn {
  background: #FFD43B;
  color: #241a10;
  border: none;
  border-radius: 18px;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 12px 28px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#piano-prompt {
  color: #fff;
  font-size: max(1.1rem, min(3.2vmin, 1.7rem));
  font-weight: 700;
  text-shadow: 2px 2px 0 #000;
  text-align: center;
  padding: max(14px, min(3vh, 28px)) 6vw 0;
  padding-top: calc(max(14px, min(3vh, 28px)) + env(safe-area-inset-top, 0px));
}

#piano-keyboard {
  position: relative;
  /* Leveys on aina pienin kolmesta: käytettävissä oleva leveys, kiinteä
     yläraja, TAI käytettävissä olevasta korkeudesta johdettu leveys (jotta
     kosketin ei venähdä epärealistisen kapeaksi/pitkäksi matalassa
     näkymässä) — ks. aspect-ratio alla joka johtaa lopullisen korkeuden
     tästä leveydestä. 4.375 = 14 valkoista kosketinta / ~3.2 (kosketimen
     karkea leveys:korkeus-suhde oikeaa pianoa jäljitellen, mutta ei niin
     kapea että pieni sormi ei osuisi). */
  width: min(96vw, 900px, calc(38vh * 4.375));
  height: min(38vh, 320px); /* varalla selaimille jotka eivät tue aspect-ratiota (esim. vanha iPad, iOS 12.5) */
  margin-top: auto;
  margin-bottom: 3vh;
}

@supports (aspect-ratio: 1 / 1) {
  #piano-keyboard {
    height: auto;
    aspect-ratio: 4.375 / 1;
  }
}

#piano-white-keys {
  display: flex;
  width: 100%;
  height: 100%;
}

.piano-key-white {
  position: relative;
  height: 100%;
  background: #fff;
  border: 2px solid #241a10;
  border-radius: 0 0 8px 8px;
  box-sizing: border-box;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.piano-key-white + .piano-key-white {
  border-left: none;
}

#piano-black-keys {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 62%;
  pointer-events: none;
}

.piano-key-black {
  position: absolute;
  top: 0;
  height: 100%;
  transform: translateX(-50%);
  background: #241a10;
  border: 2px solid #000;
  border-radius: 0 0 6px 6px;
  box-sizing: border-box;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  z-index: 2;
}

.piano-key-pressed.piano-key-white {
  background: #ffe8a3;
}

.piano-key-pressed.piano-key-black {
  background: #5c4a2e;
}

.piano-key-demo.piano-key-white {
  background: #ffd43b;
  box-shadow: 0 0 20px rgba(255,212,59,0.9);
}

.piano-key-demo.piano-key-black {
  background: #f59f00;
  box-shadow: 0 0 20px rgba(245,159,0,0.9);
}

/* Pieni pulssaava pallura seuraavan oikean koskettimen päällä — auttaa
   muistamaan mistä jatkaa kun matkittava jono kasvaa pitkäksi (etenevä
   vaikeustaso). Asetuksista pois kytkettävissä. */
.piano-key-hint::after {
  content: '';
  position: absolute;
  bottom: 14px;
  left: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #40c057;
  box-shadow: 0 0 10px rgba(64,192,87,0.9);
  animation: piano-hint-pulse 1.2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes piano-hint-pulse {
  0%, 100% { transform: translateX(-50%) scale(1); opacity: 0.8; }
  50% { transform: translateX(-50%) scale(1.3); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .piano-key-hint::after {
    animation: none;
  }
}

#piano-button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 2vh;
}

.piano-btn {
  background: rgba(255,255,255,0.9);
  color: #241a10;
  border: none;
  border-radius: 18px;
  font-size: max(0.85rem, min(2.3vmin, 1.05rem));
  font-weight: 700;
  padding: 10px 18px;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.piano-btn-stop {
  background: rgba(255,255,255,0.55);
  color: #4a1010;
}

#piano-rotate-prompt {
  display: none;
}

#piano-rotate-icon {
  font-size: 3.5rem;
  animation: piano-rotate-spin 1.8s ease-in-out infinite;
}

@keyframes piano-rotate-spin {
  0%, 20% { transform: rotate(0deg); }
  50%, 70% { transform: rotate(90deg); }
  100% { transform: rotate(90deg); }
}

#piano-rotate-text {
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  text-shadow: 2px 2px 0 #000;
  margin-top: 12px;
  text-align: center;
}

#piano-rotate-hint,
#piano-rotate-override-btn {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

#piano-rotate-prompt.piano-rotate-stuck #piano-rotate-hint,
#piano-rotate-prompt.piano-rotate-stuck #piano-rotate-override-btn {
  opacity: 1;
  pointer-events: auto;
}

#piano-rotate-hint {
  color: rgba(255,255,255,0.75);
  font-size: 0.85rem;
  text-align: center;
  max-width: 70vw;
  margin-top: 10px;
}

#piano-rotate-override-btn {
  margin-top: 22px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.85);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

/* Kosketimisto on liian kapea toimiakseen hyvin pystysuunnassa —
   kehotetaan kääntämään laite sen sijaan että yritettäisiin pakottaa
   vaakasuunta (iOS ei tue todellista orientaatiolukkoa web-sovelluksille,
   ja CSS-käännöstemppu aiheuttaisi välkkeen jos käyttäjän kääntymislukko
   on pois päältä). Jos laitteen kääntymislukko on päällä, näyttö ei
   koskaan fyysisesti käänny eikä tämä media query koskaan vaihdu — silloin
   ".piano-portrait-override" (asetettu "Jatka silti pystysuunnassa"
   -linkistä) ohittaa kehotteen ja näyttää kosketimet kaikesta huolimatta. */
@media (orientation: portrait) {
  #piano-prompt,
  #piano-keyboard,
  #piano-button-row,
  #piano-settings-btn {
    display: none;
  }

  #piano-rotate-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: auto;
  }

  #piano-container.piano-portrait-override #piano-prompt {
    display: block;
  }

  #piano-container.piano-portrait-override #piano-keyboard {
    display: block;
  }

  #piano-container.piano-portrait-override #piano-button-row,
  #piano-container.piano-portrait-override #piano-settings-btn {
    display: flex;
  }

  #piano-container.piano-portrait-override #piano-rotate-prompt {
    display: none;
  }
}
