/* Maze mini-game. Every rule is scoped to #page-games so it cannot leak. */

body:has(#page-games.mg-mz-playing) {
  height: 100dvh;
  overflow: hidden;
}

body:has(#page-games.mg-mz-playing) .app-container {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0.5rem 0.4rem;
}

body:has(#page-games.mg-mz-playing) .main-navbar {
  position: relative;
  top: 0;
  flex-shrink: 0;
  margin-bottom: 0.35rem;
}

body:has(#page-games.mg-mz-playing) .brand-avatar {
  width: 36px;
  height: 36px;
}

body:has(#page-games.mg-mz-playing) .brand-title {
  font-size: 1.05rem;
}

body:has(#page-games.mg-mz-playing) .nav-tab {
  padding: 0.28rem 0.55rem;
  font-size: 0.78rem;
}

#page-games.mg-mz-playing {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#page-games.mg-mz-playing .mg-hub-container {
  display: none;
}

#page-games .mg-card:has(.mg-play-btn[data-game-id="maze-blog"]) .mg-card-icon {
  background: linear-gradient(160deg, #e0f7ff 0%, #c4b5fd 100%);
}

#page-games .mg-card:has(.mg-play-btn[data-game-id="maze-wall"]) .mg-card-icon {
  background: linear-gradient(160deg, #ffedd5 0%, #fdba74 100%);
}

#page-games .mg-mz-container {
  display: none;
}

#page-games.mg-mz-playing .mg-mz-container {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 8px;
  width: min(100%, 760px);
  min-height: 0;
  margin: 0 auto;
  position: relative;
  outline: none;
}

#page-games .mg-mz-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  flex-shrink: 0;
}

#page-games .mg-mz-lead {
  margin: 0;
  text-align: center;
  font-family: var(--font-th), 'Mali', sans-serif;
  font-weight: 700;
  font-size: calc(1.35rem * 1.1);
  line-height: 1.25;
  background-image: linear-gradient(100deg, #ff4d8d 0%, #ff9f1c 32%, #22c55e 64%, #3b82f6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

#page-games .mg-mz-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#page-games .mg-mz-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0;
  font-family: var(--font-th), 'Mali', sans-serif;
  font-weight: 700;
  font-size: 1.02rem;
}

#page-games .mg-mz-level,
#page-games .mg-mz-steps {
  border-radius: 999px;
  padding: 0.18rem 0.75rem;
  background: #fff7e6;
  color: #9a5b00;
}

#page-games .mg-mz-steps {
  background: #efeaff;
  color: #5b46b0;
}

#page-games .mg-mz-note {
  margin: 0;
  min-height: 1.2em;
  text-align: center;
  font-family: var(--font-th), 'Mali', sans-serif;
  font-weight: 700;
  color: #c2410c;
}

#page-games .mg-mz-back,
#page-games .mg-mz-restart,
#page-games .mg-mz-bgm,
#page-games .mg-mz-dir,
#page-games .mg-mz-start,
#page-games .mg-mz-again,
#page-games .mg-mz-next,
#page-games .mg-mz-win-back {
  font-family: var(--font-th), 'Mali', sans-serif;
  cursor: pointer;
  border: none;
}

#page-games .mg-mz-back,
#page-games .mg-mz-win-back {
  background: #ffffff;
  color: #3d4a63;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  box-shadow: 0 4px 0 rgba(80, 100, 140, 0.12);
  font-weight: 700;
}

#page-games .mg-mz-tools {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

#page-games .mg-mz-restart,
#page-games .mg-mz-bgm {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 4px 0 rgba(80, 100, 140, 0.12);
  font-size: 1.15rem;
}

#page-games .mg-mz-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  overscroll-behavior: none;
}

#page-games .mg-mz-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  width: min(100%, calc(100dvh - 230px));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  gap: 3px;
  padding: 8px;
  box-sizing: border-box;
  border-radius: 22px;
  background: linear-gradient(160deg, #6d5bd0 0%, #4c3aa8 100%);
  box-shadow: 0 10px 24px rgba(76, 58, 168, 0.28);
  font-size: clamp(12px, 2.6vw, 22px);
}

#page-games .mg-mz-cell {
  position: relative;
  border-radius: 7px;
  min-width: 0;
  min-height: 0;
}

#page-games .mg-mz-cell.mg-mz-path {
  background: #fff6e8;
}

#page-games .mg-mz-cell.mg-mz-wall {
  background: #3a2b86;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

#page-games .mg-mz-cell.visited {
  background: #d4f1ff;
}

#page-games .mg-mz-cell.mg-mz-goal {
  background: #ffe08a;
}

