html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: #0a0d1c;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* iPhone の横画面では、ダイナミックアイランド(ノッチ)とホームバーの所(セーフエリアの外)にゲームを置かない。
   Android と Web 版では env(...) が 0 なので、今までと同じ */
:root {
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}

#wrap {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: var(--st) var(--sr) var(--sb) var(--sl);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 横長の画面いっぱいに広げる(縦横比 4:3 〜 2.4:1 の範囲) */
#stage {
  position: relative;
  width: min(100vw, 240vh);
  height: min(100vh, 75vw);
  width: min(calc(100vw - var(--sl) - var(--sr)), calc((100dvh - var(--st) - var(--sb)) * 2.4));
  height: min(calc(100dvh - var(--st) - var(--sb)), calc((100vw - var(--sl) - var(--sr)) * 0.75));
}

/* スマホを縦に持っているときの案内 */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #0a0d1c;
  color: #fff;
  font-family: sans-serif;
  text-align: center;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 0 16px;
}

#rotate .phone {
  width: 54px;
  height: 92px;
  border: 4px solid #ffe14d;
  border-radius: 10px;
  animation: turn 2s ease-in-out infinite;
}

#rotate p {
  margin: 0;
  font-size: 20px;
  font-weight: bold;
}

#rotate small {
  color: #b0bec5;
  font-size: 14px;
}

@keyframes turn {
  0%, 20% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}

@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: flex; }
}

#stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#view {
  background: #0a0d1c;
}

/* 結果画面のシェアボタン(キャンバスの上に重ねる) */
#share {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translateX(-50%);
  width: min(420px, 60%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: sans-serif;
  z-index: 2;
}

#share[hidden] {
  display: none;
}

#share .row {
  display: flex;
  gap: 8px;
}

#share .sbtn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  border: 0;
  border-radius: 10px;
  padding: 7px 10px;
  font: inherit;
  font-weight: 800;
  font-size: clamp(12px, 2.4vh, 16px);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  background: #dfe7f7;
  color: #1b2440;
}

#share .sbtn.main {
  padding: 9px 12px;
  font-size: clamp(14px, 3vh, 19px);
  font-weight: 900;
  background: linear-gradient(#7fe3ff, #2f9bff);
  color: #031a33;
  box-shadow: 0 4px 0 #11589b, 0 8px 18px rgba(0, 0, 0, 0.4);
}

#share .sbtn.main small {
  display: block;
  font-size: 0.65em;
  font-weight: 700;
  opacity: 0.75;
}

#share .sbtn:active {
  transform: translateY(2px);
}

/* タイトル画面の下: バージョン・プライバシーポリシー・広告の設定 */
#legal {
  position: absolute;
  right: 12px;
  bottom: 8px;
  z-index: 2;
  font-family: sans-serif;
  font-size: 12px;
  color: #b0bec5;
}

#legal[hidden],
#legal [hidden] {
  display: none;
}

#legal a {
  color: #cfe8ff;
}

#buildInfo {
  margin-right: 10px;
  opacity: 0.8;
}

/* タイトル画面の言語切り替え */
#langSel {
  position: absolute;
  left: 12px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  gap: 6px;
  font-family: sans-serif;
}

#langSel[hidden] {
  display: none;
}

#langSel .langBtn {
  font: inherit;
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  cursor: pointer;
}

#langSel .langBtn.on {
  background: rgba(255, 225, 77, 0.9);
  border-color: #ffe14d;
  color: #222;
  font-weight: bold;
}

#share .sbtn.retry,
#pauseMenu .sbtn.retry {
  background: linear-gradient(#ffe36b, #ffb300);
  color: #1b1200;
  font-weight: 900;
  box-shadow: 0 3px 0 #a86a00;
}

/* 失敗したときの「広告を見てこのコーナーキックをやり直す」(アプリのみ) */
#redo {
  position: absolute;
  left: 50%;
  top: 60%;
  transform: translateX(-50%);
  width: min(520px, 76%);
  z-index: 3;
  padding: 10px 12px 12px;
  border-radius: 14px;
  background: rgba(8, 14, 28, 0.82);
  font-family: sans-serif;
  color: #e6eef8;
  text-align: center;
}

#redo[hidden] {
  display: none;
}

#redo p {
  margin: 0 0 8px;
  font-size: clamp(11px, 2.2vh, 14px);
}

#redo .row {
  display: flex;
  gap: 8px;
}

#redo .sbtn {
  flex: 1;
  border: 0;
  border-radius: 10px;
  padding: 9px 10px;
  font: inherit;
  font-weight: 800;
  font-size: clamp(12px, 2.6vh, 16px);
  cursor: pointer;
  background: #dfe7f7;
  color: #1b2440;
}

#redo .sbtn.main {
  flex: 2;
  background: linear-gradient(#7dffb0, #1fbf63);
  color: #04210f;
}

#redo .sbtn:disabled {
  opacity: 0.6;
}

/* タイトル画面(プレイ / あそびかた)・あそびかた(タイトルへ / プレイ)のボタン */
#titleMenu,
#howtoMenu {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 3;
  font-family: sans-serif;
}

#titleMenu {
  top: 50%;
  width: min(400px, 56%);
  flex-direction: column;
}

#howtoMenu {
  top: 84%;
  width: min(560px, 70%);
}

#titleMenu[hidden],
#howtoMenu[hidden] {
  display: none;
}

#titleMenu .sbtn,
#howtoMenu .sbtn {
  flex: 1;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-weight: 900;
  font-size: clamp(16px, 4.2vh, 24px);
  cursor: pointer;
  background: #dfe7f7;
  color: #1b2440;
}

#titleMenu .sbtn.retry,
#howtoMenu .sbtn.retry {
  background: linear-gradient(#ffe36b, #ffb300);
  color: #1b1200;
  box-shadow: 0 4px 0 #a86a00, 0 8px 18px rgba(0, 0, 0, 0.4);
}

#titleMenu .sbtn:active,
#howtoMenu .sbtn:active {
  transform: translateY(2px);
}

/* web-only:start */
/* Web 版のタイトル・あそびかたに出す Android アプリ(Google Play)へのリンク */
.storeLink {
  position: absolute;
  z-index: 3;
  font-family: sans-serif;
  font-weight: bold;
  font-size: clamp(12px, 2.8vh, 16px);
  color: #cfe8ff;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(207, 232, 255, 0.5);
  border-radius: 16px;
  padding: 5px 14px;
  text-decoration: none;
  white-space: nowrap;
}

.storeLink[hidden] {
  display: none;
}

/* タイトル画面: 「あそびかた」ボタンのすぐ下(top は game.js がボタンの下の端に合わせる) */
.storeLink.onTitle {
  left: 50%;
  transform: translateX(-50%);
}

/* あそびかた: 右上(見出しや下のボタンと重ならない所) */
.storeLink.onHowto {
  right: 16px;
  top: 4%;
}
/* web-only:end */

/* ポーズ画面のボタン */
#pauseMenu {
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translateX(-50%);
  width: min(300px, 50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 3;
  font-family: sans-serif;
}

#pauseMenu[hidden] {
  display: none;
}

#pauseMenu .sbtn {
  border: 0;
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  font-weight: 900;
  font-size: clamp(14px, 3vh, 18px);
  cursor: pointer;
  background: #dfe7f7;
  color: #1b2440;
}
