html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #bfe3f7;
  touch-action: none;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

#hearts {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: calc(16px + env(safe-area-inset-left));
  display: flex;
  gap: 8px;
  pointer-events: none;
}

#hearts img {
  width: 48px;
  height: auto;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
}

#hearts img.lost { filter: grayscale(1) opacity(0.35); }

#hand {
  position: fixed;
  right: env(safe-area-inset-right);
  bottom: -7vh;
  height: 40vh;
  width: auto;
  pointer-events: none;
  transform-origin: 70% 100%;
}

#hand.throw { animation: hand-throw 0.35s ease-out; }

@keyframes hand-throw {
  40% { transform: translate(-8vw, -6vh) rotate(-14deg); }
  100% { transform: none; }
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  font-family: system-ui, sans-serif;
  color: #fff;
  text-align: center;
  background: rgba(20, 40, 60, 0.45);
  z-index: 10;
}

.overlay.start {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
}

.overlay.loading { font-size: clamp(22px, 5vmin, 36px); font-weight: 700; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); }

.overlay.rotate { z-index: 20; background: rgba(20, 40, 60, 0.92); font-size: clamp(24px, 6vw, 40px); }

.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: rgba(255, 170, 200, 0.55);
  opacity: 0;
}
.flash.on { animation: flash-pink 0.3s ease-out; }
@keyframes flash-pink { from { opacity: 1; } to { opacity: 0; } }

.overlay[hidden], .bubble[hidden] { display: none; }

.overlay h1 { margin: 0; font-size: clamp(28px, 6vw, 56px); text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); }

.menu-link {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  right: calc(env(safe-area-inset-right, 0px) + 16px);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

#play, #again, #retry {
  font-size: 32px;
  padding: 12px 40px;
  border: 0;
  border-radius: 999px;
  background: #ffd23f;
  color: #333;
  cursor: pointer;
}

#play {
  width: clamp(150px, 26vmin, 240px);
  height: clamp(150px, 26vmin, 240px);
  padding: 0;
  font-size: clamp(30px, 6vmin, 52px);
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  border-radius: 50%;
}

.bubble {
  position: fixed;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  max-width: 80vw;
  padding: 10px 18px;
  border-radius: 18px;
  background: #fff;
  font: 600 22px system-ui, sans-serif;
  width: max-content;
  white-space: pre-line;
  pointer-events: none;
}

@media (max-height: 500px), (pointer: coarse) {
  #hearts img { width: 36px; }
  #hand { height: 46vh; }
  .bubble { font-size: 16px; max-width: 60vw; padding: 8px 14px; }
}

#joystick {
  position: fixed;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.15);
  pointer-events: none;
}
#joystick[hidden] { display: none; }
#joystick.rest {
  left: calc(28px + env(safe-area-inset-left));
  bottom: calc(28px + env(safe-area-inset-bottom));
  opacity: 0.55;
}
#joystick-knob {
  position: absolute;
  left: 40px;
  top: 40px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
}

.overlay.clock { background: rgba(255, 255, 255, 0.3); color: #222; }

.clock-card {
  display: grid;
  grid-template-columns: minmax(0, 36fr) minmax(0, 64fr);
  grid-template-rows: 1fr auto;
  column-gap: clamp(12px, 3vw, 32px);
  row-gap: clamp(4px, 1.2vh, 12px);
  width: min(92vw, 1000px);
  max-height: 94vh;
  max-height: 94dvh;
  overflow-y: auto;
  box-sizing: border-box;
  padding: clamp(10px, 2.4vh, 28px) clamp(12px, 2.4vw, 32px);
  background: #fffdf6;
  border: 4px solid #333;
  border-radius: 22px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  font-family: "Chalkboard SE", "Comic Sans MS", system-ui, sans-serif;
  text-align: center;
}

.clock-left { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; }
.clock-question { font-size: clamp(20px, 4vh, 34px); font-weight: 700; }
.clock-dial { position: relative; width: min(100%, 50vh); aspect-ratio: 962 / 960; margin: clamp(4px, 1.5vh, 14px) 0; }
.clock-dial > img { display: block; width: 100%; height: 100%; }
.clock-hand { position: absolute; inset: 0; }
.clock-hand img { position: absolute; width: auto; }
.clock-answer { font-size: clamp(18px, 3.6vh, 30px); font-weight: 700; color: #1f6fd1; min-height: 1.3em; }

.clock-right { display: flex; flex-direction: column; justify-content: center; gap: clamp(4px, 1.2vh, 12px); text-align: left; }
.clock-label { font-size: clamp(15px, 2.8vh, 22px); font-weight: 700; color: #555; }
.clock-row { display: flex; flex-wrap: wrap; gap: clamp(6px, 1.2vh, 12px); }

.clock-button {
  min-height: max(44px, 8vh);
  padding: 0 clamp(12px, 1.6vw, 20px);
  border: 3px solid #333;
  border-radius: 999px;
  background: #fff;
  color: #222;
  font: 700 clamp(17px, 3.4vh, 26px) "Chalkboard SE", "Comic Sans MS", system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 3px 0 #333;
  touch-action: manipulation;
}
.clock-row.hours { display: grid; grid-template-columns: repeat(6, auto); justify-content: start; }
.clock-row.hours .clock-button { min-width: max(44px, 8vh); padding: 0; }
.clock-button.on { background: #ffe066; }
.clock-button:active { transform: translateY(2px); box-shadow: 0 1px 0 #333; }

.clock-feedback { grid-column: 1 / -1; min-height: 1.3em; font-size: clamp(17px, 3.4vh, 28px); font-weight: 700; }
.clock-feedback.hint { color: #c2410c; }
.clock-feedback.good { color: #15803d; }

@media (max-height: 500px) {
  .clock-card {
    grid-template-columns: minmax(0, 32fr) minmax(0, 68fr);
    column-gap: 10px;
    row-gap: 4px;
    width: calc(100vw - 16px - env(safe-area-inset-left) - env(safe-area-inset-right));
    max-height: calc(100vh - 8px);
    max-height: calc(100dvh - 8px);
    padding: 6px 10px;
    border-width: 3px;
  }
  .clock-question { font-size: 20px; }
  .clock-dial { margin: 4px 0; }
  .clock-answer { font-size: 17px; }
  .clock-right { gap: 4px; }
  .clock-label { font-size: 13px; }
  .clock-row { gap: 4px; }
  .clock-row.minutes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .clock-button {
    min-height: 40px;
    padding: 0 4px;
    font-size: 15px;
    line-height: 1.05;
    border-width: 2px;
  }
  .clock-row.hours .clock-button { min-width: 40px; }
  .clock-feedback { font-size: 15px; }
}