#page-games .mg-mz-cell.visited::before,
#page-games .mg-mz-cell.mg-mz-goal::before,
#page-games .mg-mz-cell.mg-mz-player::after {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  pointer-events: none;
}

#page-games .mg-mz-cell.visited::before {
  content: "🐾";
  font-size: 0.72em;
  opacity: 0.8;
}

#page-games .mg-mz-cell.mg-mz-goal::before {
  content: "🏁";
  font-size: 0.85em;
}

#page-games .mg-mz-cell.mg-mz-player::after {
  content: "🐰";
  font-size: 0.92em;
  z-index: 2;
  transform: scale(1.3);
  animation: mg-mz-hop 0.18s ease;
}

#page-games .mg-mz-cell.mg-mz-player.visited::before {
  opacity: 0.28;
}

#page-games .mg-mz-cell.mg-mz-bump {
  animation: mg-mz-shake 0.28s ease;
}

#page-games .mg-mz-container[data-mg-mz-phase="ready"] .mg-mz-pad,
#page-games .mg-mz-container[data-mg-mz-phase="countdown"] .mg-mz-pad {
  opacity: 0.4;
  pointer-events: none;
}

#page-games .mg-mz-pad {
  flex-shrink: 0;
  display: grid;
  justify-content: center;
  justify-items: center;
  gap: 6px;
}

#page-games .mg-mz-pad-row {
  display: flex;
  gap: 6px;
}

#page-games .mg-mz-dir {
  width: 58px;
  height: 46px;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 4px 0 #d7def0;
  font-size: 1.25rem;
}

#page-games .mg-mz-dir:active,
#page-games .mg-mz-restart:active,
#page-games .mg-mz-bgm:active,
#page-games .mg-mz-back:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #d7def0;
}

#page-games .mg-mz-ready,
#page-games .mg-mz-countdown {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
}

#page-games .mg-mz-ready {
  background: transparent;
}

#page-games .mg-mz-start {
  border-radius: 999px;
  padding: 0.9rem 1.6rem;
  font-size: 1.45rem;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(180deg, #ff8fb8 0%, #ff5d8f 100%);
  box-shadow: 0 6px 0 #e11d48;
}

#page-games .mg-mz-start:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #e11d48;
}

#page-games .mg-mz-countdown {
  z-index: 7;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 22px;
}

#page-games .mg-mz-countdown-circle {
  width: 156px;
  height: 156px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 105, 161, 0.94);
  border: 6px solid #facc15;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
  animation: mg-mz-countdown-pop 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-mz-countdown-circle.mg-mz-countdown-go {
  background: rgba(34, 197, 94, 0.94);
  border-color: #bbf7d0;
}

#page-games .mg-mz-countdown-circle.mg-mz-countdown-go .mg-mz-countdown-text {
  font-family: var(--font-th), 'Mali', sans-serif;
  font-size: 3rem;
}

#page-games .mg-mz-countdown-text {
  font-family: var(--font-en), 'Fredoka', sans-serif;
  font-size: 4.8rem;
  font-weight: 700;
  line-height: 1;
  color: #ffffff;
  text-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
}

#page-games .mg-mz-hint {
  margin: 0;
  flex-shrink: 0;
  text-align: center;
  font-family: var(--font-th), 'Mali', sans-serif;
  color: #718096;
  font-size: 0.92rem;
}

#page-games .mg-mz-win {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(45, 32, 96, 0.38);
  border-radius: 24px;
}

#page-games .mg-mz-win-card {
  width: min(100%, 380px);
  background: #ffffff;
  border-radius: 28px;
  padding: 1.25rem 1.1rem 1.1rem;
  text-align: center;
  box-shadow: 0 18px 40px rgba(50, 40, 100, 0.25);
  animation: mg-mz-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#page-games .mg-mz-win-icon {
  font-size: 3rem;
  animation: mg-mz-hop 0.8s ease infinite;
}

#page-games .mg-mz-win-title {
  margin: 0.2rem 0 0;
  font-family: var(--font-th), 'Mali', sans-serif;
  color: #5b46b0;
  font-size: 1.55rem;
}

#page-games .mg-mz-win-sub {
  margin: 0.35rem 0 0.9rem;
  font-family: var(--font-th), 'Mali', sans-serif;
  color: #4a5568;
}

#page-games .mg-mz-win-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#page-games .mg-mz-again,
#page-games .mg-mz-next {
  border-radius: 999px;
  padding: 0.7rem 1rem;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(180deg, #7c6cf0 0%, #5b46d6 100%);
  box-shadow: 0 4px 0 #4334a8;
}

#page-games .mg-mz-win-back {
  background: #f4f7fb;
}

#page-games .mg-mz-sparks {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 0.2rem;
  font-size: 1.4rem;
}

