* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Prompt", "Kanit", "Segoe UI", sans-serif;
  background: #dff7ff;
  color: #123;
}

.screen {
  display: none;
  min-height: 100vh;
  padding: 28px;
  position: relative;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

/* ---------- HOME ---------- */
.home-screen,
.story-screen,
.tutorial-screen,
.summary-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.city-bg,
.problem-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

.city-bg {

position:absolute;

inset:0;

background-image:url("images/background-home2.png");

background-size:cover;

background-position:center;

background-repeat:no-repeat;

overflow:hidden;

}

.sun {
  position: absolute;
  top: 38px;
  right: 80px;
  width: 95px;
  height: 95px;
  border-radius: 50%;
  background: #ffd84d;
  box-shadow: 0 0 45px rgba(255, 216, 77, 0.8);
}

.cloud {
  position: absolute;
  width: 160px;
  height: 55px;
  border-radius: 50px;
  background: rgba(255, 255, 255, 0.78);
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: inherit;
}

.cloud::before {
  width: 70px;
  height: 70px;
  left: 25px;
  top: -28px;
}

.cloud::after {
  width: 82px;
  height: 82px;
  right: 24px;
  top: -38px;
}

.c1 {
  top: 70px;
  left: 90px;
}

.c2 {
  top: 130px;
  right: 270px;
  transform: scale(0.8);
}

.building {
  position: absolute;
  bottom: 39%;
  width: 110px;
  border-radius: 16px 16px 0 0;
  background: #3b82f6;
  border: 5px solid rgba(255, 255, 255, 0.25);
}

.building::before {
  content: "";
  display: block;
  width: 72%;
  height: 80%;
  margin: 22px auto;
  background-image: radial-gradient(#fff 4px, transparent 5px);
  background-size: 25px 25px;
  opacity: 0.9;
}

.b1 {
  left: 8%;
  height: 230px;
}

.b2 {
  left: 22%;
  height: 315px;
  background: #8b5cf6;
}

.b3 {
  right: 24%;
  height: 235px;
  background: #06b6d4;
}

.b4 {
  right: 8%;
  height: 290px;
  background: #22c55e;
}

.road {
  position: absolute;
  bottom: 12%;
  left: -5%;
  width: 110%;
  height: 90px;
  background: #4b5563;
  border-top: 10px solid #374151;
  border-bottom: 10px solid #374151;
}

.road::before {
  content: "";
  position: absolute;
  top: 38px;
  left: 0;
  width: 100%;
  height: 8px;
  background: repeating-linear-gradient(90deg, #fff 0 70px, transparent 70px 135px);
}

.city-icon {
  position: absolute;
  font-size: 62px;
  filter: drop-shadow(0 8px 4px rgba(0, 0, 0, 0.18));
}

.tree {
  bottom: 32%;
  left: 42%;
}

.traffic {
  bottom: 35%;
  left: 57%;
}

.ambulance {
  bottom: 18%;
  left: 16%;
}

.trash {
  bottom: 20%;
  right: 18%;
}

.hero-card,
.story-card,
.tutorial-card,
.summary-card {
  position: relative;
  z-index: 1;
  width: min(980px, 94vw);
  background: rgba(255, 255, 255, 0.92);
  border: 4px solid rgba(255, 255, 255, 0.7);
  border-radius: 32px;
  padding: 38px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(12px);
}

.badge {
  display: inline-block;
  background: #dcfce7;
  color: #166534;
  font-size: 20px;
  font-weight: 800;
  padding: 10px 20px;
  border-radius: 999px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  color: #155e75;
  font-size: clamp(42px, 7vw, 82px);
  line-height: 1;
  letter-spacing: 1px;
}

h2 {
  color: #166534;
  font-size: clamp(30px, 4vw, 48px);
  margin: 12px 0;
}

h3 {
  margin: 8px 0 14px;
  color: #1e40af;
  font-size: 26px;
}

p {
  font-size: 22px;
  line-height: 1.65;
}

.button-row {
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 24px;
}

button {
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: 0.2s;
}

button:hover {
  transform: translateY(-3px);
}

.primary-btn,
.secondary-btn {
  padding: 16px 30px;
  border-radius: 18px;
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.18);
}

.primary-btn {
  background: #2563eb;
  color: white;
}

.secondary-btn {
  background: #fbbf24;
  color: #3b2500;
}

/* ---------- STORY ---------- */
.problem-bg {
  background: linear-gradient(#93c5fd, #bbf7d0);
}

.problem-icon {
  position: absolute;
  font-size: 82px;
  animation: float 2.5s infinite ease-in-out;
}

.p1 {
  left: 12%;
  top: 18%;
}

.p2 {
  right: 14%;
  top: 22%;
  animation-delay: 0.4s;
}

.p3 {
  left: 18%;
  bottom: 18%;
  animation-delay: 0.8s;
}

.p4 {
  right: 20%;
  bottom: 16%;
  animation-delay: 1.1s;
}

.character-large {
  font-size: 105px;
  margin-bottom: 8px;
}

.mission-list {
  display: grid;
  gap: 12px;
  max-width: 650px;
  margin: 20px auto;
}

.mission-list div {
  background: #eff6ff;
  border: 3px solid #bfdbfe;
  border-radius: 18px;
  padding: 14px;
  font-size: 24px;
  font-weight: 800;
}

/* ---------- TUTORIAL ---------- */
.tutorial-screen {
  background: linear-gradient(135deg, #dbeafe, #dcfce7);
}

.tutorial-layout {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 26px;
  text-align: left;
}

.tutorial-left,
.tutorial-right {
  background: #f8fafc;
  border-radius: 26px;
  padding: 24px;
  border: 3px solid #e2e8f0;
}

.sample-block,
.answer-box {
  background: #fbbf24;
  border: 3px solid #92400e;
  color: #3b2500;
  border-radius: 16px;
  padding: 13px 16px;
  margin: 10px 0;
  font-size: 22px;
  font-weight: 900;
}

.hint,
.quote {
  color: #475569;
  font-weight: 800;
}

.mini-grid {
  width: 280px;
  height: 280px;
  margin: 12px auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.mini-cell {
  background: #a7f3d0;
  border: 2px solid #059669;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 26px;
}

/* ---------- GAME ---------- */
.game-screen {
  background: linear-gradient(135deg, #bff5ff, #d9f99d);
  flex-direction: column;
  gap: 18px;
}

.game-header {
  background: white;
  border-radius: 26px;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.12);
  gap: 16px;
}

.game-header h2 {
  margin: 0;
  font-size: 34px;
}

.game-header p {
  margin: 6px 0 0;
  font-size: 19px;
}

.score-panel {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 22px;
  font-weight: 900;
}

.score-panel span {
  background: #eff6ff;
  padding: 12px 18px;
  border-radius: 999px;
  border: 3px solid #bfdbfe;
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 20px;
  flex: 1;
}

.map-panel,
.code-panel {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 28px;
  padding: 22px;
  box-shadow: 0 12px 45px rgba(0, 0, 0, 0.13);
}

.grid {
  width: min(680px, 100%);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: grid;
  gap: 6px;
  background: #164e63;
  padding: 8px;
  border-radius: 22px;
}

.cell {
  .cell {

border-radius:14px;

display:grid;

place-items:center;

font-size:

clamp(
14px,
2vw,
30px
);

font-weight:900;

overflow:hidden;

line-height:1;

}
  background: #b7e4c7;
  box-shadow: inset 0 -5px rgba(0, 0, 0, 0.12);
}

.road-cell {
  background: #d6a56d;
}

.grass-cell {
  background: #74c365;
}

.water-cell {
  background: #67e8f9;
}

.wall-cell {
  background: #94a3b8;
}

.target-cell {
  background: #fde68a;
  animation: glow 1.2s infinite alternate;
}

.player {
  transform: none;
  filter: none;
}

.problem-box,
.workspace-wrap {
  background: #f8fafc;
  border-radius: 20px;
  padding: 18px;
  border: 3px solid #e2e8f0;
  margin-bottom: 16px;
}

.problem-box p {
  margin: 0;
  font-size: 20px;
}

.workspace {
  min-height: 140px;
  border: 3px dashed #93c5fd;
  border-radius: 18px;
  background-image: radial-gradient(#94a3b8 1px, transparent 1px);
  background-size: 18px 18px;
  padding: 14px;
  display: flex;
  gap: 10px;
  align-content: flex-start;
  flex-wrap: wrap;
}

.empty-text {
  color: #64748b;
  font-size: 20px;
  font-weight: 800;
}

.block-bank {
  background: #e2e8f0;
  border-radius: 20px;
  padding: 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.cmd-block,
.workspace-block {
  background: #fbbf24;
  border: 3px solid #92400e;
  color: #3b2500;
  border-radius: 15px;
  padding: 12px 16px;
  font-size: 21px;
  font-weight: 900;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18);
}

.workspace-block {
  position: relative;
}

.workspace-block::after {
  content: "×";
  margin-left: 10px;
  color: #7f1d1d;
}

.control-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.run-btn,
.clear-btn,
.retry-btn {
  flex: 1;
  min-width: 150px;
  padding: 14px;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 900;
  color: white;
}

.run-btn {
  background: #16a34a;
}

.clear-btn {
  background: #f97316;
}

.retry-btn {
  background: #2563eb;
}

.feedback {
  min-height: 58px;
  margin-top: 16px;
  padding: 14px;
  border-radius: 18px;
  font-size: 22px;
  font-weight: 900;
  display: none;
}

.feedback.show {
  display: block;
}

.feedback.success {
  background: #dcfce7;
  color: #166534;
  border: 3px solid #22c55e;
}

.feedback.error {
  background: #fee2e2;
  color: #991b1b;
  border: 3px solid #ef4444;
}

/* ---------- SUMMARY ---------- */
.summary-screen {
  background: linear-gradient(135deg, #fde68a, #bbf7d0);
}

.trophy {
  font-size: 100px;
}

.big-stars {
  font-size: 48px;
  margin: 18px 0;
}

.skill-box {
  background: #f8fafc;
  border-radius: 24px;
  padding: 20px;
  text-align: left;
  max-width: 620px;
  margin: 0 auto;
}

.skill-box p {
  margin: 8px 0;
  font-weight: 800;
}

/* ---------- MODAL ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.65);
  padding: 22px;
}

.modal.show {
  display: flex;
}

.modal-card {
  position: relative;
  width: min(560px, 92vw);
  background: white;
  border-radius: 28px;
  padding: 32px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.close-btn {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #ef4444;
  color: white;
  font-size: 28px;
  font-weight: 900;
}

/* ---------- ANIMATION ---------- */
@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-18px);
  }
}

@keyframes glow {
  from {
    box-shadow: inset 0 -5px rgba(0, 0, 0, 0.12), 0 0 0 rgba(251, 191, 36, 0);
  }
  to {
    box-shadow: inset 0 -5px rgba(0, 0, 0, 0.12), 0 0 22px rgba(251, 191, 36, 0.95);
  }
}

@media (max-width: 980px) {
  .game-layout,
  .tutorial-layout {
    grid-template-columns: 1fr;
  }

  .game-header {
    flex-direction: column;
    text-align: center;
  }

  .screen {
    padding: 16px;
  }
}
html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.screen {
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
  padding: 14px;
}

.hero-card,
.story-card,
.tutorial-card,
.summary-card {
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: clamp(20px, 3vw, 34px);
}

.game-screen {
  height: 100dvh;
  padding: 12px;
  gap: 10px;
}

.game-header {
  min-height: 86px;
  padding: 12px 18px;
}

.game-header h2 {
  font-size: clamp(22px, 2.5vw, 30px);
}

.game-header p {
  font-size: clamp(14px, 1.5vw, 17px);
}

.game-layout {
  height: calc(100dvh - 120px);
  min-height: 0;
}

.map-panel,
.code-panel {
  min-height: 0;
  overflow: hidden;
  padding: 14px;
}

.code-panel {
  display: flex;
  flex-direction: column;
}

.problem-box {
  padding: 12px;
  margin-bottom: 10px;
}

.problem-box h3,
.workspace-wrap h3 {
  font-size: 20px;
  margin: 0 0 8px;
}

.problem-box p {
  font-size: 16px;
}

.workspace-wrap {
  padding: 12px;
  margin-bottom: 10px;
}

.workspace {
  min-height: 92px;
  max-height: 120px;
  overflow-y: auto;
}

.block-bank {
  padding: 10px;
  gap: 8px;
  margin-bottom: 10px;
}

.cmd-block,
.workspace-block {
  font-size: 16px;
  padding: 9px 12px;
}

.control-row button {
  font-size: 16px;
  padding: 10px;
}

.feedback {
  font-size: 16px;
  padding: 10px;
  min-height: 44px;
  margin-top: 10px;
}

.grid {
  width: min(100%, calc(100dvh - 190px));
  max-height: calc(100dvh - 190px);
}

.character-talk {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #dbeafe;
  display: grid;
  place-items: center;
  font-size: 34px;
  border: 3px solid #60a5fa;
  animation: avatarBounce 1.8s infinite ease-in-out;
}

.speech-bubble {
  flex: 1;
  background: #ffffff;
  border: 3px solid #93c5fd;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 16px;
  font-weight: 800;
  color: #1e3a8a;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.08);
}

.sound-btn {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #2563eb;
  color: white;
  font-size: 24px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.2);
}

.cmd-block.dragging {
  opacity: 0.45;
  transform: scale(1.08) rotate(-2deg);
}

.workspace.drag-over {
  background-color: #dbeafe;
  border-color: #2563eb;
  transform: scale(1.01);
}

.workspace-block {
  animation: blockPop 0.25s ease;
}

.cell.player {
  animation: playerStep 0.25s ease;
}



@keyframes blockPop {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes playerStep {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.25) translateY(-6px);
  }
  100% {
    transform: scale(1.15);
  }
}

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

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .screen {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }

  .game-layout {
    height: auto;
  }

  .map-panel,
  .code-panel {
    overflow: visible;
  }

  .grid {
    width: min(92vw, 420px);
    max-height: none;
  }
}
/* ปุ่มกลับหน้าหลักในหน้าเกม */
.home-game-btn {
  background: linear-gradient(180deg, #3b82f6, #1d4ed8);
  color: white;
  border: 4px solid #bfdbfe;
  border-radius: 18px;
  padding: 12px 20px;
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 7px 0 #1e3a8a;
  white-space: nowrap;
}

.home-game-btn:hover {
  transform: translateY(-3px);
}

/* ทำหน้าเกมให้เต็มจอมากขึ้น */
.game-screen {
  height: 100dvh;
  min-height: 100dvh;
  padding: 12px;
  gap: 10px;
  overflow: hidden;
}

.game-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
}

.game-layout {
  height: calc(100dvh - 120px);
  min-height: 0;
}

.map-panel,
.code-panel {
  min-height: 0;
  overflow: hidden;
}

/* แก้ช่องล่างไม่เต็ม */
.grid {
  width: 100%;
  height: calc(100dvh - 190px);
  max-height: 100%;
  aspect-ratio: unset;
}

/* กล่องพูดตัวละคร */
.character-talk {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #dbeafe;
  display: grid;
  place-items: center;
  font-size: 34px;
  border: 3px solid #60a5fa;
  animation: avatarBounce 1.8s infinite ease-in-out;
}

.speech-bubble {
  flex: 1;
  background: white;
  border: 3px solid #93c5fd;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 16px;
  font-weight: 800;
  color: #1e3a8a;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.08);
}

/* เพิ่มลวดลายแต่ละช่อง */
.grass-cell {
  background:
    radial-gradient(circle at 22% 28%, rgba(255,255,255,0.75) 0 4px, transparent 5px),
    radial-gradient(circle at 68% 70%, rgba(22,101,52,0.28) 0 10px, transparent 11px),
    radial-gradient(circle at 35% 75%, rgba(21,128,61,0.22) 0 7px, transparent 8px),
    linear-gradient(135deg, #8dd96f, #55b94d);
}

.road-cell {
  background:
    radial-gradient(circle at 25% 30%, rgba(120,70,30,0.22) 0 7px, transparent 8px),
    radial-gradient(circle at 70% 65%, rgba(120,70,30,0.18) 0 10px, transparent 11px),
    radial-gradient(circle at 45% 80%, rgba(255,255,255,0.17) 0 6px, transparent 7px),
    linear-gradient(135deg, #e4b06d, #c99150);
}

.water-cell {
  background:
    radial-gradient(circle at 25% 25%, rgba(255,255,255,0.45) 0 10px, transparent 11px),
    radial-gradient(circle at 70% 70%, rgba(255,255,255,0.25) 0 14px, transparent 15px),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.18) 0 8px, transparent 8px 18px),
    linear-gradient(135deg, #67e8f9, #0ea5e9);
}

.wall-cell {
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,0.35) 0 7px, transparent 8px),
    radial-gradient(circle at 70% 75%, rgba(30,41,59,0.16) 0 9px, transparent 10px),
    linear-gradient(135deg, #cbd5e1, #94a3b8);
}

.target-cell {
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.8) 0 20%, transparent 45%),
    linear-gradient(135deg, #fde68a, #facc15);
  animation: glow 1.2s infinite alternate;
}

/* เพิ่มความนูนของช่อง */
.cell {
  border: 3px solid rgba(255,255,255,0.32);
  box-shadow:
    inset 0 -7px rgba(0,0,0,0.13),
    inset 0 4px rgba(255,255,255,0.25),
    0 4px 0 rgba(0,0,0,0.15);
}

/* เอฟเฟกต์บล็อก */
.cmd-block.dragging {
  opacity: 0.5;
  transform: scale(1.08) rotate(-2deg);
}

.workspace.drag-over {
  background-color: #dbeafe;
  border-color: #2563eb;
  transform: scale(1.01);
}

.workspace-block.active-command {
  background: #22c55e;
  color: white;
  border-color: #166534;
  transform: scale(1.08);
}

@keyframes avatarBounce {
  0%, 100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-5px);
  }
}

@media (max-width: 980px) {
  .game-screen {
    overflow: auto;
    height: auto;
  }

  .game-header {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .game-layout {
    height: auto;
  }

  .grid {
    height: auto;
    aspect-ratio: 1 / 1;
  }
}
.player-avatar{

width:80%;
height:80%;
object-fit:contain;

}
.character-large-img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  animation: avatarBounce 1.8s infinite ease-in-out;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.player-avatar {
  width: clamp(28px, 7vw, 72px);
  height: clamp(28px, 7vw, 72px);
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  animation: playerFloat 1.4s infinite ease-in-out;
}

.mini-character-img {
  width: 82%;
  height: 82%;
  object-fit: contain;
}

@keyframes playerFloat{

0%,100%{

transform:
translateY(-2px);

}

50%{

transform:
translateY(-4px);

}

}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #dbeafe;
  display: grid;
  place-items: center;
  border: 3px solid #60a5fa;
  overflow: hidden;
  animation: avatarBounce 1.8s infinite ease-in-out;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.sound-btn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 999;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  color: white;
  border: 4px solid #bfdbfe;
  font-size: 26px;
  font-weight: 900;
  box-shadow: 0 8px 0 #1e3a8a;
}

