:root {
  font-family: 'Comic Sans MS', 'Chalkboard SE', system-ui, sans-serif;
  color: #fff;
  background: #1a0f2e;
}
* { box-sizing: border-box; }
body {
  margin: 0 auto;
  padding: 10px;
  max-width: 940px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 0%, #3b1f63 0%, #1a0f2e 55%, #100a20 100%);
  min-height: 100vh;
}
h1 {
  margin: .1em 0 0;
  font-size: clamp(30px, 7vw, 54px);
  letter-spacing: 4px;
  color: #9dff6a;
  text-shadow: 0 4px 0 #2c6417, 0 0 24px #7dff3a, 0 0 48px #7dff3a55;
}
#tagline { margin: 0 0 8px; color: #ffd0f0; font-size: clamp(13px, 3vw, 18px); }
#hud {
  display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; align-items: center;
  font-size: clamp(14px, 3.2vw, 20px); font-weight: bold;
  background: #2c1748; border: 3px solid #8b5fd6; border-radius: 14px;
  padding: 7px 12px; margin: 0 auto 8px; max-width: 900px;
}
#hearts { letter-spacing: 2px; }
#tornado { color: #9fe8ff; }
#tornado.cooling { color: #8590a8; }
#progress-wrap { max-width: 900px; margin: 0 auto 8px; }
#progress-label { font-size: 11px; letter-spacing: 2px; color: #c9a8ff; font-weight: bold; }
#progress-bar { height: 12px; background: #211231; border: 2px solid #8b5fd6; border-radius: 999px; overflow: hidden; }
#progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #ff8a3c, #ffd23f, #9dff6a); transition: width .2s; }

.game-shell {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  touch-action: none;
}
canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  background: #241338;
  border: 4px solid #8b5fd6;
  border-radius: 16px;
  touch-action: none;
  box-shadow: 0 10px 30px #0008, 0 0 0 2px #1a0f2e inset;
  cursor: crosshair;
}

.panel {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(88%, 520px);
  max-height: 94%;
  overflow: auto;
  padding: 18px 20px;
  background: #2b1747f2;
  border: 4px solid #ffd23f;
  border-radius: 20px;
  box-shadow: 0 12px 40px #000a;
  text-align: center;
}
.panel[hidden] { display: none; }
.panel h2 {
  margin: 0 0 8px;
  font-size: clamp(22px, 4.5vw, 34px);
  color: #9dff6a;
  text-shadow: 0 3px 0 #2c6417;
}
.panel p { margin: 8px 0; line-height: 1.4; font-size: clamp(13px, 2.7vw, 17px); }
.panel button {
  font: inherit;
  font-weight: bold;
  font-size: clamp(16px, 3.4vw, 22px);
  padding: 11px 28px;
  margin-top: 6px;
  border: 3px solid #fff;
  border-radius: 14px;
  cursor: pointer;
  color: #10340a;
  background: #9dff6a;
  box-shadow: 0 4px 0 #2c6417;
}
.panel button:active { transform: translateY(3px); box-shadow: none; }
.riddle { background: #22103cf5; border-color: #9fe8ff; }
.riddle h2 { color: #9fe8ff; text-shadow: 0 3px 0 #174b63; }
#scientist { font-style: italic; color: #ffd0f0; }
#riddle-text { font-weight: bold; color: #fff3a8; font-size: clamp(15px, 3.2vw, 20px); }
#riddle-options { display: grid; gap: 8px; margin: 12px 0; }
#riddle-options button {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  background: #472a72;
  color: #fff;
  border-color: #b58cff;
  box-shadow: 0 3px 0 #1b0f2c;
  font-size: clamp(15px, 3.2vw, 19px);
}
#riddle-options button:hover { background: #5b3690; }
#riddle-options button.wrong { animation: shake .3s; background: #7d2338; border-color: #ff7188; }
#riddle-feedback { min-height: 1.3em; font-weight: bold; color: #9dff6a; }

#joystick[hidden] { display: none !important; }
#joystick {
  display: none;
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: min(34vw, 150px);
  aspect-ratio: 1;
  touch-action: none;
  z-index: 3;
}
#joyBase {
  width: 100%; height: 100%;
  border-radius: 50%;
  background: #1a0f2e66;
  border: 3px solid #c9a8ffaa;
  box-shadow: 0 0 18px #0008 inset;
  position: relative;
}
#joyKnob {
  position: absolute;
  left: 50%; top: 50%;
  width: 44%; height: 44%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #9dff6acc;
  border: 3px solid #fff;
  box-shadow: 0 2px 10px #0008;
}

#skip-cutscene {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  top: calc(12px + env(safe-area-inset-top));
  z-index: 4;
  padding: 9px 16px;
  border: 2px solid #c9a8ff;
  border-radius: 999px;
  background: #1a0f2ecc;
  color: #fff;
  font: bold 15px system-ui, sans-serif;
  cursor: pointer;
}
#skip-cutscene[hidden] { display: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
#skip-cutscene:active { transform: scale(.96); }

#help {
  font-size: clamp(12px, 2.6vw, 15px);
  max-width: 900px;
  margin: 10px auto 4px;
  color: #e4d3ff;
  line-height: 1.5;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  50% { transform: translateX(7px); }
  75% { transform: translateX(-4px); }
}

@media (hover: none) and (pointer: coarse) {
  #joystick { display: block; }
  canvas { cursor: default; }
  .riddle {
    position: fixed;
    max-height: 90dvh;
    width: min(92vw, 520px);
    z-index: 20;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  body { padding: 4px; max-width: none; }
  h1 { font-size: 22px; letter-spacing: 2px; }
  #tagline, #help, #progress-label { display: none; }
  #hud { font-size: 13px; padding: 3px 8px; margin-bottom: 4px; }
  #progress-wrap { margin-bottom: 4px; }
  canvas {
    width: min(100vw - 8px, calc((100dvh - 88px) * 3 / 2));
    border-width: 2px;
    border-radius: 10px;
    margin: 0 auto;
  }
  .game-shell { width: min(100vw - 8px, calc((100dvh - 88px) * 3 / 2)); }
  #joystick { width: min(22vh, 120px); }
  .panel { padding: 10px 14px; }
  .panel h2 { font-size: 20px; }
  .panel p { font-size: 13px; margin: 4px 0; }
  .panel button { font-size: 15px; padding: 8px 20px; }
  #riddle-options { gap: 5px; margin: 6px 0; }
  #riddle-options button { padding: 7px 10px; font-size: 14px; }
}

@media (max-width: 480px) {
  body { padding: 6px; }
  #hud { gap: 4px 10px; }
  #progress-wrap { margin-bottom: 6px; }
}

/* Readable game information stays below the play area at every screen size. */
.game-guide {
  box-sizing: border-box;
  width: 100%;
  max-width: 800px;
  margin: 24px auto;
  padding: 20px;
  border: 1px solid currentColor;
  border-radius: 16px;
  background: transparent;
  color: inherit;
  text-align: left;
  font-size: 1rem;
  line-height: 1.65;
  overflow-wrap: break-word;
}
.game-guide h2 { margin: 0 0 8px; font-size: 1.35rem; }
.game-guide h3 { margin: 18px 0 8px; font-size: 1.1rem; }
.game-guide p { margin: 0 0 12px; }
.game-guide a { color: inherit; text-underline-offset: 3px; }
.game-guide .guide-home { margin-bottom: 0; }
