:root {
  --brand: #0f8f4f;
  --brand-deep: #075b36;
  --cream: #fff8e8;
  --gold: #ffb31a;
  --red: #e53935;
  --mint: #eaf3e4;
  --ink: #173b27;
  --shadow: 0 14px 28px rgba(7, 91, 54, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
  color: var(--ink);
  background: #d7ead0;
}

body {
  display: flex;
  justify-content: center;
}

button {
  font: inherit;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  position: relative;
  width: min(100vw, 430px);
  min-height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(234, 243, 228, 0.2), rgba(15, 143, 79, 0.18)),
    url("./assets/art/game_background.png") center / cover no-repeat,
    #eaf3e4;
  box-shadow: 0 0 0 1px rgba(7, 91, 54, 0.14), 0 22px 70px rgba(0, 0, 0, 0.22);
}

.screen {
  display: none;
  min-height: 100dvh;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}

.screen.is-active {
  display: flex;
  flex-direction: column;
}

.brand-row,
.top-actions,
.game-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-mark {
  color: var(--brand-deep);
  line-height: 1;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
}

.brand-mark strong {
  display: block;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-mark span,
.brand-mini {
  font-size: 11px;
  font-weight: 800;
}

.halal-badge,
.icon-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: var(--brand-deep);
  background: rgba(255, 248, 232, 0.82);
  border: 2px solid rgba(7, 91, 54, 0.28);
  box-shadow: var(--shadow);
  font-weight: 900;
}

.icon-button {
  font-size: 24px;
}

.hero-title,
.level-head {
  margin-top: 12px;
  text-align: center;
}

.league-ribbon,
.card-ribbon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 5px 18px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(180deg, #119f58, #08643a);
  box-shadow: 0 5px 0 #064a2e, 0 12px 24px rgba(7, 91, 54, 0.24);
  font-weight: 900;
}

.hero-title h1 {
  margin: 10px 0 4px;
  font-size: clamp(44px, 15vw, 66px);
  line-height: 0.95;
  font-weight: 1000;
  letter-spacing: 0;
  color: #fff9df;
  text-shadow:
    0 5px 0 #0b6e40,
    0 9px 0 #f6a313,
    0 13px 18px rgba(7, 91, 54, 0.45);
  -webkit-text-stroke: 2px var(--brand-deep);
}

.hero-title p,
.level-head p {
  margin: 8px auto 0;
  width: min(100%, 360px);
  padding: 8px 12px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(180deg, #14a75f, #086039);
  box-shadow: 0 5px 0 #064a2e;
  font-size: 15px;
  font-weight: 900;
}

.home-stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 10px;
  margin-top: 12px;
}

.home-visual {
  position: relative;
  width: min(100%, 380px);
  margin: 8px auto 0;
  overflow: hidden;
  border-radius: 26px;
  border: 4px solid rgba(255, 248, 232, 0.86);
  background: rgba(255, 248, 232, 0.18);
  box-shadow: var(--shadow);
}

.home-visual img {
  display: block;
  width: 100%;
  height: clamp(180px, 28dvh, 260px);
  object-fit: cover;
  object-position: center 56%;
}

.mascot-wrap,
.intro-mascot {
  position: relative;
  min-height: 210px;
}

.mascot-wrap img,
.intro-mascot img {
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: min(210px, 54vw);
  transform: translateX(-50%);
  filter: drop-shadow(0 14px 16px rgba(7, 91, 54, 0.25));
}

.speech {
  position: absolute;
  z-index: 2;
  top: 4px;
  left: 0;
  max-width: 150px;
  padding: 12px 14px;
  border-radius: 24px;
  color: var(--brand-deep);
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid rgba(15, 143, 79, 0.26);
  box-shadow: var(--shadow);
  font-size: 15px;
  line-height: 1.35;
  font-weight: 900;
}

.preview-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 10px;
  border-radius: 28px;
  background: rgba(15, 143, 79, 0.88);
  border: 4px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
}

.preview-board img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 18px;
  background: #fff8e8;
  box-shadow: inset 0 0 0 2px rgba(255, 179, 26, 0.25);
}

