:root {
  --bg-main: #fbf7f2;
  --bg-card: #ffffff;
  --text-main: #3d342f;
  --text-muted: #8c827a;
  --primary: #ff8566;
  --primary-hover: #ff6f4c;
  --primary-light: #fff0eb;
  --accent: #ffb84d;
  --line-green: #06c755;
  --line-hover: #05a647;
  --danger: #ff5252;
  --board-border: #4a3e3d;
  --shadow-sm: 0 2px 8px rgba(61, 52, 47, 0.08);
  --shadow-md: 0 6px 20px rgba(61, 52, 47, 0.12);
  --shadow-lg: 0 12px 30px rgba(61, 52, 47, 0.18);
  --font-family: 'M PLUS Rounded 1c', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* パステル領域カラーパレット */
  --color-zone-0: #ffe4e6; /* さくらピンク */
  --color-zone-1: #dbeafe; /* パウダーブルー */
  --color-zone-2: #fef3c7; /* ハニーイエロー */
  --color-zone-3: #dcfce7; /* ミントグリーン */
  --color-zone-4: #f3e8ff; /* ラベンダーパープル */
  --color-zone-5: #ffedd5; /* ピーチオレンジ */
  --color-zone-6: #e0e7ff; /* ペリウィンクル */
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12px;
  overflow-x: hidden;
}

#app {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* ヘッダー */
.game-header {
  text-align: center;
  padding: 4px 0;
}

/* ゲームタブ（ステージ / デイリー / 無限） */
.game-tabs {
  display: flex;
  gap: 6px;
  width: 100%;
  background: #ede7e1;
  padding: 4px;
  border-radius: 14px;
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 6px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

/* 挑戦状バナー */
.challenge-banner {
  width: 100%;
  background: linear-gradient(90deg, #ff9a76 0%, #ff6f4c 100%);
  color: #fff;
  padding: 8px 12px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 800;
  box-shadow: 0 4px 10px rgba(255, 111, 76, 0.25);
  animation: pulseBounce 2s infinite ease-in-out;
}

.challenge-banner.hidden {
  display: none;
}

/* 無限パズル用サイズセレクタ */
.size-btn {
  border: 1px solid #ebd9cc;
  background: #fff;
  color: var(--text-main);
  padding: 6px 8px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.size-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.new-puzzle-btn {
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 800;
}

.logo-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.logo-icon {
  font-size: 1.6rem;
  animation: pawWiggle 2s infinite ease-in-out;
}

.game-title {
  font-size: 1.7rem;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: 1px;
}

.sub-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
}

.tagline {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 700;
}

/* ステータスバー */
.status-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  padding: 8px 16px;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

.stage-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  background: var(--primary);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 20px;
}

.stage-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
}

.stats {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.95rem;
  font-weight: 800;
}

.timer-box {
  background: #f1ede8;
  padding: 4px 10px;
  border-radius: 12px;
  color: var(--text-main);
}

/* ルールミニバー */
.rule-hint-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  width: 100%;
}

.rule-chip {
  background: #fff;
  border: 1px solid #ebd9cc;
  color: #6d5d54;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
}

.roomba-chip {
  background: #fff0eb;
  border-color: #ffbfae;
  color: #d84315;
}

/* ゲーム盤面コンテナ */
.board-container {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 4px 0;
}

#board-wrapper {
  position: relative;
  background: #503d35;
  padding: 8px;
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  border: 3px solid #3c2a23;
}

.board {
  display: grid;
  gap: 3px;
  background-color: #3c2a23;
  border-radius: 10px;
  overflow: hidden;
}

/* 各セル（マス） */
.cell {
  width: 58px;
  height: 58px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.8rem;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s ease, filter 0.15s ease, background-color 0.2s ease;
  user-select: none;
  border-radius: 4px;
}

/* 7x7盤面の縮小 */
.board-size-7 .cell {
  width: 44px;
  height: 44px;
  font-size: 1.4rem;
}

