/* =====================================================
   MEKANIK: HIJAIYAH (Petualangan Huruf Hijaiyah)
   ===================================================== */
:root {
  --hj-teal-900: #0a2e30;
  --hj-teal-800: #0d4245;
  --hj-teal-700: #10555a;
  --hj-teal-600: #146b70;
  --hj-gold: #f2b705;
  --hj-gold-deep: #d99a00;
  --hj-coral: #f2542d;
  --hj-cream: #fdf6e3;
  --hj-cream-dim: #f3e9ce;
  --hj-mint: #4fb878;
  --hj-ink: #0a2e30;
  --hj-shadow: rgba(10, 46, 48, 0.32);
}

#screen-hijaiyah {
  font-family: "Nunito", sans-serif;
  color: var(--hj-cream);
  background: var(--hj-teal-800) url("../assets/images/backgrounds/background_hijaiya.webp") center center / cover no-repeat;
  min-height: 100vh;
  min-height: 100dvh;
  display: none;
  align-items: flex-start;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

#screen-hijaiyah.active {
  display: flex;
}

#screen-hijaiyah .pattern-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  display: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90' viewBox='0 0 90 90'%3E%3Cg fill='none' stroke='%23F2B705' stroke-width='1.4'%3E%3Cpath d='M45 6 L54 27 L76 27 L59 41 L66 63 L45 50 L24 63 L31 41 L14 27 L36 27 Z'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 110px 110px;
}

#screen-hijaiyah .stage {
  width: 100%;
  max-width: 460px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  padding: 18px 16px calc(22px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
}

/* Keep every stage reachable on short landscape screens. */
@media (max-height: 600px) {
  #screen-hijaiyah .stage {
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
  }

  #screen-hijaiyah .hj-topbar {
    margin-bottom: 6px;
    row-gap: 4px;
    gap: 6px;
  }

  #screen-hijaiyah .hj-btn {
    padding: 6px 12px;
    font-size: 14px;
  }

  #hj-screen-intro {
    gap: 8px;
  }

  #screen-hijaiyah .intro-art {
    font-size: 34px;
  }

  #screen-hijaiyah .intro-card {
    padding: 10px 14px 8px;
    border-radius: 18px;
    box-shadow: 0 8px 0 var(--hj-shadow);
  }

  #screen-hijaiyah .intro-card h1 {
    font-size: 18px;
    margin-bottom: 4px;
  }

  #screen-hijaiyah .intro-card p {
    font-size: 11px;
    line-height: 1.3;
    margin-bottom: 6px;
  }

  #screen-hijaiyah .steps-mini {
    gap: 6px;
    margin-bottom: 7px;
  }

  #screen-hijaiyah .steps-mini .step {
    padding: 4px 3px;
    font-size: 9px;
    border-radius: 10px;
  }

  #screen-hijaiyah .steps-mini .step .emoji {
    font-size: 16px;
    margin-bottom: 2px;
  }

  #screen-hijaiyah #hj-audio-status {
    margin-top: 3px !important;
    font-size: 10px !important;
  }

  #screen-hijaiyah .audio-warning {
    padding: 6px 8px;
    margin-top: 4px;
  }

  #screen-hijaiyah #hj-screen-quiz,
  #screen-hijaiyah #hj-screen-match,
  #screen-hijaiyah #hj-screen-race {
    gap: 8px;
  }

  #screen-hijaiyah .option-btn {
    max-height: 112px;
  }

  #screen-hijaiyah .road-wrap {
    height: clamp(130px, 30vh, 220px);
  }

  #screen-hijaiyah .lane-btn {
    padding: 8px 0;
  }
}

#screen-hijaiyah h1,
#screen-hijaiyah h2,
#screen-hijaiyah h3 {
  font-family: "Baloo 2", sans-serif;
  margin: 0;
}

#screen-hijaiyah .hj-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 8px;
  gap: 10px;
  margin-bottom: 14px;
}

#screen-hijaiyah .hj-quit-btn {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  touch-action: manipulation;
}

#screen-hijaiyah .hj-quit-btn img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.3));
  transition: transform 0.15s ease;
}

#screen-hijaiyah .hj-quit-btn:hover img {
  transform: translateY(-3px) scale(1.05);
}

#screen-hijaiyah .hj-quit-btn:active img {
  transform: translateY(2px) scale(0.95);
}