.challenge-card,
.info-card,
.tip-card,
.reward-card,
.goal-card,
.modal-card {
  position: relative;
  border-radius: 28px;
  background: rgba(255, 248, 232, 0.92);
  border: 3px solid rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.challenge-card {
  margin-top: 8px;
  padding: 18px 12px 10px;
  text-align: center;
}

.card-ribbon {
  position: absolute;
  top: -18px;
  left: 50%;
  min-height: 30px;
  transform: translateX(-50%);
  font-size: 16px;
}

.challenge-card h2 {
  margin: 2px 0 2px;
  font-size: 22px;
  font-weight: 1000;
}

.challenge-card h2::first-letter {
  color: var(--gold);
}

.challenge-card p,
.tip-card p,
.reward-card p,
.modal-card p {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.45;
}

.benefit-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.benefit-list span,
.benefit-list button {
  padding: 6px 3px;
  border-radius: 12px;
  color: var(--brand-deep);
  background: #fff3c8;
  border: 1px solid rgba(255, 179, 26, 0.45);
  font-size: 11px;
  font-weight: 900;
}

.benefit-list button {
  min-width: 0;
  cursor: pointer;
}

.benefit-list button:active {
  transform: translateY(1px) scale(0.98);
}

.primary-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: min(100%, 330px);
  min-height: 56px;
  margin: 10px auto 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(180deg, #ffd667 0%, #ff9d19 55%, #ee7d00 100%);
  border: 3px solid #fff2b8;
  box-shadow: 0 6px 0 #087143, 0 14px 24px rgba(7, 91, 54, 0.28);
  font-size: 24px;
  font-weight: 1000;
  text-shadow: 0 2px 0 rgba(194, 74, 0, 0.45);
}

.primary-button b {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #ff9d19;
  background: #fff;
  font-size: 20px;
  text-shadow: none;
}

.primary-button:active,
.tool-row button:active,
.icon-button:active {
  transform: translateY(2px) scale(0.98);
}

.pulse {
  animation: pulse 1.9s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.08);
    box-shadow: 0 8px 0 #087143, 0 0 26px rgba(255, 179, 26, 0.85);
  }
}