@media (max-width: 400px) {
  .cell {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
  }
  .board-size-7 .cell {
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
  }
}

.cell:active {
  transform: scale(0.92);
}

/* ゾーンごとの背景色 */
.zone-0 { background-color: var(--color-zone-0); }
.zone-1 { background-color: var(--color-zone-1); }
.zone-2 { background-color: var(--color-zone-2); }
.zone-3 { background-color: var(--color-zone-3); }
.zone-4 { background-color: var(--color-zone-4); }
.zone-5 { background-color: var(--color-zone-5); }
.zone-6 { background-color: var(--color-zone-6); }

/* 境界線の太さ（異なるゾーンの間） */
.border-top { border-top: 3px solid #5d4037 !important; }
.border-bottom { border-bottom: 3px solid #5d4037 !important; }
.border-left { border-left: 3px solid #5d4037 !important; }
.border-right { border-right: 3px solid #5d4037 !important; }

/* 猫が置かれたセル */
.cell.has-cat {
  animation: catBounce 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cell .cat-icon {
  display: inline-block;
  transform: translateY(-2px);
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.2));
}

/* ×マークが置かれたセル */
.cell.has-cross {
  color: #a89f91;
  font-size: 1.3rem;
  font-weight: 900;
  opacity: 0.65;
}

/* ルンバ専用マス（障害物） */
.cell.is-roomba-path {
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 133, 102, 0.15),
    rgba(255, 133, 102, 0.15) 8px,
    transparent 8px,
    transparent 16px
  );
}

.roomba-indicator {
  font-size: 1.3rem;
  opacity: 0.8;
  animation: pulseRotate 3s infinite linear;
}

/* コタツ専用マス */
.cell.is-kotatsu {
  font-size: 1.5rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

/* エラーセル（重複・近接など） */
.cell.is-conflict {
  background-color: #ffcdd2 !important;
  animation: shake 0.4s ease-in-out;
}

/* ルンバ走行レイヤー */
#roomba-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.animated-roomba {
  position: absolute;
  width: 48px;
  height: 48px;
  background: #333;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
}

/* 操作パネル */
.control-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* モード切り替え（猫 / ✕） */
.mode-selector {
  display: flex;
  gap: 8px;
  width: 100%;
}

.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  background: #fff;
  border: 2px solid #e0d5cb;
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.mode-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.mode-btn .btn-emoji {
  font-size: 1.3rem;
}

/* アクションボタン（ヒント、アンドゥ、リセット） */
.action-buttons {
  display: flex;
  gap: 8px;
  width: 100%;
}

.action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  background: #fff;
  border: 1px solid #e0d5cb;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  position: relative;
  transition: all 0.12s ease;
}

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

.action-btn .btn-emoji {
  font-size: 1.2rem;
  margin-bottom: 2px;
}

.hint-btn {
  background: #fff9e6;
  border-color: #ffd166;
  color: #a05e03;
}

.hint-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 900;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ステージナビゲーション */
.stage-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.stage-nav-btn {
  background: #f1ede8;
  border: none;
  padding: 8px 10px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
}

.stage-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#stage-select {
  flex: 1;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid #e0d5cb;
  background: #fff;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
}

/* フッター */
.game-footer {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.text-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

.promo-box {
  width: 100%;
  background: #eefbee;
  border: 1.5px dashed var(--line-green);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.promo-text {
  font-size: 0.78rem;
  font-weight: 700;
  color: #276738;
}

.promo-btn {
  background: var(--line-green);
  color: #fff;
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 20px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(6, 199, 85, 0.3);
  transition: background 0.15s ease;
}

.promo-btn:hover {
  background: var(--line-hover);
}

/* モーダル共通 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(40, 30, 25, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 16px;
  animation: fadeIn 0.2s ease-out;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background: #fff;
  border-radius: 24px;
  padding: 24px 20px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  position: relative;
  animation: popUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* クリアモーダル（ビクトリーカード） */
.victory-card {
  border: 4px solid var(--accent);
}

.star-burst {
  font-size: 2rem;
}

.victory-title {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--primary);
  margin-top: 4px;
}

.victory-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 700;
}