#screen-hijaiyah .hj-brand {
  color: var(--hj-cream);
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 6px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  white-space: nowrap;
}

#screen-hijaiyah .hj-top-hearts {
  display: none;
  font-size: 20px;
  letter-spacing: 2px;
  white-space: nowrap;
}

#screen-hijaiyah.hj-race-active .hj-brand,
#screen-hijaiyah.hj-substage-active .hj-brand {
  display: none;
}

#screen-hijaiyah.hj-race-active .hj-top-hearts,
#screen-hijaiyah.hj-substage-active .hj-top-hearts {
  display: block;
}

#screen-hijaiyah .hj-path {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(10, 46, 48, 0.72);
  border: 1px solid rgba(253, 246, 227, 0.3);
  border-radius: 999px;
  padding: 6px 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
}

#screen-hijaiyah .hj-path::-webkit-scrollbar {
  display: none;
}

#screen-hijaiyah .hj-path .pill {
  font-size: 10.5px;
  font-weight: 800;
  color: var(--hj-cream);
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(253, 246, 227, 0.16);
  opacity: 1;
  white-space: nowrap;
  transition: all 0.25s ease;
}

@media (max-width: 380px) {
  #screen-hijaiyah .hj-brand {
    font-size: 12.5px;
  }
  #screen-hijaiyah .hj-path .pill {
    font-size: 9.5px;
    padding: 3px 6px;
  }
  #screen-hijaiyah .hj-path .arrow {
    font-size: 10px;
  }
}

#screen-hijaiyah .hj-path .pill.active {
  opacity: 1;
  background: var(--hj-gold);
  color: var(--hj-ink);
}

#screen-hijaiyah .hj-path .pill.done {
  opacity: 1;
  background: var(--hj-mint);
  color: #fff;
}

#screen-hijaiyah .hj-path .arrow {
  color: var(--hj-cream);
  opacity: 1;
  font-size: 12px;
}

#screen-hijaiyah .hj-screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  animation: fadeInHJ 0.35s ease;
}

#screen-hijaiyah .hj-screen.active {
  display: flex;
}

@keyframes fadeInHJ {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- INTRO ---------- */
#hj-screen-intro {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
}

#screen-hijaiyah .intro-art {
  font-size: 60px;
  line-height: 1;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.25));
}

#screen-hijaiyah .intro-card {
  background: var(--hj-cream);
  color: var(--hj-ink);
  border-radius: 26px;
  padding: 28px 22px 24px;
  box-shadow: 0 14px 0 var(--hj-shadow);
  width: 100%;
}

#screen-hijaiyah .intro-card h1 {
  font-size: 24px;
  color: var(--hj-ink);
  margin-bottom: 8px;
}

#screen-hijaiyah .intro-card p {
  font-size: 14.5px;
  line-height: 1.55;
  color: #3e5b5c;
  margin: 0 0 18px;
}

#screen-hijaiyah .steps-mini {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

#screen-hijaiyah .steps-mini .step {
  flex: 1;
  background: var(--hj-cream-dim);
  border-radius: 16px;
  padding: 12px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--hj-ink);
}

#screen-hijaiyah .steps-mini .step .emoji {
  font-size: 22px;
  display: block;
  margin-bottom: 4px;
}

#screen-hijaiyah button {
  font-family: "Baloo 2", sans-serif;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

#screen-hijaiyah .hj-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--hj-ink);
  background: var(--hj-gold);
  padding: 14px 26px;
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--hj-gold-deep);
  transition: transform 0.08s ease;
  width: 100%;
}

#screen-hijaiyah .hj-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--hj-gold-deep);
}

#screen-hijaiyah .hj-btn.green {
  background: var(--hj-mint);
  color: #fff;
  box-shadow: 0 6px 0 #2f8a56;
}

#screen-hijaiyah .hj-btn.green:active {
  box-shadow: 0 2px 0 #2f8a56;
}

#screen-hijaiyah .hj-btn.ghost {
  background: rgba(253, 246, 227, 0.15);
  color: var(--hj-cream);
  box-shadow: none;
}

#screen-hijaiyah .hj-btn.outline {
  background: transparent;
  color: var(--hj-teal-600);
  box-shadow: none;
  border: 2px solid var(--hj-teal-600);
}