.sound-btn:hover {
  transform: translateY(-3px);
}
.success-popup{

display:flex;

flex-direction:column;

align-items:center;

gap:14px;

}

.popup-emoji{

font-size:72px;

animation:

popupBounce

1s infinite;

}

.popup-stars{

font-size:34px;

}

.popup-buttons{

display:flex;

gap:12px;

flex-wrap:wrap;

justify-content:center;

margin-top:10px;

}

.popup-next{

background:

#16a34a;

color:white;

padding:

14px 22px;

border:none;

border-radius:

16px;

font-size:18px;

font-weight:900;

box-shadow:

0 5px 0

#166534;

}

.popup-retry{

background:

#2563eb;

color:white;

padding:

14px 22px;

border:none;

border-radius:

16px;

font-size:18px;

font-weight:900;

box-shadow:

0 5px 0

#1e3a8a;

}

@keyframes popupBounce{

0%,100%{

transform:

translateY(0);

}

50%{

transform:

translateY(-10px);

}

}
.repeat-tutorial-popup{
display:flex;
flex-direction:column;
align-items:center;
gap:8px;
}

.repeat-tutorial-popup p{
font-size:18px;
line-height:1.6;
margin:4px 0;
}

.repeat-example{
display:flex;
align-items:center;
justify-content:center;
gap:10px;
flex-wrap:wrap;
width:100%;
margin:8px 0;
}

.repeat-old,
.repeat-new{
background:#f8fafc;
border:3px solid #dbeafe;
border-radius:20px;
padding:14px;
min-width:170px;
}

.repeat-old h3,
.repeat-new h3{
font-size:18px;
margin:0 0 10px;
color:#1e40af;
}

.example-block{
background:#fbbf24;
border:3px solid #92400e;
color:#3b2500;
border-radius:14px;
padding:8px 12px;
margin:7px 0;
font-size:18px;
font-weight:900;
box-shadow:0 4px 0 rgba(0,0,0,.18);
}

.repeat-example-block{
background:#a78bfa;
border-color:#5b21b6;
color:white;
}

.repeat-arrow{
font-size:34px;
font-weight:900;
color:#2563eb;
}

.repeat-note{
background:#dcfce7;
border:3px solid #22c55e;
border-radius:16px;
padding:10px 14px;
color:#166534;
font-weight:800;
}
.certificate-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #dbeafe, #dcfce7);
}

.certificate-card {
  width: min(1000px, 94vw);
  min-height: 620px;
  background: #ffffff;
  border: 12px solid #facc15;
  border-radius: 32px;
  padding: 44px;
  text-align: center;
  box-shadow: 0 25px 80px rgba(0,0,0,.25);
  position: relative;
}

.certificate-card::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 4px dashed #60a5fa;
  border-radius: 22px;
  pointer-events: none;
}

.cert-logo {
  font-size: 72px;
}

.certificate-card h1 {
  color: #1e40af;
  font-size: 64px;
  margin: 0;
}

.cert-subtitle {
  font-size: 24px;
  margin: 12px 0;
}

#certificateName {
  font-size: 52px;
  color: #166534;
  margin: 16px 0;
  border-bottom: 4px solid #facc15;
  display: inline-block;
  padding: 0 40px 8px;
}

.cert-text {
  font-size: 24px;
  line-height: 1.8;
}

.cert-stars {
  font-size: 36px;
  margin: 18px 0;
}

.cert-date {
  font-size: 20px;
  font-weight: 800;
  color: #475569;
}
.result-box {
  background: #eff6ff;
  border: 3px solid #bfdbfe;
  border-radius: 24px;
  padding: 20px;
  max-width: 680px;
  margin: 18px auto;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.result-item {
  background: white;
  border: 3px solid #dbeafe;
  border-radius: 20px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 6px 0 rgba(0,0,0,.08);
}

.result-number {
  display: block;
  font-size: 34px;
  font-weight: 900;
  color: #2563eb;
}

.result-item p {
  margin: 6px 0 0;
  font-size: 18px;
  font-weight: 800;
  color: #475569;
}
.learning-objective{

background:#f8fafc;

border:3px solid #bfdbfe;

border-radius:22px;

padding:18px;

margin-top:20px;

max-width:720px;

margin-left:auto;

margin-right:auto;

}

.learning-objective h3{

margin-top:0;

font-size:24px;

color:#1e40af;

}

.objective-item{

background:white;

padding:12px 16px;

border-radius:14px;

margin:10px 0;

font-size:18px;

font-weight:700;

border-left:6px solid #2563eb;

box-shadow:

0 3px 0

rgba(0,0,0,.08);

text-align:left;

}
.summary-congrats-img {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: 24px;
  margin-bottom: 16px;
  border: 4px solid #facc15;
}
.result-grid {
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 720px) {
  .result-grid {
    grid-template-columns: 1fr;
  }
}
.hint-btn {
  flex: 1;
  min-width: 150px;
  padding: 14px;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 900;
  color: #3b2500;
  background: #facc15;
  box-shadow: 0 5px 0 #92400e;
}

.feedback.hint {
  display: block;
  background: #fef9c3;
  color: #854d0e;
  border: 3px solid #facc15;
}
/* HOME ANIMATION */
.home-screen .hero-card {
  animation: heroFloat 3.5s ease-in-out infinite;
}

.home-cloud {
  position: absolute;
  width: 170px;
  height: 58px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  z-index: 0;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.08));
}

.home-cloud::before,
.home-cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.home-cloud::before {
  width: 72px;
  height: 72px;
  left: 28px;
  top: -32px;
}

.home-cloud::after {
  width: 88px;
  height: 88px;
  right: 24px;
  top: -42px;
}

.cloud-a {
  top: 9%;
  left: -220px;
  transform: scale(.8);
  animation: cloudDrift 42s linear infinite;
}

.cloud-b {
  top: 22%;
  left: -260px;
  transform: scale(.6);
  animation: cloudDrift 58s linear infinite;
  animation-delay: -18s;
}

.cloud-c {
  top: 14%;
  left: -300px;
  transform: scale(1);
  animation: cloudDrift 70s linear infinite;
  animation-delay: -35s;
}

.sparkle {
  position: absolute;
  z-index: 1;
  font-size: 28px;
  opacity: .8;
  animation: sparkleBlink 2.2s ease-in-out infinite;
}

.sp1 {
  top: 18%;
  left: 18%;
}

.sp2 {
  top: 28%;
  right: 20%;
  animation-delay: .7s;
}

.sp3 {
  bottom: 28%;
  left: 28%;
  animation-delay: 1.2s;
}

@keyframes cloudDrift {
  from {
    left: -300px;
  }

  to {
    left: 110%;
  }
}

@keyframes sparkleBlink {
  0%, 100% {
    opacity: .15;
    transform: scale(.7) rotate(0deg);
  }

  50% {
    opacity: 1;
    transform: scale(1.15) rotate(12deg);
  }
}

@keyframes heroFloat {
  0%, 100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}
.level-progress-wrap {
  background: rgba(255,255,255,.92);
  border-radius: 18px;
  padding: 10px 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,.1);
}

.level-progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 900;
  color: #1e40af;
  margin-bottom: 6px;
}

.level-progress-bar {
  width: 100%;
  height: 18px;
  background: #dbeafe;
  border-radius: 999px;
  overflow: hidden;
  border: 3px solid #bfdbfe;
}

.level-progress-fill {
  height: 100%;
  width: 10%;
  background: linear-gradient(90deg, #22c55e, #16a34a, #facc15);
  border-radius: 999px;
  transition: width .4s ease;
}
.result-grid {
  grid-template-columns: repeat(5, 1fr);
}

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

@media (max-width: 520px) {
  .result-grid {
    grid-template-columns: 1fr;
  }
}
/* FIX: ป้องกันกระดานเกมล้นกรอบฝั่งซ้าย */
.map-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.grid {
  width: 100%;
  max-width: 620px;
  height: auto;
  aspect-ratio: 1 / 1;
  max-height: calc(100dvh - 260px);
  margin: 0 auto;
  overflow: hidden;
}

.cell {
  min-width: 0;
  min-height: 0;
}

@media (min-width: 1200px) {
  .grid {
    max-width: 580px;
  }
}
.mission-alert {
  position: absolute;
  top: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(-120px);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.96);
  border: 4px solid #facc15;
  border-radius: 24px;
  padding: 14px 22px;
  box-shadow: 0 12px 35px rgba(0,0,0,.22);
  opacity: 0;
  animation: missionAlertShow 4.5s ease forwards;
}

.alert-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #fee2e2;
  display: grid;
  place-items: center;
  font-size: 34px;
  animation: sirenPulse 0.8s infinite alternate;
}

.mission-alert h3 {
  margin: 0;
  color: #dc2626;
  font-size: 24px;
  line-height: 1.1;
}

.mission-alert p {
  margin: 4px 0 0;
  color: #1e3a8a;
  font-size: 18px;
  font-weight: 900;
  line-height: 1.2;
}

@keyframes missionAlertShow {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(-120px) scale(.85);
  }

  15% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1.04);
  }

  25% {
    transform: translateX(-50%) translateY(0) scale(1);
  }

  75% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-120px) scale(.9);
    pointer-events: none;
  }
}

@keyframes sirenPulse {
  from {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(239, 68, 68, 0);
  }

  to {
    transform: scale(1.1);
    box-shadow: 0 0 22px rgba(239, 68, 68, .75);
  }
}
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, .72);
  padding: 20px;
}

.login-overlay.show {
  display: flex;
}

.login-card {
  width: min(460px, 92vw);
  background: white;
  border-radius: 30px;
  padding: 34px;
  text-align: center;
  border: 5px solid #bfdbfe;
  box-shadow: 0 30px 90px rgba(0,0,0,.35);
}

.player-name-input {
  width: 100%;
  margin: 18px 0;
  padding: 16px 18px;
  border-radius: 18px;
  border: 3px solid #93c5fd;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
}

.leaderboard-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 44px 1fr 80px 70px;
  gap: 8px;
  align-items: center;
  background: #eff6ff;
  border: 3px solid #bfdbfe;
  border-radius: 16px;
  padding: 10px;
  font-size: 16px;
  font-weight: 900;
}

.rank {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #facc15;
  color: #3b2500;
}

.leader-name {
  text-align: left;
}
.leaderboard-row {
  grid-template-columns: 44px 1fr 160px;
}

.leaderboard-row span {
  white-space: nowrap;
}

.leaderboard-row span:last-child {
  text-align: right;
}
.intro-info-popup {
  text-align: left;
  max-height: 72vh;
  overflow-y: auto;
  padding-right: 8px;
}

.intro-info-popup h2 {
  text-align: center;
  color: #166534;
  font-size: 36px;
  margin-top: 0;
}

.intro-section {
  background: #f8fafc;
  border: 3px solid #dbeafe;
  border-radius: 20px;
  padding: 16px;
  margin: 14px 0;
}

.intro-section h3 {
  margin-top: 0;
  color: #1e40af;
  font-size: 22px;
}

.intro-section p {
  font-size: 17px;
  line-height: 1.6;
  margin: 7px 0;
}

.intro-info-popup .popup-next {
  display: block;
  margin: 18px auto 0;
}
.mission-brief-card {

max-width: 980px;

margin: 0 auto;

display: flex;

flex-direction: column;

align-items: center;

text-align: center;

}

.mission-badge {
  display: inline-block;
  background: #fee2e2;
  color: #b91c1c;
  border: 3px solid #fca5a5;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 10px;
}

.mission-story-text {
  max-width: 780px;
  margin: 14px auto;
  font-size: 21px;
  line-height: 1.7;
}

.mission-brief-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
  margin: 22px auto;
  max-width: 860px;
}

.brief-box {
  background: #f8fafc;
  border: 3px solid #bfdbfe;
  border-radius: 22px;
  padding: 18px;
  text-align: left;
  box-shadow: 0 6px 0 rgba(0,0,0,.08);
}

.brief-box h3 {
  margin-top: 0;
  color: #1e40af;
}

.brief-box p {
  font-size: 17px;
  font-weight: 800;
  margin: 8px 0;
}

.mission-tip {
  background: #fef9c3;
  border: 3px solid #facc15;
  border-radius: 18px;
  padding: 14px;
  max-width: 760px;
  margin: 12px auto;
  font-size: 20px;
  font-weight: 900;
  color: #854d0e;
}

@media (max-width: 760px) {
  .mission-brief-grid {
    grid-template-columns: 1fr;
  }

  .mission-story-text {
    font-size: 18px;
  }
}
.wall-cell,
.water-cell,
.target-cell{

font-size:

clamp(
14px,
2vw,
26px
);

display:flex;

align-items:center;

justify-content:center;

overflow:hidden;

line-height:1;

}

.player-avatar {

width:72%;

height:72%;

max-width:100%;

max-height:100%;

object-fit:contain;

pointer-events:none;

user-select:none;

animation:
playerFloat
1.4s
infinite
ease-in-out;

}
.cell.player {
  overflow: hidden;
}

.player-avatar {
  width: 70%;
  height: 70%;
  max-width: 70%;
  max-height: 70%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  animation: playerFloat 1.4s infinite ease-in-out;
}

@keyframes playerFloat {
  0%, 100% {
    transform: translateY(-2px);
  }

  50% {
    transform: translateY(-4px);
  }
}
/* FIX PLAYER SIZE - ให้ตัวละครพอดีทุกด่าน */
.cell.player {
  transform: none !important;
  animation: none !important;
  overflow: hidden !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.player-avatar {
  width: 90% !important;
  height: 90% !important;
  max-width: 90% !important;
  max-height: 90% !important;
  object-fit: contain !important;
  transform: translateY(-3px) !important;
  animation: none !important;
  pointer-events: none;
  user-select: none;
}
.game-logo{
  width: 620px;
  max-width: 92%;
  display: block;
  margin: 0 auto -110px;
}

@keyframes floatLogo{
  0%{
    transform: translateY(0px);
  }

  50%{
    transform: translateY(-8px);
  }

  100%{
    transform: translateY(0px);
  }
}
/* ---------- HOME CYBER SECURITY REFRESH ---------- */
.home-screen {
  isolation: isolate;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 3vw, 36px);
  background:
    radial-gradient(circle at 18% 20%, rgba(233, 196, 106, 0.28), transparent 28%),
    radial-gradient(circle at 82% 22%, rgba(244, 162, 97, 0.22), transparent 30%),
    linear-gradient(135deg, #102a38 0%, #174554 42%, #2a9d8f 100%);
}

.home-screen::before,
.home-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.home-screen::before {
  background:
    linear-gradient(rgba(255,255,255,0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.07) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.95), rgba(0,0,0,0.2));
}

.home-screen::after {
  background:
    radial-gradient(circle at 50% 0%, rgba(255,255,255,0.18), transparent 38%),
    linear-gradient(120deg, transparent 0 42%, rgba(233, 196, 106, 0.18) 43% 44%, transparent 45% 100%);
  opacity: 0.9;
}

.home-screen .city-bg {
  z-index: 0;
  background-image:
    linear-gradient(rgba(16, 42, 56, 0.55), rgba(16, 42, 56, 0.5)),
    url("images/background-home2.png");
  background-size: cover;
  background-position: center;
  filter: saturate(1.12) contrast(1.03);
}

.home-screen .city-bg::before {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 42%;
  background:
    linear-gradient(to top, rgba(16, 42, 56, 0.78), transparent),
    repeating-linear-gradient(90deg, rgba(233,196,106,0.26) 0 2px, transparent 2px 58px);
  pointer-events: none;
}

.home-screen .hero-card {
  width: min(940px, 94vw);
  max-height: calc(100dvh - 32px);
  padding: clamp(22px, 4vw, 42px);
  border-radius: 26px;
  border: 1px solid rgba(233, 196, 106, 0.6);
  background:
    linear-gradient(145deg, rgba(255,255,255,0.96), rgba(236,252,248,0.9));
  box-shadow:
    0 28px 70px rgba(5, 26, 36, 0.38),
    0 0 0 8px rgba(42, 157, 143, 0.12),
    inset 0 1px 0 rgba(255,255,255,0.95);
  backdrop-filter: blur(18px);
  animation: heroFloat 4.4s ease-in-out infinite;
}

.home-screen .hero-card::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(42, 157, 143, 0.22);
  border-radius: 20px;
  pointer-events: none;
}

.home-screen .badge {
  margin-bottom: 6px;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(42, 157, 143, 0.13);
  border: 2px solid rgba(42, 157, 143, 0.34);
  color: #176e65;
  font-size: clamp(15px, 2vw, 19px);
  letter-spacing: 0;
  box-shadow: 0 8px 22px rgba(42, 157, 143, 0.18);
}

.home-screen .badge::before {
  content: "🛡️ ";
}

.home-screen .game-logo {
  width: min(560px, 88vw);
  margin: -4px auto -78px;
  filter: drop-shadow(0 18px 18px rgba(16, 42, 56, 0.26));
}

.home-screen .hero-card p {
  max-width: 740px;
  margin: 18px auto 0;
  color: #21444a;
  font-size: clamp(17px, 2.1vw, 22px);
  line-height: 1.65;
  font-weight: 800;
}

.home-screen .button-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(126px, 1fr));
  gap: 12px;
  margin-top: clamp(22px, 3vw, 32px);
}

.home-screen .primary-btn,
.home-screen .secondary-btn {
  min-height: 58px;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: clamp(15px, 1.5vw, 19px);
  line-height: 1.2;
  box-shadow: 0 7px 0 rgba(16, 42, 56, 0.28), 0 14px 28px rgba(16, 42, 56, 0.16);
  transform: translateY(0);
}

