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

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100dvw;
  height: 100dvh;
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  color: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#game-area {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  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);
  background-image: url("../image/background.png");
  background-repeat: no-repeat;
  background-size: 100% auto;
  background-position: center 100%;
  transition: background-position 0.4s ease;
  overflow: hidden;
}

body.colors-3 #game-area {
  background-position: center 75%;
}

body.colors-4 #game-area {
  background-position: center 50%;
}

body.colors-5 #game-area {
  background-position: center 25%;
}

body.colors-6 #game-area {
  background-position: center 0%;
}

#assets {
  display: none;
}

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

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

.title-screen,
.game-screen {
  display: none;
}

@keyframes screen-fade-in {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}


body.title-screen-active .title-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  position: relative;
  padding: 24px;
  animation: screen-fade-in 1s;
}

body.game-screen-active .game-screen {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  animation: screen-fade-in 1s;
}

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

.title-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 440px;
  width: 100%;
  padding: 8px 8px 20px;
  background: rgba(255, 255, 255, 0.5);
  border: 4px solid rgba(255, 255, 255, 0.8);
  border-radius: 20px;
}

.title-card .logo {
  max-width: 100%;
  height: auto;
  margin-bottom: 12px;
}

.title-main {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: #ffffff;
  margin-bottom: 8px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.color-count-control {
  width: min(100%, 300px);
  margin: 0 0 20px;
  color: black;
  font-size: 24px;
  font-weight: 700;
  text-shadow: 0 0 5px rgba(255, 255, 255, 1);
}

.color-count-control .label {
  margin-bottom: 8px;
}

body:not(.colors-2) .color-count-control .label.colors-2,
body:not(.colors-3) .color-count-control .label.colors-3,
body:not(.colors-4) .color-count-control .label.colors-4,
body:not(.colors-5) .color-count-control .label.colors-5,
body:not(.colors-6) .color-count-control .label.colors-6 {
  display: none;
}

#colorCountSlider {
  display: block;
  width: 100%;
  height: 40px;
  margin: 0;
  accent-color: #ffffff;
  transition: accent-color 0.4s ease;
  cursor: pointer;
}

#colorCountSlider::-webkit-slider-thumb {
  width: 40px;
  height: 40px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
}

#colorCountSlider::-moz-range-thumb {
  width: 40px;
  height: 40px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
}

body.colors-3 #colorCountSlider {
  accent-color: #007bff;
}

body.colors-4 #colorCountSlider {
  accent-color: #8c00ff;
}

body.colors-5 #colorCountSlider {
  accent-color: #ff00f2;
}

body.colors-6 #colorCountSlider {
  accent-color: #ff0000;
}

.main-action-btn {
  color: #14151f;
  border-style: solid;
  border-width: 2px;
  padding: 14px 44px;
  border-radius: 30px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1.5px;
  cursor: pointer;
  transition: all 0.4s ease;
}

body.colors-2 .main-action-btn {
  background-color: #ffffff;
  color: #000000;
  border-color: #000000;
}

body.colors-3 .main-action-btn {
  background-color: #007bff;
  color: #ffffff;
  border-color: #ffffff;
}

body.colors-4 .main-action-btn {
  background-color: #8c00ff;
  color: #ffffff;
  border-color: #ffffff;
}

body.colors-5 .main-action-btn {
  background-color: #ff00f2;
  color: #ffffff;
  border-color: #ffffff;
}

body.colors-6 .main-action-btn {
  background-color: #ff0000;
  color: #ffffff;
  border-color: #ffffff;
}

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

/****************************************
** Game Screen & Canvas
*/

#canvas-container {
  width: 100%;
  position: absolute;
  top: 0;
  bottom: 90px;
  left: 0;
  z-index: 1;
}

#canvas-container canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/****************************************
** Game Screen HUD
*/

#game-header {
  position: absolute;
  top: 14px;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0 16px;
  z-index: 10;
  pointer-events: none;
}

.header-left,
.header-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.header-right {
  align-items: flex-end;
}

.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
}

.ui-box {
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: bold;
  pointer-events: auto;
  text-shadow: 0 0 10px black;
}

.ui-box .dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 2px;
  background-color: transparent;
}

body.colors-2 .ui-box .dot.color-1,
body.colors-3 .ui-box .dot.color-1,
body.colors-4 .ui-box .dot.color-1,
body.colors-5 .ui-box .dot.color-1,
body.colors-6 .ui-box .dot.color-1 {
  background-color: #ffffff;
}

body.colors-2 .ui-box .dot.color-2,
body.colors-3 .ui-box .dot.color-2,
body.colors-4 .ui-box .dot.color-2,
body.colors-5 .ui-box .dot.color-2,
body.colors-6 .ui-box .dot.color-2 {
  background-color: #1E88E5;
}