#screen-hijaiyah .hj-btn.outline:active {
  transform: translateY(2px);
}

/* ---------- QUIZ STAGE ---------- */
#hj-screen-quiz {
  width: min(100%, 760px);
  margin-inline: auto;
  gap: 14px;
  justify-content: center;
}

#screen-hijaiyah .options-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  align-content: center;
}

#screen-hijaiyah .option-btn {
  aspect-ratio: 1/1;
  max-height: 150px;
  background: var(--hj-cream);
  border-radius: 20px;
  font-family: "Noto Naskh Arabic", serif;
  font-size: 46px;
  color: var(--hj-ink);
  box-shadow: 0 6px 0 var(--hj-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.08s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}

#screen-hijaiyah .option-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--hj-shadow);
}

#screen-hijaiyah .option-btn.correct {
  background: var(--hj-mint);
  color: #fff;
  box-shadow: 0 6px 0 #2f8a56;
}

#screen-hijaiyah .option-btn.wrong {
  background: var(--hj-coral);
  color: #fff;
  box-shadow: 0 6px 0 #c23b1b;
}

#screen-hijaiyah .option-btn:disabled {
  cursor: default;
}

/* ---------- MATCH STAGE ---------- */
#hj-screen-match {
  gap: 14px;
}

#screen-hijaiyah .match-header {
  text-align: center;
  color: var(--hj-cream);
}

#screen-hijaiyah .match-header h2 {
  font-size: 19px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}

#screen-hijaiyah .match-header p {
  margin: 4px 0 0;
  font-size: 13px;
  opacity: 0.9;
}

#screen-hijaiyah .progress-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 8px;
}

#screen-hijaiyah .progress-dots span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(253, 246, 227, 0.25);
}

#screen-hijaiyah .progress-dots span.filled {
  background: var(--hj-gold);
}

#screen-hijaiyah .card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  perspective: 800px;
}

#screen-hijaiyah .hj-card {
  aspect-ratio: 3/4;
  cursor: pointer;
}

#screen-hijaiyah .hj-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

#screen-hijaiyah .hj-card.flipped .hj-card-inner {
  transform: rotateY(180deg);
}

#screen-hijaiyah .hj-card.matched .hj-card-inner {
  transform: rotateY(180deg) scale(0.96);
}

#screen-hijaiyah .hj-card.matched {
  cursor: default;
}

#screen-hijaiyah .hj-card-face {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  box-shadow: 0 6px 0 rgba(10, 46, 48, 0.3);
}

#screen-hijaiyah .hj-card-front {
  background: var(--hj-teal-600);
  color: var(--hj-gold);
  font-size: 24px;
}

#screen-hijaiyah .hj-card-back {
  background: var(--hj-cream);
  transform: rotateY(180deg);
  flex-direction: column;
  color: var(--hj-ink);
}

#screen-hijaiyah .hj-card-back .ar {
  font-family: "Noto Naskh Arabic", serif;
  font-size: 32px;
  line-height: 1;
}

#screen-hijaiyah .hj-card-back .latin {
  font-family: "Baloo 2", sans-serif;
  font-size: 14px;
  font-weight: 600;
  margin-top: 4px;
  color: var(--hj-teal-700);
}

#screen-hijaiyah .hj-card.matched .hj-card-back {
  background: var(--hj-mint);
  color: #fff;
}

#screen-hijaiyah .hj-card.matched .hj-card-back .latin {
  color: #fff;
}

/* ---------- RACE STAGE ---------- */
#hj-screen-race {
  gap: 12px;
}

#screen-hijaiyah .race-header {
  color: var(--hj-cream);
  text-align: center;
}
#screen-hijaiyah .race-header h2 {
  font-size: 18px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}

#screen-hijaiyah .hj-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(253, 246, 227, 0.12);
  border-radius: 16px;
  padding: 8px 12px;
}

#screen-hijaiyah .hj-hud .hj-hearts {
  font-size: 16px;
  letter-spacing: 2px;
}

#screen-hijaiyah .round-count {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--hj-ink);
  background: var(--hj-gold);
  padding: 4px 10px;
  border-radius: 999px;
}

#screen-hijaiyah .listen-box {
  background: var(--hj-cream);
  border-radius: 18px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 6px 0 var(--hj-shadow);
}

#screen-hijaiyah .listen-box .txt {
  flex: 1;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--hj-ink);
}

