: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;
  font-family: sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: #87CEEB;
  color: #ffffff;
}

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

#game-area {
  position: relative;
  flex: 1;
  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: cover;
  background-position: center;
}

#ad-area {
  display: none;
  height: 60px;
  margin-top: 10px;
}

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

#assets {
  display: none;
}

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

/****************************************
** Ad Container
*/

body.has-ad-area {
  padding-bottom: var(--safe-area-inset-bottom);
}

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%;
}

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

.title-screen,
.game-screen {
  width: 100%;
  height: 100%;
}

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

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

.title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  text-align: center;
  background-color: rgba(0,0,0,0.3);
}

.title-close-button {
  position: absolute;
  top: 18px;
  left: 18px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: solid 2px #ffffff;
  border-radius: 50%;
  background: rgba(220, 0, 0, 0.7);
  cursor: pointer;
}

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

.title-close-button img {
  width: 22px;
  height: 22px;
}

.title-hero {
  width: 100%;
  height: 40%;
  padding: 20px 0;
  background: rgba(2255, 255, 255, 0.5);
  border-style: solid;
  border-width: 4px 0;
  border-color: #ffffff;
}

.title-logo {
  width: auto;
  height: 100%;
}

.title-start-options {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 36px;
  padding: 6px;
  max-width: calc(100% - 32px);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.58);
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.title-option-button {
  appearance: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.4px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, transform 0.12s ease, box-shadow 0.16s ease;
}

.title-option-button:hover:not(.is-selected) {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.14);
}

.title-option-button:active {
  transform: scale(0.96);
}

.title-option-button.is-selected {
  background: #ffffff;
  color: #0369a1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

@media (max-width: 420px) {
  .title-start-options {
    margin-top: 28px;
    padding: 5px;
    gap: 4px;
  }

  .title-option-button {
    padding: 9px 14px;
    font-size: 14px;
  }
}

.title-action-button {
  background: #2ed573;
  color: #ffffff;
  border: 3px solid #ffffff;
  margin-top: 24px;
  padding: 14px 48px;
  border-radius: 30px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1.5px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s ease, background-color 0.2s ease;
}

.title-action-button:hover {
  background: #26b863;
}

.title-action-button:active {
  transform: scale(0.95);
}

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

.game-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.game-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  height: 60px;
  background: rgba(0, 0, 0, 0.3);
}

.game-header .left-panel {
  padding: 10px 0 10px 10px;
  text-align: left;
  line-height: 40px;
}

.game-header .right-panel {
  padding: 10px 10px 10px 0;
  text-align: right;
  line-height: 40px;
}

.game-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 60px;
  padding: 0 10px;
  background: rgba(0, 0, 0, 0.3);
}

.ball-gauge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  max-width: 660px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.52);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.ball-gauge-item {
  flex: 1 1 0;
  min-width: 0;
  max-width: 36px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  display: block;
  transition: opacity 0.2s ease, transform 0.2s ease;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}

.ball-gauge-item.is-used {
  opacity: 0.32;
  transform: scale(0.9);
}

#canvas-container {
  position: relative;
  flex: 1;
  width: 100%;
  overflow: hidden;
  touch-action: none;
  background: #a0e2fa;
}

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

.game-header .right-panel {
  display: flex;
  justify-content: right;
  align-items: center;
  gap: 10px;
}

.sound-button {
  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: rgba(0,0,0,0.7);
  color: #ffffff;
  padding: 8px 12px;
  border: none;
  border-radius: 10px;
  border: solid 1px #ffffff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform 0.1s;
}

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

/****************************************
** In-Game HUD & Overlays (matching prototype.html)
*/

@keyframes blink {
  0% { opacity: 1; }
  100% { opacity: 0.3; }
}

#reticle {
  position: absolute;
  width: 32px;
  height: 32px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  display: none;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
  z-index: 15;
}

#reticle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background: #ff4757;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

body.reticle-visible #reticle {
  display: block;
}

.result-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: auto;
  display: none;
  z-index: 20;
  width: max-content;
  max-width: calc(100% - 32px);
}

.modal-clear {
  min-height: 150px;
}

body.stage-cleared .result-modal,
body.game-over .result-modal {
  display: block;
}

body.stage-cleared .modal-over,
body.game-over .modal-clear {
  display: none;
}

.modal-title {
  font-size: 38px;
  font-weight: bold;
  color: #FFD700;
  text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
}

.modal-sub {
  font-size: 18px;
  font-weight: bold;
  color: #ffffff;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
  margin: 10px 0 0 0;
}

.modal-btn {
  margin-top: 20px;
  padding: 12px 26px;
  font-size: 20px;
  font-weight: bold;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.1s;
}

.modal-btn:active {
  transform: scale(0.95);
}

.btn-clear {
  background: #2ed573;
}

.btn-over {
  background: #eb4d4b;
}

body.clear-process-paused .modal-clear .modal-btn {
  display: none;
}

/****************************************
** Tutorial Modal
*/

.tutorial-modal {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
  z-index: 25;
  pointer-events: auto;
}

body.tutorial-visible .tutorial-modal {
  display: flex;
}

.tutorial-card {
  width: 100%;
  max-width: 360px;
  padding: 24px 22px 22px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #ffffff;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.35);
  color: #1e293b;
  text-align: center;
}

.tutorial-can-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.tutorial-can-img {
  width: 112px;
  height: 112px;
  object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(15, 23, 42, 0.2));
}

.tutorial-can-img.tutorial-item-11 {
  width: 100%;
  max-width: 240px;
  height: auto;
  aspect-ratio: 4 / 3;
  filter: none;
  mix-blend-mode: multiply;
}

.tutorial-text {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.55;
  color: #1e293b;
}

.tutorial-item-1,
.tutorial-item-2,
.tutorial-item-4,
.tutorial-item-5,
.tutorial-item-7,
.tutorial-item-8,
.tutorial-item-10,
.tutorial-item-11 {
  display: none;
}

body.tutorial-stage-1 .tutorial-item-1,
body.tutorial-stage-2 .tutorial-item-2,
body.tutorial-stage-4 .tutorial-item-4,
body.tutorial-stage-5 .tutorial-item-5,
body.tutorial-stage-7 .tutorial-item-7,
body.tutorial-stage-8 .tutorial-item-8,
body.tutorial-stage-10 .tutorial-item-10,
body.tutorial-stage-11 .tutorial-item-11 {
  display: inline;
}

body.tutorial-stage-1 .tutorial-can-img.tutorial-item-1,
body.tutorial-stage-2 .tutorial-can-img.tutorial-item-2,
body.tutorial-stage-4 .tutorial-can-img.tutorial-item-4,
body.tutorial-stage-5 .tutorial-can-img.tutorial-item-5,
body.tutorial-stage-7 .tutorial-can-img.tutorial-item-7,
body.tutorial-stage-8 .tutorial-can-img.tutorial-item-8,
body.tutorial-stage-10 .tutorial-can-img.tutorial-item-10,
body.tutorial-stage-11 .tutorial-can-img.tutorial-item-11 {
  display: block;
}

.btn-tutorial {
  margin-top: 18px;
  min-width: 150px;
  padding: 11px 28px;
  font-size: 18px;
  background: #0ea5e9;
  border-radius: 999px;
}

.btn-tutorial:hover {
  background: #0284c7;
}

