:root {
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
  font-family: "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", "M PLUS Rounded 1c", system-ui, -apple-system, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: #7cc514;
  background-image:
    linear-gradient(45deg, rgba(103, 178, 8, 0.45) 25%, transparent 25%, transparent 75%, rgba(103, 178, 8, 0.45) 75%),
    linear-gradient(45deg, rgba(103, 178, 8, 0.45) 25%, transparent 25%, transparent 75%, rgba(103, 178, 8, 0.45) 75%);
  background-size: 48px 48px;
  background-position: 0 0, 24px 24px;
  color: #222222;
}

.game-area,
#ad-area {
  width: 100%;
  overflow: hidden;
}

.game-area {
  position: relative;
  flex: 1;
  min-height: 0;
  padding-top: var(--safe-area-inset-top);
  padding-right: var(--safe-area-inset-right);
  padding-bottom: var(--safe-area-inset-bottom);
  padding-left: var(--safe-area-inset-left);
  display: flex;
  justify-content: center;
  align-items: center;
}

#ad-area {
  display: none;
  height: 60px;
  margin-top: 20px;
  flex-shrink: 0;
}

@media (min-width: 800px) {
  #ad-area {
    height: 90px;
  }
}

body.has-ad-area .game-area {
  padding-bottom: 0;
}

body.has-ad-area #ad-area {
  display: block;
}

#ad-area .adsbygoogle {
  display: block;
  width: 100%;
  height: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* 言語切り替え */
html[lang="ja"] .lang-en,
html:not([lang="ja"]) .lang-ja {
  display: none;
}

/* ========================================
** Screen Switcher
*/

.loading-screen,
.title-screen,
.game-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

body:not(.loading-screen-active) .loading-screen,
body:not(.title-screen-active) .title-screen,
body:not(.game-screen-active) .game-screen {
  display: none;
}

/* ========================================
** 2:3 Portrait Stage Frame
*/

.stage-frame {
  position: relative;
  width: min(100%, calc((100dvh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom)) * 2 / 3));
  max-height: 100%;
  aspect-ratio: 2 / 3;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

body.has-ad-area .stage-frame {
  width: min(100%, calc((100dvh - var(--safe-area-inset-top) - 80px) * 2 / 3));
}

@media (min-width: 800px) {
  body.has-ad-area .stage-frame {
    width: min(100%, calc((100dvh - var(--safe-area-inset-top) - 110px) * 2 / 3));
  }
}

.game-screen .stage-frame {
  width: min(100%, calc((100dvh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom) - 42px) * 2 / 3));
}

body.has-ad-area .game-screen .stage-frame {
  width: min(100%, calc((100dvh - var(--safe-area-inset-top) - 122px) * 2 / 3));
}

@media (min-width: 800px) {
  body.has-ad-area .game-screen .stage-frame {
    width: min(100%, calc((100dvh - var(--safe-area-inset-top) - 152px) * 2 / 3));
  }
}

/* ========================================
** Title Screen
*/

.title-stage {
  background-image: url("../image/ui/iPhone_startView.png");
}

.title-close-button {
  position: absolute;
  top: 2.5%;
  left: 3.75%;
  width: 11%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(220, 0, 0, 0.78);
  cursor: pointer;
  z-index: 5;
}

body:not(.is-web-page) .title-close-button {
  display: none;
}

.title-close-button img {
  width: 55%;
  height: 55%;
  filter: brightness(0) invert(1);
}

.title-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2.5%;
}

.title-logo {
  width: 95%;
  height: auto;
  display: block;
  pointer-events: none;
}

.title-menu {
  width: 62.5%;
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.2dvh, 10px);
}

.mode-btn {
  width: 100%;
  aspect-ratio: 600 / 144;
  border: none;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.mode-btn:hover {
  transform: scale(1.03);
}

.mode-btn:active {
  transform: scale(0.96);
}

html[lang="ja"] .mode-btn-easy { background-image: url("../image/ui/button-startEasyGame.png"); }
html:not([lang="ja"]) .mode-btn-easy { background-image: url("../image-en/ui/button-startEasyGame.png"); }

html[lang="ja"] .mode-btn-normal { background-image: url("../image/ui/button-startNormalGame.png"); }
html:not([lang="ja"]) .mode-btn-normal { background-image: url("../image-en/ui/button-startNormalGame.png"); }

html[lang="ja"] .mode-btn-endless { background-image: url("../image/ui/button-startEndlessGame.png"); }
html:not([lang="ja"]) .mode-btn-endless { background-image: url("../image-en/ui/button-startEndlessGame.png"); }

html[lang="ja"] .mode-btn-timetrial { background-image: url("../image/ui/button-startTimeTrial.png"); }
html:not([lang="ja"]) .mode-btn-timetrial { background-image: url("../image-en/ui/button-startTimeTrial.png"); }

/* モード説明ポップアップ */
.mode-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  background: rgba(18, 34, 6, 0.56);
  backdrop-filter: blur(2px);
  animation: fadeSlideIn 0.18s ease;
}