.home-screen .primary-btn {
  background: linear-gradient(180deg, #2a9d8f, #1f7f75);
  color: white;
  border: 2px solid rgba(255,255,255,0.54);
}

.home-screen .secondary-btn {
  background: linear-gradient(180deg, #fff6d8, #e9c46a);
  color: #4a3510;
  border: 2px solid rgba(244, 162, 97, 0.48);
}

.home-screen .secondary-btn:nth-child(3) {
  background: linear-gradient(180deg, #fff2df, #f4a261);
  color: #4b2714;
}

.home-screen .primary-btn:hover,
.home-screen .secondary-btn:hover {
  transform: translateY(-4px);
  filter: brightness(1.04);
  box-shadow: 0 10px 0 rgba(16, 42, 56, 0.25), 0 18px 34px rgba(16, 42, 56, 0.22);
}

.home-screen .mission-alert {
  width: min(620px, calc(100vw - 28px));
  top: 18px;
  border-radius: 20px;
  border: 2px solid rgba(233, 196, 106, 0.95);
  background: rgba(255, 252, 239, 0.96);
  box-shadow: 0 18px 42px rgba(16, 42, 56, 0.32);
}

.home-screen .alert-icon {
  background: #fce7d1;
  color: #b54822;
}

.home-screen .mission-alert h3 {
  color: #176e65;
}

.home-screen .mission-alert p {
  color: #21444a;
}

.home-screen .home-cloud {
  background: rgba(255, 255, 255, 0.78);
  filter: drop-shadow(0 10px 16px rgba(16, 42, 56, 0.18));
}

.home-screen .sparkle {
  color: #e9c46a;
  text-shadow: 0 0 18px rgba(233, 196, 106, 0.75);
}

@media (max-width: 980px) {
  .home-screen .button-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .home-screen .button-row .secondary-btn:last-child {
    grid-column: 1 / -1;
  }

  .home-screen .game-logo {
    margin-bottom: -54px;
  }
}

@media (max-width: 560px) {
  .home-screen {
    padding: 12px;
  }

  .home-screen .hero-card {
    width: 100%;
    border-radius: 22px;
    padding: 22px 16px 18px;
  }

  .home-screen .hero-card::before {
    inset: 8px;
    border-radius: 16px;
  }

  .home-screen .badge {
    max-width: 100%;
    white-space: normal;
  }

  .home-screen .game-logo {
    width: min(360px, 94vw);
    margin: 0 auto -34px;
  }

  .home-screen .hero-card p {
    font-size: 16px;
    line-height: 1.55;
  }

  .home-screen .button-row {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 18px;
  }

  .home-screen .button-row .secondary-btn:last-child {
    grid-column: auto;
  }

  .home-screen .primary-btn,
  .home-screen .secondary-btn {
    width: 100%;
    min-height: 52px;
    font-size: 16px;
  }

  .home-screen .mission-alert {
    align-items: flex-start;
    padding: 12px 14px;
  }

  .home-screen .mission-alert h3 {
    font-size: 20px;
  }

  .home-screen .mission-alert p {
    font-size: 15px;
  }
}

/* ---------- HOME POLISH: ALERT, MOTION, CTA BUTTONS ---------- */
.home-screen .city-bg {
  background-image:
    linear-gradient(rgba(16, 42, 56, 0.2), rgba(42, 157, 143, 0.16)),
    url("images/background-home2.png");
}

.home-screen .city-bg::after {
  content: "🍃";
  position: absolute;
  top: 18%;
  left: -80px;
  z-index: 1;
  color: #e9c46a;
  font-size: 26px;
  text-shadow:
    170px 70px 0 rgba(233, 196, 106, 0.74),
    410px -26px 0 rgba(244, 162, 97, 0.68),
    690px 96px 0 rgba(233, 196, 106, 0.62),
    920px 18px 0 rgba(244, 162, 97, 0.58);
  opacity: 0.9;
  animation: leafDrift 16s linear infinite;
  pointer-events: none;
}

.home-screen .home-cloud {
  opacity: 0.92;
  animation-name: cloudDrift, cloudBob;
  animation-timing-function: linear, ease-in-out;
  animation-iteration-count: infinite, infinite;
}

.home-screen .cloud-a {
  animation-duration: 38s, 5.5s;
}

.home-screen .cloud-b {
  animation-duration: 52s, 6.5s;
}

.home-screen .cloud-c {
  animation-duration: 64s, 7s;
}

.home-screen .mission-alert {
  width: auto;
  min-width: min(430px, calc(100vw - 32px));
  max-width: min(560px, calc(100vw - 32px));
  left: 50%;
  right: auto;
  top: 16px;
  transform: translateX(-50%) translateY(-120px);
  justify-content: center;
  gap: 12px;
  padding: 12px 18px;
  border-radius: 18px;
  border: 2px solid rgba(244, 162, 97, 0.92);
  background: rgba(255, 248, 232, 0.86);
  backdrop-filter: blur(10px);
  box-shadow: 0 14px 34px rgba(16, 42, 56, 0.24);
}

.home-screen .mission-alert h3 {
  color: #dc2626;
  font-size: clamp(21px, 2.5vw, 28px);
  text-shadow: 0 1px 0 rgba(255,255,255,0.8);
}

.home-screen .mission-alert p {
  color: #173d43;
  font-size: clamp(15px, 1.6vw, 18px);
}

.home-screen .alert-icon {
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
  background: rgba(254, 226, 226, 0.9);
  color: #dc2626;
}

.home-screen .button-row {
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 14px;
  max-width: 940px;
  margin-left: auto;
  margin-right: auto;
}

.home-screen .button-row .primary-btn,
.home-screen .button-row .secondary-btn {
  position: relative;
  overflow: hidden;
  min-height: 64px;
  border-radius: 18px;
}

.home-screen .button-row .primary-btn::after,
.home-screen .button-row .secondary-btn::after {
  content: "";
  position: absolute;
  inset: -80% auto auto -40%;
  width: 50%;
  height: 220%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.48), transparent);
  transform: rotate(22deg);
  animation: buttonShine 4.8s ease-in-out infinite;
  pointer-events: none;
}

.home-screen .button-row .primary-btn {
  grid-column: 1 / span 2;
}

.home-screen .button-row .secondary-btn:nth-child(2) {
  grid-column: 4 / span 2;
}

.home-screen .button-row .secondary-btn:nth-child(4) {
  grid-column: 7 / span 2;
}

.home-screen .button-row .secondary-btn:nth-child(3) {
  grid-column: 1 / span 2;
  grid-row: 2;
}

.home-screen .button-row .secondary-btn:nth-child(5) {
  grid-column: 3 / span 4;
  grid-row: 2;
}

.home-screen .button-row .secondary-btn:nth-child(6) {
  grid-column: 7 / span 2;
  grid-row: 2;
}

.home-screen .primary-btn {
  background: linear-gradient(180deg, #34c6b5, #2a9d8f 58%, #1d736b);
}

.home-screen .secondary-btn {
  background: linear-gradient(180deg, #fff8dd, #e9c46a 64%, #d5a947);
}

.home-screen .contact-home-btn {
  background: linear-gradient(180deg, #ffe7d1, #f4a261 62%, #de7f40);
  border-color: rgba(255,255,255,0.72);
  color: #4a2a10;
  box-shadow: 0 8px 0 rgba(122, 62, 20, 0.28), 0 18px 28px rgba(244,162,97,0.22);
}

.home-screen .secondary-btn:nth-child(3),
.home-screen .secondary-btn:nth-child(5) {
  background: linear-gradient(180deg, #ffe9d3, #f4a261 62%, #de7f40);
}

.home-screen .primary-btn:hover,
.home-screen .secondary-btn:hover {
  transform: translateY(-5px) scale(1.025);
}

@keyframes leafDrift {
  0% {
    transform: translateX(-120px) translateY(0) rotate(0deg);
  }

  50% {
    transform: translateX(55vw) translateY(34px) rotate(18deg);
  }

  100% {
    transform: translateX(112vw) translateY(-8px) rotate(36deg);
  }
}

@keyframes cloudBob {
  0%, 100% {
    margin-top: 0;
  }

  50% {
    margin-top: 12px;
  }
}

@keyframes buttonShine {
  0%, 54% {
    left: -56%;
  }

  72%, 100% {
    left: 120%;
  }
}

@media (max-width: 980px) {
  .home-screen .button-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 560px;
  }

  .home-screen .button-row .primary-btn,
  .home-screen .button-row .secondary-btn,
  .home-screen .button-row .secondary-btn:nth-child(2),
  .home-screen .button-row .secondary-btn:nth-child(3),
  .home-screen .button-row .secondary-btn:nth-child(4),
  .home-screen .button-row .secondary-btn:nth-child(5),
  .home-screen .button-row .secondary-btn:nth-child(6) {
    grid-column: auto;
    grid-row: auto;
  }

  .home-screen .button-row .primary-btn {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .home-screen .mission-alert {
    min-width: 0;
    width: calc(100vw - 24px);
    max-width: 420px;
    padding: 10px 12px;
  }

  .home-screen .alert-icon {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    font-size: 28px;
  }

  .home-screen .button-row {
    grid-template-columns: 1fr;
    max-width: 100%;
  }
}

/* ---------- HOME PREMIUM MOTION LAYER ---------- */
.home-screen {
  perspective: 1200px;
  background:
    radial-gradient(circle at 12% 18%, rgba(233, 196, 106, 0.28), transparent 30%),
    radial-gradient(circle at 86% 16%, rgba(244, 162, 97, 0.22), transparent 28%),
    radial-gradient(circle at 50% 105%, rgba(42, 157, 143, 0.45), transparent 36%),
    linear-gradient(135deg, #0c2632 0%, #174554 46%, #2a9d8f 100%);
}

.home-screen::before {
  background:
    radial-gradient(circle, rgba(233,196,106,0.55) 0 2px, transparent 3px),
    radial-gradient(circle, rgba(255,255,255,0.5) 0 1px, transparent 2px),
    linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 140px 140px, 90px 90px, 46px 46px, 46px 46px;
  background-position: 0 0, 30px 20px, 0 0, 0 0;
  animation: particleFloat 18s linear infinite;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.9), rgba(0,0,0,0.18));
}

.home-screen::after {
  background:
    radial-gradient(circle at 50% 0%, rgba(255,255,255,0.2), transparent 34%),
    radial-gradient(circle at 70% 35%, rgba(233,196,106,0.16), transparent 20%),
    linear-gradient(120deg, transparent 0 38%, rgba(255,255,255,0.12) 42%, transparent 48% 100%);
  animation: ambientSweep 9s ease-in-out infinite;
}

.home-screen .city-bg {
  transform: translateZ(-30px) scale(1.04);
  background-size: 108% auto, cover;
  background-position: center 48%;
  animation: bgDepthShift 18s ease-in-out infinite alternate;
}

.home-screen .city-bg::before {
  height: 48%;
  background:
    linear-gradient(to top, rgba(12, 38, 50, 0.56), rgba(12, 38, 50, 0.05)),
    radial-gradient(circle at 18% 48%, rgba(233,196,106,0.75) 0 2px, transparent 3px),
    radial-gradient(circle at 36% 38%, rgba(233,196,106,0.6) 0 2px, transparent 3px),
    radial-gradient(circle at 62% 44%, rgba(233,196,106,0.7) 0 2px, transparent 3px),
    radial-gradient(circle at 78% 36%, rgba(244,162,97,0.68) 0 2px, transparent 3px),
    repeating-linear-gradient(90deg, rgba(233,196,106,0.16) 0 2px, transparent 2px 58px);
  animation: buildingLights 2.8s ease-in-out infinite alternate;
}

.home-screen .city-bg::after {
  content: "🍃";
  top: 18%;
  left: -90px;
  font-size: 24px;
  text-shadow:
    170px 70px 0 rgba(233, 196, 106, 0.66),
    410px -26px 0 rgba(244, 162, 97, 0.62),
    690px 96px 0 rgba(233, 196, 106, 0.58),
    920px 18px 0 rgba(244, 162, 97, 0.52);
  animation: leafDrift 18s linear infinite;
}

.home-screen .hero-card {
  background:
    linear-gradient(145deg, rgba(255,255,255,0.82), rgba(236,252,248,0.68));
  border: 1px solid rgba(255,255,255,0.62);
  box-shadow:
    0 30px 80px rgba(5, 26, 36, 0.4),
    0 0 0 1px rgba(42, 157, 143, 0.2),
    0 0 36px rgba(42, 157, 143, 0.18),
    inset 0 1px 0 rgba(255,255,255,0.9);
  backdrop-filter: blur(24px) saturate(1.25);
  -webkit-backdrop-filter: blur(24px) saturate(1.25);
}

.home-screen .hero-card::before {
  border-color: rgba(233, 196, 106, 0.3);
  box-shadow: inset 0 0 28px rgba(42, 157, 143, 0.12);
}

.home-screen .hero-card::after {
  content: "";
  position: fixed;
  right: clamp(12px, 3vw, 42px);
  bottom: clamp(12px, 3vw, 32px);
  width: clamp(96px, 14vw, 158px);
  aspect-ratio: 1 / 1;
  z-index: 12;
  background: url("images/character.png") center / contain no-repeat;
  filter: drop-shadow(0 18px 18px rgba(12, 38, 50, 0.35));
  animation: mascotIdle 2.8s ease-in-out infinite;
  pointer-events: none;
}

.home-screen .badge::after {
  content: "  |  เรียนรู้ผ่านภารกิจ";
  color: #b66a21;
  animation: dynamicSubtitle 9s steps(1, end) infinite;
}

.home-screen .hero-card p::after {
  content: "พร้อมออกสำรวจเมืองอัจฉริยะหรือยัง?";
  position: fixed;
  right: clamp(82px, 15vw, 185px);
  bottom: clamp(92px, 16vw, 148px);
  z-index: 13;
  max-width: min(320px, 58vw);
  padding: 12px 16px;
  border-radius: 18px 18px 4px 18px;
  background: rgba(255, 248, 232, 0.9);
  border: 2px solid rgba(233, 196, 106, 0.88);
  color: #174554;
  font-size: clamp(14px, 1.4vw, 17px);
  font-weight: 900;
  line-height: 1.35;
  box-shadow: 0 14px 28px rgba(12, 38, 50, 0.22);
  backdrop-filter: blur(12px);
  animation: speechPulse 3.8s ease-in-out infinite;
  pointer-events: none;
}

.home-screen .button-row .primary-btn,
.home-screen .button-row .secondary-btn {
  animation: ctaBreathe 4.5s ease-in-out infinite;
}

.home-screen .button-row .secondary-btn:nth-child(2) {
  animation-delay: 0.18s;
}

.home-screen .button-row .secondary-btn:nth-child(3) {
  animation-delay: 0.36s;
}

.home-screen .button-row .secondary-btn:nth-child(4) {
  animation-delay: 0.54s;
}

.home-screen .button-row .secondary-btn:nth-child(5) {
  animation-delay: 0.72s;
}

.home-screen .button-row .secondary-btn:nth-child(6) {
  animation-delay: 0.9s;
}

.home-screen .primary-btn:hover,
.home-screen .secondary-btn:hover {
  box-shadow:
    0 12px 0 rgba(16, 42, 56, 0.25),
    0 22px 38px rgba(16, 42, 56, 0.26),
    0 0 26px rgba(233, 196, 106, 0.36);
}

.home-screen .primary-btn:active,
.home-screen .secondary-btn:active {
  transform: translateY(1px) scale(0.98);
  box-shadow:
    0 4px 0 rgba(16, 42, 56, 0.25),
    0 10px 20px rgba(16, 42, 56, 0.18),
    0 0 18px rgba(42, 157, 143, 0.28);
}

.home-screen .mission-alert::after {
  content: "🚗";
  position: fixed;
  left: -80px;
  bottom: clamp(34px, 7vw, 88px);
  z-index: -1;
  font-size: 24px;
  filter: drop-shadow(0 8px 8px rgba(12, 38, 50, 0.28));
  animation: tinyCar 13s linear infinite;
  pointer-events: none;
}

.home-screen .mission-alert::before {
  content: "▵";
  position: fixed;
  top: clamp(86px, 13vw, 142px);
  left: -54px;
  z-index: -1;
  width: 34px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255,255,255,0.58);
  color: #2a9d8f;
  border: 1px solid rgba(233,196,106,0.65);
  box-shadow: 0 0 18px rgba(42,157,143,0.36);
  animation: droneFly 19s linear infinite;
  pointer-events: none;
}

@keyframes dynamicSubtitle {
  0%, 33% {
    content: "  |  เรียนรู้ผ่านภารกิจ";
  }

  34%, 66% {
    content: "  |  ฝึกคิดอย่างเป็นระบบ";
  }

  67%, 100% {
    content: "  |  แก้ปัญหาในเมืองอัจฉริยะ";
  }
}

@keyframes particleFloat {
  from {
    background-position: 0 0, 30px 20px, 0 0, 0 0;
  }

  to {
    background-position: 140px -140px, -60px 110px, 46px 46px, 46px 46px;
  }
}

@keyframes ambientSweep {
  0%, 100% {
    opacity: 0.55;
    transform: translateX(-1.5%);
  }

  50% {
    opacity: 0.95;
    transform: translateX(1.5%);
  }
}

@keyframes bgDepthShift {
  from {
    background-position: center 47%;
    filter: saturate(1.08) contrast(1.02) blur(0px);
  }

  to {
    background-position: center 51%;
    filter: saturate(1.18) contrast(1.04) blur(0.2px);
  }
}

@keyframes buildingLights {
  0%, 100% {
    opacity: 0.42;
  }

  45% {
    opacity: 0.78;
  }

  70% {
    opacity: 0.52;
  }
}

@keyframes mascotIdle {
  0%, 100% {
    transform: translateY(0) rotate(-1deg);
  }

  50% {
    transform: translateY(-9px) rotate(1.5deg);
  }
}

@keyframes speechPulse {
  0%, 100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(-4px) scale(1.02);
  }
}

@keyframes tinyCar {
  0% {
    transform: translateX(-90px);
  }

  100% {
    transform: translateX(calc(100vw + 180px));
  }
}

@keyframes droneFly {
  0% {
    transform: translateX(-80px) translateY(0) rotate(0deg);
  }

  50% {
    transform: translateX(55vw) translateY(-24px) rotate(5deg);
  }

  100% {
    transform: translateX(calc(100vw + 90px)) translateY(10px) rotate(-4deg);
  }
}

@keyframes ctaBreathe {
  0%, 100% {
    filter: brightness(1);
  }

  50% {
    filter: brightness(1.06);
  }
}

@media (max-width: 980px) {
  .home-screen .hero-card::after {
    width: clamp(82px, 18vw, 126px);
  }

  .home-screen .hero-card p::after {
    right: clamp(70px, 17vw, 145px);
    bottom: clamp(76px, 17vw, 122px);
    max-width: 240px;
  }
}

@media (max-width: 560px) {
  .home-screen .badge::after {
    display: block;
    margin-top: 4px;
  }

  .home-screen .hero-card::after {
    right: 8px;
    bottom: 8px;
    width: 76px;
  }

  .home-screen .hero-card p::after {
    right: 62px;
    bottom: 66px;
    max-width: 210px;
    padding: 9px 11px;
    font-size: 12px;
  }
}

/* JS-backed dynamic subtitle text */
.home-screen .badge::after {
  content: "  |  " attr(data-subtitle);
  animation: subtitleGlow 3s ease-in-out infinite;
}

@keyframes subtitleGlow {
  0%, 100% {
    opacity: 0.72;
  }

  50% {
    opacity: 1;
  }
}

/* ---------- HOME MASCOT POSITION FIX ---------- */
.home-screen .hero-card::after {
  position: fixed;
  right: clamp(18px, 3.2vw, 52px);
  bottom: clamp(54px, 6.5vw, 82px);
  width: clamp(170px, 15vw, 260px);
  height: clamp(210px, 22vw, 360px);
  aspect-ratio: auto;
  z-index: 45;
  background: url("images/character.png") bottom center / contain no-repeat;
  filter: drop-shadow(0 22px 20px rgba(12, 38, 50, 0.38));
  transform-origin: bottom center;
  animation: mascotBigIdle 3s ease-in-out infinite;
}

.home-screen .hero-card p::after {
  right: clamp(158px, 17vw, 290px);
  bottom: clamp(250px, 27vw, 390px);
  z-index: 46;
  max-width: min(330px, 34vw);
  border-radius: 18px 18px 4px 18px;
  transform-origin: bottom right;
}

.sound-btn {
  z-index: 80;
}

@keyframes mascotBigIdle {
  0%, 100% {
    transform: translateY(0) rotate(-1deg) scale(1);
  }

  50% {
    transform: translateY(-8px) rotate(1deg) scale(1.02);
  }
}

@media (min-width: 1200px) {
  .home-screen .hero-card {
    padding-right: clamp(42px, 9vw, 150px);
  }
}

@media (max-width: 980px) {
  .home-screen .hero-card::after {
    right: 12px;
    bottom: 58px;
    width: clamp(118px, 24vw, 170px);
    height: clamp(150px, 32vw, 230px);
  }

  .home-screen .hero-card p::after {
    right: clamp(110px, 27vw, 172px);
    bottom: clamp(176px, 39vw, 260px);
    max-width: min(260px, 48vw);
  }
}

@media (max-width: 560px) {
  .home-screen .hero-card {
    padding-bottom: 92px;
  }

  .home-screen .hero-card::after {
    right: 8px;
    bottom: 62px;
    width: 112px;
    height: 150px;
    z-index: 45;
  }

  .home-screen .hero-card p::after {
    right: 88px;
    bottom: 168px;
    max-width: 190px;
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* ---------- HOME MASCOT OUTSIDE MENU AREA ---------- */
.home-screen .hero-card::after {
  right: max(18px, calc((100vw - min(940px, 94vw)) / 2 - 130px));
  bottom: clamp(68px, 8vw, 108px);
  width: clamp(180px, 16vw, 285px);
  height: clamp(230px, 24vw, 390px);
  z-index: 44;
}

.home-screen .hero-card p::after {
  right: max(148px, calc((100vw - min(940px, 94vw)) / 2 + 18px));
  bottom: clamp(318px, 31vw, 445px);
  max-width: min(310px, 28vw);
  z-index: 46;
}

@media (min-width: 1500px) {
  .home-screen .hero-card::after {
    right: max(24px, calc((100vw - min(940px, 94vw)) / 2 - 165px));
  }
}

@media (max-width: 1180px) {
  .home-screen .hero-card::after {
    right: -12px;
    bottom: 72px;
    width: clamp(140px, 17vw, 190px);
    height: clamp(180px, 25vw, 260px);
  }

  .home-screen .hero-card p::after {
    right: 118px;
    bottom: clamp(232px, 28vw, 300px);
    max-width: min(260px, 34vw);
  }
}

@media (max-width: 980px) {
  .home-screen .hero-card::after {
    right: -22px;
    bottom: 64px;
    width: 132px;
    height: 178px;
  }

  .home-screen .hero-card p::after {
    right: 86px;
    bottom: 210px;
    max-width: 220px;
  }
}

@media (max-width: 720px) {
  .home-screen .hero-card::after {
    right: -28px;
    bottom: 58px;
    width: 105px;
    height: 144px;
  }

  .home-screen .hero-card p::after {
    right: 58px;
    bottom: 174px;
    max-width: 190px;
  }
}

@media (max-width: 560px) {
  .home-screen .hero-card::after {
    right: -34px;
    bottom: 58px;
    width: 92px;
    height: 126px;
  }

  .home-screen .hero-card p::after {
    right: 44px;
    bottom: 158px;
    max-width: 172px;
  }
}

/* ---------- HOME CENTERING + NON-BLOCKING MASCOT FIX ---------- */
.home-screen .hero-card {
  padding-left: clamp(22px, 4vw, 42px) !important;
  padding-right: clamp(22px, 4vw, 42px) !important;
  text-align: center !important;
}

.home-screen .badge,
.home-screen .game-logo,
.home-screen .hero-card > p,
.home-screen .button-row {
  position: relative;
  z-index: 2;
  margin-left: auto !important;
  margin-right: auto !important;
}

.home-screen .game-logo {
  display: block !important;
  left: auto !important;
  right: auto !important;
  transform: none;
}

.home-screen .button-row {
  justify-content: center !important;
  justify-items: center !important;
  align-items: center !important;
}

.home-screen .button-row .primary-btn,
.home-screen .button-row .secondary-btn {
  width: 100%;
  max-width: 330px;
}

/* Final home CTA layout: 3 / 2 */
.home-screen .button-row {
  display: grid !important;
  grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
  gap: 15px 16px !important;
  width: min(860px, 100%) !important;
  max-width: 860px !important;
  margin-top: clamp(18px, 2.8vw, 28px) !important;
}

.home-screen .button-row .primary-btn,
.home-screen .button-row .secondary-btn {
  max-width: none !important;
  min-height: 62px;
}

.home-screen .button-row .primary-btn {
  grid-column: 5 / span 4 !important;
  grid-row: 1 !important;
  min-height: 76px;
  font-size: clamp(24px, 2.5vw, 31px);
  transform: scale(1.04);
  box-shadow: 0 10px 0 rgba(16,42,56,0.3), 0 22px 36px rgba(42,157,143,0.28);
}

.home-screen .button-row .secondary-btn:nth-child(1) {
  grid-column: 1 / span 4 !important;
  grid-row: 1 !important;
}

.home-screen .button-row .secondary-btn:nth-child(3) {
  grid-column: 9 / span 4 !important;
  grid-row: 1 !important;
}

.home-screen .button-row .secondary-btn:nth-child(4) {
  grid-column: 2 / span 5 !important;
  grid-row: 2 !important;
}

.home-screen .button-row .secondary-btn:nth-child(5) {
  grid-column: 7 / span 5 !important;
  grid-row: 2 !important;
}

@media (max-width: 760px) {
  .home-screen .button-row {
    grid-template-columns: 1fr !important;
    width: min(420px, 100%) !important;
  }

  .home-screen .button-row .primary-btn,
  .home-screen .button-row .secondary-btn,
  .home-screen .button-row .secondary-btn:nth-child(1),
  .home-screen .button-row .secondary-btn:nth-child(2),
  .home-screen .button-row .secondary-btn:nth-child(3),
  .home-screen .button-row .secondary-btn:nth-child(4),
  .home-screen .button-row .secondary-btn:nth-child(5) {
    grid-column: 1 !important;
    grid-row: auto !important;
  }
}

.home-screen .hero-card::after {
  right: -86px !important;
  bottom: 70px !important;
  width: clamp(120px, 12vw, 190px) !important;
  height: clamp(158px, 18vw, 270px) !important;
  z-index: 1 !important;
  opacity: 0.98;
  pointer-events: none;
}

.home-screen .hero-card p::after {
  right: 42px !important;
  bottom: clamp(220px, 22vw, 320px) !important;
  max-width: min(260px, 28vw) !important;
  z-index: 3 !important;
  transform: translateX(0);
}

.sound-btn {
  z-index: 90 !important;
}

@media (min-width: 1200px) {
  .home-screen .hero-card {
    padding-right: clamp(22px, 4vw, 42px) !important;
  }
}

@media (max-width: 1180px) {
  .home-screen .hero-card::after {
    right: -74px !important;
    bottom: 66px !important;
    width: 128px !important;
    height: 174px !important;
  }

  .home-screen .hero-card p::after {
    right: 28px !important;
    bottom: 210px !important;
    max-width: 230px !important;
  }
}

@media (max-width: 980px) {
  .home-screen .hero-card::after {
    right: -70px !important;
    bottom: 62px !important;
    width: 112px !important;
    height: 154px !important;
  }

  .home-screen .hero-card p::after {
    right: 18px !important;
    bottom: 188px !important;
    max-width: 205px !important;
  }
}

@media (max-width: 720px) {
  .home-screen .hero-card::after,
  .home-screen .hero-card p::after {
    display: none !important;
  }

  .home-screen .hero-card {
    padding-bottom: 22px !important;
  }
}

/* ---------- HOME REMOVE MASCOT AND SPEECH BUBBLE ---------- */
.home-screen .hero-card::after,
.home-screen .hero-card p::after {
  content: none !important;
  display: none !important;
}

.home-screen .hero-card {
  padding-left: clamp(22px, 4vw, 42px) !important;
  padding-right: clamp(22px, 4vw, 42px) !important;
  padding-bottom: clamp(22px, 4vw, 42px) !important;
}

/* ---------- STORY SCREEN MISSION HUD REFRESH ---------- */
.story-screen {
  isolation: isolate;
  padding: clamp(14px, 2.4vw, 30px);
  background:
    radial-gradient(circle at 18% 18%, rgba(233, 196, 106, 0.26), transparent 28%),
    radial-gradient(circle at 84% 24%, rgba(244, 162, 97, 0.18), transparent 24%),
    linear-gradient(135deg, #0d2a37 0%, #185261 48%, #2a9d8f 100%);
}

.story-screen .problem-bg {
  background:
    linear-gradient(rgba(13, 42, 55, 0.3), rgba(13, 42, 55, 0.18)),
    radial-gradient(circle at 50% 30%, rgba(255,255,255,0.2), transparent 30%),
    url("images/background-home.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  overflow: hidden;
}

.story-screen .problem-bg::before,
.story-screen .problem-bg::after {
  content: "";
  position: absolute;
  pointer-events: none;
  z-index: 0;
}

.story-screen .problem-bg::before {
  left: 4%;
  top: 12%;
  width: 220px;
  height: 148px;
  border-radius: 22px;
  border: 2px solid rgba(233, 196, 106, 0.62);
  background:
    linear-gradient(90deg, rgba(42,157,143,0.78) 0 42%, transparent 42% 100%),
    linear-gradient(rgba(255,255,255,0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.16) 1px, transparent 1px),
    rgba(9, 35, 47, 0.28);
  background-size: 100% 100%, 26px 26px, 26px 26px, 100% 100%;
  box-shadow: 0 0 34px rgba(42, 157, 143, 0.28), inset 0 0 24px rgba(255,255,255,0.13);
  backdrop-filter: blur(10px);
  animation: hudFloat 5s ease-in-out infinite;
}

.story-screen .problem-bg::after {
  right: 4%;
  top: 12%;
  width: 250px;
  height: 118px;
  border-radius: 20px;
  border: 2px solid rgba(42, 157, 143, 0.5);
  background:
    linear-gradient(90deg, #2a9d8f 0 68%, rgba(255,255,255,0.2) 68% 100%) 18px 82px / 190px 12px no-repeat,
    radial-gradient(circle at 26px 26px, #e9c46a 0 8px, transparent 9px),
    radial-gradient(circle at 70px 26px, #f4a261 0 8px, transparent 9px),
    radial-gradient(circle at 114px 26px, #2a9d8f 0 8px, transparent 9px),
    rgba(255, 255, 255, 0.22);
  box-shadow: 0 20px 48px rgba(13, 42, 55, 0.2), inset 0 0 28px rgba(255,255,255,0.22);
  backdrop-filter: blur(10px);
  animation: hudFloat 5.8s ease-in-out infinite reverse;
}

.story-screen .story-card {
  width: min(1040px, 94vw);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  border-radius: 26px;
  border: 1px solid rgba(255,255,255,0.62);
  background: linear-gradient(145deg, rgba(255,255,255,0.84), rgba(234, 252, 248, 0.68));
  box-shadow:
    0 34px 80px rgba(7, 29, 40, 0.38),
    0 0 0 8px rgba(42, 157, 143, 0.1),
    inset 0 1px 0 rgba(255,255,255,0.92);
  backdrop-filter: blur(22px) saturate(1.2);
  -webkit-backdrop-filter: blur(22px) saturate(1.2);
}

.story-screen .story-card::before {
  content: "Mission 1 / 5    ⭐ คะแนน : 120    🏆 Rank : Explorer";
  display: block;
  width: min(760px, 100%);
  margin: 0 auto 16px;
  padding: 10px 16px;
  border-radius: 999px;
  color: #16444a;
  font-size: clamp(15px, 1.8vw, 20px);
  font-weight: 900;
  background: rgba(255, 248, 232, 0.72);
  border: 2px solid rgba(233, 196, 106, 0.74);
  box-shadow: 0 12px 28px rgba(13, 42, 55, 0.13), inset 0 1px 0 rgba(255,255,255,0.88);
}

.story-screen .story-card::after {
  content: "ประชาชนกำลังรอความช่วยเหลือจากคุณ";
  display: block;
  width: min(680px, 100%);
  margin: 14px auto 4px;
  padding: 13px 18px;
  border-radius: 18px;
  color: #123d43;
  font-size: clamp(17px, 2vw, 22px);
  font-weight: 900;
  background: rgba(255, 255, 255, 0.72);
  border: 2px solid rgba(42, 157, 143, 0.46);
  box-shadow: 0 14px 28px rgba(13, 42, 55, 0.13);
  animation: dialoguePulse 3s ease-in-out infinite;
}

.story-screen .character-large-img {
  width: clamp(150px, 16vw, 190px);
  height: clamp(150px, 16vw, 190px);
  filter: drop-shadow(0 20px 18px rgba(13, 42, 55, 0.28));
  transform-origin: bottom center;
  animation: storyMascotIdle 2.8s ease-in-out infinite;
}

.story-screen .mission-badge {
  background: rgba(220, 38, 38, 0.11);
  color: #dc2626;
  border-color: rgba(244, 162, 97, 0.8);
  box-shadow: 0 8px 24px rgba(220, 38, 38, 0.1);
}

.story-screen .mission-story-text {
  position: relative;
  color: #173d43;
  font-weight: 800;
}

.story-screen .mission-story-text::after {
  content: "STATUS: CITY NEEDS HELP";
  display: block;
  width: fit-content;
  margin: 12px auto 0;
  padding: 7px 12px;
  border-radius: 999px;
  color: #176e65;
  font-size: 14px;
  letter-spacing: 0;
  background: rgba(42, 157, 143, 0.13);
  border: 1px solid rgba(42, 157, 143, 0.35);
}

.story-screen .mission-brief-grid {
  position: relative;
  z-index: 1;
}

.story-screen .mission-brief-grid::before {
  content: "MINI MAP";
  position: absolute;
  left: 50%;
  top: -10px;
  transform: translate(-50%, -100%);
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(13, 42, 55, 0.7);
  color: #e9c46a;
  border: 1px solid rgba(233,196,106,0.55);
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 0 20px rgba(42,157,143,0.28);
}

.story-screen .brief-box {
  border: 1px solid rgba(255,255,255,0.7);
  background: linear-gradient(145deg, rgba(255,255,255,0.78), rgba(235,252,248,0.62));
  box-shadow:
    0 18px 34px rgba(13, 42, 55, 0.15),
    0 0 0 1px rgba(42,157,143,0.16),
    inset 0 1px 0 rgba(255,255,255,0.9);
  backdrop-filter: blur(14px);
  animation: briefFloat 4.5s ease-in-out infinite;
}

.story-screen .brief-box:nth-child(2) {
  animation-delay: 0.55s;
}

.story-screen .brief-box h3 {
  color: #176e65;
}

.story-screen .mission-tip {
  background: rgba(255, 248, 222, 0.82);
  border-color: rgba(233, 196, 106, 0.92);
  color: #8a4d16;
  box-shadow: 0 12px 28px rgba(13, 42, 55, 0.12);
}

.story-screen .primary-btn {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, #34c6b5, #2a9d8f 58%, #1d736b);
  border: 2px solid rgba(255,255,255,0.62);
  box-shadow:
    0 8px 0 rgba(16, 42, 56, 0.28),
    0 18px 34px rgba(42, 157, 143, 0.25),
    0 0 26px rgba(42, 157, 143, 0.3);
  animation: missionButtonPulse 2.4s ease-in-out infinite;
}

.story-screen .primary-btn::after {
  content: "";
  position: absolute;
  left: -30%;
  top: 50%;
  width: 22%;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #e9c46a, transparent);
  opacity: 0;
  transform: translateY(-50%);
}

.story-screen .primary-btn:hover {
  transform: translateY(-5px) scale(1.035);
  box-shadow:
    0 12px 0 rgba(16, 42, 56, 0.24),
    0 24px 42px rgba(42, 157, 143, 0.32),
    0 0 34px rgba(233, 196, 106, 0.48);
}

.story-screen .primary-btn:hover::after {
  opacity: 1;
  animation: rocketTrail 0.75s ease-out infinite;
}

.story-screen .secondary-btn {
  background: linear-gradient(180deg, #fff6d8, #e9c46a);
}

.story-screen .problem-icon {
  filter: drop-shadow(0 12px 12px rgba(13, 42, 55, 0.2));
}

.story-screen .p1 {
  animation: trafficBlink 1.4s ease-in-out infinite;
}

.story-screen .p2 {
  animation: trashWiggle 2.2s ease-in-out infinite;
}

.story-screen .p3 {
  animation: treeSway 2.6s ease-in-out infinite;
}

.story-screen .p4 {
  animation: bulbGlow 1.8s ease-in-out infinite;
}

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

@keyframes dialoguePulse {
  0%, 100% { transform: translateY(0); box-shadow: 0 14px 28px rgba(13, 42, 55, 0.13); }
  50% { transform: translateY(-4px); box-shadow: 0 18px 36px rgba(42, 157, 143, 0.2); }
}

@keyframes storyMascotIdle {
  0%, 100% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-8px) scale(1.035); }
  48%, 52% { filter: drop-shadow(0 20px 18px rgba(13, 42, 55, 0.28)) brightness(0.96); }
}

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

@keyframes missionButtonPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.08); }
}

@keyframes rocketTrail {
  from { left: -30%; }
  to { left: 112%; }
}

@keyframes trafficBlink {
  0%, 100% { opacity: 1; transform: translateY(0); }
  50% { opacity: 0.58; transform: translateY(-8px); }
}

@keyframes trashWiggle {
  0%, 100% { transform: rotate(0deg) translateY(0); }
  25% { transform: rotate(-5deg) translateY(-6px); }
  75% { transform: rotate(5deg) translateY(-3px); }
}

@keyframes treeSway {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(3deg) translateY(-8px); }
}

@keyframes bulbGlow {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(233,196,106,0.45)); transform: translateY(0) scale(1); }
  50% { filter: drop-shadow(0 0 24px rgba(233,196,106,0.95)); transform: translateY(-8px) scale(1.08); }
}

@media (max-width: 980px) {
  .story-screen .problem-bg::before,
  .story-screen .problem-bg::after {
    opacity: 0.55;
    transform: scale(0.82);
  }

  .story-screen .story-card::before {
    white-space: normal;
    border-radius: 18px;
  }

  .story-screen .character-large-img {
    width: 140px;
    height: 140px;
  }
}

@media (max-width: 620px) {
  .story-screen .problem-bg::before,
  .story-screen .problem-bg::after,
  .story-screen .mission-brief-grid::before {
    display: none;
  }

  .story-screen .story-card::before {
    content: "Mission 1 / 5  ⭐ 120  🏆 Explorer";
    font-size: 14px;
  }

  .story-screen .story-card::after {
    font-size: 16px;
  }

  .story-screen .character-large-img {
    width: 124px;
    height: 124px;
  }
}

/* ---------- STORY FINAL SPACING + BADGE EFFECT ---------- */
.story-screen .story-card::before {
  content: none !important;
  display: none !important;
}

.story-screen .character-large {
  margin-bottom: 0 !important;
  line-height: 0;
}

.story-screen .character-large-img {
  margin-bottom: -6px;
}

.story-screen .mission-badge {
  margin-top: 0 !important;
  margin-bottom: 10px !important;
  animation: missionBadgeBlink 1.25s ease-in-out infinite;
}

@keyframes missionBadgeBlink {
  0%, 100% {
    opacity: 1;
    box-shadow:
      0 8px 24px rgba(220, 38, 38, 0.1),
      0 0 0 rgba(244, 162, 97, 0);
    transform: scale(1);
  }

  50% {
    opacity: 0.82;
    box-shadow:
      0 10px 28px rgba(220, 38, 38, 0.18),
      0 0 24px rgba(244, 162, 97, 0.58);
    transform: scale(1.025);
  }
}

/* ---------- PREMIUM LEADERBOARD MODAL ---------- */
.modal-card:has(.leaderboard-list) {
  width: min(760px, 94vw);
  max-height: min(86vh, 760px);
  overflow: hidden;
  padding: clamp(26px, 4vw, 42px);
  border-radius: 30px;
  border: 1px solid rgba(255,255,255,0.72);
  background:
    radial-gradient(circle at 18% 8%, rgba(233,196,106,0.34), transparent 28%),
    radial-gradient(circle at 82% 16%, rgba(244,162,97,0.22), transparent 26%),
    linear-gradient(145deg, rgba(255,255,255,0.94), rgba(235,252,248,0.9));
  box-shadow:
    0 34px 90px rgba(7, 29, 40, 0.42),
    0 0 0 8px rgba(42,157,143,0.12),
    inset 0 1px 0 rgba(255,255,255,0.95);
  backdrop-filter: blur(22px) saturate(1.18);
  -webkit-backdrop-filter: blur(22px) saturate(1.18);
}

.modal-card:has(.leaderboard-list)::before {
  content: "";
  position: absolute;
  inset: 16px;
  border-radius: 22px;
  border: 1px solid rgba(42,157,143,0.22);
  box-shadow: inset 0 0 28px rgba(42,157,143,0.1);
  pointer-events: none;
}

.modal-card:has(.leaderboard-list) .close-btn {
  top: 16px;
  right: 16px;
  background: linear-gradient(180deg, #ff5c5c, #ef4444);
  box-shadow: 0 7px 0 #b91c1c, 0 12px 24px rgba(239,68,68,0.22);
}

.modal-card:has(.leaderboard-list) h2 {
  margin: 4px 48px 8px;
  color: #176e65;
  font-size: clamp(42px, 6vw, 68px);
  line-height: 1;
  text-shadow: 0 4px 0 rgba(233,196,106,0.18);
}

.modal-card:has(.leaderboard-list) h2::after {
  content: " Top Explorers";
  display: block;
  width: fit-content;
  margin: 12px auto 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(42,157,143,0.13);
  border: 2px solid rgba(42,157,143,0.28);
  color: #b66a21;
  font-size: clamp(14px, 1.8vw, 18px);
  font-weight: 900;
}

.modal-card:has(.leaderboard-list) > #modalContent > p {
  margin: 18px auto 22px;
  width: fit-content;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 248, 232, 0.82);
  border: 2px solid rgba(233,196,106,0.65);
  color: #173d43;
  font-size: clamp(18px, 2.3vw, 25px);
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(13,42,55,0.1);
}

.leaderboard-list {
  position: relative;
  max-height: min(52vh, 440px);
  overflow-y: auto;
  padding: 8px 4px 4px;
  gap: 13px;
  scrollbar-width: thin;
  scrollbar-color: #2a9d8f rgba(42,157,143,0.12);
}

.leaderboard-list::before {
  content: "⚡ ภารกิจเร็วที่สุด";
  display: block;
  margin: 0 auto 10px;
  width: fit-content;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(13, 42, 55, 0.82);
  color: #e9c46a;
  font-size: 15px;
  font-weight: 900;
  box-shadow: 0 0 22px rgba(42,157,143,0.24);
}

.leaderboard-row {
  position: relative;
  grid-template-columns: 54px minmax(0, 1fr) auto !important;
  min-height: 72px;
  padding: 12px 16px;
  border-radius: 22px;
  border: 2px solid rgba(191, 219, 254, 0.9);
  background:
    linear-gradient(90deg, rgba(255,255,255,0.84), rgba(239,246,255,0.9));
  box-shadow:
    0 8px 0 rgba(13,42,55,0.08),
    0 16px 30px rgba(13,42,55,0.11),
    inset 0 1px 0 rgba(255,255,255,0.92);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.leaderboard-row:hover {
  transform: translateY(-4px) scale(1.01);
  border-color: rgba(42,157,143,0.6);
  box-shadow:
    0 10px 0 rgba(13,42,55,0.08),
    0 22px 38px rgba(13,42,55,0.16),
    0 0 26px rgba(42,157,143,0.18);
}

.leaderboard-row:nth-child(2) {
  border-color: rgba(233,196,106,0.95);
  background:
    linear-gradient(90deg, rgba(255,248,223,0.98), rgba(255,255,255,0.9));
  box-shadow:
    0 8px 0 rgba(151,106,16,0.18),
    0 20px 38px rgba(233,196,106,0.24),
    0 0 30px rgba(233,196,106,0.28);
}

.leaderboard-row:nth-child(3) {
  border-color: rgba(42,157,143,0.5);
  background: linear-gradient(90deg, rgba(232,252,248,0.98), rgba(255,255,255,0.9));
}

.leaderboard-row:nth-child(4) {
  border-color: rgba(244,162,97,0.62);
  background: linear-gradient(90deg, rgba(255,239,224,0.96), rgba(255,255,255,0.9));
}

.leaderboard-row .rank,
.leaderboard-row .leader-name,
.leaderboard-row span:last-child {
  position: relative;
  z-index: 1;
}

.leaderboard-row .rank {
  width: 42px;
  height: 42px;
  background: linear-gradient(180deg, #ffe27a, #e9c46a 58%, #d5a947);
  border: 2px solid rgba(255,255,255,0.72);
  color: #4a3510;
  font-size: 20px;
  font-weight: 1000;
  box-shadow: 0 6px 0 rgba(151,106,16,0.2);
}

.leaderboard-row:nth-child(2) .rank {
  width: 48px;
  height: 48px;
  background: linear-gradient(180deg, #fff4b8, #facc15 56%, #d9a400);
  box-shadow: 0 7px 0 rgba(151,106,16,0.26), 0 0 20px rgba(250,204,21,0.48);
}

.leaderboard-row:nth-child(2)::before,
.leaderboard-row:nth-child(3)::before,
.leaderboard-row:nth-child(4)::before {
  position: absolute;
  right: 18px;
  top: -14px;
  font-size: 28px;
  filter: drop-shadow(0 8px 8px rgba(13,42,55,0.2));
}

.leaderboard-row:nth-child(2)::before {
  content: "🥇";
}

.leaderboard-row:nth-child(3)::before {
  content: "🥈";
}

.leaderboard-row:nth-child(4)::before {
  content: "🥉";
}

.leader-name {
  min-width: 0;
  color: #102a38;
  font-size: clamp(17px, 2vw, 22px);
  font-weight: 1000;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-row span:last-child {
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.78);
  border: 1px solid rgba(42,157,143,0.22);
  color: #173d43;
  font-size: clamp(15px, 1.8vw, 19px);
  font-weight: 1000;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.86);
}

@media (max-width: 620px) {
  .modal-card:has(.leaderboard-list) {
    padding: 22px 14px;
    border-radius: 24px;
  }

  .modal-card:has(.leaderboard-list) h2 {
    margin-left: 34px;
    margin-right: 34px;
    font-size: 38px;
  }

  .modal-card:has(.leaderboard-list) > #modalContent > p {
    font-size: 17px;
    white-space: normal;
  }

  .leaderboard-row {
    grid-template-columns: 46px minmax(0, 1fr) !important;
    gap: 8px;
    min-height: 78px;
  }

  .leaderboard-row span:last-child {
    grid-column: 2;
    width: fit-content;
    padding: 6px 10px;
    font-size: 14px;
  }

  .leaderboard-row:nth-child(2)::before,
  .leaderboard-row:nth-child(3)::before,
  .leaderboard-row:nth-child(4)::before {
    right: 12px;
    top: -10px;
    font-size: 22px;
  }
}

/* ---------- LEADERBOARD READABILITY + CORRECT MEDALS ---------- */
.modal-card:has(.leaderboard-list) {
  width: min(700px, 94vw);
  padding: clamp(24px, 3.2vw, 36px);
  background: linear-gradient(145deg, rgba(255,255,255,0.96), rgba(241,252,249,0.94));
}

.modal-card:has(.leaderboard-list) h2 {
  margin-bottom: 12px;
  color: #176e65;
  font-size: clamp(38px, 5vw, 58px);
}

.modal-card:has(.leaderboard-list) h2::after,
.leaderboard-list::before {
  display: none !important;
}

.modal-card:has(.leaderboard-list) > #modalContent > p {
  margin: 12px auto 20px;
  padding: 8px 14px;
  font-size: clamp(17px, 2vw, 22px);
  background: rgba(233, 196, 106, 0.18);
  border-color: rgba(233, 196, 106, 0.42);
}

.leaderboard-list {
  gap: 10px;
  padding: 4px 2px;
}

.leaderboard-row {
  grid-template-columns: 52px minmax(0, 1fr) auto !important;
  min-height: 64px;
  padding: 10px 14px;
  border-radius: 18px;
  background: #f3f8ff;
  border: 2px solid #bfdbfe;
  box-shadow: 0 5px 0 rgba(13,42,55,0.08);
}

.leaderboard-row:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 rgba(13,42,55,0.08), 0 14px 24px rgba(13,42,55,0.12);
}

.leaderboard-row:nth-child(1),
.leaderboard-row:nth-child(2),
.leaderboard-row:nth-child(3),
.leaderboard-row:nth-child(4) {
  background: #f3f8ff;
  border-color: #bfdbfe;
  box-shadow: 0 5px 0 rgba(13,42,55,0.08);
}

.leaderboard-row:nth-child(1) {
  background: linear-gradient(90deg, #fff7d6, #ffffff);
  border-color: #e9c46a;
}

.leaderboard-row:nth-child(2) {
  background: linear-gradient(90deg, #eef4fb, #ffffff);
  border-color: #cbd5e1;
}

.leaderboard-row:nth-child(3) {
  background: linear-gradient(90deg, #fff0df, #ffffff);
  border-color: #f4a261;
}

.leaderboard-row:nth-child(1)::before,
.leaderboard-row:nth-child(2)::before,
.leaderboard-row:nth-child(3)::before {
  position: static;
  grid-column: 1;
  grid-row: 1;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 24px;
  filter: none;
  background: rgba(255,255,255,0.75);
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 5px 0 rgba(13,42,55,0.08);
}

.leaderboard-row:nth-child(1)::before {
  content: "🥇";
}

.leaderboard-row:nth-child(2)::before {
  content: "🥈";
}

.leaderboard-row:nth-child(3)::before {
  content: "🥉";
}

.leaderboard-row:nth-child(1) .rank,
.leaderboard-row:nth-child(2) .rank,
.leaderboard-row:nth-child(3) .rank {
  display: none;
}

.leaderboard-row:nth-child(n+4) .rank {
  width: 40px;
  height: 40px;
  font-size: 18px;
  background: #e9c46a;
  box-shadow: none;
}

.leader-name {
  font-size: clamp(17px, 1.8vw, 21px);
  color: #102a38;
}

.leaderboard-row span:last-child {
  min-width: 116px;
  text-align: center;
  padding: 8px 12px;
  background: white;
  color: #173d43;
  border-color: rgba(42,157,143,0.2);
  font-size: clamp(14px, 1.6vw, 18px);
}

@media (max-width: 620px) {
  .leaderboard-row {
    grid-template-columns: 46px minmax(0, 1fr) !important;
    min-height: 72px;
  }

  .leaderboard-row:nth-child(1)::before,
  .leaderboard-row:nth-child(2)::before,
  .leaderboard-row:nth-child(3)::before {
    width: 38px;
    height: 38px;
    font-size: 21px;
  }

  .leaderboard-row span:last-child {
    grid-column: 2;
    min-width: 0;
    width: fit-content;
    text-align: left;
  }
}

/* ---------- LEADERBOARD REMOVE EXTRA MEDALS AFTER TOP 3 ---------- */
.leaderboard-row:nth-child(n+4)::before {
  content: none !important;
  display: none !important;
}

/* ---------- GAME SCREEN PREMIUM PLAYFIELD REFRESH ---------- */
.game-screen {
  position: relative;
  isolation: isolate;
  background:
    radial-gradient(circle at 12% 14%, rgba(233,196,106,0.24), transparent 28%),
    radial-gradient(circle at 86% 18%, rgba(244,162,97,0.16), transparent 24%),
    linear-gradient(135deg, #bff5ff, #d9f99d);
}

.game-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle, rgba(255,255,255,0.42) 0 1px, transparent 2px),
    linear-gradient(rgba(42,157,143,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42,157,143,0.08) 1px, transparent 1px);
  background-size: 92px 92px, 44px 44px, 44px 44px;
  animation: gameParticles 22s linear infinite;
  opacity: 0.72;
}

.game-header,
.level-progress-wrap,
.game-layout {
  position: relative;
  z-index: 1;
}

.game-header {
  border: 1px solid rgba(255,255,255,0.74);
  background: linear-gradient(145deg, rgba(255,255,255,0.88), rgba(235,252,248,0.72));
  box-shadow:
    0 18px 44px rgba(13,42,55,0.18),
    0 0 0 6px rgba(42,157,143,0.08),
    inset 0 1px 0 rgba(255,255,255,0.96);
  backdrop-filter: blur(18px) saturate(1.15);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
}

.game-header h2 {
  color: #176e65;
  text-shadow: 0 3px 0 rgba(233,196,106,0.12);
}

.score-panel span,
#levelBadge {
  border-color: rgba(42,157,143,0.26);
  background: rgba(255,255,255,0.72);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.92), 0 8px 18px rgba(13,42,55,0.08);
}

.level-progress-wrap {
  border: 1px solid rgba(255,255,255,0.7);
  background: linear-gradient(145deg, rgba(255,255,255,0.82), rgba(235,252,248,0.68));
  box-shadow: 0 12px 30px rgba(13,42,55,0.14), inset 0 1px 0 rgba(255,255,255,0.9);
  backdrop-filter: blur(14px);
}

.level-progress-fill {
  background: linear-gradient(90deg, #2a9d8f, #e9c46a, #f4a261);
  box-shadow: 0 0 18px rgba(42,157,143,0.46);
}

.map-panel,
.code-panel {
  border: 1px solid rgba(255,255,255,0.68);
  background: linear-gradient(145deg, rgba(255,255,255,0.84), rgba(235,252,248,0.68));
  box-shadow:
    0 24px 54px rgba(13,42,55,0.18),
    0 0 0 1px rgba(42,157,143,0.12),
    inset 0 1px 0 rgba(255,255,255,0.92);
  backdrop-filter: blur(18px) saturate(1.12);
  -webkit-backdrop-filter: blur(18px) saturate(1.12);
}

.code-panel {
  position: relative;
  overflow: hidden;
}

.code-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(135deg, transparent 0 47%, rgba(42,157,143,0.12) 48% 49%, transparent 50% 100%),
    linear-gradient(rgba(42,157,143,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42,157,143,0.08) 1px, transparent 1px),
    radial-gradient(circle at 86% 12%, rgba(233,196,106,0.22), transparent 18%);
  background-size: 120px 120px, 26px 26px, 26px 26px, 100% 100%;
  opacity: 0.8;
}

.code-panel > * {
  position: relative;
  z-index: 1;
}

.problem-box,
.workspace-wrap,
.block-bank {
  border: 1px solid rgba(255,255,255,0.72);
  background: rgba(255,255,255,0.72);
  box-shadow: 0 12px 24px rgba(13,42,55,0.1), inset 0 1px 0 rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
}

.grid {
  position: relative;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.36);
  background:
    linear-gradient(145deg, #0f3d4c, #164e63);
  box-shadow:
    0 24px 42px rgba(13,42,55,0.28),
    0 10px 0 rgba(8,47,73,0.5),
    inset 0 1px 0 rgba(255,255,255,0.2);
  transform: perspective(1100px) rotateX(1.5deg);
  transform-origin: center bottom;
}

.grid::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 16px;
  pointer-events: none;
  box-shadow: inset 0 0 32px rgba(255,255,255,0.08), inset 0 0 0 1px rgba(255,255,255,0.12);
}

