@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;
  cursor: 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: center;
  padding: 20px 0;
  gap: max(12px, min(3vh, 28px));
  background: linear-gradient(to bottom, #e8d6a6 0%, #dcc78e 100%);
  overflow: hidden;
  position: relative;
}

#menu::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.7;
  background-image:
    radial-gradient(260px 180px at 10% 15%, rgba(160,120,60,0.28), transparent),
    radial-gradient(300px 200px at 88% 78%, rgba(160,120,60,0.25), transparent),
    radial-gradient(200px 140px at 70% 10%, rgba(160,120,60,0.2), transparent),
    radial-gradient(220px 160px at 25% 85%, rgba(160,120,60,0.2), 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: #4a3018;
  text-align: center;
  letter-spacing: -0.02em;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  padding: 0.5em 1.1em;
  background: #f0e2ba;
  border: 3px solid #5c3d1f;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(74,48,24,0.25);
}

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

#menu-grid {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: max(28px, min(5vw, 56px));
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  position: relative;
  z-index: 1;
  padding: 34px 12vw;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='120' viewBox='0 0 160 120'%3E%3Cpath d='M0,60 Q40,16 80,60 T160,60' fill='none' stroke='%235c3d1f' stroke-opacity='0.3' stroke-width='3' stroke-dasharray='1 13' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-position: left center;
  background-size: 160px 120px;
}

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

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  flex: 0 0 auto;
  width: max(92px, min(17vw, 148px));
  scroll-snap-align: center;
  user-select: none;
  position: relative;
}

/* Jokainen pysäkki saa oman teemamaastonsa taakseen (Seikkailukartta vaihe 3) */
.mode-card::before {
  content: '';
  position: absolute;
  top: -14%;
  left: 50%;
  transform: translateX(-50%);
  width: 190%;
  height: 130%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  z-index: -1;
  pointer-events: none;
}

.mode-card[data-terrain="forest"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 140'%3E%3Cg fill='%236b7d4a' fill-opacity='0.55' stroke='%235c3d1f' stroke-opacity='0.4' stroke-width='2'%3E%3Cpath d='M55,90 L75,40 L95,90 Z'/%3E%3Cpath d='M40,95 L58,55 L76,95 Z'/%3E%3Cpath d='M115,92 L133,48 L151,92 Z'/%3E%3Cpath d='M130,96 L146,60 L162,96 Z'/%3E%3C/g%3E%3C/svg%3E");
}

.mode-card[data-terrain="meadow"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 140'%3E%3Cpath d='M40,80 A60,60 0 0 1 160,80' fill='none' stroke='%23a4472c' stroke-opacity='0.4' stroke-width='6'/%3E%3Cpath d='M50,80 A50,50 0 0 1 150,80' fill='none' stroke='%23dcae3c' stroke-opacity='0.45' stroke-width='6'/%3E%3Cpath d='M60,80 A40,40 0 0 1 140,80' fill='none' stroke='%236b7d4a' stroke-opacity='0.45' stroke-width='6'/%3E%3Cg fill='%23a4472c' fill-opacity='0.45'%3E%3Ccircle cx='35' cy='100' r='7'/%3E%3Ccircle cx='165' cy='102' r='7'/%3E%3Ccircle cx='100' cy='112' r='7'/%3E%3C/g%3E%3C/svg%3E");
}

.mode-card[data-terrain="cave"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 140'%3E%3Cpath d='M45,120 Q45,45 100,45 Q155,45 155,120 Z' fill='%235c3d1f' fill-opacity='0.28' stroke='%235c3d1f' stroke-opacity='0.45' stroke-width='3'/%3E%3Cellipse cx='100' cy='100' rx='32' ry='26' fill='%233a2712' fill-opacity='0.55'/%3E%3C/svg%3E");
}

.mode-card[data-terrain="sea"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 140'%3E%3Cg fill='none' stroke='%232a5a6b' stroke-opacity='0.4' stroke-width='4'%3E%3Cpath d='M30,70 q17,-14 34,0 t34,0 t34,0 t34,0'/%3E%3Cpath d='M30,95 q17,-14 34,0 t34,0 t34,0 t34,0'/%3E%3Cpath d='M30,120 q17,-14 34,0 t34,0 t34,0 t34,0'/%3E%3C/g%3E%3C/svg%3E");
}

