:root {
  --cell-size: 74px;
  --grid-gap: 6px;
  --board-pad: 10px;
  --exit-thickness: 26px;
  --board-size: calc(var(--cell-size) * 6 + var(--grid-gap) * 5 + var(--board-pad) * 2);

  --bg-sky: #e0f4ff;
  --panel-bg: rgba(255, 255, 255, 0.96);
  --panel-border: #ffffff;
  --text-main: #2b2d42;
  --text-muted: #5c677d;
  --accent-pink: #ff4d6d;
  --accent-blue: #00bbf9;
  --accent-yellow: #ffbe0b;
  --accent-green: #06d6a0;
  --accent-purple: #9b5de5;
}

/* Responsive --cell-size, --grid-gap, --board-pad, and --exit-thickness are dynamically computed in main.js updateResponsiveMetrics() */

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

body {
  font-family: 'Fredoka', 'Noto Sans TC', sans-serif;
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  background-color: var(--bg-sky);
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28) 0%, rgba(224, 244, 255, 0.55) 100%),
    url('../assets/images/bg-playroom.webp');
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
  display: none;
}

.app-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
}

/* ==================== TOP BAR ==================== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--panel-bg);
  border: 3px solid #ffffff;
  border-radius: 26px;
  padding: 10px 18px;
  box-shadow: 0 10px 26px rgba(29, 53, 87, 0.14), 0 4px 0 rgba(168, 218, 220, 0.65);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transform: translateZ(0);
  backface-visibility: hidden;
  transition: transform 0.18s ease;
}

.brand-group:hover {
  transform: scale(1.02);
}

.top-logo {
  height: 58px;
  width: auto;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.16));
}

.brand-titles h1 {
  font-size: 1.45rem;
  font-weight: 900;
  color: #1d3557;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-kid {
  background: linear-gradient(135deg, #ff4d6d, #ff7b00);
  color: #fff;
  font-size: 0.85rem;
  padding: 3px 10px;
  border-radius: 999px;
  box-shadow: 0 3px 0 #c9184a;
}

.brand-titles p {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-top: 2px;
}

/* ==================== HUD STATS ==================== */
.hud-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  background: #ffffff;
  border: 2.5px solid #e2eafc;
  border-radius: 18px;
  padding: 7px 14px;
  box-shadow: 0 4px 0 #d0d9f2;
  position: relative;
  overflow: hidden;
}

.level-pill {
  cursor: pointer;
  border-color: #a9def9;
  box-shadow: 0 4px 0 #72efdd;
  transform: translateZ(0);
  backface-visibility: hidden;
  transition: transform 0.15s;
}

.level-pill:hover {
  transform: translateY(-2px);
}

.score-pill {
  border-color: #ffe169;
  box-shadow: 0 4px 0 #ffbe0b;
}

.level-score-pill {
  border-color: #80ffdb;
  box-shadow: 0 4px 0 #06d6a0;
}

.level-score-pill.deducting {
  border-color: #ff85a1;
  box-shadow: 0 4px 0 #ff4d6d;
  background: #fff0f3;
  animation: pulseWarn 0.9s infinite alternate;
}

.timer-pill {
  min-width: 158px;
  border-color: #a9def9;
  box-shadow: 0 4px 0 #00bbf9;
  padding-bottom: 12px;
}

.timer-pill.warning {
  border-color: #ffbe0b;
  box-shadow: 0 4px 0 #fb5607;
  background: #fff9db;
}

.timer-pill.overtime {
  border-color: #ff4d6d;
  box-shadow: 0 4px 0 #c9184a;
  background: #ffe5ec;
  animation: pulseWarn 0.6s infinite alternate;
}

@keyframes pulseWarn {
  0% { transform: scale(1); }
  100% { transform: scale(1.035); }
}

.stat-icon {
  font-size: 1.45rem;
}

.stat-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 700;
}

.stat-text strong {
  font-size: 1.15rem;
  font-weight: 900;
  color: #1d3557;
}

.timer-bar-wrap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: #e9ecef;
}

.timer-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #06d6a0, #00bbf9);
  transition: width 0.25s linear, background 0.3s ease;
}