#screen-hijaiyah .listen-box .txt small {
  display: block;
  font-weight: 600;
  color: var(--hj-teal-700);
  font-size: 11.5px;
  margin-top: 2px;
}

#screen-hijaiyah .replay-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--hj-coral);
  color: #fff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 5px 0 #c23b1b;
  flex-shrink: 0;
  touch-action: manipulation;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

#screen-hijaiyah .replay-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c23b1b;
}

#screen-hijaiyah .replay-btn.speaking {
  animation: pulseSpeak 0.55s ease-in-out infinite;
}

@keyframes pulseSpeak {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.12);
  }
}

#screen-hijaiyah .audio-warning {
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.55;
  text-align: left;
  color: #7a2400;
  background: #ffe3d6;
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 8px;
  display: none;
}

#screen-hijaiyah .audio-warning strong {
  font-weight: 800;
}
#screen-hijaiyah .audio-warning.show {
  display: block;
}

#screen-hijaiyah .road-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  height: clamp(220px, 42vh, 340px);
  background: linear-gradient(180deg, rgba(10, 78, 77, 0.78), rgba(6, 52, 53, 0.86));
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 3px rgba(253, 246, 227, 0.35),
    0 8px 0 var(--hj-shadow);
}

#screen-hijaiyah .road-wrap::after {
  content: "Tangkap huruf yang kamu dengar";
  position: absolute;
  bottom: 7px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(253, 246, 227, 0.76);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  pointer-events: none;
}

#screen-hijaiyah .lane {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 33.333%;
  border-right: 2px dashed rgba(253, 246, 227, 0.28);
}

#screen-hijaiyah .lane:nth-child(1) {
  left: 0;
}
#screen-hijaiyah .lane:nth-child(2) {
  left: 33.333%;
}
#screen-hijaiyah .lane:nth-child(3) {
  left: 66.666%;
  border-right: none;
}

#screen-hijaiyah .tile {
  position: absolute;
  top: -90px;
  left: 50%;
  transform: translateX(-50%);
  width: 58px;
  height: 58px;
  background: var(--hj-cream);
  border: 3px solid var(--hj-gold);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Noto Naskh Arabic", serif;
  font-size: 30px;
  color: var(--hj-ink);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.25), 0 0 0 3px rgba(253, 246, 227, 0.16);
  z-index: 3;
}

#screen-hijaiyah .car {
  position: absolute;
  bottom: 14px;
  left: 16.666%;
  transform: translateX(-50%);
  font-size: 38px;
  transition: left 0.18s ease;
  filter: drop-shadow(0 6px 4px rgba(0, 0, 0, 0.35));
  z-index: 4;
}

#screen-hijaiyah .feedback-flash {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Baloo 2", sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  text-align: center;
  padding: 0 20px;
  z-index: 10;
}

#screen-hijaiyah .feedback-flash.show {
  opacity: 1;
}

#screen-hijaiyah .race-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
}

#screen-hijaiyah #hj-screen-race .race-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 11;
  width: auto;
  margin: 0;
  gap: 6px;
}

#screen-hijaiyah .lane-btn {
  flex: 0 0 56px;
  width: 56px;
  background: rgba(253, 246, 227, 0.18);
  color: var(--hj-cream);
  font-size: 22px;
  padding: 9px 0;
  border-radius: 12px;
}

#screen-hijaiyah #hj-screen-race .lane-btn {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 15px;
  background: rgba(10, 46, 48, 0.82);
  border: 1px solid rgba(253, 246, 227, 0.5);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
}

#screen-hijaiyah .lane-btn:active {
  background: rgba(253, 246, 227, 0.32);
}

#hj-screen-race .listen-box {
  width: min(100%, 600px);
  margin-left: auto;
  margin-right: auto;
  padding: 8px 12px;
}

#hj-screen-race .listen-box .txt {
  font-size: 12px;
}

#hj-screen-race .listen-box .txt small {
  font-size: 10px;
}

#hj-screen-race .hj-hud {
  width: min(100%, 600px);
  margin-left: auto;
  margin-right: auto;
  justify-content: flex-end;
  padding: 0;
  background: transparent;
}

/* ---------- RESULT ---------- */
#hj-screen-result {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
}