.mode-card[data-terrain="hills"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 140'%3E%3Cpath d='M0,110 Q50,70 100,110 T200,110 L200,140 L0,140 Z' fill='%236b7d4a' fill-opacity='0.4'/%3E%3Cpath d='M0,125 Q50,95 100,125 T200,125 L200,140 L0,140 Z' fill='%235c6d3f' fill-opacity='0.4'/%3E%3C/svg%3E");
}

.mode-card[data-terrain="mountain"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 140'%3E%3Cpath d='M20,110 L70,50 L100,85 L135,35 L180,110 Z' fill='%235c3d1f' fill-opacity='0.3' stroke='%235c3d1f' stroke-opacity='0.45' stroke-width='3' stroke-linejoin='round'/%3E%3Cpath d='M60,72 Q70,60 80,68' fill='none' stroke='%23fff' stroke-opacity='0.5' stroke-width='3'/%3E%3C/svg%3E");
}

.mode-card:nth-child(4n+1) { transform: translateY(-20px); }
.mode-card:nth-child(4n+2) { transform: translateY(0px); }
.mode-card:nth-child(4n+3) { transform: translateY(20px); }
.mode-card:nth-child(4n+4) { transform: translateY(0px); }

.mode-stop {
  width: max(80px, min(16vw, 140px));
  height: max(80px, min(16vw, 140px));
  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: 4px solid #4a3018;
  box-shadow: 0 6px 14px rgba(74,48,24,0.35);
  cursor: pointer;
}

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

.mode-stop.unavailable {
  background: rgba(74,48,24,0.1);
  border: 4px solid rgba(74,48,24,0.3);
  opacity: 0.55;
}

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

.mode-card-name {
  font-size: max(0.85rem, min(2.2vmin, 1.1rem));
  font-weight: 700;
  color: #4a3018;
  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(74,48,24,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;
  font-size: 1.4rem;
  color: rgba(255,255,255,0.35);
  background: none;
  border: none;
  border-radius: 50%;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s, background 0.2s;
  z-index: 210;
  font-family: inherit;
  cursor: default;
}

#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(255,255,255,0.35);
  font-family: monospace;
}

#settings-back-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.6);
  border-radius: 12px;
  font-size: 1rem;
  padding: 10px 24px;
  cursor: pointer;
  font-family: inherit;
  margin-top: 8px;
}

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

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

.settings-label {
  color: rgba(255,255,255,0.7);
  font-size: 1.05rem;
  font-weight: 700;
  font-family: sans-serif;
}

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

.settings-opt-btn {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 2px solid transparent;
  color: rgba(255,255,255,0.85);
  border-radius: 14px;
  padding: 12px 4px;
  font-size: 1.1rem;
  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 {
  position: fixed;
  bottom: 0px;
  bottom: env(safe-area-inset-bottom);
  right: 0px;
  right: env(safe-area-inset-right);
  width: 60px;
  height: 60px;
  background: none;
  border: none;
  font-size: 1.6rem;
  opacity: 0.25;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  -webkit-tap-highlight-color: transparent;
}

#pw-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#pw-box {
  background: #222;
  border-radius: 20px;
  padding: 28px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 260px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

#pw-input {
  background: #333;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  color: #fff;
  font-size: 1.1rem;
  padding: 12px 16px;
  outline: none;
  font-family: inherit;
  width: 100%;
}

#pw-btn-row {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

#pw-cancel {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.6);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
}

#pw-ok {
  background: #FF6B35;
  border: none;
  color: #fff;
  border-radius: 10px;
  padding: 10px 24px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

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

#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: 15vh;
  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: 6vh;
  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(80vw, 360px);
  min-height: 60px;
  padding: 8px 20px;
  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, 4.2vw);
  font-weight: 700;
  font-family: sans-serif;
  white-space: nowrap;
  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;
}

#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: 15vh;
  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: 6vh;
  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(80vw, 360px);
  min-height: 60px;
  padding: 8px 20px;
  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, 4.2vw);
  font-weight: 700;
  font-family: sans-serif;
  white-space: nowrap;
  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));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: max(2rem, min(6vw, 3.2rem));
  pointer-events: none;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
  will-change: transform;
}

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

#route-success-text {
  font-size: max(3rem, min(10vw, 8rem));
  font-weight: 900;
  color: #fff;
  text-shadow: 4px 4px 0 #000;
  letter-spacing: 0.05em;
}

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