body.colors-3 .ui-box .dot.color-3,
body.colors-4 .ui-box .dot.color-3,
body.colors-5 .ui-box .dot.color-3,
body.colors-6 .ui-box .dot.color-3 {
  background-color: #FB8C00;
}

body.colors-4 .ui-box .dot.color-4,
body.colors-5 .ui-box .dot.color-4,
body.colors-6 .ui-box .dot.color-4 {
  background-color: #FDD835;
}

body.colors-5 .ui-box .dot.color-5,
body.colors-6 .ui-box .dot.color-5 {
  background-color: #43A047;
}

body.colors-6 .ui-box .dot.color-6 {
  background-color: #E53935;
}

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

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

.sound-button:active {
  transform: scale(0.92);
}

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

.control-text-btn {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 0, 0, 1);
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform 0.1s;
}

.control-text-btn:active {
  transform: scale(0.92);
}

/****************************************
** Clear Banner & Next Button
*/

#msg-container {
  position: absolute;
  bottom: 10%;
  left: 0;
  width: 100%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  pointer-events: none;
  background-color: rgba(0, 0, 0, 0.25);
  border-width: 4px 0;
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.8);
}

body:not(.stage-cleared) #msg-container {
  display: none;
}

.tutorial-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
  cursor: pointer;
  touch-action: manipulation;
}

body.tutorial-active .tutorial-overlay {
  display: block;
}

.pause-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 30;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
  touch-action: manipulation;
}

body.game-paused .pause-overlay {
  display: flex;
}

.pause-label {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 2px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.75);
}

.tutorial-indicator {
  position: absolute;
  width: 56px;
  height: 56px;
  filter: brightness(0) invert(1) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.75));
  animation: tutorial-float 1.6s ease-in-out infinite;
  pointer-events: none;
}

.tutorial-start .tutorial-indicator {
  transform: translate(-40%, -2%);
}

.tutorial-wall .tutorial-indicator,
.tutorial-fixed .tutorial-indicator {
  width: 48px;
  height: 48px;
  transform: translate(-50%, -83.333%);
}

.tutorial-message {
  position: absolute;
  bottom: 30px;
  left: 50%;
  width: min(320px, calc(100% - 32px));
  padding: 14px 18px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  color: #14151f;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transform: translateX(-50%);
  animation: tutorial-float 1.6s ease-in-out infinite;
  pointer-events: none;
}

@keyframes tutorial-float {
  0%, 100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tutorial-indicator,
  .tutorial-message {
    animation: none;
  }
}

.tutorial-message > span {
  display: none;
}

html[lang="ja"] .tutorial-start .tutorial-message .tutorial-message-start.lang-ja,
html[lang="ja"] .tutorial-wall .tutorial-message .tutorial-message-wall.lang-ja,
html[lang="ja"] .tutorial-fixed .tutorial-message .tutorial-message-fixed.lang-ja,
html:not([lang="ja"]) .tutorial-start .tutorial-message .tutorial-message-start.lang-en,
html:not([lang="ja"]) .tutorial-wall .tutorial-message .tutorial-message-wall.lang-en,
html:not([lang="ja"]) .tutorial-fixed .tutorial-message .tutorial-message-fixed.lang-en {
  display: block;
}

#game-actions {
  position: absolute;
  width: 100%;
  bottom: 30px;
  left: 50%;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 12px;
  transform: translateX(-50%);
}

#msg-container .action-btn {
  min-width: 140px;
}

.action-btn#retryAfterClearButton {
  color: red;
}

.action-btn#nextStageButton {
  color: blue;
}
#game-actions .action-btn {
  min-width: 140px;
}

.action-btn#retryButton {
  color: red;
}

.action-btn#hintButton {
  color: green;
}

body:not(.stage-cleared) #game-actions .action-btn {
  display: inline-block;
}

body.stage-cleared #game-actions {
  display: none;
}

#clear-banner {
  font-size: 24px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 2px;
  line-height: 2;
  text-shadow: 0 0 15px rgba(255, 255, 255, 0.5), 0 2px 8px rgba(0, 0, 0, 0.7);
}

body.stage-cleared #clear-banner {
  animation: stage-clear-appear 0.6s ease-out both;
}

@keyframes stage-clear-appear {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.clear-button-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: auto;
  width: 100%;
  min-height: 60px;
}

.action-btn {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.9);
  color: #14151f;
  border: none;
  padding: 12px;
  border: 2px solid #ffffff;
  border-radius: 30px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 255, 255, 0.22);
  display: none;
  transition: transform 0.1s, box-shadow 0.2s;
}

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

body.stage-cleared:not(.clear-process-paused) #retryAfterClearButton,
body.stage-cleared:not(.clear-process-paused) #nextStageButton {
  display: inline-block;
  animation: stage-clear-buttons-appear 0.4s ease;
}

@keyframes stage-clear-buttons-appear {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}