#screen-hijaiyah .hj-stars {
  font-size: 44px;
  letter-spacing: 6px;
  line-height: 1;
}

#screen-hijaiyah .result-card .hj-stars {
  margin: 0 0 12px;
}

#screen-hijaiyah .result-card {
  background: var(--hj-cream);
  color: var(--hj-ink);
  border-radius: 26px;
  padding: 26px 22px;
  width: 100%;
  box-shadow: 0 14px 0 var(--hj-shadow);
}

#screen-hijaiyah .result-card h2 {
  font-size: 22px;
  margin-bottom: 6px;
}

#screen-hijaiyah .result-stats {
  display: flex;
  gap: 10px;
  margin: 16px 0 20px;
}

#screen-hijaiyah .result-stats .stat {
  flex: 1;
  background: #fff;
  border-radius: 14px;
  padding: 12px 6px;
}

#screen-hijaiyah .result-stats .stat .num {
  font-family: "Baloo 2", sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--hj-gold-deep);
}

#screen-hijaiyah .result-stats .stat .lbl {
  font-size: 11px;
  font-weight: 700;
  color: var(--hj-teal-700);
  margin-top: 2px;
}

#screen-hijaiyah .result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#screen-hijaiyah .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* Responsive layout: wider game board on desktop, compact touch layout on mobile. */
@media (min-width: 700px) {
  #screen-hijaiyah .stage {
    max-width: none;
    padding: 18px 28px calc(24px + env(safe-area-inset-bottom, 0px));
  }

  #screen-hijaiyah .hj-topbar {
    flex-wrap: nowrap;
  }

  #screen-hijaiyah .hj-brand {
    flex: 1;
    font-size: 17px;
  }

  #screen-hijaiyah .hj-path {
    flex-shrink: 0;
  }

  #screen-hijaiyah .intro-card {
    max-width: 680px;
    padding: clamp(24px, 3vw, 36px) clamp(26px, 4vw, 48px) clamp(22px, 3vw, 32px);
  }

  #screen-hijaiyah .intro-card h1 {
    font-size: clamp(24px, 3vw, 34px);
  }

  #screen-hijaiyah .intro-card p {
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
  }

  #screen-hijaiyah .options-grid {
    flex: 0 1 auto;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    width: 100%;
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
  }

  #hj-screen-quiz .listen-box {
    width: 100%;
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
  }

  #screen-hijaiyah .option-btn {
    max-height: 190px;
  }

  #screen-hijaiyah .card-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
    max-width: 960px;
    width: 100%;
    margin: auto;
  }

  #screen-hijaiyah .road-wrap {
    height: clamp(240px, 42vh, 360px);
  }

  #screen-hijaiyah .result-card {
    max-width: 800px;
    padding: 30px 32px;
  }

  #screen-hijaiyah .result-actions {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
  }
}