.cell {
  position: relative;
  transition: transform 0.18s ease, filter 0.18s ease, box-shadow 0.18s ease;
  transform-style: preserve-3d;
}

.cell:hover {
  transform: translateY(-4px) scale(1.025);
  filter: brightness(1.08);
  z-index: 2;
  box-shadow:
    inset 0 -7px rgba(0,0,0,0.13),
    inset 0 4px rgba(255,255,255,0.25),
    0 8px 0 rgba(0,0,0,0.13),
    0 14px 22px rgba(13,42,55,0.2);
}

.grass-cell::after,
.road-cell::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.34), transparent 30%);
  opacity: 0.45;
}

.water-cell {
  overflow: hidden;
}

.water-cell::before {
  content: "";
  position: absolute;
  inset: -35%;
  background: repeating-radial-gradient(circle, rgba(255,255,255,0.34) 0 2px, transparent 3px 16px);
  animation: waterRipple 2.8s linear infinite;
  opacity: 0.55;
}

.target-cell {
  box-shadow:
    inset 0 -7px rgba(0,0,0,0.13),
    inset 0 4px rgba(255,255,255,0.32),
    0 0 26px rgba(233,196,106,0.68);
  animation: targetGlowPremium 1.45s ease-in-out infinite alternate;
}

.wall-cell {
  box-shadow:
    inset 0 -8px rgba(0,0,0,0.18),
    inset 0 4px rgba(255,255,255,0.28),
    0 7px 0 rgba(71,85,105,0.38);
}

