* { margin: 0; padding: 0; box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
}

body {
  background: #1a1a2e;
  font-family: 'Courier New', monospace;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100dvh;
  touch-action: none;
}

#game-area,
#ad-area {
  width: 100vw;
  overflow: hidden;
}
#game-area {
  position: relative;
  flex: 1;
}
#ad-area {
  height: 60px;
  margin-top: 20px;
}

@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:not(.has-ad-area) #ad-area {
  display: none;
}

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


/****************************************
** Game Container
*/

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

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


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

.title-screen {
  position: relative;
}
#btn-landing {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-bottom: 4px solid #8f2338;
  border-radius: 50%;
  background: linear-gradient(180deg, #ff8a9a 0%, #e84c62 100%);
  color: #fff;
  cursor: pointer;
}
#btn-landing img {
  width: 20px;
  height: 20px;
}
.title-logo {
  position: absolute;
  top: 33.333%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 400px;
  image-rendering: pixelated;
  animation: titleFloat 3s ease-in-out infinite;
}
.title-logo img {
  display: block;
  width: 100%;
  height: auto;
}
#stage-options {
  position: absolute;
  top: 57%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
}
.stage-option {
  appearance: none;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 2px;
  cursor: pointer;
}
body.normal-mode #stage-option-normal,
body.difficult-mode #stage-option-difficult {
  border-color: #fff;
}
#btn-start {
  position: absolute;
  top: 76%;
  left: 50%;
  translate: -50% -50%;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.button-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}
@keyframes titleFloat {
  0%, 100% { transform: translate(-50%, -50%); }
  50% { transform: translate(-50%, -50%) translateY(-10px); }
}
.pixel-btn {
  background: linear-gradient(180deg, #ff9de2 0%, #ff6fc8 50%, #e0429d 100%);
  color: white;
  border: none;
  border-bottom: 4px solid #a02070;
  border-right: 4px solid #a02070;
  padding: 16px 32px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 2px;
  transition: transform 0.08s, border 0.08s;
  font-family: inherit;
}
.pixel-btn:active {
  transform: translate(2px, 2px);
  border-bottom: 2px solid #a02070;
  border-right: 2px solid #a02070;
}
.pixel-btn.green {
  background: linear-gradient(180deg, #9de28a 0%, #6fc862 50%, #42a020 100%);
  border-color: #207010;
}
.pixel-btn.blue {
  background: linear-gradient(180deg, #8ad0e2 0%, #62b0e0 50%, #2070c0 100%);
  border-color: #103070;
}
.pixel-btn.gray {
  background: linear-gradient(180deg, #ccc 0%, #aaa 50%, #888 100%);
  border-color: #555;
}
.result-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
}
.pixel-btn.small {
  font-size: 11px;
  padding: 8px 12px;
}
.pixel-btn.icon-btn {
  font-size: 16px;
  padding: 8px 12px;
  background: linear-gradient(180deg, #b8a0e8 0%, #9070d0 50%, #6040a0 100%);
  border-color: #402080;
}
#sound-buttons .pixel-btn,
#btn-quit.pixel-btn {
  border-radius: 10px;
}
.stars-bg {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  overflow: hidden;
}
.star {
  position: absolute;
  background: white;
  width: 3px; height: 3px;
  animation: twinkle 2s ease-in-out infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 1; }
}


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

.game-screen {
  position: relative;
  background: #2d5a27;
}
#stage-intro {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
body.stage-intro-active #stage-intro {
  display: flex;
}
#stage-intro-text {
  padding: 12px 24px;
  color: #fff4b5;
  background: rgba(26, 26, 46, 0.82);
  border: 3px solid #ff9de2;
  border-radius: 12px;
  font-size: clamp(30px, 10vw, 52px);
  font-weight: bold;
  letter-spacing: 0.08em;
  animation: stageIntroPop 2s ease-out forwards;
}
@keyframes stageIntroPop {
  0% { opacity: 0; transform: scale(0.6); }
  18% { opacity: 1; transform: scale(1.08); }
  30%, 72% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.12); }
}
#hud {
  width: 100%;
  background: linear-gradient(105deg, #fff1f7 0%, #fff8e8 52%, #e9f8ff 100%);
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 3px solid #f5b7d2;
  flex-shrink: 0;
}
#stage-display {
  color: #8f527d;
  background: #fff;
  border: 2px solid #f6c7dc;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: bold;
  white-space: nowrap;
}
#score-display {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(100deg, #fff1f7, #fff9e8 52%, #edf8ff);
  border-top: 2px solid #fff;
  flex-shrink: 0;
}
#hud-spacer { flex: 1; }
.score-card {
  min-width: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 5px 12px;
  background: rgba(255,255,255,0.88);
  border: 2px solid #f3d9e5;
  border-radius: 16px;
  box-shadow: 0 3px 0 rgba(190,142,166,0.2);
}
.score-card.white-card {
  border-color: #cce8f2;
  box-shadow: 0 3px 0 rgba(122,177,196,0.2);
}
.score-label {
  display: block;
  color: #927185;
  font: bold 10px/1.2 Arial, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  letter-spacing: 0.04em;
}
.score-disc {
  display: block;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  background-image: url("../image/koma.png");
  background-size: 400% 200%;
  background-repeat: no-repeat;
}
.score-disc.black { background-position: left top; }
.score-disc.white { background-position: left bottom; }
.score-count {
  color: #463b52;
  font: 800 27px/1 Arial, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: center;
}
.score-vs {
  color: #bc82a1;
  font: bold 12px Arial, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}
#btn-sound-enabled,
#btn-sound-disabled {
  display: inline-block;
  padding: 7px 10px;
  background: linear-gradient(180deg, #d5f8e8 0%, #9be5c4 100%);
  border-color: #69bd98;
  color: #287d61;
  min-width: 42px;
  text-align: center;
}
body.sound-enabled #btn-sound-disabled,
body.sound-disabled #btn-sound-enabled {
  display: none;
}
.sound-icon {
  display: block;
  width: 20px;
  height: 20px;
}
#btn-quit {
  font-size: 10px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #c8efff 0%, #91d9f5 100%);
  border-color: #5eacd0;
  color: #343a40;
  white-space: nowrap;
}
#board-area {
  width: 100%;
  flex: 1;
  position: relative;
  overflow: hidden;
}
@media (max-width: 380px) {
  #hud { padding: 8px; gap: 6px; }
  .score-card { min-width: 96px; gap: 5px; padding: 4px 8px; }
  .score-disc { flex-basis: 32px; width: 32px; height: 32px; }
  .score-count { font-size: 23px; }
  #score-display { gap: 7px; padding: 8px; }
  #btn-quit { font-size: 9px; padding: 7px; }
}
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* Overlay */

.overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(0,0,0,0.75);
  z-index: 10;
}
body.win-overlay-active #win-overlay,
body.lose-overlay-active #lose-overlay {
  display: flex;
}
.result-img {
  width: 80%;
  max-width: 320px;
  max-height: calc(100% - 100px);
  object-fit: contain;
  animation: resultBounce 0.5s ease-out;
}
.result-img img {
  display: block;
  width: 100%;
  height: auto;
}
@keyframes resultBounce {
  0% { transform: scale(0.3); opacity: 0; }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}
.btn-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