/* ---------- Tablet Landscape & Layar Tinggi (iPad / Layar Tinggi > 700px) ---------- */
@media (min-width: 700px) and (min-height: 700px) {
  #screen-hijaiyah .stage {
    padding: 24px 36px calc(32px + env(safe-area-inset-bottom, 0px));
  }

  #screen-hijaiyah .hj-topbar {
    margin-bottom: 24px;
  }

  #screen-hijaiyah .hj-brand {
    font-size: 20px;
  }

  #screen-hijaiyah .hj-path .pill {
    font-size: 13px;
    padding: 6px 14px;
  }

  /* Quiz Stage: Terpusat seimbang di tengah pemandangan gurun */
  #hj-screen-quiz {
    justify-content: center !important;
    width: min(100%, 880px);
    margin: auto;
    gap: clamp(18px, 2.8vh, 32px);
  }

  #screen-hijaiyah .match-header {
    margin-bottom: 6px;
  }

  #screen-hijaiyah .match-header h2 {
    font-size: clamp(24px, 2.6vw, 32px);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }

  #screen-hijaiyah .match-header p {
    font-size: clamp(14px, 1.5vw, 17px);
    margin-top: 6px;
  }

  #screen-hijaiyah .progress-dots {
    margin-top: 10px;
    gap: 8px;
  }

  #screen-hijaiyah .progress-dots span {
    width: 12px;
    height: 12px;
  }

  #hj-screen-quiz .listen-box {
    width: 100%;
    max-width: 880px;
    padding: 16px 24px;
    border-radius: 20px;
    box-shadow: 0 8px 0 var(--hj-shadow);
  }

  #screen-hijaiyah .listen-box .txt {
    font-size: 16px;
  }

  #screen-hijaiyah .listen-box .txt small {
    font-size: 13px;
    margin-top: 4px;
  }

  #screen-hijaiyah .replay-btn {
    width: 52px;
    height: 52px;
    font-size: 24px;
    border-radius: 14px;
  }

  #screen-hijaiyah .options-grid {
    flex: 0 1 auto;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(16px, 1.8vw, 24px);
    width: 100%;
    max-width: 880px;
    margin: 0 auto;
  }

  #screen-hijaiyah .option-btn {
    aspect-ratio: 1 / 1;
    max-height: 190px;
    min-height: 140px;
    font-size: clamp(52px, 5.5vw, 70px);
    border-radius: 24px;
    box-shadow: 0 8px 0 var(--hj-shadow);
  }

  /* Match Stage (Memory Game) */
  #hj-screen-match {
    justify-content: center !important;
    width: min(100%, 880px);
    margin: auto;
    gap: 20px;
  }

  #screen-hijaiyah .card-grid {
    max-width: 880px;
    gap: 14px;
  }

  #screen-hijaiyah .hj-card-back .ar {
    font-size: 42px;
  }

  #screen-hijaiyah .hj-card-back .latin {
    font-size: 16px;
  }

  /* Race Stage (Unta) */
  #hj-screen-race {
    justify-content: center !important;
    width: min(100%, 880px);
    margin: auto;
    gap: 20px;
  }

  #screen-hijaiyah .road-wrap {
    height: clamp(280px, 38vh, 420px);
    max-width: 880px;
  }
}

/* Centre the level title where there is enough room for the progress path. */
@media (min-width: 1000px) {
  #screen-hijaiyah .hj-topbar {
    position: relative;
  }

  #screen-hijaiyah .hj-brand {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }

  #screen-hijaiyah .hj-path {
    margin-left: auto;
  }
}

/* Keep the quiz stacked on short desktop windows without overlapping. */
@media (min-width: 700px) and (max-height: 600px) {
  #hj-screen-quiz {
    justify-content: center;
    gap: 8px;
  }

  #screen-hijaiyah .match-header h2 {
    font-size: 18px;
  }

  #screen-hijaiyah .match-header p {
    margin-top: 2px;
    font-size: 12px;
  }

  #screen-hijaiyah .progress-dots {
    margin-top: 5px;
  }

  #hj-screen-quiz .listen-box {
    padding: 8px 12px;
  }

  #screen-hijaiyah .options-grid {
    flex: 0 1 auto;
    width: min(100%, 480px);
    max-width: 480px;
    gap: 10px;
  }

  #screen-hijaiyah .option-btn {
    max-height: 112px;
  }

  #hj-screen-match {
    gap: 6px;
  }

  #screen-hijaiyah .card-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    width: min(100%, 570px);
    max-width: 570px;
    gap: 6px;
    margin: 0 auto;
  }

  #screen-hijaiyah .hj-card {
    aspect-ratio: 1 / 1;
  }

  /* Compact race and result layouts for short desktop windows. */
  #hj-screen-race {
    gap: 7px;
  }

  #screen-hijaiyah .race-header h2 {
    font-size: 18px;
  }

  #screen-hijaiyah .hj-hud,
  #hj-screen-race .listen-box {
    width: min(100%, 640px);
    margin-left: auto;
    margin-right: auto;
  }

  #screen-hijaiyah .hj-hud,
  #hj-screen-race .listen-box {
    padding: 7px 10px;
  }

  #hj-screen-race .replay-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  #screen-hijaiyah .road-wrap {
    flex: 1;
    width: min(100%, 760px);
    min-height: 180px;
    height: auto;
    margin: 0 auto;
  }

  #screen-hijaiyah .tile {
    width: 44px;
    height: 44px;
    font-size: 25px;
  }

  #screen-hijaiyah .car {
    bottom: 8px;
    font-size: 30px;
  }

  #screen-hijaiyah .race-controls {
    width: min(100%, 420px);
    margin: 0 auto;
    gap: 8px;
  }

  #screen-hijaiyah .lane-btn {
    padding: 7px 0;
    font-size: 18px;
  }

  #hj-screen-result {
    gap: 0;
  }

  #screen-hijaiyah .result-card {
    max-width: 680px;
    padding: 16px 24px;
    border-radius: 22px;
  }

  #screen-hijaiyah .result-card .hj-stars {
    font-size: 34px;
    margin-bottom: 7px;
  }

  #screen-hijaiyah .result-card h2 {
    font-size: 20px;
    margin-bottom: 3px;
  }

  #screen-hijaiyah .result-stats {
    margin: 10px 0 12px;
  }

  #screen-hijaiyah .result-stats .stat {
    padding: 8px 5px;
  }

  #screen-hijaiyah .result-actions {
    gap: 7px;
  }

  #screen-hijaiyah .result-actions .hj-btn {
    padding: 8px 16px;
    font-size: 14px;
  }
}