/* ==================== AUDIO BUTTONS ==================== */
.audio-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 2.5px solid #e2eafc;
  background: #f8f9fa;
  color: #495057;
  padding: 8px 13px;
  border-radius: 16px;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.86rem;
  cursor: pointer;
  box-shadow: 0 4px 0 #ced4da;
  transform: translateZ(0);
  backface-visibility: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.icon-btn:hover {
  transform: translateY(-2px);
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #ced4da;
}

.icon-btn.active {
  background: linear-gradient(180deg, #e0fbfc 0%, #c2f8cb 100%);
  border-color: #06d6a0;
  color: #046648;
  box-shadow: 0 4px 0 #06d6a0;
}

.icon-btn.studio-btn {
  background: linear-gradient(180deg, #f3e8ff 0%, #e0c3fc 100%);
  border-color: #9b5de5;
  color: #4a148c;
  box-shadow: 0 4px 0 #9b5de5;
}

/* ==================== MAIN GAME STAGE ==================== */
.game-stage {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 22px;
  align-items: start;
  flex: 1;
}

@media (max-width: 920px) {
  .game-stage {
    grid-template-columns: minmax(0, 1fr);
  }
  .mascot-panel {
    order: 2;
  }
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mascot-card, .legend-card {
  background: var(--panel-bg);
  border: 3px solid #ffffff;
  border-radius: 26px;
  padding: 16px;
  box-shadow: 0 10px 24px rgba(29, 53, 87, 0.12), 0 4px 0 rgba(168, 218, 220, 0.6);
}

.mascot-speech {
  background: #ffffff;
  border: 2.5px solid #a9def9;
  border-radius: 18px;
  padding: 11px 14px;
  font-size: 0.92rem;
  line-height: 1.45;
  color: #1d3557;
  font-weight: 700;
  position: relative;
  box-shadow: 0 4px 0 rgba(0, 187, 249, 0.2);
}

.mascot-speech::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 10px 10px 0;
  border-style: solid;
  border-color: #a9def9 transparent;
}

.mascot-img-wrap {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
}

.mascot-img {
  width: 150px;
  height: 150px;
  object-fit: contain;
  filter: drop-shadow(0 8px 12px rgba(29, 53, 87, 0.18));
  will-change: transform;
  animation: mascotFloat 2.8s ease-in-out infinite;
}

@keyframes mascotFloat {
  0%, 100% { transform: translateY(0px) rotate(-1deg); }
  50% { transform: translateY(-7px) rotate(2deg); }
}

.level-badge-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 2px dashed #e2eafc;
  font-size: 0.88rem;
  font-weight: 800;
}

.difficulty-tag {
  background: #fff3b0;
  color: #b07d00;
  padding: 4px 10px;
  border-radius: 999px;
}

.overtime-alert {
  background: linear-gradient(135deg, #ff4d6d, #c9184a);
  color: #ffffff;
  border: 3px solid #ffffff;
  border-radius: 22px;
  padding: 14px 16px;
  box-shadow: 0 8px 20px rgba(201, 24, 74, 0.35);
  animation: pulseWarn 0.6s infinite alternate;
}

.overtime-title {
  font-weight: 900;
  font-size: 1rem;
  margin-bottom: 4px;
}

.overtime-desc {
  font-size: 0.82rem;
  opacity: 0.95;
  margin-bottom: 8px;
}

.overtime-progress-track {
  height: 10px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 999px;
  overflow: hidden;
}

.overtime-progress-fill {
  height: 100%;
  width: 100%;
  background: #ffbe0b;
  transition: width 0.15s linear;
}

.legend-card h3 {
  font-size: 1.02rem;
  color: #1d3557;
  margin-bottom: 10px;
}

.legend-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  font-weight: 900;
  font-size: 0.78rem;
  flex-shrink: 0;
  color: #fff;
}

.legend-dot.free { background: #ff4d6d; }
.legend-dot.ice { background: linear-gradient(135deg, #00bbf9, #72efdd); }
.legend-dot.stone { background: linear-gradient(135deg, #7a869a, #4b5563); }
.legend-dot.lock-h { background: #00bbf9; }
.legend-dot.lock-v { background: #9b5de5; }
.legend-dot.lshape { background: #ffbe0b; color: #5c3c00; }

.copyright-card {
  background: rgba(255, 255, 255, 0.95);
  border: 2.5px solid #ffffff;
  border-radius: 18px;
  padding: 10px 14px;
  text-align: center;
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--text-muted);
  box-shadow: 0 6px 16px rgba(29, 53, 87, 0.1), 0 3px 0 rgba(168, 218, 220, 0.55);
}

.copyright-card a {
  color: #0077b6;
  text-decoration: none;
  font-weight: 900;
  transition: color 0.15s ease;
}

.copyright-card a:hover {
  color: #ff4d6d;
  text-decoration: underline;
}

/* ==================== BOARD SECTION ==================== */
.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--panel-bg);
  border: 3px solid #ffffff;
  border-radius: 30px;
  padding: 18px 24px 22px;
  box-shadow: 0 12px 30px rgba(29, 53, 87, 0.15), 0 5px 0 rgba(168, 218, 220, 0.7);
}

.level-banner {
  width: 100%;
  max-width: calc(var(--board-size) + var(--exit-thickness) * 2 + 20px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(90deg, #1d3557, #2a4d7d);
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 18px;
  box-shadow: 0 4px 0 #0f1e36;
}

.level-banner h2 {
  font-size: 1.2rem;
  font-weight: 900;
}

.move-counter {
  background: rgba(255, 255, 255, 0.18);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 700;
}

/* Outer frame holding the 4 exit rims + 6x6 grid */
.board-outer-frame {
  position: relative;
  padding: calc(var(--exit-thickness) + 6px);
  border-radius: 34px;
  background: linear-gradient(145deg, #3d5a80, #293241);
  box-shadow:
    inset 0 4px 10px rgba(255, 255, 255, 0.2),
    0 12px 0 #1b222c,
    0 18px 32px rgba(0, 0, 0, 0.28);
  touch-action: none;
}

.board-grid {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  background: #edf2fb;
  border-radius: 20px;
  padding: var(--board-pad);
  box-shadow: inset 0 5px 12px rgba(29, 53, 87, 0.18);
}

.grid-bg-cells {
  display: grid;
  grid-template-columns: repeat(6, var(--cell-size));
  grid-template-rows: repeat(6, var(--cell-size));
  gap: var(--grid-gap);
  width: 100%;
  height: 100%;
}

.grid-cell {
  background: #dbe4f3;
  border-radius: 13px;
  box-shadow: inset 0 3px 5px rgba(29, 53, 87, 0.12);
  position: relative;
}

.grid-cell::after {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.35);
}

/* ==================== EXIT GATES ==================== */
.exits-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.exit-gate {
  position: absolute;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-weight: 900;
  color: #ffffff;
  font-size: 0.85rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  border: 2.5px solid #ffffff;
  overflow: hidden;
  transition: transform 0.2s ease, filter 0.2s ease, box-shadow 0.2s ease;
  z-index: 5;
}

.exit-gate::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.22),
    rgba(255, 255, 255, 0.22) 8px,
    transparent 8px,
    transparent 16px
  );
  animation: stripeMove 1.2s linear infinite;
}

@keyframes stripeMove {
  0% { background-position: 0 0; }
  100% { background-position: 24px 24px; }
}

.exit-gate.active-match {
  transform: scale(1.08);
  filter: brightness(1.18);
  z-index: 15;
}

.exit-gate-label {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  letter-spacing: 0.5px;
}

/* ==================== BLOCKS LAYER ==================== */
.blocks-layer, .hint-layer {
  position: absolute;
  top: var(--board-pad);
  left: var(--board-pad);
  right: var(--board-pad);
  bottom: var(--board-pad);
  pointer-events: none;
}

.puzzle-block {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  transition: transform 0.13s cubic-bezier(0.22, 1, 0.36, 1), filter 0.15s ease;
  z-index: 10;
}

.puzzle-block.dragging {
  z-index: 30;
  filter: brightness(1.08) drop-shadow(0 10px 18px rgba(0, 0, 0, 0.28));
  transition: transform 0.05s linear;
}

.puzzle-block.selected {
  z-index: 25;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.95));
}

.puzzle-block.exiting {
  z-index: 40;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.26s ease;
  opacity: 0;
}

.puzzle-block.hint-pulse {
  animation: blockHintPulse 0.65s ease-in-out infinite alternate;
  z-index: 35;
}

@keyframes blockHintPulse {
  0% { filter: brightness(1) drop-shadow(0 0 4px #ffffff); }
  100% { filter: brightness(1.22) drop-shadow(0 0 16px #ffbe0b); }
}

.block-cell {
  position: absolute;
  pointer-events: auto;
  cursor: grab;
  border-radius: 15px;
  border: 2.5px solid rgba(255, 255, 255, 0.72);
  box-shadow:
    inset 0 4px 6px rgba(255, 255, 255, 0.55),
    inset 0 -5px 8px rgba(0, 0, 0, 0.22),
    0 5px 0 var(--block-dark, #333),
    0 7px 12px rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.block-cell:active {
  cursor: grabbing;
}

/* Specular toy shine */
.block-cell::before {
  content: '';
  position: absolute;
  top: 5px;
  left: 8px;
  right: 8px;
  height: 22%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.04));
  pointer-events: none;
  z-index: 1;
}

.block-cell.no-top-shine::before {
  display: none;
}

.block-stud {
  position: absolute;
  inset: 10px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.06));
  pointer-events: none;
}

/* Cute kawaii face & emoji on the anchor cell */
.block-face {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  pointer-events: none;
}

.face-eyes {
  font-size: 0.78rem;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.96);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  line-height: 1;
}

.face-emoji {
  font-size: 1.05rem;
  line-height: 1;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.2));
}

.axis-badge {
  position: absolute;
  bottom: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  z-index: 3;
  pointer-events: none;
}

/* Frozen Block Icy Crystal Overlay & Badge */
.puzzle-block.is-frozen .block-cell {
  cursor: not-allowed;
  border-color: #caf0f8;
  box-shadow:
    inset 0 0 14px rgba(202, 240, 248, 0.85),
    inset 0 -4px 8px rgba(0, 119, 182, 0.45),
    0 5px 0 #0077b6,
    0 7px 12px rgba(0, 187, 249, 0.28);
}

.puzzle-block.is-frozen .block-cell::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg,
      rgba(202, 240, 248, 0.58) 0%,
      rgba(144, 224, 239, 0.28) 45%,
      rgba(255, 255, 255, 0.65) 50%,
      rgba(144, 224, 239, 0.32) 55%,
      rgba(0, 180, 216, 0.42) 100%);
  pointer-events: none;
  z-index: 2;
}