.mode-popup-overlay[hidden] {
  display: none;
}

.mode-popup-card {
  width: min(84vw, calc((100dvh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom)) * 2 / 3 * 0.84));
  background: #fffef5;
  border: 4px solid #72b800;
  border-radius: 22px;
  box-shadow:
    0 14px 32px rgba(0, 0, 0, 0.32),
    inset 0 0 0 3px #e9fbb9;
  padding: clamp(16px, 4vw, 24px) clamp(16px, 4vw, 22px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  animation: popupBounceIn 0.2s cubic-bezier(0.22, 1.28, 0.36, 1);
}

@keyframes popupBounceIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.mode-popup-badge {
  width: 68%;
  aspect-ratio: 2 / 1;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

html[lang="ja"] body.popup-mode-easy .mode-popup-badge { background-image: url("../image/ui/label-easy.png"); }
html:not([lang="ja"]) body.popup-mode-easy .mode-popup-badge { background-image: url("../image-en/ui/label-easy.png"); }

html[lang="ja"] body.popup-mode-normal .mode-popup-badge { background-image: url("../image/ui/label-normal.png"); }
html:not([lang="ja"]) body.popup-mode-normal .mode-popup-badge { background-image: url("../image-en/ui/label-normal.png"); }

html[lang="ja"] body.popup-mode-endless .mode-popup-badge { background-image: url("../image/ui/label-endless.png"); }
html:not([lang="ja"]) body.popup-mode-endless .mode-popup-badge { background-image: url("../image-en/ui/label-endless.png"); }

html[lang="ja"] body.popup-mode-timetrial .mode-popup-badge { background-image: url("../image/ui/label-timeTrial.png"); }
html:not([lang="ja"]) body.popup-mode-timetrial .mode-popup-badge { background-image: url("../image-en/ui/label-timeTrial.png"); }

.mode-popup-sr,
.mode-popup-desc {
  display: none;
}

body.popup-mode-easy .mode-popup-sr-easy,
body.popup-mode-normal .mode-popup-sr-normal,
body.popup-mode-endless .mode-popup-sr-endless,
body.popup-mode-timetrial .mode-popup-sr-timetrial,
body.popup-mode-easy .mode-popup-desc-easy,
body.popup-mode-normal .mode-popup-desc-normal,
body.popup-mode-endless .mode-popup-desc-endless,
body.popup-mode-timetrial .mode-popup-desc-timetrial {
  display: block;
}

.mode-popup-descriptions {
  width: 100%;
}

.mode-popup-desc {
  font-size: clamp(13px, 3.6vw, 15px);
  font-weight: 700;
  line-height: 1.55;
  color: #2b3319;
}

.mode-popup-start-btn {
  width: 78%;
  padding: 11px 20px;
  border: 3px solid #d47a00;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff159 0%, #ffc800 100%);
  box-shadow:
    0 4px 0 #b86200,
    0 6px 14px rgba(0, 0, 0, 0.18);
  color: #9e1142;
  font-family: inherit;
  font-size: clamp(16px, 4.4vw, 19px);
  font-weight: 900;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.mode-popup-start-btn:hover {
  transform: scale(1.03);
}

.mode-popup-start-btn:active {
  transform: translateY(2px) scale(0.98);
  box-shadow:
    0 2px 0 #b86200,
    0 3px 8px rgba(0, 0, 0, 0.16);
}

/* ========================================
** Game Screen
*/

.game-utility-bar {
  width: min(100%, calc((100dvh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom) - 42px) * 2 / 3));
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  background: rgba(20, 30, 10, 0.72);
  border-radius: 10px 10px 0 0;
}

body.has-ad-area .game-utility-bar {
  width: min(100%, calc((100dvh - var(--safe-area-inset-top) - 122px) * 2 / 3));
}

@media (min-width: 800px) {
  body.has-ad-area .game-utility-bar {
    width: min(100%, calc((100dvh - var(--safe-area-inset-top) - 152px) * 2 / 3));
  }
}

.utility-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sound-button {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
}

.sound-button img {
  width: 20px;
  height: 20px;
  filter: brightness(0) invert(1);
}

body.sound-enabled .sound-button.sound-disabled-button,
body.sound-disabled .sound-button.sound-enabled-button {
  display: none;
}

.game-sub-button {
  background-color: #ffffff;
  color: #1a1a1a;
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.game-sub-button:active {
  transform: scale(0.96);
}

.game-stage {
  background-image: url("../image/ui/iPhone_gameView.png");
  border-radius: 0 0 10px 10px;
}

.hud-level-digits {
  position: absolute;
  left: 4.375%;
  top: 5.833%;
  width: 18.75%;
  height: 4.167%;
  display: flex;
  align-items: center;
}

.hud-level-digits img {
  width: 25%;
  height: 100%;
  object-fit: contain;
}

.hud-life-hearts {
  position: absolute;
  left: 26.25%;
  top: 3.75%;
  width: 28.125%;
  height: 6.25%;
  display: flex;
  align-items: center;
}

.hud-life-hearts img {
  width: 33.333%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.25s ease;
}

.hud-life-hearts img.heart-pop {
  transform: scale(1.35);
}

.hud-score-digits {
  position: absolute;
  left: 58.4375%;
  top: 5.833%;
  width: 37.5%;
  height: 4.167%;
  display: flex;
  align-items: center;
  transition: transform 0.18s ease;
}

.hud-score-digits.is-pulsing {
  transform: scale(1, 1.45);
}

.hud-score-digits img {
  width: 12.5%;
  height: 100%;
  object-fit: contain;
}

/* 正方形ゲーム盤 */
.board-container {
  position: absolute;
  left: 0;
  top: 15.833%;
  width: 100%;
  aspect-ratio: 1 / 1;
  background-image: url("../image/ui/iPhone_gameField.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

.board-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: pointer;
}

.interval-detail-box {
  position: absolute;
  left: 25%;
  top: 50%;
  width: 50%;
  height: 39%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  font-size: clamp(12px, 3.6vw, 17px);
  font-weight: 800;
  color: #111111;
}

.interval-detail-box[hidden] {
  display: none;
}

.detail-line {
  display: none;
}

body.detail-speed .detail-line-speed,
body.detail-time .detail-line-time {
  display: block;
}

.detail-amount {
  margin-top: 4px;
  font-size: clamp(16px, 4.8vw, 24px);
  color: #d11a54;
}

/* ポーズ・ゲームオーバーオーバーレイ */
.paused-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
}

.paused-overlay[hidden] {
  display: none;
}

.paused-bg {
  position: absolute;
  inset: 0;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  pointer-events: none;
}

body.game-paused .paused-bg {
  background-image: url("../image/intervals/interval-paused.png");
}

body.game-over .paused-bg {
  background-image: url("../image/intervals/interval-gameOver.png");
}

body.game-finished .paused-bg {
  background-image: url("../image/intervals/interval-finished.png");
}

.paused-detail-box {
  position: absolute;
  left: 25%;
  top: 50%;
  width: 50%;
  height: 25%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: clamp(10px, 2.8vw, 13px);
  font-weight: 800;
  color: #111111;
  line-height: 1.35;
  pointer-events: none;
}

.paused-detail {
  display: none;
}

body.detail-complete .paused-detail-complete,
body.detail-gameover .paused-detail-gameover {
  display: block;
}

.paused-life-line {
  margin-top: 4px;
  color: #d11a54;
}

.overlay-btn {
  position: absolute;
  top: 77.5%;
  width: 20%;
  height: 20%;
  border: none;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  cursor: pointer;
}

.overlay-btn[hidden] {
  display: none;
}

.overlay-btn:active {
  transform: scale(0.94);
}

.overlay-btn-retry { left: 6.25%; }
.overlay-btn-continue { left: 73.75%; }

html[lang="ja"] .overlay-btn-retry { background-image: url("../image/ui/button-retry.png"); }
html:not([lang="ja"]) .overlay-btn-retry { background-image: url("../image-en/ui/button-retry.png"); }

html[lang="ja"] .overlay-btn-continue { background-image: url("../image/ui/button-continue.png"); }
html:not([lang="ja"]) .overlay-btn-continue { background-image: url("../image-en/ui/button-continue.png"); }

/* 残り時間バー */
.hud-time-digits {
  position: absolute;
  left: 1.875%;
  top: 85.417%;
  width: 11.25%;
  height: 3.333%;
  display: flex;
  align-items: center;
}

.hud-time-digits img {
  width: 33.333%;
  height: 100%;
  object-fit: contain;
}

.time-bar-track {
  position: absolute;
  left: 14.375%;
  top: 86.04%;
  width: 83.75%;
  height: 2.29%;
  background: rgb(0, 63, 113);
  border-radius: 6px;
  overflow: hidden;
  transition: transform 0.18s ease;
}

.time-bar-track.is-pulsing {
  transform: scale(1, 1.5);
}

.time-bar-fill {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  transition: width 0.18s linear, background-color 0.2s ease;
}

.time-bar-fill.tone-high {
  background-color: rgb(119, 182, 10);
}

.time-bar-fill.tone-middle {
  background-color: rgb(255, 223, 0);
}

.time-bar-fill.tone-low {
  background-color: rgb(179, 0, 63);
}

/* 下部コントロール */
.game-mode-badge {
  position: absolute;
  left: 1.875%;
  top: 90.417%;
  width: 25%;
  height: 8.333%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

html[lang="ja"] body.mode-easy .game-mode-badge { background-image: url("../image/ui/label-easy.png"); }
html:not([lang="ja"]) body.mode-easy .game-mode-badge { background-image: url("../image-en/ui/label-easy.png"); }

html[lang="ja"] body.mode-normal .game-mode-badge { background-image: url("../image/ui/label-normal.png"); }
html:not([lang="ja"]) body.mode-normal .game-mode-badge { background-image: url("../image-en/ui/label-normal.png"); }

html[lang="ja"] body.mode-endless .game-mode-badge { background-image: url("../image/ui/label-endless.png"); }
html:not([lang="ja"]) body.mode-endless .game-mode-badge { background-image: url("../image-en/ui/label-endless.png"); }

html[lang="ja"] body.mode-timetrial .game-mode-badge { background-image: url("../image/ui/label-timeTrial.png"); }
html:not([lang="ja"]) body.mode-timetrial .game-mode-badge { background-image: url("../image-en/ui/label-timeTrial.png"); }

.game-ctrl-btn {
  position: absolute;
  top: 90%;
  width: 15%;
  height: 10%;
  border: none;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  cursor: pointer;
}

.game-ctrl-btn[hidden] {
  display: none;
}

.game-ctrl-btn:active {
  transform: scale(0.94);
}

.game-ctrl-pause { left: 42.5%; }
.game-ctrl-next { left: 82.5%; }

html[lang="ja"] .game-ctrl-pause { background-image: url("../image/ui/button-pause.png"); }
html:not([lang="ja"]) .game-ctrl-pause { background-image: url("../image-en/ui/button-pause.png"); }

html[lang="ja"] .game-ctrl-next { background-image: url("../image/ui/button-next.png"); }
html:not([lang="ja"]) .game-ctrl-next { background-image: url("../image-en/ui/button-next.png"); }

body.clear-process-paused .game-ctrl-pause,
body.clear-process-paused .game-ctrl-next,
body.clear-process-paused .overlay-btn {
  display: none;
}

.ok-balloon {
  position: absolute;
  left: 75.625%;
  top: 82.29%;
  width: 15%;
  height: 10%;
  object-fit: contain;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.ok-balloon[hidden] {
  display: none;
}

.ok-balloon.is-dim {
  opacity: 0.45;
}

/* ストーリー / フィーバーオーバーレイ */
.story-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: #e9fbb9;
  animation: fadeSlideIn 0.8s ease;
}

.story-overlay[hidden] {
  display: none;
}

.story-overlay img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@keyframes fadeSlideIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* エンディングオーバーレイ */
.ending-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  background: #ffffff;
  animation: fadeSlideIn 1.5s ease;
}

.ending-overlay[hidden] {
  display: none;
}

.ending-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.ending-message {
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  transform: translateY(-50%);
  text-align: center;
  padding: 0 16px;
  font-size: clamp(16px, 4.5vw, 22px);
  font-weight: 800;
  color: #000000;
  pointer-events: none;
}

.ending-msg-collected,
.ending-msg-thankyou {
  display: none;
}

body.ending-phase-collected .ending-msg-collected,
body.ending-phase-thankyou .ending-msg-thankyou {
  display: block;
  animation: fadeSlideIn 0.8s ease;
}
