:root {
  --primary: #ff7e67;
  --primary-hover: #ff9480;
  --primary-dark: #e85a43;
  --accent: #ffd166;
  --accent-pink: #ff85a1;
  --mint: #8ee4af;
  --bg-creamy: #fffdf9;
  --bg-soft: #fcf4ec;
  --bg-card: rgba(255, 255, 255, 0.94);
  --ink: #4a3728;
  --ink-light: #806856;
  --border-subtle: #f5dfcf;
  --border-strong: #ebbca6;
  --shadow-soft: 0 12px 32px rgba(180, 110, 80, 0.12);
  --cell: clamp(30px, 7.2vw, 56px);
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic UI", ui-rounded, system-ui, -apple-system, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100dvh;
  overflow: hidden;
  background-color: #fcf3eb;
  background-image: 
    radial-gradient(circle at 12% 15%, #ffe6dc 0%, transparent 32%),
    radial-gradient(circle at 88% 82%, #e2f4ed 0%, transparent 34%),
    radial-gradient(circle at 50% 50%, #fffbf5 0%, #f7ebe1 100%);
  position: relative;
}

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


/****************************************
** タイトル画面
*/

#game-area {
  background-image: url("../image/background.png");
  background-repeat: no-repeat;
  background-size: 100% auto;
  background-position: center center;
}

@media (min-aspect-ratio: 3/4) {
  #game-area {
    background-position: center 70%;
  }
}

.title-screen {
  position: relative;
}

.title-screen-inner {
  position: absolute;
  width: 100%;
  height: auto;
  top: 100px;
  bottom: 40%;
  padding: 0 20px;
}

.title-screen .logo {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: calc(100% - 140px);
  margin: 0 auto;
}

.title-screen .title-buttons {
  display: block;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  text-align: center;
}

.title-screen .title-buttons .primary-button {
  font-size: 18px;
  margin: 8px 4px 0;
  min-width: 160px;
}

.recovery-code,
.recovery-code-input {
  width: 200px;
  margin: 0 auto;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid #ffffff;
  border-radius: 8px;
  position: absolute;
  bottom: 20px;
}

.recovery-code #copyRecoveryCodeButton,
.recovery-code-input #pasteRecoveryCodeButton {
  display: block;
  position: absolute;
  width: 20px;
  height: 20px;
  top: 2px;
  right: 2px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

.recovery-code .copied {
  display: block;
  position: absolute;
  top: 2px;
  right: 2px;
  background: #ffffff;
  border-radius: 4px;
  color: green;
  border: solid 1px green;
  border-radius: 4px;
  padding: 0 8px;
  font-size: 12px;
  line-height: 2;
}

body:not(.code-copied) .recovery-code .copied {
  display: none;
}

.title-home-button {
  position: absolute;
  top: 20px;
  left: 20px;
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  background: linear-gradient(145deg, #ff8a7c, #e85a52);
  box-shadow: 0 4px 0 #c94943, 0 7px 16px rgba(180, 70, 60, 0.22);
  color: #fff;
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.title-home-button .close-icon {
  width: 28px;
  height: 28px;
  color: #fff;
}

.title-home-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #c94943, 0 9px 18px rgba(180, 70, 60, 0.24);
}

.title-home-button:focus-visible {
  outline: 3px solid #806856;
  outline-offset: 4px;
}

.title-screen.hidden {
  display: none;
}

.title-screen .eyebrow {
  margin-bottom: 12px;
  font-size: 12px;
  letter-spacing: 0.18em;
}


/****************************************
** ゲーム画面
*/

/* ヘッダー */
.topbar {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border: 2px solid #f3d5d2;
  background: linear-gradient(115deg, #ffe6dc, #f9e8f3 55%, #e1f4e9);
  box-shadow: 0 6px 18px rgba(180, 110, 80, 0.1);
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.icon-button, .soft-button, .primary-button {
  font: inherit;
  cursor: pointer;
  border-radius: 14px;
  transition: all 0.18s cubic-bezier(0.2, 0.8, 0.3, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.icon-button {
  width: 44px;
  height: 44px;
  background: #ffffff;
  border: 2px solid var(--border-subtle);
  font-size: 19px;
  box-shadow: 0 4px 10px rgba(180, 110, 80, 0.08);
  position: relative;
}

.icon-button .sound-icon {
  width: 24px;
  height: 24px;
  color: #000;
}

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

.icon-button:hover {
  background: #fff8f4;
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(180, 110, 80, 0.14);
}

.icon-button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 4px rgba(180, 110, 80, 0.08);
}

.soft-button {
  background: #ffffff;
  border: 2px solid var(--border-subtle);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  padding: 10px 16px;
  box-shadow: 0 4px 12px rgba(180, 110, 80, 0.08);
}

.soft-button:hover {
  background: #fff8f4;
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(180, 110, 80, 0.12);
}

.soft-button:active {
  transform: translateY(1px);
}

.primary-button {
  background: linear-gradient(135deg, #ff8b73, #ff6b52);
  color: #ffffff;
  border: none;
  font-size: 14px;
  font-weight: 900;
  padding: 12px 22px;
  border-radius: 16px;
  box-shadow: 0 6px 0 #d94b32, 0 10px 20px rgba(255, 107, 82, 0.3);
  letter-spacing: 0.02em;
}

.primary-button:hover {
  background: linear-gradient(135deg, #ff9782, #ff7860);
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #d94b32, 0 12px 24px rgba(255, 107, 82, 0.35);
}

.primary-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #d94b32, 0 4px 10px rgba(255, 107, 82, 0.2);
}

.stage-pill {
  flex: none;
  color: #8c4e2b;
  font-size: 18px;
  font-weight: 900;
}

.stage-intro {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  place-items: center;
  pointer-events: none;
}

body.stage-intro-active .stage-intro {
  display: grid;
}

.stage-intro-label {
  padding: 14px 28px;
  border: 3px solid #f3d5d2;
  border-radius: 24px;
  background: linear-gradient(115deg, rgba(255, 230, 220, 0.96), rgba(249, 232, 243, 0.96) 55%, rgba(225, 244, 233, 0.96));
  box-shadow: 0 10px 28px rgba(120, 75, 55, 0.2);
  color: #8c4e2b;
  font-size: clamp(18px, 4.5vw, 36px);
  font-weight: 900;
  letter-spacing: 0.04em;
  animation: stage-intro-pop 0.35s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

.tutorial-modal {
  position: absolute;
  inset: 10px;
  z-index: 11;
  display: none;
  place-items: center;
  padding: 16px;
  border-radius: 18px;
  background: rgba(80, 45, 25, 0.58);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

body.tutorial-1-active .tutorial-modal,
body.tutorial-4-active .tutorial-modal,
body.tutorial-7-active .tutorial-modal {
  display: grid;
}

.tutorial-card {
  width: min(100%, 360px);
  padding: 20px 22px;
  border: 3px solid #ffdec9;
  border-radius: 26px;
  background: linear-gradient(145deg, #ffffff, #fffaf5);
  box-shadow: 0 24px 60px rgba(70, 35, 15, 0.35);
  text-align: center;
  animation: pop-modal 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tutorial-content {
  display: none;
}

body.tutorial-1-active .tutorial-content.stage-1,
body.tutorial-4-active .tutorial-content.stage-4,
body.tutorial-7-active .tutorial-content.stage-7 {
  display: block;
}

.tutorial-image {
  display: block;
  width: 100%;
  max-height: 30vh;
  margin: 0 auto 12px;
  object-fit: contain;
}

.tutorial-card p {
  margin: 0 0 16px;
  color: #8c4e2b;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.6;
}

.tutorial-card .primary-button {
  width: 100%;
}

@keyframes stage-intro-pop {
  from { opacity: 0; transform: scale(0.78); }
  to { opacity: 1; transform: scale(1); }
}

.game-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  flex: 1;
  padding: 20px 0;
  background-color: rgba(0, 0, 0, 0.75);
  animation: game-background 0.5s;
}

@keyframes game-background {
  0% { background-color: rgba(255, 255, 255, 0); }
  100% { background-color: rgba(0, 0, 0, 0.75); }
}

.game-instruction {
  margin: 0 0 8px;
  padding: 8px 16px 8px 4px;
  color: #8c4e2b;
  font-size: 16px;
  font-weight: 900;
  text-align: center;
  line-height: 20px;
  background-color: #fff;
  border-radius: 10px;
}

body:not(.move-phase) .game-instruction.move,
body:not(.move-faster-phase) .game-instruction.move-faster,
body:not(.goal-phase) .game-instruction.goal {
  display: none;
}

.game-instruction .tile {
  display: inline-block;
  width: 40px;
  height: 40px;
  vertical-align: middle;
}

.game-instruction .cat-sprite {
  display: inline-block;
  width: 40px;
  height: 40px;
  vertical-align: middle;
}

body.tabby-cat-stage .game-instruction .cat-sprite.tabby-cat,
body.black-cat-stage .game-instruction .cat-sprite.black-cat {
  display: none;
}

.board-container {
  position: relative;
  width: 100%;
  flex: 1;
  container-name: board-container;
  container-type: size;
}

.board {
  display: grid;
  aspect-ratio: 1;
  margin: auto;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: 0;
  touch-action: none;
  user-select: none;
}

@container board-container (aspect-ratio > 1) {
  .board {
    height: 100%;
  }
}

@container board-container (aspect-ratio <= 1) {
  .board {
    width: 100%;
    position: absolute;
    top: 0;
    bottom: 0;
  }
}


/* タイル設計 */
.tile {
  position: relative;
  border-radius: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: background-color 0.15s;
}

.tile.has-player {
  z-index: 3;
  overflow: visible;
}

.tile.has-disturber {
  z-index: 3;
  overflow: visible;
}

.tile.box-moving {
  overflow: visible;
}

/* 歩いたときの可愛い肉球足跡 */
.paw-print {
  position: absolute;
  font-size: clamp(14px, 3.2vw, 20px);
  color: #ff9478;
  opacity: 0.75;
  pointer-events: none;
  z-index: 1;
  filter: grayscale(1) brightness(0) invert(0.9);
  animation: paw-fade 0.75s ease-out forwards;
}

@keyframes paw-fade {
  0% { transform: scale(0.65) translateY(0); opacity: 0.85; }
  40% { transform: scale(1.05) translateY(-2px); opacity: 0.7; }
  100% { transform: scale(1.15) translateY(-6px); opacity: 0; }
}

/* マップタイル */
.tile.wall {
  background-image: url("../image/map-sprites.png");
  background-size: 400% 300%;
  background-position: 33.3333% 0;
  background-repeat: no-repeat;
  border: none;
}

.tile.floor {
  background-image: url("../image/map-sprites.png");
  background-size: 400% 300%;
  background-position: 0 0;
  background-repeat: no-repeat;
  border: none;
  cursor: pointer;
}

.move-marker {
  position: absolute;
  top: 2px;
  left: 50%;
  z-index: 4;
  width: 12px;
  height: 10px;
  background: #e53935;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  pointer-events: none;
  transform: translateX(-50%);
  animation: marker-bob 0.6s ease-in-out infinite alternate;
}

@keyframes marker-bob {
  to { margin-top: 4px; }
}

.tile.goal::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("../image/map-sprites.png");
  background-size: 400% 300%;
  background-position: 66.6667% 50%;
  background-repeat: no-repeat;
  z-index: 1;
  pointer-events: none;
}

.tile.exit::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("../image/map-sprites.png");
  background-size: 400% 300%;
  background-position: 0 100%;
  background-repeat: no-repeat;
  z-index: 1;
  pointer-events: none;
}

.tile.exit.exit-ready::after {
  background-position: 33.3333% 100%;
  animation: flag-jump 0.8s ease-in-out infinite;
  animation-delay: var(--flag-jump-delay, 0s);
}

@keyframes flag-jump {
  0%, 100% { transform: translateY(0); }
  45% { transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  .tile.exit.exit-ready::after {
    animation: none;
  }
}

/* アイテム（荷物） */
.piece {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 90%;
  height: 90%;
  transition: transform 0.12s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.piece.sprite-item {
  background-image: url("../image/map-sprites.png");
  background-size: 400% 300%;
  background-repeat: no-repeat;
}

.piece.on-goal {
  background-position: 0 50%;
}

.piece:not(.on-goal) {
  background-position: 33.3333% 50%;
}

.piece.boxed {
  transform: translateY(-2px);
}

.piece.smooth-moving {
  animation: box-slide 0.3s linear;
  z-index: 5;
}

@keyframes box-slide {
  0% {
    transform: translate(var(--box-start-x), var(--box-start-y)) translateY(-2px);
  }
  50% {
    transform: translate(var(--box-middle-x), var(--box-middle-y)) translateY(-2px);
  }
  100% { transform: translateY(-2px); }
}

/* プレーヤースプライト */
.cat-sprite {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  background-image: url("../image/player-sprites.png");
  background-size: 400% 100%;
  background-repeat: no-repeat;
  transition: transform 0.14s ease-out;
}

.cat-sprite.black-cat {
  background-image: url("../image/player-sprites2.png");
}

.cat-sprite.facing-down { background-position: 0 0; }
.cat-sprite.facing-up { background-position: 33.3333% 0; }
.cat-sprite.facing-left { background-position: 66.6667% 0; }
.cat-sprite.facing-right { background-position: 100% 0; }

.cat-sprite.walking {
  animation: cat-hop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cat-sprite.disturber-arriving {
  animation: cat-hop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cat-sprite.walking.smooth-walking {
  animation: cat-hop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
    cat-walk-step 0.3s linear;
}

@keyframes cat-hop {
  0% { transform: translateY(0) scale(1, 1); }
  45% { transform: translateY(-7px) scale(0.94, 1.06); }
  85% { transform: translateY(1px) scale(1.05, 0.95); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes cat-walk-step {
  0% { left: var(--walk-start-x); top: var(--walk-start-y); }
  50% { left: var(--walk-middle-x); top: var(--walk-middle-y); }
  100% { left: 0; top: 0; }
}

/* アクション行ボタン */
.action-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 16px 0;
}

.action-row .soft-button {
  flex: 0 0 160px;
  padding: 13px;
  font-size: 14px;
}

.give-up-button {
  background: #e98783;
  border-color: #d96d69;
  color: #ffffff;
}

.give-up-button:hover {
  background: #df7773;
  border-color: #ca5c58;
}

/* モーダルオーバーレイ */
.overlay {
  position: absolute;
  inset: 10px;
  z-index: 10;
  display: none;
  place-items: center;
  border-radius: 18px;
  background: rgba(80, 45, 25, 0.48);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  padding: 16px;
  opacity: 1;
  transition: opacity 0.25s ease-out;
}

body.win-overlay-active .overlay,
body.lose-overlay-active .overlay {
  display: grid;
}

.overlay-card {
  display: none;
  width: min(100%, 340px, 65vh);
  aspect-ratio: 1;
  text-align: center;
  background: linear-gradient(145deg, #ffffff, #fffaf5);
  border: 3px solid #ffdec9;
  border-radius: 26px;
  padding: 0;
  box-shadow: 0 24px 60px rgba(70, 35, 15, 0.35);
  animation: pop-modal 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  overflow: hidden;
}

body.win-overlay-active .overlay-card.win,
body.lose-overlay-active .overlay-card.lose {
  display: block;
}

.overlay-result-image {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.overlay-actions {
  position: absolute;
  right: 14px;
  bottom: 16px;
  left: 14px;
  justify-content: center;
}

.overlay-actions button {
  min-height: 48px;
  padding: 10px 12px;
  border-color: rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 12px rgba(55, 30, 15, 0.28);
}

@keyframes pop-modal {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes bounce-cat {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-8px) scale(1.06); }
}

.overlay-card .primary-button {
  width: 100%;
  padding: 14px;
  font-size: 16px;
}

.overlay-actions {
  display: flex;
  gap: 10px;
}

.overlay-actions button {
  flex: 1;
  padding: 13px 8px;
  font-size: 15px;
}

body.hide-overlay-buttons .overlay-actions {
  display: none;
}

/* レスポンシブ対応 */
@media (max-width: 480px) {
  :root { --cell: clamp(24px, 7.6vw, 36px); }
  .stage-pill { font-size: 16px; }
}

/* ステージ表示 */
body.tutorial-stage span.regular-stage,
body.regular-stage span.tutorial-stage {
  display: none;
}