.cell.player {
  z-index: 3;
}

.player-avatar {
  filter: drop-shadow(0 10px 8px rgba(13,42,55,0.28));
  transform-origin: bottom center !important;
  animation: gamePlayerIdle 1.5s ease-in-out infinite !important;
}

.cell.player::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 7%;
  height: 12%;
  border-radius: 50%;
  background: rgba(13,42,55,0.18);
  filter: blur(5px);
  z-index: -1;
  animation: playerShadowPulse 1.5s ease-in-out infinite;
}

.avatar {
  box-shadow: 0 0 0 4px rgba(42,157,143,0.12), 0 10px 18px rgba(13,42,55,0.14);
}

.speech-bubble {
  border-color: rgba(42,157,143,0.42);
  box-shadow: 0 8px 0 rgba(13,42,55,0.07), 0 14px 22px rgba(13,42,55,0.1);
}

.cmd-block,
.workspace-block {
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.cmd-block:hover,
.workspace-block:hover {
  transform: translateY(-4px) scale(1.035);
  filter: brightness(1.05);
  box-shadow: 0 8px 0 rgba(0,0,0,0.18), 0 14px 24px rgba(13,42,55,0.18);
}

.run-btn {
  background: linear-gradient(180deg, #34c6b5, #2a9d8f 58%, #1d736b);
  box-shadow: 0 7px 0 rgba(16,42,56,0.28), 0 0 22px rgba(42,157,143,0.24);
}

.hint-btn {
  background: linear-gradient(180deg, #fff6d8, #e9c46a);
}

.clear-btn {
  background: linear-gradient(180deg, #ffb178, #f4a261 58%, #de7f40);
}

.retry-btn {
  background: linear-gradient(180deg, #4fa8ff, #2563eb);
}

@keyframes gameParticles {
  from { background-position: 0 0, 0 0, 0 0; }
  to { background-position: 92px -92px, 44px 44px, 44px 44px; }
}

@keyframes waterRipple {
  from { transform: scale(0.9) rotate(0deg); }
  to { transform: scale(1.15) rotate(18deg); }
}

@keyframes targetGlowPremium {
  from {
    filter: brightness(1);
    box-shadow: inset 0 -7px rgba(0,0,0,0.13), 0 0 18px rgba(233,196,106,0.5);
  }
  to {
    filter: brightness(1.12);
    box-shadow: inset 0 -7px rgba(0,0,0,0.13), 0 0 34px rgba(233,196,106,0.92);
  }
}

@keyframes gamePlayerIdle {
  0%, 100% { transform: translateY(-3px) rotate(-1deg) scale(1) !important; }
  50% { transform: translateY(-8px) rotate(1deg) scale(1.035) !important; }
}

@keyframes playerShadowPulse {
  0%, 100% { transform: scaleX(1); opacity: 0.2; }
  50% { transform: scaleX(0.82); opacity: 0.13; }
}

@media (max-width: 980px) {
  .grid {
    transform: none;
  }

  .game-screen::before {
    opacity: 0.42;
  }

  .cell:hover {
    transform: none;
  }
}

/* ---------- GAME PLAYER IDLE COMPATIBILITY FIX ---------- */
.game-screen .player-avatar {
  position: relative !important;
  top: 0;
  animation: gamePlayerIdleTop 1.5s ease-in-out infinite !important;
}

@keyframes gamePlayerIdleTop {
  0%, 100% {
    top: 0;
    filter: drop-shadow(0 10px 8px rgba(13,42,55,0.28)) brightness(1);
  }

  50% {
    top: -6px;
    filter: drop-shadow(0 14px 10px rgba(13,42,55,0.24)) brightness(1.05);
  }
}

/* ---------- SUMMARY SCREEN CELEBRATION REFRESH ---------- */
.summary-screen {
  isolation: isolate;
  position: relative;
  background:
    radial-gradient(circle at 18% 16%, rgba(233,196,106,0.34), transparent 28%),
    radial-gradient(circle at 82% 20%, rgba(244,162,97,0.22), transparent 24%),
    linear-gradient(135deg, #fde68a, #bbf7d0);
}

.summary-screen::before,
.summary-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.summary-screen::before {
  background:
    radial-gradient(circle, rgba(255,255,255,0.92) 0 2px, transparent 3px),
    radial-gradient(circle, rgba(233,196,106,0.72) 0 3px, transparent 4px),
    radial-gradient(circle, rgba(244,162,97,0.62) 0 2px, transparent 3px),
    linear-gradient(rgba(42,157,143,0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42,157,143,0.07) 1px, transparent 1px);
  background-size: 120px 120px, 170px 170px, 92px 92px, 44px 44px, 44px 44px;
  background-position: 0 0, 40px 30px, 70px 10px, 0 0, 0 0;
  animation: summaryConfetti 18s linear infinite;
  opacity: 0.66;
}

.summary-screen::after {
  background:
    radial-gradient(circle at 50% 8%, rgba(255,255,255,0.36), transparent 28%),
    linear-gradient(115deg, transparent 0 38%, rgba(255,255,255,0.18) 44%, transparent 50% 100%);
  animation: summaryLightSweep 8s ease-in-out infinite;
}

.summary-card {
  position: relative;
  z-index: 1;
  border-radius: 28px;
  border: 1px solid rgba(255,255,255,0.72);
  background: linear-gradient(145deg, rgba(255,255,255,0.9), rgba(246,253,242,0.78));
  box-shadow:
    0 34px 88px rgba(13,42,55,0.24),
    0 0 0 8px rgba(42,157,143,0.09),
    inset 0 1px 0 rgba(255,255,255,0.96);
  backdrop-filter: blur(18px) saturate(1.16);
  -webkit-backdrop-filter: blur(18px) saturate(1.16);
}

.summary-card::before {
  content: "MISSION COMPLETE";
  position: sticky;
  top: 0;
  z-index: 4;
  display: inline-block;
  margin: 0 auto 12px;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(42,157,143,0.14);
  border: 2px solid rgba(42,157,143,0.3);
  color: #176e65;
  font-size: 15px;
  font-weight: 1000;
  box-shadow: 0 10px 22px rgba(13,42,55,0.08);
}

.summary-congrats-img {
  box-shadow: 0 18px 36px rgba(13,42,55,0.16), 0 0 28px rgba(233,196,106,0.28);
  animation: summaryImageFloat 4.8s ease-in-out infinite;
}

.summary-card .trophy {
  animation: trophyPop 2.8s ease-in-out infinite;
  filter: drop-shadow(0 16px 14px rgba(151,106,16,0.24));
}

.summary-card h2 {
  color: #176e65;
  text-shadow: 0 4px 0 rgba(233,196,106,0.16);
}

.big-stars {
  color: #facc15;
  text-shadow: 0 0 20px rgba(250,204,21,0.46), 0 7px 0 rgba(151,106,16,0.12);
  animation: starTwinkle 1.8s ease-in-out infinite;
}

.result-box,
.skill-box {
  border: 1px solid rgba(255,255,255,0.72);
  background: linear-gradient(145deg, rgba(255,255,255,0.76), rgba(239,246,255,0.64));
  box-shadow:
    0 22px 42px rgba(13,42,55,0.14),
    0 0 0 1px rgba(42,157,143,0.12),
    inset 0 1px 0 rgba(255,255,255,0.92);
  backdrop-filter: blur(14px);
}

.result-box {
  animation: summaryPanelFloat 5s ease-in-out infinite;
}

.skill-box {
  animation: summaryPanelFloat 5.4s ease-in-out infinite reverse;
}

.result-item {
  border-color: rgba(191,219,254,0.85);
  background: rgba(255,255,255,0.82);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.result-item:hover {
  transform: translateY(-5px) scale(1.02);
  border-color: rgba(42,157,143,0.46);
  box-shadow: 0 12px 0 rgba(13,42,55,0.08), 0 20px 30px rgba(13,42,55,0.13), 0 0 22px rgba(42,157,143,0.16);
}

.result-number {
  color: #2563eb;
  text-shadow: 0 5px 0 rgba(37,99,235,0.08);
}

.skill-box h3,
.result-box h3 {
  color: #176e65;
}

.summary-screen .button-row {
  gap: 16px;
  align-items: center;
}

.summary-screen .primary-btn,
.summary-screen .secondary-btn {
  position: relative;
  overflow: hidden;
  min-width: 170px;
  min-height: 62px;
  border-radius: 18px;
  border: 2px solid rgba(255,255,255,0.62);
  box-shadow: 0 8px 0 rgba(13,42,55,0.22), 0 16px 28px rgba(13,42,55,0.14);
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  animation: summaryButtonBreathe 4s ease-in-out infinite;
}

.summary-screen .primary-btn {
  background: linear-gradient(180deg, #34c6b5, #2a9d8f 58%, #1d736b);
}

.summary-screen .secondary-btn {
  background: linear-gradient(180deg, #fff6d8, #e9c46a 62%, #d9a93b);
  color: #3b2500;
}

.summary-screen .secondary-btn:last-child {
  background: linear-gradient(180deg, #ffe7d1, #f4a261 62%, #de7f40);
}

.summary-screen .primary-btn::after,
.summary-screen .secondary-btn::after {
  content: "";
  position: absolute;
  top: -80%;
  left: -55%;
  width: 48%;
  height: 230%;
  transform: rotate(24deg);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.52), transparent);
  animation: summaryButtonShine 4.5s ease-in-out infinite;
  pointer-events: none;
}

.summary-screen .primary-btn:hover,
.summary-screen .secondary-btn:hover {
  transform: translateY(-6px) scale(1.035);
  filter: brightness(1.04);
  box-shadow: 0 12px 0 rgba(13,42,55,0.22), 0 24px 38px rgba(13,42,55,0.18), 0 0 28px rgba(233,196,106,0.34);
}

.summary-screen .primary-btn:active,
.summary-screen .secondary-btn:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 4px 0 rgba(13,42,55,0.2), 0 10px 18px rgba(13,42,55,0.12);
}

@keyframes summaryConfetti {
  from { background-position: 0 0, 40px 30px, 70px 10px, 0 0, 0 0; }
  to { background-position: 120px 180px, -130px 250px, 200px 170px, 44px 44px, 44px 44px; }
}

@keyframes summaryLightSweep {
  0%, 100% { opacity: 0.58; transform: translateX(-1.5%); }
  50% { opacity: 0.95; transform: translateX(1.5%); }
}

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

@keyframes trophyPop {
  0%, 100% { transform: translateY(0) rotate(-2deg) scale(1); }
  50% { transform: translateY(-8px) rotate(2deg) scale(1.08); }
}

@keyframes starTwinkle {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.04); filter: brightness(1.12); }
}

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

@keyframes summaryButtonBreathe {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.06); }
}

@keyframes summaryButtonShine {
  0%, 55% { left: -55%; }
  75%, 100% { left: 118%; }
}

@media (max-width: 720px) {
  .summary-screen .primary-btn,
  .summary-screen .secondary-btn {
    width: 100%;
    min-width: 0;
  }

  .summary-screen::before {
    opacity: 0.36;
  }
}

/* ---------- LANDSCAPE CERTIFICATE LAYOUT ---------- */
.certificate-screen {
  padding: 12px;
  overflow: auto;
}

.certificate-card {
  width: min(1180px, calc(100vw - 28px));
  min-height: auto;
  aspect-ratio: 16 / 9;
  max-height: calc(100dvh - 28px);
  padding: clamp(24px, 3.4vw, 42px) clamp(42px, 5vw, 76px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-width: 10px;
  border-radius: 26px;
}

.certificate-card::before {
  inset: 18px;
  border-radius: 18px;
}

.cert-logo {
  font-size: clamp(44px, 5vw, 64px);
  line-height: 1;
  margin-bottom: 4px;
}

.certificate-card h1 {
  font-size: clamp(44px, 6vw, 72px);
  line-height: 1;
  margin: 2px 0 8px;
}

.cert-subtitle {
  font-size: clamp(18px, 2vw, 24px);
  line-height: 1.35;
  margin: 4px 0 8px;
}

#certificateName {
  font-size: clamp(38px, 5vw, 64px);
  line-height: 1.08;
  margin: 8px 0 12px;
  padding: 0 clamp(36px, 6vw, 90px) 8px;
}

.cert-text {
  font-size: clamp(17px, 2vw, 25px);
  line-height: 1.55;
  margin: 8px auto;
  max-width: 920px;
}

.cert-stars {
  font-size: clamp(28px, 3.2vw, 40px);
  line-height: 1;
  margin: 12px 0;
}

.cert-date {
  font-size: clamp(16px, 1.8vw, 22px);
  margin: 4px 0 12px;
}

.certificate-screen .button-row {
  margin-top: 8px;
}

.certificate-screen .primary-btn,
.certificate-screen .secondary-btn {
  padding: 12px 24px;
  border-radius: 16px;
  font-size: clamp(18px, 2vw, 24px);
}

@media (max-height: 720px) and (orientation: landscape) {
  .certificate-card {
    width: min(1120px, calc(100vw - 24px));
    padding: 20px 58px;
  }

  .cert-logo {
    font-size: 42px;
  }

  .certificate-card h1 {
    font-size: 52px;
  }

  #certificateName {
    font-size: 44px;
    margin: 6px 0 8px;
  }

  .cert-text {
    font-size: 18px;
    line-height: 1.45;
  }

  .cert-stars {
    font-size: 30px;
    margin: 8px 0;
  }

  .cert-date {
    margin-bottom: 8px;
  }

  .certificate-screen .button-row {
    margin-top: 4px;
  }
}

@media (max-width: 760px) {
  .certificate-card {
    aspect-ratio: auto;
    max-height: none;
    min-height: calc(100dvh - 24px);
    padding: 28px 20px;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 0;
  }

  body {
    background: white !important;
  }

  .certificate-screen {
    padding: 0 !important;
    background: white !important;
  }

  .certificate-card {
    width: 297mm !important;
    height: 210mm !important;
    max-height: none !important;
    aspect-ratio: auto !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  .certificate-screen .button-row,
  .sound-btn {
    display: none !important;
  }
}

/* ---------- MISSION START LOADING TRANSITION ---------- */
.mission-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 35%, rgba(233,196,106,0.26), transparent 28%),
    linear-gradient(135deg, rgba(13,42,55,0.92), rgba(42,157,143,0.88));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s ease, visibility 0.28s ease;
}

.mission-loading-overlay.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.mission-loading-card {
  width: min(420px, calc(100vw - 36px));
  padding: 28px 24px;
  border-radius: 28px;
  text-align: center;
  color: white;
  border: 1px solid rgba(255,255,255,0.55);
  background: linear-gradient(145deg, rgba(255,255,255,0.18), rgba(255,255,255,0.08));
  box-shadow: 0 28px 70px rgba(5,26,36,0.38), inset 0 1px 0 rgba(255,255,255,0.5);
  backdrop-filter: blur(20px) saturate(1.2);
  transform: translateY(14px) scale(0.96);
  animation: missionCardIn 0.55s ease forwards;
}

.mission-loader-icon {
  width: 88px;
  height: 88px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 42px;
  background: rgba(233,196,106,0.18);
  border: 3px solid rgba(233,196,106,0.75);
  box-shadow: 0 0 30px rgba(233,196,106,0.45);
  animation: missionRadarPulse 1.1s ease-in-out infinite;
}

.mission-loading-card h3 {
  margin: 8px 0;
  color: #e9c46a;
  font-size: clamp(24px, 4vw, 34px);
}

.mission-loading-card p {
  margin: 0;
  color: rgba(255,255,255,0.92);
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 900;
}

.mission-loading-bar {
  width: 100%;
  height: 14px;
  margin-top: 20px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.28);
}