#page-games .mg-mz-sparks span {
  display: inline-block;
  animation: mg-mz-hop 0.7s ease infinite;
}

#page-games .mg-mz-sparks span:nth-child(2) { animation-delay: 0.12s; }
#page-games .mg-mz-sparks span:nth-child(3) { animation-delay: 0.24s; }

@keyframes mg-mz-hop {
  0% { transform: translateY(2px) scale(1.15); }
  60% { transform: translateY(-3px) scale(1.38); }
  100% { transform: translateY(0) scale(1.3); }
}

@keyframes mg-mz-countdown-pop {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes mg-mz-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@keyframes mg-mz-pop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-lead {
  font-size: calc(1.35rem * 1.1);
  background-image: linear-gradient(100deg, #fb7185 0%, #fb923c 34%, #facc15 66%, #34d399 100%);
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-grid {
  position: relative;
  gap: 0;
  padding: 0;
  background: var(--mg-mz-outside, #fff7ed);
  box-shadow: 0 10px 24px rgba(80, 50, 20, 0.16);
}

#page-games .mg-mz-fox,
#page-games .mg-mz-run {
  position: absolute;
  left: 0;
  top: 0;
  display: none;
  pointer-events: none;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-fox {
  display: block;
  z-index: 4;
}

#page-games .mg-mz-fox svg {
  display: block;
  width: 100%;
  height: 100%;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-run.mg-mz-run-on {
  display: block;
  z-index: 2;
  border-radius: 999px;
  background: var(--mg-mz-trail, #fb7185);
  transform-origin: 0 50%;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell {
  border-radius: 0;
  box-sizing: border-box;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.mg-mz-wall {
  background: var(--mg-mz-outside, #fff7ed);
  box-shadow: none;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.mg-mz-path,
#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.mg-mz-goal {
  background-color: var(--mg-mz-floor, #ffffff);
  border-style: solid;
  border-width: 3px;
  border-color: transparent;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.mg-mz-goal {
  background-color: var(--mg-mz-floor, #ffffff);
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.mg-mz-edge-n { border-top-color: var(--mg-mz-line, #ea580c); }
#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.mg-mz-edge-e { border-right-color: var(--mg-mz-line, #ea580c); }
#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.mg-mz-edge-s { border-bottom-color: var(--mg-mz-line, #ea580c); }
#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.mg-mz-edge-w { border-left-color: var(--mg-mz-line, #ea580c); }

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.visited {
  background-color: var(--mg-mz-floor, #ffffff);
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.visited::before {
  content: none;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.mg-mz-goal::before {
  content: "🏁";
  font-size: 0.85em;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-trail-h,
#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-trail-v {
  background-repeat: no-repeat;
  background-position: center;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-trail-h {
  background-image: linear-gradient(var(--mg-mz-trail, #fb7185), var(--mg-mz-trail, #fb7185));
  background-size: 100% 22%;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-trail-v {
  background-image: linear-gradient(var(--mg-mz-trail, #fb7185), var(--mg-mz-trail, #fb7185));
  background-size: 22% 100%;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-trail-h.mg-mz-trail-v {
  background-image:
    linear-gradient(var(--mg-mz-trail, #fb7185), var(--mg-mz-trail, #fb7185)),
    linear-gradient(var(--mg-mz-trail, #fb7185), var(--mg-mz-trail, #fb7185));
  background-size: 100% 22%, 22% 100%;
  background-position: center, center;
}

#page-games .mg-mz-container[data-mg-mz-mode="wall"] .mg-mz-cell.mg-mz-player::after {
  content: none;
}

@media (max-width: 768px) {
  body:has(#page-games.mg-mz-playing) .navbar-inner {
    flex-direction: row;
    align-items: center;
  }

  body:has(#page-games.mg-mz-playing) .tab-label {
    display: none;
  }

  #page-games .mg-mz-lead {
    font-size: calc(1.2rem * 1.1);
  }

  #page-games .mg-mz-meta {
    width: 100%;
    order: -1;
  }
}

@media (max-height: 740px) {
  #page-games .mg-mz-hint {
    display: none;
  }

  #page-games .mg-mz-dir {
    width: 50px;
    height: 38px;
  }

  #page-games .mg-mz-grid {
    padding: 5px;
    gap: 2px;
    border-radius: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #page-games .mg-mz-cell.mg-mz-player::after,
  #page-games .mg-mz-cell.mg-mz-bump,
  #page-games .mg-mz-win-card,
  #page-games .mg-mz-win-icon,
  #page-games .mg-mz-sparks span,
  #page-games .mg-mz-countdown-circle {
    animation: none;
  }
}
