:root {
  color-scheme: light;
  font-family: "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --ink: #2c1d17;
  --cream: #fff6e7;
  --sky: #7fd8ef;
  --leaf: #58a857;
  --fire: #ff7a22;
}

* {
  box-sizing: border-box;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  align-items: center;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.8), transparent 24rem),
    linear-gradient(160deg, #79d9f0 0%, #fae59f 58%, #78c873 100%);
  color: var(--ink);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 18px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

body::before {
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 203, 101, 0.88), transparent 11rem),
    linear-gradient(160deg, #5e4aa8 0%, #ef7055 44%, #ffc36d 68%, #8a6840 100%);
  content: "";
  inset: 0;
  opacity: var(--sunset-opacity, 0);
  pointer-events: none;
  position: fixed;
  transition: opacity 650ms ease;
  z-index: 0;
}

body::after {
  background:
    radial-gradient(circle at 78% 72%, rgba(255, 180, 80, 0.24), transparent 14rem),
    linear-gradient(160deg, rgba(255, 255, 255, 0) 0%, rgba(255, 199, 74, 0.22) 72%, rgba(255, 126, 72, 0.12) 100%);
  content: "";
  inset: 0;
  opacity: var(--challenge-opacity, 0);
  pointer-events: none;
  position: fixed;
  transition: opacity 650ms ease;
  z-index: 0;
}

.game-shell {
  display: grid;
  gap: 12px;
  max-width: 980px;
  position: relative;
  width: min(100%, 980px);
  z-index: 1;
}

.hud {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.hud {
  background: rgba(255, 246, 231, 0.78);
  border: 3px solid rgba(44, 29, 23, 0.16);
  border-radius: 8px;
  padding: 10px 14px;
}

.label {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  opacity: 0.62;
}

.rank-meter {
  align-items: center;
  display: grid;
  gap: 5px;
  grid-template-columns: auto minmax(96px, 150px) auto;
  margin-top: 7px;
  max-width: 310px;
}

.rank-meter span {
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

#rankLabel,
#resultRankLabel {
  color: #b23b2a;
  font-size: 0.9rem;
}

.meter-track {
  background: rgba(44, 29, 23, 0.16);
  border: 2px solid rgba(44, 29, 23, 0.15);
  border-radius: 999px;
  height: 12px;
  overflow: hidden;
}

.meter-track span {
  background: linear-gradient(90deg, #8e3027, #c94a3c);
  display: block;
  height: 100%;
  transition: width 180ms ease;
  width: 0%;
}

.result-meter {
  grid-template-columns: auto 1fr auto;
  margin: 8px auto 0;
  max-width: 320px;
}

strong {
  display: block;
  font-size: clamp(1.4rem, 4vw, 2.25rem);
  line-height: 1;
  transition: color 180ms ease, text-shadow 180ms ease;
}

#score.hot {
  color: #d61f1f;
  text-shadow: 0 2px 0 rgba(255, 240, 200, 0.7);
}

#score.warm {
  color: #d47a16;
  text-shadow: 0 2px 0 rgba(255, 250, 215, 0.72);
}

.play-area {
  position: relative;
}

canvas {
  aspect-ratio: 16 / 9;
  background: #fff6e7;
  border: 4px solid rgba(44, 29, 23, 0.3);
  border-radius: 8px;
  box-shadow: 0 18px 35px rgba(44, 29, 23, 0.18);
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  width: 100%;
}

.how-to {
  background: rgba(255, 246, 231, 0.7);
  border: 2px solid rgba(44, 29, 23, 0.12);
  border-radius: 8px;
  font-size: clamp(0.86rem, 2.8vw, 1rem);
  font-weight: 800;
  line-height: 1.45;
  margin: 0;
  padding: 9px 12px;
  text-align: center;
}

.share-panel {
  background: rgba(255, 246, 231, 0.94);
  border: 3px solid rgba(44, 29, 23, 0.22);
  border-radius: 8px;
  box-shadow: 0 18px 35px rgba(44, 29, 23, 0.22);
  display: grid;
  gap: 10px;
  left: 50%;
  max-width: min(86%, 430px);
  padding: 14px;
  position: absolute;
  text-align: center;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 430px;
  z-index: 2;
}

.share-panel::before {
  background: rgba(44, 29, 23, 0.18);
  border-radius: 8px;
  content: "";
  inset: -999px;
  pointer-events: none;
  position: absolute;
  z-index: -1;
}

.share-panel[hidden] {
  display: none;
}

.share-panel p {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.45;
  margin: 0;
}

.share-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

button {
  appearance: none;
  background: var(--ink);
  border: 0;
  border-radius: 8px;
  color: #fff6e7;
  cursor: pointer;
  font: inherit;
  font-size: clamp(0.95rem, 3vw, 1.08rem);
  font-weight: 800;
  min-height: 46px;
  padding: 10px 12px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

#retryButton {
  background: #b23b2a;
}

@media (max-width: 560px) {
  body {
    padding: 10px;
  }

  .hud {
    padding: 8px 10px;
  }

  .rank-meter {
    grid-template-columns: auto minmax(82px, 1fr);
    max-width: 210px;
  }

  .rank-meter span:last-child {
    grid-column: 1 / -1;
  }

  .game-shell {
    gap: 8px;
  }

  .share-actions {
    grid-template-columns: 1fr;
  }

  .share-panel {
    gap: 8px;
    max-width: 88%;
    padding: 10px;
  }
}