.mission-loading-fill {
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2a9d8f, #e9c46a, #f4a261);
  box-shadow: 0 0 18px rgba(233,196,106,0.58);
  animation: missionLoadingFill 1.15s ease-in-out infinite;
}

@keyframes missionCardIn {
  to {
    transform: translateY(0) scale(1);
  }
}

@keyframes missionRadarPulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(233,196,106,0), 0 0 30px rgba(233,196,106,0.45);
  }

  50% {
    transform: scale(1.08);
    box-shadow: 0 0 0 14px rgba(233,196,106,0.12), 0 0 38px rgba(233,196,106,0.72);
  }
}

@keyframes missionLoadingFill {
  0% {
    transform: translateX(-115%);
  }

  100% {
    transform: translateX(260%);
  }
}

.cutscene-overlay {
  background: #03111a;
}

.cutscene-frame {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: #03111a;
}

.cutscene-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #03111a;
}

.cutscene-topbar {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.cutscene-topbar span {
  padding: 9px 14px;
  border-radius: 999px;
  color: rgba(255,255,255,0.92);
  background: rgba(3,17,26,0.48);
  border: 1px solid rgba(255,255,255,0.28);
  font-size: clamp(12px, 1.5vw, 16px);
  font-weight: 1000;
  letter-spacing: 0;
  backdrop-filter: blur(12px);
}

.skip-cutscene-btn {
  pointer-events: auto;
  min-width: 82px;
  min-height: 42px;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.65);
  color: #073143;
  background: linear-gradient(180deg, #ffffff, #dff7ff);
  box-shadow: 0 10px 24px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.85);
  font-family: inherit;
  font-size: clamp(15px, 1.8vw, 18px);
  font-weight: 1000;
  cursor: pointer;
}

.skip-cutscene-btn:active {
  transform: translateY(2px);
}

.cutscene-fallback {
  position: absolute;
  left: 50%;
  bottom: max(26px, env(safe-area-inset-bottom));
  z-index: 1;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - 32px));
  padding: 16px 18px;
  border-radius: 22px;
  text-align: center;
  color: white;
  background: rgba(3,17,26,0.5);
  border: 1px solid rgba(255,255,255,0.25);
  backdrop-filter: blur(14px);
}

.cutscene-fallback h3 {
  margin: 0 0 4px;
  color: #e9c46a;
  font-size: clamp(18px, 3vw, 28px);
}

.cutscene-fallback p {
  margin: 0;
  color: rgba(255,255,255,0.88);
  font-size: clamp(14px, 2vw, 18px);
  font-weight: 900;
}

.cutscene-overlay.is-playing .cutscene-fallback {
  display: none;
}

/* ---------- LEVEL START COUNTDOWN ---------- */
.level-countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 5600;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 50% 44%, rgba(233,196,106,0.2), transparent 28%),
    rgba(3,17,26,0.62);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  backdrop-filter: blur(6px);
}

.level-countdown-overlay.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.level-countdown-card {
  width: min(360px, calc(100vw - 40px));
  min-height: 300px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  border-radius: 32px;
  color: white;
  text-align: center;
  background:
    linear-gradient(145deg, rgba(42,157,143,0.9), rgba(13,42,55,0.92));
  border: 3px solid rgba(255,255,255,0.68);
  box-shadow:
    0 28px 70px rgba(3,17,26,0.44),
    inset 0 1px 0 rgba(255,255,255,0.38);
}