.level-map {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.level-node {
  display: grid;
  gap: 2px;
  justify-items: center;
  padding: 4px 3px 6px;
  border-radius: 16px;
  color: var(--brand-deep);
  background: rgba(234, 243, 228, 0.72);
  border: 2px solid rgba(15, 143, 79, 0.22);
  font-weight: 900;
}

.level-node b {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(180deg, #14a75f, #075b36);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.65), 0 4px 0 #064a2e;
  font-size: 20px;
}

.level-node.is-current b {
  color: var(--brand-deep);
  background: linear-gradient(180deg, #ffe98d, var(--gold));
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.75), 0 5px 0 #b66a00;
}

.level-node.is-locked {
  cursor: not-allowed;
  filter: saturate(0.62) brightness(0.84);
}

.level-node.is-locked b {
  color: rgba(255, 248, 232, 0.92);
  background: linear-gradient(180deg, #7a9b88, #456454);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.35), 0 5px 0 #2c4438;
  font-size: 18px;
}

.level-node span {
  width: 100%;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-footer {
  margin-top: auto;
  padding: 8px 6px 0;
  color: #fff;
  text-align: center;
  font-size: 12px;
  font-weight: 900;
  text-shadow: 0 2px 5px rgba(7, 91, 54, 0.8);
}

.level-head {
  margin-top: 4px;
}

.level-number {
  display: inline-grid;
  place-items: center;
  min-width: 112px;
  min-height: 44px;
  margin-top: 9px;
  padding: 0 16px;
  border-radius: 999px;
  color: #fff6d2;
  background: linear-gradient(180deg, #e74b2c, #b92318);
  border: 3px solid #ffd895;
  box-shadow: 0 5px 0 #7b180f;
  font-size: 24px;
  font-weight: 1000;
}

.level-head h2 {
  margin: 10px 0 0;
  font-size: clamp(33px, 11vw, 48px);
  line-height: 1.05;
  color: #fff8dc;
  text-shadow: 0 4px 0 var(--brand-deep), 0 7px 14px rgba(7, 91, 54, 0.42);
  -webkit-text-stroke: 1.4px var(--brand-deep);
}

.intro-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 176px;
  align-items: end;
  gap: 8px;
  margin-top: 10px;
}

.intro-mascot {
  min-height: 196px;
}

.intro-mascot img {
  width: 210px;
}

.goal-card {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-height: 178px;
  padding: 24px 12px 12px;
  text-align: center;
}

.goal-card img {
  width: 72px;
  height: 72px;
}

.goal-card strong {
  font-size: 17px;
  line-height: 1.25;
}

.goal-card span {
  color: var(--brand-deep);
  font-size: 14px;
  font-weight: 900;
}

.info-card,
.tip-card,
.reward-card {
  margin-top: 12px;
  padding: 24px 16px 14px;
}

.info-grid {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px 12px;
  align-items: center;
}

.info-grid span {
  color: var(--brand);
  font-size: 14px;
  font-weight: 900;
}

.info-grid strong {
  min-width: 0;
  font-size: 16px;
}

.screen-game {
  gap: 10px;
}

.game-status {
  min-height: 52px;
}

.game-status > div {
  min-width: 0;
  color: #fff;
  text-align: center;
  text-shadow: 0 2px 5px rgba(7, 91, 54, 0.75);
}

.game-status span {
  display: block;
  font-size: 13px;
  font-weight: 900;
}

.game-status strong {
  display: block;
  max-width: 230px;
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.stats-row div {
  padding: 8px 4px;
  border-radius: 16px;
  color: var(--brand-deep);
  background: rgba(255, 248, 232, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.84);
  text-align: center;
  box-shadow: 0 7px 18px rgba(7, 91, 54, 0.16);
}

.stats-row span {
  display: block;
  font-size: 11px;
  font-weight: 900;
}

.stats-row strong {
  display: block;
  margin-top: 2px;
  font-size: 17px;
  font-weight: 1000;
}

.knowledge-strip {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 9px;
  min-height: 60px;
  padding: 8px 12px;
  border-radius: 18px;
  color: var(--brand-deep);
  background: rgba(255, 248, 232, 0.93);
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow);
}

.knowledge-strip img {
  width: 44px;
  height: 44px;
}

.knowledge-strip p {
  margin: 0;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.35;
}

.board-wrap {
  flex: 0 0 auto;
  min-height: 382px;
  padding: 8px;
  border-radius: 24px;
  background: rgba(6, 77, 45, 0.84);
  border: 4px solid rgba(255, 248, 232, 0.75);
  box-shadow: inset 0 0 0 2px rgba(255, 179, 26, 0.3), var(--shadow);
}

.tile-board {
  position: relative;
  --tile-size: clamp(45px, 13.6vw, 54px);
  min-height: 364px;
  height: clamp(364px, 48dvh, 430px);
}

.tile {
  position: absolute;
  display: grid;
  place-items: center;
  left: calc(var(--tile-x) * 1%);
  top: calc(var(--tile-y) * 1%);
  z-index: var(--tile-z);
  width: var(--tile-size);
  height: var(--tile-size);
  padding: 0;
  border-radius: 9px;
  background: #fff8e8;
  box-shadow:
    0 4px 0 rgba(69, 83, 42, 0.45),
    0 8px 12px rgba(0, 0, 0, 0.2),
    inset 0 0 0 2px rgba(255, 179, 26, 0.22);
  transform: rotate(var(--tile-tilt));
  transition: transform 0.16s ease, filter 0.16s ease, opacity 0.16s ease;
}

.tile img {
  width: 90%;
  height: 90%;
  object-fit: contain;
  pointer-events: none;
}

.tile.is-target {
  box-shadow: 0 5px 0 rgba(90, 84, 43, 0.38), 0 0 18px rgba(255, 179, 26, 0.9), inset 0 0 0 3px var(--gold);
}

.tile.is-hint {
  animation: hint 0.6s ease-in-out 3;
}

.tile.is-covered {
  filter: saturate(0.74) brightness(0.72);
  opacity: 0.86;
  cursor: not-allowed;
}

.tile.is-covered::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(135deg, rgba(7, 91, 54, 0.34), rgba(255, 248, 232, 0.05)),
    repeating-linear-gradient(45deg, rgba(7, 91, 54, 0.12) 0 4px, transparent 4px 9px);
  box-shadow: inset 0 0 0 2px rgba(7, 91, 54, 0.28);
}

.tile:active {
  transform: rotate(var(--tile-tilt)) scale(0.94);
}

@keyframes hint {
  50% {
    transform: translateY(-6px) rotate(var(--tile-tilt)) scale(1.05);
    filter: brightness(1.12);
  }
}

.slot-area {
  padding: 8px 10px 10px;
  border-radius: 22px;
  background: rgba(255, 248, 232, 0.95);
  border: 3px solid rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}

.slot-title {
  margin-bottom: 6px;
  color: var(--brand-deep);
  text-align: center;
  font-size: 13px;
  font-weight: 1000;
}

.slots {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.slot {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 13px;
  background: #f4e8c9;
  border: 2px dashed rgba(7, 91, 54, 0.22);
}

.slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.slots.is-shaking {
  animation: shake 0.32s ease-in-out;
}

@keyframes shake {
  25% {
    transform: translateX(-8px);
  }
  50% {
    transform: translateX(7px);
  }
  75% {
    transform: translateX(-4px);
  }
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.tool-row button {
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 7px 4px 8px;
  border-radius: 18px;
  color: var(--brand-deep);
  background: rgba(255, 248, 232, 0.94);
  border: 2px solid rgba(255, 255, 255, 0.86);
  box-shadow: 0 6px 16px rgba(7, 91, 54, 0.18);
  font-weight: 900;
}

.tool-row b {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(180deg, #15a65f, #075b36);
  font-size: 16px;
}

.tool-row span {
  font-size: 12px;
}

.result-modal {
  width: min(360px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  background: transparent;
}

.result-modal::backdrop {
  background: rgba(3, 45, 26, 0.6);
  backdrop-filter: blur(3px);
}

.modal-card {
  overflow: hidden;
  padding: 30px 18px 18px;
  text-align: center;
  transform: scale(0.94);
  animation: pop 0.22s ease forwards;
}

.modal-shine {
  position: absolute;
  inset: -45% 30% auto;
  height: 120px;
  transform: rotate(18deg);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.85), transparent);
  animation: shine 1.2s ease-in-out infinite;
}

@keyframes pop {
  to {
    transform: scale(1);
  }
}

@keyframes shine {
  0% {
    translate: -170% 0;
  }
  100% {
    translate: 170% 0;
  }
}

.modal-card h2 {
  position: relative;
  margin: 0 0 8px;
  color: var(--brand-deep);
  font-size: 30px;
  font-weight: 1000;
}

.modal-reward {
  margin-top: 12px;
  padding: 12px;
  border-radius: 16px;
  color: var(--brand-deep);
  background: #fff2c7;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.45;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.modal-actions button {
  min-height: 46px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(180deg, #15a65f, #075b36);
  box-shadow: 0 5px 0 #064a2e;
  font-size: 15px;
  font-weight: 1000;
}

.modal-actions button.is-gold {
  color: var(--brand-deep);
  background: linear-gradient(180deg, #ffe98d, var(--gold));
  box-shadow: 0 5px 0 #b66a00;
}

.music-toggle {
  position: fixed;
  right: max(14px, calc((100vw - 430px) / 2 + 14px));
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 18;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff8e8;
  background: linear-gradient(180deg, #14a75f, #075b36);
  border: 2px solid rgba(255, 248, 232, 0.8);
  box-shadow: 0 6px 0 #064a2e, 0 14px 24px rgba(7, 91, 54, 0.26);
  font-size: 22px;
  font-weight: 1000;
}

.music-toggle.is-muted {
  filter: saturate(0.5) brightness(0.82);
}

body[data-screen="game"] .music-toggle {
  top: calc(18px + env(safe-area-inset-top));
  right: max(72px, calc((100vw - 430px) / 2 + 72px));
  bottom: auto;
}

.training-modal {
  width: min(380px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  background: transparent;
}

.training-modal::backdrop {
  background: rgba(3, 45, 26, 0.62);
  backdrop-filter: blur(3px);
}

.training-card {
  padding: 28px 14px 16px;
}

.training-card > p {
  margin: 0 8px 12px;
  color: var(--brand-deep);
  font-size: 13px;
}

.training-close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  background: #0f8f4f;
  font-size: 24px;
  line-height: 1;
}

.training-grid {
  display: grid;
  gap: 8px;
  max-height: min(55dvh, 420px);
  overflow: auto;
  padding: 4px;
}

.training-item {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(255, 243, 200, 0.78);
  border: 1px solid rgba(15, 143, 79, 0.18);
  text-align: left;
}

.training-item img {
  width: 54px;
  height: 54px;
  object-fit: contain;
}

.training-item strong {
  display: block;
  color: var(--brand-deep);
  font-size: 14px;
  font-weight: 1000;
}

.training-item p {
  margin: 2px 0 0;
  font-size: 12px;
  line-height: 1.35;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 20;
  width: min(360px, calc(100vw - 34px));
  padding: 12px 16px;
  border-radius: 999px;
  color: #fff;
  background: rgba(7, 91, 54, 0.95);
  text-align: center;
  font-weight: 900;
  box-shadow: var(--shadow);
  transform: translate(-50%, 90px);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 370px) {
  .screen {
    padding-left: 12px;
    padding-right: 12px;
  }

  .hero-title h1 {
    font-size: 43px;
  }

  .home-stage,
  .intro-main {
    grid-template-columns: 1fr;
  }

  .preview-board {
    width: min(240px, 100%);
    margin: 0 auto;
  }

  .home-visual img {
    height: 255px;
  }

  .mascot-wrap,
  .intro-mascot {
    min-height: 180px;
  }

  .goal-card {
    min-height: 150px;
  }
}
