
/* ==========================
   共通
========================== */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;

  font-family:
    "Arial Rounded MT Bold",
    "Hiragino Maru Gothic ProN",
    sans-serif;
}

body {
  background: #87ceeb;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

/* ==========================
   ゲーム画面
========================== */

#game {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

#readyScreen {
  position: absolute;
  inset: 0;

  background: linear-gradient(
    to bottom,
    #87ceeb 0%,
    #e2f6ff 62%,
    #91c879 62%,
    #71b65c 100%
  );
}

/* ==========================
   スコア
========================== */

#score {
  position: absolute;
  top: calc(
    env(safe-area-inset-top, 0px) + 22px
  );
  left: 0;
  width: 100%;

  text-align: center;
  font-size: clamp(20px, 6vw, 28px);
  font-weight: 900;
  color: #263a4c;
}

/* ==========================
   キャラクター
========================== */

#character {
  position: absolute;
  left: 50%;
  bottom: 20%;

  width: min(52vw, 210px, 33dvh);

  transform: translateX(-50%);
  transform-origin: center bottom;

  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#character canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}

#character.pulled {
  transform: translateX(-50%) scale(1.025);
}

#character.recoil {
  animation: recoil 0.28s ease-out;
}

@keyframes recoil {
  0% {
    transform:
      translateX(-50%) scale(1.05, 0.90);
  }

  45% {
    transform:
      translateX(-50%) scale(0.96, 1.10);
  }

  100% {
    transform:
      translateX(-50%) scale(1, 1);
  }
}

/* ==========================
   パワーゲージ
========================== */

#meterArea {
  position: absolute;

  right: max(
    14px,
    calc(env(safe-area-inset-right, 0px) + 10px)
  );

  bottom: 26%;

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;

  pointer-events: none;
}

#powerValue {
  font-size: clamp(16px, 5vw, 22px);
  font-weight: 900;
  color: #263a4c;
}

#meter {
  position: relative;
  width: 34px;
  height: clamp(120px, 28dvh, 240px);

  overflow: hidden;
  border: 3px solid #333;
  border-radius: 12px;
  background: white;
}

#power {
  position: absolute;
  bottom: 0;
  left: 0;

  width: 100%;
  height: 0%;

  background: linear-gradient(
    to top,
    #54d66d,
    #ffd13e,
    #ff5353
  );
}

#meterLabel {
  font-size: 12px;
  font-weight: 900;
  color: #263a4c;
}

/* ==========================
   操作ガイド
========================== */

#guide {
  position: absolute;

  bottom: calc(
    env(safe-area-inset-bottom, 0px) + 28px
  );

  left: 5%;
  width: 90%;

  text-align: center;

  font-size: clamp(16px, 4.5vw, 21px);
  font-weight: 900;
  color: #263a4c;

  pointer-events: none;
}

/* ==========================
   3D飛行画面
========================== */

#flightScreen {
  position: absolute;
  inset: 0;
  z-index: 10;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;

  background: #87ceeb;

  transition:
    opacity 0.3s ease,
    visibility 0.3s;
}

#flightScreen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

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

/* ==========================
   飛行中の表示
========================== */

#flightHud {
  position: absolute;

  top: calc(
    env(safe-area-inset-top, 0px) + 25px
  );

  left: 0;
  z-index: 2;

  width: 100%;
  text-align: center;

  color: white;
  text-shadow: 0 2px 6px #333;

  pointer-events: none;
}

#flightDistance {
  font-size: clamp(23px, 7vw, 33px);
  font-weight: 900;
}

#flightPower {
  margin-top: 5px;
  font-size: 16px;
  font-weight: 800;
}

/* ==========================
   発射フラッシュ
========================== */

#flightFlash {
  position: absolute;
  inset: 0;
  z-index: 4;

  background: white;
  opacity: 0;
  pointer-events: none;
}

#flightFlash.play {
  animation: launchFlash 0.45s ease-out;
}

@keyframes launchFlash {
  0% { opacity: 0.85; }
  35% { opacity: 0.3; }
  100% { opacity: 0; }
}

/* ==========================
   結果画面
========================== */

#flightResult {
  position: absolute;
  inset: 0;
  z-index: 5;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  justify-content: safe center;
  gap: 18px;

  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;

  padding:
    calc(env(safe-area-inset-top, 0px) + 24px)
    20px
    calc(env(safe-area-inset-bottom, 0px) + 24px);

  background: rgba(0, 0, 0, 0.5);
  color: white;
  text-align: center;
}

#flightResult[hidden] {
  display: none;
}

#resultText {
  font-size: clamp(25px, 8vw, 38px);
  font-weight: 900;
  line-height: 1.5;
  flex-shrink: 0;
}

#resultText small {
  font-size: 0.55em;
}

/* ==========================
   共有・リトライ
========================== */

#resultActions {
  display: flex;
  flex-direction: column;
  gap: 12px;

  width: min(82vw, 290px);
  flex-shrink: 0;
}

#shareButton,
#retryButton {
  display: flex;
  align-items: center;
  justify-content: center;

  width: 100%;
  min-height: 56px;

  border: none;
  border-radius: 16px;

  font: inherit;
  font-size: 20px;
  font-weight: 900;

  text-align: center;
  text-decoration: none;

  cursor: pointer;
  touch-action: manipulation;
}

#shareButton {
  background: #111111;
  color: white;
  border: 2px solid #555;
}

#retryButton {
  background: #ffb347;
  color: #352715;
}

#shareButton:active,
#retryButton:active {
  transform: scale(0.97);
}

/* ==========================
   制作者のSNS
========================== */

#creatorLinks {
  width: min(90vw, 340px);
  flex-shrink: 0;

  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.35);
}

#creatorTitle {
  margin-bottom: 12px;

  color: #eeeeee;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.05em;
}

#socialLinks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.socialLink {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;

  min-width: 0;
  min-height: 65px;
  padding: 9px 6px;

  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 14px;

  color: #ffffff;
  text-decoration: none;
  font-size: 12px;
  font-weight: bold;
  overflow-wrap: anywhere;

  cursor: pointer;
  touch-action: manipulation;
}

.socialIcon {
  font-size: 21px;
  line-height: 1;
}

.noteLink {
  background: #238c70;
}

.xLink {
  background: #161616;
}

.socialLink:active {
  transform: scale(0.96);
}

/* ==========================
   小さいスマホ
========================== */

@media (max-height: 700px) {
  #character {
    bottom: 18%;
    width: min(42vw, 165px, 31dvh);
  }

  #meterArea {
    bottom: 23%;
  }

  #meter {
    height: 24dvh;
  }

  #flightResult {
    gap: 12px;
  }

  #resultText {
    font-size: 25px;
  }

  #resultActions {
    gap: 9px;
  }

  #shareButton,
  #retryButton {
    min-height: 48px;
  }

  #creatorLinks {
    padding-top: 10px;
  }

  .socialLink {
    min-height: 55px;
  }
}

/* ==========================
   動きを抑える設定
========================== */

@media (prefers-reduced-motion: reduce) {
  #flightScreen {
    transition: none;
  }

  #character.recoil {
    animation: none;
  }

  #flightFlash.play {
    animation: none;
  }
}