.countdown-label {
  padding: 8px 16px;
  border-radius: 999px;
  color: #073143;
  background: linear-gradient(180deg, #fff7bf, #e9c46a);
  font-size: clamp(13px, 2vw, 16px);
  font-weight: 1000;
}

.level-countdown-card strong {
  display: block;
  min-width: 180px;
  color: #ffffff;
  font-size: clamp(86px, 18vw, 150px);
  line-height: 0.95;
  font-weight: 1000;
  text-shadow:
    0 8px 0 rgba(3,17,26,0.25),
    0 0 32px rgba(233,196,106,0.72);
}

.level-countdown-card strong.pop {
  animation: countdownPop 0.62s cubic-bezier(.18, .89, .32, 1.28);
}

.level-countdown-card small {
  color: rgba(255,255,255,0.92);
  font-size: clamp(16px, 2.5vw, 22px);
  font-weight: 1000;
}

@keyframes countdownPop {
  0% {
    transform: scale(0.58);
    opacity: 0;
  }

  55% {
    transform: scale(1.12);
    opacity: 1;
  }

  100% {
    transform: scale(1);
  }
}

/* ---------- CINEMATIC SMART CITY MAP ---------- */
.home-screen,
.story-screen {
  perspective: 1200px;
}

.home-screen .city-bg,
.story-screen .problem-bg {
  background-size: cover;
  background-position: center;
  filter: saturate(1.18) contrast(1.04);
}

.home-screen .city-bg {
  background-image:
    linear-gradient(rgba(13, 42, 55, 0.08), rgba(13, 42, 55, 0.1)),
    url("images/background-home2.png");
}

.home-screen .city-bg::before,
.story-screen .problem-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(to top, rgba(255,255,255,0.1) 0 16%, transparent 42%),
    repeating-linear-gradient(90deg, transparent 0 52px, rgba(233,196,106,0.18) 53px 55px, transparent 56px 116px),
    linear-gradient(90deg, transparent 0 12%, rgba(42,157,143,0.16) 13% 13.4%, transparent 14% 100%);
  clip-path: none;
  opacity: 0.32;
  animation: cityWindowPulse 3.6s ease-in-out infinite alternate;
}

.home-screen .city-bg::after,
.story-screen .problem-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 24%, rgba(233,196,106,0.44) 0 2px, transparent 3px),
    radial-gradient(circle at 38% 34%, rgba(42,157,143,0.58) 0 2px, transparent 3px),
    radial-gradient(circle at 68% 26%, rgba(244,162,97,0.44) 0 2px, transparent 3px),
    radial-gradient(circle at 82% 46%, rgba(42,157,143,0.5) 0 2px, transparent 3px),
    linear-gradient(100deg, transparent 0 42%, rgba(255,255,255,0.22) 48%, transparent 54% 100%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 1px, transparent 1px 34px),
    repeating-linear-gradient(90deg, rgba(42,157,143,0.08) 0 1px, transparent 1px 34px);
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 180% 100%, 100% 100%, 100% 100%;
  mix-blend-mode: screen;
  opacity: 0.82;
  animation: smartCityScan 8s ease-in-out infinite;
}

.home-screen .home-cloud {
  z-index: 3;
  opacity: 0.72;
  filter: blur(0.2px) drop-shadow(0 10px 18px rgba(4,23,33,0.16));
}

.home-screen .sparkle {
  z-index: 4;
  width: 28px;
  height: 28px;
  right: auto;
  color: transparent;
  text-shadow: none;
  animation: leafFly 13s linear infinite;
}

.home-screen .sparkle::before {
  content: "🍃";
  color: #58b947;
  font-size: 26px;
  filter: drop-shadow(0 8px 8px rgba(14, 94, 48, 0.2));
}

.home-screen .sp1 {
  top: 18%;
  animation-delay: -2s;
  animation-duration: 14s;
}

.home-screen .sp2 {
  top: 32%;
  animation-delay: -6s;
  animation-duration: 17s;
}

.home-screen .sp3 {
  top: 54%;
  animation-delay: -10s;
  animation-duration: 19s;
}

.story-screen::after {
  content: "🍃";
  position: absolute;
  left: -80px;
  top: 18%;
  z-index: 0;
  pointer-events: none;
  color: #58b947;
  font-size: 24px;
  text-shadow:
    180px 38px 0 rgba(88,185,71,0.62),
    420px 126px 0 rgba(125,211,96,0.58),
    760px -18px 0 rgba(88,185,71,0.54),
    1040px 92px 0 rgba(125,211,96,0.5);
  filter: drop-shadow(0 8px 8px rgba(14, 94, 48, 0.18));
  animation: storyLeafFly 18s linear infinite;
}

.home-screen .mission-alert,
.home-screen .hero-card,
.story-screen .mission-brief-card {
  box-shadow:
    0 30px 86px rgba(4,23,33,0.38),
    0 0 0 1px rgba(255,255,255,0.28),
    0 0 34px rgba(42,157,143,0.18),
    inset 0 1px 0 rgba(255,255,255,0.86);
}

.home-screen .hero-card,
.story-screen .mission-brief-card {
  background:
    linear-gradient(145deg, rgba(255,255,255,0.88), rgba(236,252,248,0.72));
  backdrop-filter: blur(22px) saturate(1.22);
  -webkit-backdrop-filter: blur(22px) saturate(1.22);
}

.story-screen {
  background:
    radial-gradient(circle at 18% 12%, rgba(233,196,106,0.22), transparent 26%),
    radial-gradient(circle at 86% 24%, rgba(42,157,143,0.22), transparent 24%),
    linear-gradient(135deg, #0d2a37 0%, #123d49 52%, #176e65 100%);
}

.story-screen .problem-bg {
  transform: scale(1.03);
  animation: cinematicDrift 16s ease-in-out infinite alternate;
}

.story-screen .problem-icon {
  z-index: 3;
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.38);
  box-shadow: 0 18px 34px rgba(4,23,33,0.22), inset 0 1px 0 rgba(255,255,255,0.36);
  backdrop-filter: blur(12px);
}

.story-screen .mission-badge {
  box-shadow: 0 0 24px rgba(233,196,106,0.38);
}

@keyframes smartCityScan {
  0%, 100% {
    background-position: 0 0, 0 0, 0 0, 0 0, -75% 0, 0 0, 0 0;
    opacity: 0.68;
  }

  50% {
    background-position: 0 0, 0 0, 0 0, 0 0, 75% 0, 0 18px, 18px 0;
    opacity: 0.94;
  }
}

@keyframes cityWindowPulse {
  from {
    filter: brightness(0.9);
  }

  to {
    filter: brightness(1.18);
  }
}

@keyframes cinematicDrift {
  from {
    transform: scale(1.03) translate3d(-8px, -4px, 0);
  }

  to {
    transform: scale(1.06) translate3d(8px, 4px, 0);
  }
}

@keyframes signalBlink {
  0%, 100% {
    opacity: 0.48;
    transform: scale(0.92);
  }

  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

@keyframes leafFly {
  0% {
    left: -90px;
    transform: translateY(0) rotate(0deg) scale(0.8);
    opacity: 0;
  }

  8% {
    opacity: 0.95;
  }

  50% {
    transform: translateY(44px) rotate(145deg) scale(1);
  }

  92% {
    opacity: 0.95;
  }

  100% {
    left: calc(100% + 90px);
    transform: translateY(-18px) rotate(315deg) scale(0.9);
    opacity: 0;
  }
}

@keyframes storyLeafFly {
  0% {
    transform: translate3d(-120px, 0, 0) rotate(0deg);
    opacity: 0;
  }

  8%, 88% {
    opacity: 0.9;
  }

  100% {
    transform: translate3d(calc(100vw + 180px), 64px, 0) rotate(280deg);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .home-screen .city-bg::before,
  .home-screen .city-bg::after,
  .story-screen .problem-bg,
  .story-screen .problem-bg::before,
  .story-screen .problem-bg::after,
  .story-screen::after,
  .home-screen .sparkle {
    animation: none !important;
  }
}

/* ---------- DEVELOPER CONTACT PADLET BOARD ---------- */
.modal-card:has(.contact-board) {
  width: min(980px, 94vw);
  max-height: min(88vh, 780px);
  overflow: hidden;
  padding: clamp(22px, 3vw, 34px);
  border-radius: 30px;
  background:
    radial-gradient(circle at 16% 10%, rgba(233,196,106,0.3), transparent 24%),
    radial-gradient(circle at 86% 18%, rgba(42,157,143,0.2), transparent 26%),
    linear-gradient(145deg, rgba(255,255,255,0.96), rgba(236,252,248,0.92));
  border: 1px solid rgba(255,255,255,0.72);
  box-shadow:
    0 34px 90px rgba(7, 29, 40, 0.38),
    0 0 0 8px rgba(42,157,143,0.1),
    inset 0 1px 0 rgba(255,255,255,0.94);
}

.contact-board {
  position: relative;
  max-height: calc(min(88vh, 780px) - 70px);
  overflow-y: auto;
  padding: 6px 6px 12px;
  text-align: left;
  scrollbar-width: thin;
  scrollbar-color: #2a9d8f rgba(42,157,143,0.14);
}

.contact-board-header {
  display: flex;
  gap: 16px;
  align-items: center;
  margin: 0 46px 22px 0;
  padding: 18px 20px;
  border-radius: 24px;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(42,157,143,0.22);
  box-shadow: 0 14px 30px rgba(13,42,55,0.1), inset 0 1px 0 rgba(255,255,255,0.9);
}

.contact-pin {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(180deg, #fff6d8, #e9c46a);
  border: 2px solid rgba(255,255,255,0.8);
  font-size: 30px;
  box-shadow: 0 8px 0 rgba(151,106,16,0.16);
  flex: 0 0 auto;
}

.contact-board-header h2 {
  margin: 0 0 4px;
  color: #176e65;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.05;
}

.contact-board-header p {
  margin: 0;
  color: #34535a;
  font-size: clamp(16px, 2vw, 21px);
  font-weight: 800;
  line-height: 1.45;
}

.contact-notes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.contact-note {
  position: relative;
  min-height: 190px;
  padding: 20px 18px 18px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.7);
  box-shadow:
    0 14px 0 rgba(13,42,55,0.08),
    0 24px 38px rgba(13,42,55,0.12),
    inset 0 1px 0 rgba(255,255,255,0.82);
  transform: rotate(-0.6deg);
}

.contact-note:nth-child(even) {
  transform: rotate(0.7deg);
}

.contact-note::before {
  content: "";
  position: absolute;
  top: 10px;
  left: 50%;
  width: 54px;
  height: 12px;
  border-radius: 999px;
  transform: translateX(-50%) rotate(-2deg);
  background: rgba(255,255,255,0.5);
  box-shadow: 0 3px 8px rgba(13,42,55,0.08);
}

.note-icon {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 10px;
  border-radius: 16px;
  background: rgba(255,255,255,0.55);
  font-size: 28px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.75);
}

.contact-note h3 {
  margin: 0 0 10px;
  color: #173d43;
  font-size: clamp(20px, 2.2vw, 26px);
  line-height: 1.15;
}

.contact-note p,
.contact-note a {
  display: block;
  margin: 6px 0;
  color: #173d43;
  font-size: clamp(15px, 1.75vw, 19px);
  font-weight: 800;
  line-height: 1.45;
}

.contact-note a {
  width: fit-content;
  padding: 8px 12px;
  border-radius: 999px;
  color: #0f766e;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(42,157,143,0.28);
  text-decoration: none;
}

.contact-note a:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(13,42,55,0.12);
}