/* ルンバに乗る猫のアニメーションステージ */
.roomba-ride-stage {
  height: 120px;
  margin: 16px 0;
  background: linear-gradient(180deg, #fff0eb 0%, #ffe4d9 100%);
  border-radius: 16px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.riding-cat-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: roombaDrive 4s infinite ease-in-out;
}

.cat-rider {
  position: relative;
  font-size: 3rem;
  line-height: 1;
  animation: catJoy 0.8s infinite alternate ease-in-out;
}

.cat-rider .sunglasses {
  position: absolute;
  top: 10px;
  left: 6px;
  font-size: 1.8rem;
}

.roomba-base {
  width: 80px;
  height: 24px;
  background: #2b2b2b;
  border-radius: 12px;
  margin-top: -6px;
  border-bottom: 4px solid #1a1a1a;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.roomba-light {
  width: 8px;
  height: 8px;
  background: #00ff88;
  border-radius: 50%;
  position: absolute;
  top: 4px;
  animation: blinkLight 0.5s infinite alternate;
}

.roomba-label {
  font-size: 0.5rem;
  color: #aaa;
  letter-spacing: 1px;
  font-weight: 800;
  margin-top: 6px;
}

.dust-sparkles {
  position: absolute;
  bottom: 8px;
  font-size: 0.8rem;
  opacity: 0.7;
}

.victory-stats {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 12px 0;
}

.stat-pill {
  background: #f8f4f0;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 800;
}

.victory-quote {
  font-size: 0.82rem;
  font-style: italic;
  color: #7a6e67;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 14px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 133, 102, 0.35);
  transition: background 0.15s ease;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

.share-btn {
  border: none;
  padding: 10px;
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}

.share-btn.challenge-color {
  background: linear-gradient(135deg, #ff9a76 0%, #ff5252 100%);
  color: #fff;
  box-shadow: 0 4px 10px rgba(255, 82, 82, 0.3);
}

.challenge-card {
  border: 4px solid #ff8566;
}

.target-time-box {
  background: #fff0eb;
  border: 1px dashed #ff8566;
  padding: 10px 16px;
  border-radius: 12px;
  margin: 14px 0 18px 0;
  font-size: 1rem;
  color: #d84315;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dot-separator {
  color: #ccc;
}

@keyframes pulseBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.sub-btn {
  background: #f1ede8;
  color: var(--text-main);
  border: none;
  padding: 8px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

/* 遊び方モーダル */
.help-card {
  text-align: left;
}

.help-card h2 {
  font-size: 1.3rem;
  color: var(--primary);
  text-align: center;
  margin-bottom: 16px;
}

.help-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.rule-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #faf6f2;
  padding: 8px 12px;
  border-radius: 12px;
}

.rule-item.highlight {
  background: #fff8e7;
  border: 1px solid #ffd166;
}

.rule-icon {
  font-size: 1.5rem;
}

.rule-desc strong {
  display: block;
  font-size: 0.85rem;
  color: var(--text-main);
  margin-bottom: 2px;
}

.rule-desc p {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* 紙吹雪Canvas */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 99;
}

/* アニメーションキーフレーム */
@keyframes pawWiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(12deg); }
}

@keyframes catBounce {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

@keyframes pulseRotate {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes popUp {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes roombaDrive {
  0% { transform: translateX(-60px); }
  50% { transform: translateX(60px); }
  100% { transform: translateX(-60px); }
}

@keyframes catJoy {
  0% { transform: translateY(0); }
  100% { transform: translateY(-4px) rotate(2deg); }
}

@keyframes blinkLight {
  0% { opacity: 0.2; }
  100% { opacity: 1; filter: drop-shadow(0 0 6px #00ff88); }
}