.ice-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: linear-gradient(135deg, #0077b6, #00bbf9);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 900;
  border: 1.5px solid #caf0f8;
  box-shadow: 0 2px 6px rgba(0, 119, 182, 0.5);
  z-index: 4;
  pointer-events: none;
}

/* Stone Blocker Styling */
.puzzle-block.is-stone .block-cell {
  border-color: rgba(226, 232, 240, 0.8);
}

.stone-badge {
  position: absolute;
  bottom: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.65);
  color: #f1f5f9;
  font-size: 0.66rem;
  font-weight: 900;
  border: 1px solid rgba(255, 255, 255, 0.45);
  z-index: 3;
  pointer-events: none;
}

/* Ghost hint indicator */
.hint-ghost {
  position: absolute;
  border: 3px dashed #ffbe0b;
  background: rgba(255, 190, 11, 0.28);
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: #1d3557;
  font-size: 0.95rem;
  box-shadow: 0 0 16px rgba(255, 190, 11, 0.7);
  animation: pulseWarn 0.55s infinite alternate;
}

/* ==================== BOTTOM TOOLBAR ==================== */
.action-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #ffffff;
  border: 2.5px solid #cbd5e1;
  color: #1d3557;
  padding: 10px 18px;
  border-radius: 18px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 #94a3b8;
  transform: translateZ(0);
  backface-visibility: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 8px 8px 20px;
    gap: 10px;
  }
  .top-bar {
    padding: 10px 12px;
    border-radius: 20px;
    gap: 10px;
  }
  .top-logo {
    height: 46px;
  }
  .brand-titles h1 {
    font-size: 1.18rem;
    flex-wrap: wrap;
    gap: 6px;
  }
  .badge-kid {
    font-size: 0.76rem;
    padding: 2px 8px;
    white-space: nowrap;
  }
  .audio-controls {
    width: 100%;
    justify-content: space-between;
    gap: 6px;
  }
  .icon-btn {
    flex: 1;
    justify-content: center;
    padding: 7px 8px;
    font-size: 0.78rem;
    white-space: nowrap;
  }
  .board-section {
    width: 100%;
    padding: 12px 8px 16px;
    border-radius: 22px;
  }
  .board-outer-frame {
    border-radius: 24px;
  }
  .level-banner {
    padding: 8px 14px;
  }
  .level-banner h2 {
    font-size: 1.02rem;
  }
  .block-stud {
    inset: 6px;
    border-radius: 7px;
  }
  .face-emoji {
    font-size: 0.85rem;
  }
  .face-eyes {
    font-size: 0.6rem;
  }
  .axis-badge, .stone-badge {
    font-size: 0.54rem;
    padding: 1px 4px;
    bottom: 2px;
  }
  .ice-badge {
    font-size: 0.56rem;
    padding: 1px 4px;
    top: 2px;
    right: 2px;
  }
  .action-toolbar {
    gap: 8px;
    width: 100%;
  }
  .tool-btn {
    padding: 8px 12px;
    font-size: 0.85rem;
    border-radius: 14px;
  }
}