@media (max-width: 699px) {
  #screen-hijaiyah .stage {
    max-width: 560px;
    padding: 12px 12px calc(18px + env(safe-area-inset-bottom, 0px));
  }

  #screen-hijaiyah .hj-topbar {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
  }

  #screen-hijaiyah .hj-brand {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #screen-hijaiyah .hj-path {
    grid-column: 1 / -1;
    justify-content: center;
    width: 100%;
  }

  #screen-hijaiyah .intro-art {
    font-size: clamp(42px, 13vw, 60px);
  }

  #screen-hijaiyah .intro-card {
    padding: clamp(18px, 5vw, 28px) clamp(14px, 4vw, 22px) 18px;
  }

  #screen-hijaiyah .intro-card h1 {
    font-size: clamp(21px, 6vw, 28px);
  }

  #screen-hijaiyah .intro-card p {
    font-size: clamp(13px, 3.5vw, 14.5px);
  }

  #screen-hijaiyah .steps-mini {
    gap: 7px;
  }

  #screen-hijaiyah .steps-mini .step {
    min-width: 0;
    padding: 9px 5px;
    font-size: clamp(10px, 2.8vw, 12px);
  }

  #screen-hijaiyah .options-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
    align-content: center;
  }

  #screen-hijaiyah .option-btn {
    max-height: none;
    font-size: clamp(34px, 11vw, 46px);
    border-radius: 16px;
  }

  #screen-hijaiyah .card-grid {
    gap: 8px;
  }

  #screen-hijaiyah .hj-card-face {
    border-radius: 11px;
  }

  #screen-hijaiyah .hj-card-back .ar {
    font-size: clamp(24px, 8vw, 32px);
  }

  #screen-hijaiyah .hj-card-back .latin {
    font-size: clamp(11px, 3vw, 14px);
  }

  #screen-hijaiyah .listen-box {
    padding: 10px 11px;
    gap: 8px;
  }

  #screen-hijaiyah .listen-box .txt {
    font-size: clamp(12px, 3.3vw, 13.5px);
  }

  #screen-hijaiyah .replay-btn {
    width: 44px;
    height: 44px;
  }

  #screen-hijaiyah .road-wrap {
    height: clamp(150px, 34vh, 280px);
  }

  #screen-hijaiyah .result-card {
    max-width: 440px;
    padding: 22px 16px;
    border-radius: 20px;
    box-shadow: 0 10px 0 var(--hj-shadow);
  }

  #screen-hijaiyah .result-card .hj-stars {
    font-size: clamp(34px, 11vw, 42px);
    letter-spacing: 4px;
    margin-bottom: 10px;
  }

  #screen-hijaiyah .result-card h2 {
    font-size: clamp(20px, 6vw, 24px);
    line-height: 1.2;
  }

  #screen-hijaiyah .result-card p {
    line-height: 1.45;
  }

  #screen-hijaiyah .result-actions {
    gap: 8px;
  }

  #screen-hijaiyah .result-stats {
    gap: 7px;
    margin: 14px 0 18px;
  }

  #screen-hijaiyah .result-stats .stat {
    padding: 10px 4px;
  }

  #screen-hijaiyah .result-stats .stat .num {
    font-size: clamp(18px, 6vw, 22px);
  }
}