.note-developer {
  background: linear-gradient(145deg, #fff6d8, #ffe9a6);
}

.note-school {
  background: linear-gradient(145deg, #e4f8ff, #bfefff);
}

.note-media {
  background: linear-gradient(145deg, #e7f9ee, #bdf2cf);
}

.note-links {
  background: linear-gradient(145deg, #fff0df, #ffd0a7);
}

.note-feedback {
  background: linear-gradient(145deg, #eef2ff, #d8e0ff);
}

.note-thanks {
  background: linear-gradient(145deg, #f2fbde, #dff5a8);
}

@media (max-width: 860px) {
  .contact-notes {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .modal-card:has(.contact-board) {
    padding: 18px 12px;
  }

  .contact-board-header {
    margin-right: 34px;
    padding: 14px;
    align-items: flex-start;
  }

  .contact-pin {
    width: 46px;
    height: 46px;
    font-size: 24px;
  }

  .contact-notes {
    grid-template-columns: 1fr;
  }

  .contact-note {
    min-height: 0;
    transform: none !important;
  }
}

/* ---------- TUTORIAL SCREEN REFRESH ---------- */
.tutorial-screen {
  isolation: isolate;
  background:
    radial-gradient(circle at 14% 18%, rgba(233,196,106,0.25), transparent 26%),
    radial-gradient(circle at 84% 16%, rgba(42,157,143,0.2), transparent 26%),
    linear-gradient(135deg, #dff7ff, #e7f9ee 58%, #fff4d8);
}

.tutorial-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(42,157,143,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42,157,143,0.08) 1px, transparent 1px),
    radial-gradient(circle at 70% 24%, rgba(255,255,255,0.6), transparent 26%);
  background-size: 42px 42px, 42px 42px, 100% 100%;
  animation: gameParticles 24s linear infinite;
}

.tutorial-card {
  width: min(1120px, 96vw);
  border-radius: 28px;
  border: 1px solid rgba(255,255,255,0.72);
  background: linear-gradient(145deg, rgba(255,255,255,0.92), rgba(236,252,248,0.78));
  box-shadow:
    0 34px 88px rgba(13,42,55,0.22),
    0 0 0 8px rgba(42,157,143,0.09),
    inset 0 1px 0 rgba(255,255,255,0.96);
  backdrop-filter: blur(18px) saturate(1.15);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
}

.tutorial-card h2 {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 18px;
  padding: 10px 22px;
  border-radius: 999px;
  background: rgba(42,157,143,0.12);
  border: 2px solid rgba(42,157,143,0.24);
  color: #176e65;
  font-size: clamp(30px, 4vw, 46px);
}

.tutorial-card h2::before {
  content: "📖";
}

.tutorial-layout {
  grid-template-columns: 0.9fr 1.15fr;
  align-items: stretch;
  gap: 18px;
}

.tutorial-left,
.tutorial-right {
  border-radius: 24px;
  border: 1px solid rgba(255,255,255,0.74);
  background:
    linear-gradient(145deg, rgba(255,255,255,0.78), rgba(239,246,255,0.66));
  box-shadow: 0 18px 38px rgba(13,42,55,0.12), inset 0 1px 0 rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
}

.tutorial-left h3,
.tutorial-right h3 {
  color: #176e65;
  font-size: clamp(22px, 2.5vw, 30px);
}

.tutorial-left {
  display: grid;
  align-content: start;
}

.sample-block {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 2px solid rgba(151,106,16,0.24);
  background: linear-gradient(180deg, #fff6d8, #e9c46a);
  color: #3b2500;
  box-shadow: 0 6px 0 rgba(151,106,16,0.16), 0 12px 18px rgba(13,42,55,0.08);
}

.tutorial-left .hint {
  margin: 16px 0 0;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(42,157,143,0.1);
  border: 1px solid rgba(42,157,143,0.24);
  color: #173d43;
  font-size: clamp(16px, 1.8vw, 20px);
}

.tutorial-right > p {
  margin: 0 auto 10px;
  color: #173d43;
  font-weight: 900;
  font-size: clamp(17px, 2vw, 22px);
}

.mini-grid {
  width: min(360px, 78vw);
  height: auto;
  aspect-ratio: 1 / 1;
  padding: 8px;
  gap: 6px;
  border-radius: 24px;
  background: linear-gradient(145deg, #0f3d4c, #164e63);
  box-shadow:
    0 20px 32px rgba(13,42,55,0.25),
    0 8px 0 rgba(8,47,73,0.42),
    inset 0 1px 0 rgba(255,255,255,0.18);
}

.mini-cell {
  position: relative;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.34);
  box-shadow:
    inset 0 -5px rgba(0,0,0,0.12),
    inset 0 3px rgba(255,255,255,0.22),
    0 3px 0 rgba(0,0,0,0.12);
  overflow: hidden;
}

.mini-grass {
  background:
    radial-gradient(circle at 26% 26%, rgba(255,255,255,0.52) 0 5px, transparent 6px),
    linear-gradient(135deg, #8dd96f, #55b94d);
}

.mini-road {
  background:
    radial-gradient(circle at 70% 65%, rgba(120,70,30,0.18) 0 8px, transparent 9px),
    linear-gradient(135deg, #e4b06d, #c99150);
}

.mini-wall {
  background: linear-gradient(135deg, #cbd5e1, #94a3b8);
}

.mini-target {
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.82) 0 24%, transparent 48%),
    linear-gradient(135deg, #fde68a, #facc15);
  animation: targetGlowPremium 1.35s ease-in-out infinite alternate;
}

.mini-success {
  box-shadow:
    inset 0 -5px rgba(0,0,0,0.12),
    0 0 28px rgba(250,204,21,0.9),
    0 0 0 5px rgba(250,204,21,0.18);
}

.mini-player-cell {
  z-index: 2;
}

.mini-character-img {
  width: 86%;
  height: 86%;
  object-fit: contain;
  filter: drop-shadow(0 8px 7px rgba(13,42,55,0.3));
  animation: miniPlayerHop 0.52s ease;
}

.tutorial-command-demo {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 14px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.78);
  background: rgba(255,255,255,0.72);
  box-shadow: 0 12px 24px rgba(13,42,55,0.1), inset 0 1px 0 rgba(255,255,255,0.9);
}

.tutorial-command-demo > span {
  color: #176e65;
  font-size: 18px;
  font-weight: 1000;
}

.demo-command-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.demo-command-row b {
  min-width: 86px;
  padding: 9px 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, #fff6d8, #e9c46a);
  color: #3b2500;
  border: 2px solid rgba(151,106,16,0.22);
  box-shadow: 0 5px 0 rgba(151,106,16,0.14);
  transition: transform 0.18s ease, filter 0.18s ease, box-shadow 0.18s ease;
}

.demo-command-row b.active-demo-command {
  transform: translateY(-4px) scale(1.06);
  filter: brightness(1.08);
  background: linear-gradient(180deg, #34c6b5, #2a9d8f);
  color: white;
  box-shadow: 0 7px 0 rgba(16,42,56,0.22), 0 0 22px rgba(42,157,143,0.34);
}

.tutorial-command-demo small {
  color: #34535a;
  font-size: 15px;
  font-weight: 900;
}

.tutorial-right .quote {
  display: inline-block;
  margin-top: 14px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(42,157,143,0.12);
  color: #176e65;
  font-size: clamp(16px, 1.8vw, 20px);
}

@keyframes miniPlayerHop {
  0% {
    transform: translateY(6px) scale(0.92);
  }

  55% {
    transform: translateY(-6px) scale(1.05);
  }

  100% {
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 980px) {
  .tutorial-layout {
    grid-template-columns: 1fr;
  }
}

/* ---------- SUCCESS POPUP CELEBRATION REFRESH ---------- */
.modal-card:has(.success-popup) {
  width: min(720px, 92vw);
  padding: 0;
  overflow: hidden;
  border-radius: 34px;
  border: 1px solid rgba(255,255,255,0.82);
  background:
    radial-gradient(circle at 18% 12%, rgba(233,196,106,0.36), transparent 25%),
    radial-gradient(circle at 86% 18%, rgba(42,157,143,0.22), transparent 28%),
    linear-gradient(145deg, rgba(255,255,255,0.98), rgba(236,252,248,0.92));
  box-shadow:
    0 34px 90px rgba(7,29,40,0.42),
    0 0 0 8px rgba(42,157,143,0.1),
    inset 0 1px 0 rgba(255,255,255,0.96);
}

.modal-card:has(.success-popup)::before,
.modal-card:has(.success-popup)::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.modal-card:has(.success-popup)::before {
  background:
    radial-gradient(circle, rgba(250,204,21,0.78) 0 3px, transparent 4px),
    radial-gradient(circle, rgba(244,162,97,0.64) 0 2px, transparent 3px),
    radial-gradient(circle, rgba(42,157,143,0.52) 0 2px, transparent 3px);
  background-size: 120px 120px, 88px 88px, 150px 150px;
  background-position: 18px 20px, 60px 42px, 16px 88px;
  opacity: 0.54;
  animation: successConfettiDrift 12s linear infinite;
}

.modal-card:has(.success-popup)::after {
  background:
    linear-gradient(115deg, transparent 0 36%, rgba(255,255,255,0.32) 44%, transparent 52% 100%),
    radial-gradient(circle at 50% 6%, rgba(255,255,255,0.48), transparent 28%);
  animation: successSweep 6s ease-in-out infinite;
}

.modal-card:has(.success-popup) .close-btn {
  top: 16px;
  right: 16px;
  z-index: 4;
  background: linear-gradient(180deg, #ff6b6b, #ef4444);
  box-shadow: 0 7px 0 #b91c1c, 0 14px 24px rgba(239,68,68,0.2);
}

.success-popup {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: clamp(34px, 5vw, 54px) clamp(22px, 5vw, 64px) clamp(28px, 4vw, 42px);
  text-align: center;
}

.success-ribbon {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(42,157,143,0.14);
  border: 2px solid rgba(42,157,143,0.28);
  color: #176e65;
  font-size: clamp(13px, 1.6vw, 16px);
  font-weight: 1000;
  letter-spacing: 0.06em;
  box-shadow: 0 10px 22px rgba(13,42,55,0.08);
}

.success-ribbon::before,
.success-ribbon::after {
  content: "✦";
  color: #e9c46a;
}

.success-popup .popup-emoji {
  width: clamp(86px, 10vw, 116px);
  height: clamp(86px, 10vw, 116px);
  display: grid;
  place-items: center;
  margin: 4px 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255,255,255,0.86), transparent 28%),
    linear-gradient(145deg, #fff4a3, #f59e0b);
  border: 4px solid rgba(255,255,255,0.78);
  color: #7c4a03;
  font-size: clamp(54px, 7vw, 76px);
  box-shadow:
    0 14px 0 rgba(151,106,16,0.2),
    0 24px 42px rgba(233,196,106,0.32),
    0 0 44px rgba(250,204,21,0.42);
  animation: successTrophyPop 2.4s ease-in-out infinite;
}

.success-popup h2 {
  margin: 4px 0 0;
  color: #176e65;
  font-size: clamp(42px, 6vw, 64px);
  line-height: 1;
  text-shadow: 0 5px 0 rgba(233,196,106,0.14);
}

.success-popup p {
  max-width: 620px;
  margin: 8px 0;
  padding: 14px 18px;
  border-radius: 22px;
  background: rgba(255,255,255,0.66);
  border: 1px solid rgba(42,157,143,0.16);
  color: #173d43;
  font-size: clamp(20px, 2.4vw, 28px);
  font-weight: 900;
  line-height: 1.5;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.86);
}

.success-popup .popup-stars {
  display: inline-grid;
  gap: 4px;
  min-width: min(360px, 90%);
  padding: 12px 20px;
  border-radius: 999px;
  background: linear-gradient(145deg, rgba(255,248,223,0.96), rgba(255,255,255,0.82));
  border: 2px solid rgba(233,196,106,0.46);
  box-shadow: 0 14px 30px rgba(151,106,16,0.12), inset 0 1px 0 rgba(255,255,255,0.92);
}

.success-popup .popup-stars span {
  color: #facc15;
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1;
  text-shadow: 0 0 18px rgba(250,204,21,0.5), 0 4px 0 rgba(151,106,16,0.12);
}

.success-popup .popup-stars small {
  color: #7c4a03;
  font-size: 14px;
  font-weight: 1000;
}

.success-popup .popup-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 14px;
  width: min(460px, 100%);
  margin-top: 6px;
}

.success-popup .popup-next,
.success-popup .popup-retry {
  min-height: 60px;
  padding: 14px 18px;
  border-radius: 18px;
  font-size: clamp(18px, 2vw, 23px);
  font-weight: 1000;
  border: 2px solid rgba(255,255,255,0.58);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.success-popup .popup-next {
  background: linear-gradient(180deg, #34c6b5, #16a34a 64%, #0f7d35);
  box-shadow: 0 8px 0 #0f6b31, 0 18px 28px rgba(22,163,74,0.22);
}

.success-popup .popup-retry {
  background: linear-gradient(180deg, #5da8ff, #2563eb 64%, #1d4ed8);
  box-shadow: 0 8px 0 #1e3a8a, 0 18px 28px rgba(37,99,235,0.2);
}

.success-popup .popup-next:hover,
.success-popup .popup-retry:hover {
  transform: translateY(-4px) scale(1.025);
  filter: brightness(1.05);
}

@keyframes successConfettiDrift {
  from {
    background-position: 18px 20px, 60px 42px, 16px 88px;
  }

  to {
    background-position: 138px 180px, -28px 170px, 166px 238px;
  }
}

@keyframes successSweep {
  0%, 100% {
    opacity: 0.55;
    transform: translateX(-2%);
  }

  50% {
    opacity: 0.92;
    transform: translateX(2%);
  }
}

@keyframes successTrophyPop {
  0%, 100% {
    transform: translateY(0) rotate(-2deg) scale(1);
  }

  50% {
    transform: translateY(-8px) rotate(2deg) scale(1.06);
  }
}

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

  .success-popup p {
    font-size: 18px;
  }
}

/* ---------- MOBILE RESPONSIVE SAFETY OVERRIDES ---------- */
.mission-alert,
.home-screen .mission-alert {
  display: none !important;
}

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .screen {
    width: 100%;
    min-height: 100dvh;
    height: auto;
    padding: 10px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .home-screen,
  .story-screen,
  .tutorial-screen,
  .summary-screen,
  .certificate-screen {
    align-items: flex-start;
    justify-content: center;
  }

  .home-screen {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 10px !important;
    padding-top: 10px !important;
  }

  .home-screen .hero-card {
    position: relative !important;
    z-index: 2 !important;
    width: min(100%, 430px) !important;
    margin: 0 auto !important;
  }

  .hero-card,
  .story-card,
  .tutorial-card,
  .summary-card,
  .certificate-card {
    width: min(100%, 460px) !important;
    max-width: 100% !important;
    max-height: none !important;
    margin: 0 auto;
    padding: 18px 14px !important;
    border-radius: 22px !important;
    overflow: visible;
  }

  .home-screen .game-logo {
    width: min(86vw, 360px) !important;
    max-width: 100% !important;
  }

  .home-screen .badge {
    max-width: 100%;
    white-space: normal;
    font-size: 15px !important;
    line-height: 1.3;
    padding: 8px 12px;
  }

  .home-screen .hero-card > p {
    font-size: 16px !important;
    line-height: 1.45;
  }

  .home-screen .button-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    width: min(100%, 360px) !important;
    max-width: 360px !important;
    gap: 10px !important;
  }

  .home-screen .button-row .primary-btn,
  .home-screen .button-row .secondary-btn,
  .home-screen .button-row .secondary-btn:nth-child(1),
  .home-screen .button-row .secondary-btn:nth-child(2),
  .home-screen .button-row .secondary-btn:nth-child(3),
  .home-screen .button-row .secondary-btn:nth-child(4),
  .home-screen .button-row .secondary-btn:nth-child(5) {
    grid-column: 1 !important;
    grid-row: auto !important;
    width: 100% !important;
    min-height: 52px !important;
    max-width: none !important;
    padding: 12px 14px !important;
    font-size: 17px !important;
    transform: none !important;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .home-screen .hero-card::after,
  .home-screen .hero-card p::after {
    display: none !important;
  }

  .game-screen {
    min-height: 100dvh;
    height: auto !important;
    padding: 8px;
    gap: 8px;
    overflow-y: auto !important;
  }

  .game-header {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px;
    min-height: 0;
    padding: 12px;
    text-align: center;
    border-radius: 20px;
  }

  .home-game-btn {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    font-size: 17px;
  }

  .game-header h2 {
    font-size: 21px !important;
    line-height: 1.2;
  }

  .game-header p {
    font-size: 14px !important;
    line-height: 1.35;
  }

  .score-panel {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    font-size: 14px;
  }

  .score-panel span {
    min-width: 0;
    padding: 8px 6px !important;
    border-radius: 14px;
    font-size: 13px !important;
    white-space: nowrap;
  }

  .level-progress-wrap {
    padding: 10px 12px;
    border-radius: 16px;
  }

  .level-progress-info {
    font-size: 13px;
  }

  .game-layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    height: auto !important;
    gap: 10px;
  }

  .map-panel,
  .code-panel {
    width: 100%;
    min-width: 0;
    overflow: visible !important;
    padding: 10px;
    border-radius: 20px;
  }

  .character-talk {
    align-items: flex-start;
    gap: 8px;
  }

  .avatar {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
  }

  .speech-bubble {
    min-width: 0;
    padding: 9px 10px;
    font-size: 13px !important;
    line-height: 1.35;
    border-radius: 16px;
  }

  .grid {
    width: min(100%, 92vw) !important;
    height: auto !important;
    max-height: none !important;
    aspect-ratio: 1 / 1 !important;
    gap: 4px !important;
    padding: 6px !important;
    transform: none !important;
    border-radius: 18px;
  }

  .cell {
    border-width: 2px !important;
    border-radius: 10px !important;
  }

  .water-cell,
  .wall-cell,
  .target-cell {
    border-width: 3px !important;
  }

  .water-cell::after,
  .wall-cell::after {
    width: 18px;
    height: 18px;
    font-size: 13px;
    border-width: 1px;
  }

  .problem-box,
  .workspace-wrap,
  .block-bank {
    padding: 10px;
    border-radius: 16px;
  }

  .problem-box h3,
  .workspace-wrap h3 {
    font-size: 17px !important;
  }

  .problem-box p,
  .empty-text {
    font-size: 14px !important;
    line-height: 1.4;
  }

  .workspace {
    min-height: 82px;
    max-height: 150px;
    padding: 10px;
    gap: 8px;
  }

  .block-bank {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .cmd-block,
  .workspace-block {
    width: 100%;
    min-width: 0;
    padding: 10px 8px;
    font-size: 14px !important;
    border-radius: 13px;
    white-space: normal;
  }

  .repeat-block {
    grid-column: 1 / -1;
  }

  .control-row {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .control-row button,
  .run-btn,
  .hint-btn,
  .clear-btn,
  .retry-btn {
    min-width: 0 !important;
    width: 100%;
    padding: 11px 8px !important;
    font-size: 14px !important;
    border-radius: 14px;
    white-space: normal;
  }

  .feedback {
    font-size: 14px !important;
    line-height: 1.35;
  }

  .tutorial-layout,
  .mission-brief-grid,
  .result-grid,
  .contact-notes {
    grid-template-columns: 1fr !important;
  }

  .tutorial-left,
  .tutorial-right,
  .brief-box,
  .result-item,
  .contact-note {
    min-width: 0;
  }

  .modal {
    padding: 10px;
  }

  .modal-card,
  .modal-card:has(.leaderboard-list),
  .modal-card:has(.contact-board),
  .modal-card:has(.success-popup) {
    width: min(100%, 440px) !important;
    max-width: 100% !important;
    max-height: calc(100dvh - 20px) !important;
    padding: 18px 12px !important;
    border-radius: 22px !important;
    overflow-y: auto !important;
  }

  .modal-card:has(.success-popup) {
    padding: 0 !important;
  }

  .modal-card h2,
  .modal-card:has(.leaderboard-list) h2 {
    font-size: 32px !important;
    line-height: 1.1;
    margin-left: 36px;
    margin-right: 36px;
  }

  .close-btn {
    width: 40px;
    height: 40px;
    top: 10px !important;
    right: 10px !important;
  }

  .leaderboard-row {
    grid-template-columns: 42px minmax(0, 1fr) !important;
    gap: 8px;
    min-height: 68px;
    padding: 9px 10px;
  }

  .leaderboard-row span:last-child {
    grid-column: 2;
    min-width: 0;
    width: fit-content;
    font-size: 13px !important;
  }

  .sound-btn {
    width: 50px;
    height: 50px;
    right: 10px;
    bottom: 10px;
    font-size: 22px;
  }
}

@media (max-width: 390px) {
  .home-screen {
    padding-top: 8px !important;
  }

  .score-panel,
  .block-bank,
  .control-row {
    grid-template-columns: 1fr;
  }

  .home-screen .button-row {
    width: 100% !important;
  }

  .game-header h2 {
    font-size: 19px !important;
  }

  .cmd-block,
  .workspace-block,
  .control-row button {
    font-size: 13px !important;
  }
}

/* ---------- PLAYFIELD READABILITY BOOST ---------- */
.map-legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 auto 10px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.82);
  border: 1px solid rgba(255,255,255,0.7);
  color: #173d43;
  font-size: clamp(13px, 1.3vw, 16px);
  font-weight: 1000;
  box-shadow: 0 8px 18px rgba(13,42,55,0.1), inset 0 1px 0 rgba(255,255,255,0.9);
}

.legend-item i {
  width: 20px;
  height: 20px;
  border-radius: 7px;
  box-shadow: inset 0 2px rgba(255,255,255,0.34), 0 2px 0 rgba(13,42,55,0.12);
}

.legend-safe i {
  background: linear-gradient(135deg, #9be66f, #4fb84e);
}

.legend-danger i {
  background: repeating-linear-gradient(45deg, #ef4444 0 7px, #fee2e2 7px 14px);
}

.legend-goal i {
  background: radial-gradient(circle, #fff 0 25%, transparent 26%), linear-gradient(135deg, #fde047, #f59e0b);
}

.grid {
  gap: 8px;
  background:
    linear-gradient(145deg, #082f3d, #0e5264) !important;
  border: 3px solid rgba(255,255,255,0.45);
}

.cell {
  border-width: 3px;
  isolation: isolate;
}

.grass-cell,
.road-cell {
  border-color: rgba(255,255,255,0.62) !important;
  outline: 2px solid rgba(22, 163, 74, 0.2);
  outline-offset: -7px;
}

.grass-cell {
  background:
    linear-gradient(135deg, rgba(255,255,255,0.34) 0 12%, transparent 13% 100%),
    radial-gradient(circle at 24% 24%, rgba(255,255,255,0.72) 0 4px, transparent 5px),
    linear-gradient(135deg, #a8ef79, #43b94d) !important;
}

.road-cell {
  background:
    linear-gradient(90deg, transparent 0 43%, rgba(255,255,255,0.42) 44% 48%, transparent 49% 100%),
    radial-gradient(circle at 70% 66%, rgba(120,70,30,0.12) 0 8px, transparent 9px),
    linear-gradient(135deg, #f0c983, #c58a47) !important;
}

.water-cell,
.wall-cell {
  border: 4px solid #ef4444 !important;
  outline: 3px solid rgba(127, 29, 29, 0.28);
  outline-offset: -8px;
  color: white;
  text-shadow: 0 3px 0 rgba(127, 29, 29, 0.34), 0 0 14px rgba(255,255,255,0.46);
  box-shadow:
    inset 0 -8px rgba(127,29,29,0.28),
    inset 0 4px rgba(255,255,255,0.2),
    0 7px 0 rgba(127,29,29,0.28),
    0 0 20px rgba(239,68,68,0.24) !important;
}

.water-cell {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.28) 0 8px, transparent 8px 17px),
    linear-gradient(135deg, #38bdf8 0 38%, #ef4444 39% 44%, #0284c7 45% 100%) !important;
}

.wall-cell {
  background:
    repeating-linear-gradient(45deg, rgba(127,29,29,0.28) 0 9px, transparent 9px 18px),
    linear-gradient(135deg, #64748b, #334155) !important;
}

.water-cell::after,
.wall-cell::after {
  content: "!";
  position: absolute;
  top: 6%;
  right: 6%;
  z-index: 4;
  width: clamp(18px, 2vw, 28px);
  height: clamp(18px, 2vw, 28px);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ef4444;
  color: white;
  border: 2px solid rgba(255,255,255,0.86);
  font-size: clamp(13px, 1.5vw, 20px);
  font-weight: 1000;
  box-shadow: 0 5px 0 rgba(127,29,29,0.28), 0 0 16px rgba(239,68,68,0.42);
}

.water-cell::before {
  opacity: 0.32;
}

.target-cell {
  border: 4px solid #facc15 !important;
  outline: 4px solid rgba(250,204,21,0.36);
  outline-offset: -9px;
  color: #4a3510;
  text-shadow: 0 2px 0 rgba(255,255,255,0.78), 0 0 18px rgba(250,204,21,0.92);
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.95) 0 20%, transparent 43%),
    repeating-radial-gradient(circle, rgba(250,204,21,0.28) 0 4px, transparent 5px 15px),
    linear-gradient(135deg, #fff4a3, #f59e0b) !important;
  box-shadow:
    inset 0 -7px rgba(151,106,16,0.18),
    inset 0 5px rgba(255,255,255,0.36),
    0 0 0 5px rgba(250,204,21,0.14),
    0 0 32px rgba(250,204,21,0.88) !important;
}

.target-cell::after {
  content: "GOAL";
  position: absolute;
  left: 50%;
  bottom: 7%;
  z-index: 4;
  transform: translateX(-50%);
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.84);
  color: #92400e;
  font-size: clamp(8px, 0.9vw, 12px);
  font-weight: 1000;
  letter-spacing: 0;
  box-shadow: 0 4px 10px rgba(151,106,16,0.18);
}

.cell.player {
  border-color: #2563eb !important;
  outline: 4px solid rgba(37,99,235,0.25);
  outline-offset: -8px;
}

@media (max-width: 980px) {
  .target-cell::after {
    display: none;
  }

  .map-legend {
    gap: 6px;
  }
}

/* ---------- MOBILE SCREEN SWITCHING GUARD ---------- */
.screen:not(.active) {
  display: none !important;
}

@media (max-width: 760px) {
  .screen:not(.active) {
    display: none !important;
  }

  .screen.active {
    display: flex !important;
  }

  .home-screen.active {
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 10px !important;
    padding-top: 10px !important;
  }

  .game-screen.active {
    flex-direction: column !important;
  }
}