.tool-btn:hover {
  transform: translateY(-2px);
}

.tool-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #94a3b8;
}

.tool-btn.hint-btn {
  background: linear-gradient(180deg, #fff3b0 0%, #ffbe0b 100%);
  border-color: #ffffff;
  color: #5c3c00;
  box-shadow: 0 5px 0 #d48c00;
}

.tool-btn.levels-btn {
  background: linear-gradient(180deg, #a9def9 0%, #00bbf9 100%);
  border-color: #ffffff;
  color: #023e8a;
  box-shadow: 0 5px 0 #0077b6;
}

/* ==================== MODALS ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 54, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 500;
}

.hidden {
  display: none !important;
}

.modal-card {
  background: #ffffff;
  border: 4px solid #a9def9;
  border-radius: 32px;
  padding: 26px 30px;
  max-width: 620px;
  width: 100%;
  text-align: center;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.35), 0 8px 0 #00bbf9;
  animation: modalPop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-height: 92vh;
  overflow-y: auto;
}

@keyframes modalPop {
  0% { transform: scale(0.82); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.welcome-logo {
  width: 250px;
  max-width: 80%;
  height: auto;
  margin-bottom: 6px;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.18));
}

.modal-card h2 {
  font-size: 1.55rem;
  font-weight: 900;
  color: #1d3557;
  margin-bottom: 6px;
}

.welcome-lead, .modal-desc {
  font-size: 0.98rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 18px;
}

.rules-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  text-align: left;
  margin-bottom: 22px;
}

@media (max-width: 560px) {
  .rules-grid {
    grid-template-columns: 1fr;
  }
}

.rule-item {
  display: flex;
  gap: 10px;
  background: #f4f9ff;
  border: 2px solid #d8eafe;
  border-radius: 18px;
  padding: 12px;
}

.rule-emoji {
  font-size: 1.65rem;
  flex-shrink: 0;
  width: 34px;
  text-align: center;
  line-height: 1.2;
}

.rule-item > div > strong {
  font-size: 0.94rem;
  color: #1d3557;
  display: block;
  margin-bottom: 4px;
}

.rule-item p {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.rule-item p strong {
  display: inline;
  font-size: inherit;
  color: #1d3557;
  font-weight: 800;
}

.primary-cta-btn {
  background: linear-gradient(180deg, #06d6a0 0%, #04966f 100%);
  color: #ffffff;
  border: 3px solid #ffffff;
  padding: 13px 28px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1.12rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 0 #03664b, 0 10px 20px rgba(6, 214, 160, 0.35);
  transform: translateZ(0);
  backface-visibility: hidden;
  transition: transform 0.15s ease;
}

.primary-cta-btn:hover {
  transform: translateY(-2px) scale(1.02);
}

.primary-cta-btn:active {
  transform: translateY(3px);
}

.secondary-btn {
  background: #edf2fb;
  color: #1d3557;
  border: 2.5px solid #cbd5e1;
  padding: 12px 22px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 5px 0 #94a3b8;
}

.modal-mascot {
  width: 118px;
  height: 118px;
  object-fit: contain;
  margin-bottom: 2px;
}

.clear-stars-banner {
  font-size: 1.75rem;
  font-weight: 900;
  color: #d48c00;
  letter-spacing: 3px;
  margin-bottom: 2px;
  filter: drop-shadow(0 3px 6px rgba(255, 190, 11, 0.4));
}

.score-breakdown-card {
  background: #f4f9ff;
  border: 2px solid #d8eafe;
  border-radius: 18px;
  padding: 10px 16px;
  margin: 10px 0 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 700;
  color: #334155;
}

.breakdown-row em {
  font-style: normal;
  font-weight: 900;
  color: #0077b6;
}

.breakdown-row strong {
  font-size: 0.96rem;
  font-weight: 900;
  color: #1d3557;
}

.score-summary-box {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 12px 0 16px;
  flex-wrap: wrap;
}

.summary-item {
  background: #f8f9fa;
  border: 2.5px solid #e2eafc;
  border-radius: 18px;
  padding: 12px 18px;
  min-width: 135px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-item.highlight {
  background: #fff9db;
  border-color: #ffbe0b;
}

.summary-item span {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 700;
}

.summary-item strong {
  font-size: 1.35rem;
  color: #1d3557;
  font-weight: 900;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ==================== LEVEL SELECT GRID ==================== */
.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.close-x-btn {
  background: #f1f5f9;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: 900;
  cursor: pointer;
  color: #475569;
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}

@media (max-width: 520px) {
  .levels-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.level-node-btn {
  background: #f8fafc;
  border: 2.5px solid #cbd5e1;
  border-radius: 18px;
  padding: 10px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-family: inherit;
  box-shadow: 0 4px 0 #cbd5e1;
  transition: transform 0.15s;
}

.level-node-btn:hover {
  transform: translateY(-2px);
}

.level-node-btn.current {
  background: #e0fbfc;
  border-color: #00bbf9;
  box-shadow: 0 4px 0 #00bbf9;
}

.level-node-btn.cleared {
  background: #f0fff4;
  border-color: #06d6a0;
  box-shadow: 0 4px 0 #06d6a0;
}

.level-node-btn.locked {
  background: #f1f5f9;
  border: 2.5px dashed #cbd5e1;
  box-shadow: 0 3px 0 #e2e8f0;
  opacity: 0.65;
  cursor: not-allowed;
}

.level-node-btn.locked:hover {
  transform: none;
}

.level-node-btn.locked .level-node-num,
.level-node-btn.locked .level-node-name,
.level-node-btn.locked .level-node-best {
  color: #94a3b8;
}

.level-node-num {
  font-size: 1.15rem;
  font-weight: 900;
  color: #1d3557;
}

.level-node-name {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 700;
}

.level-node-best {
  font-size: 0.76rem;
  font-weight: 900;
  color: #d48c00;
}

/* ==================== MUSIC STUDIO MODAL ==================== */
.music-settings-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  padding: 12px 16px;
  border-radius: 16px;
  border: 2px solid #e2e8f0;
  font-weight: 800;
}

.setting-row input[type="range"] {
  width: 180px;
  accent-color: #9b5de5;
}

.track-selector, .live-gen-box {
  background: #f8fafc;
  padding: 14px 16px;
  border-radius: 18px;
  border: 2px solid #e2e8f0;
}

.track-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

@media (max-width: 520px) {
  .track-buttons {
    grid-template-columns: 1fr;
  }
}

.track-btn {
  padding: 9px 12px;
  border-radius: 12px;
  border: 2px solid #cbd5e1;
  background: #ffffff;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.84rem;
  cursor: pointer;
  text-align: left;
}

.track-btn.active {
  background: #f3e8ff;
  border-color: #9b5de5;
  color: #4a148c;
}

.small-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 4px 0 10px;
}

.preset-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.chip-btn {
  background: #ffffff;
  border: 1.5px solid #c77dff;
  color: #5a189a;
  padding: 5px 11px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
}

.chip-btn:hover {
  background: #f3e8ff;
}

.custom-prompt-row {
  display: flex;
  gap: 8px;
}

.custom-prompt-row input {
  flex: 1;
  padding: 9px 12px;
  border-radius: 12px;
  border: 2px solid #cbd5e1;
  font-family: inherit;
  font-size: 0.88rem;
}

.small-cta {
  padding: 9px 16px;
  font-size: 0.88rem;
}

.music-gen-status {
  margin-top: 8px;
  font-size: 0.84rem;
  font-weight: 800;
  color: #5a189a;
}