@media (max-width: 699px) and (orientation: landscape) {
  #screen-hijaiyah .stage {
    padding-top: 8px;
    padding-bottom: 10px;
  }

  #screen-hijaiyah .hj-topbar {
    margin-bottom: 6px;
  }

  #screen-hijaiyah .intro-art {
    font-size: 34px;
  }

  #screen-hijaiyah .intro-card {
    padding: 10px 14px 8px;
  }

  #screen-hijaiyah .intro-card h1 {
    font-size: 19px;
  }

  #screen-hijaiyah .intro-card p {
    font-size: 11px;
    line-height: 1.3;
    margin-bottom: 7px;
  }

  #screen-hijaiyah .steps-mini {
    margin-bottom: 8px;
  }

  #screen-hijaiyah .steps-mini .step {
    padding: 4px 3px;
    font-size: 9px;
  }

  #screen-hijaiyah .steps-mini .step .emoji {
    font-size: 16px;
    margin-bottom: 2px;
  }

  #screen-hijaiyah #hj-audio-status {
    margin-top: 3px !important;
    font-size: 10px !important;
  }

  #screen-hijaiyah .hj-btn {
    padding: 7px 12px;
    font-size: 14px;
  }

  #screen-hijaiyah .road-wrap {
    height: clamp(130px, 30vh, 220px);
  }

  #hj-screen-match {
    gap: 6px;
  }

  #screen-hijaiyah .card-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    width: min(100%, 570px);
    max-width: 570px;
    gap: 6px;
    margin: 0 auto;
  }

  #screen-hijaiyah .hj-card {
    aspect-ratio: 1 / 1;
  }
}

@media (max-width: 380px) {
  #screen-hijaiyah .stage {
    padding-left: 9px;
    padding-right: 9px;
  }

  #screen-hijaiyah .steps-mini {
    gap: 4px;
  }

  #screen-hijaiyah .steps-mini .step {
    padding-left: 3px;
    padding-right: 3px;
    font-size: 9px;
  }

  #screen-hijaiyah .hj-path {
    padding-left: 5px;
    padding-right: 5px;
  }
}

@media (max-width: 360px) {
  #screen-hijaiyah .hj-card-back .ar {
    font-size: 28px;
  }
  #screen-hijaiyah .tile {
    width: 50px;
    height: 50px;
    font-size: 26px;
  }
}

@media (max-height: 600px) {
  #screen-hijaiyah .hj-btn {
    padding: 6px 12px;
    font-size: 14px;
  }
  #screen-hijaiyah .intro-card {
    padding: 10px 14px 8px;
  }
  #screen-hijaiyah .intro-card h1 {
    font-size: 18px;
  }
  #screen-hijaiyah .intro-card p {
    font-size: 11px;
    margin-bottom: 6px;
  }
  #screen-hijaiyah .steps-mini {
    margin-bottom: 7px;
  }
  #screen-hijaiyah .steps-mini .step {
    padding: 4px 3px;
    font-size: 9px;
  }
  #screen-hijaiyah #hj-audio-status {
    margin-top: 3px !important;
    font-size: 10px !important;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  #screen-hijaiyah .stage {
    padding-top: 6px !important;
    padding-bottom: 8px !important;
    max-width: 640px !important;
  }
  #screen-hijaiyah .hj-topbar {
    margin-bottom: 4px !important;
  }
  #screen-hijaiyah .hj-quit-btn {
    width: 38px !important;
    height: 38px !important;
    flex: 0 0 38px !important;
  }
  #hj-screen-quiz {
    gap: 6px !important;
    justify-content: flex-start !important;
  }
  #screen-hijaiyah .match-header {
    margin-bottom: 0 !important;
  }
  #screen-hijaiyah .match-header h2 {
    font-size: 15px !important;
  }
  #screen-hijaiyah .match-header p {
    display: none !important;
  }
  #screen-hijaiyah .progress-dots {
    margin-top: 2px !important;
  }
  #hj-screen-quiz .listen-box {
    padding: 6px 14px !important;
    border-radius: 12px !important;
    width: 100% !important;
  }
  #screen-hijaiyah .replay-btn {
    width: 36px !important;
    height: 36px !important;
    font-size: 16px !important;
  }
  #screen-hijaiyah .options-grid {
    gap: 8px !important;
    width: 100% !important;
    max-width: 480px !important;
    margin: 0 auto !important;
  }
  #screen-hijaiyah .option-btn {
    height: 70px !important;
    max-height: 70px !important;
    font-size: 32px !important;
    border-radius: 14px !important;
  }
}

