:root {
  color-scheme: light;
  --ink: #173042;
  --muted: #5d7484;
  --paper: #fffaf0;
  --glass: rgba(255, 255, 255, 0.68);
  --glass-strong: rgba(255, 255, 255, 0.82);
  --line: rgba(255, 255, 255, 0.58);
  --green: #48b96b;
  --deep-green: #1d8051;
  --blue: #3b9be9;
  --water: #49c6dc;
  --yellow: #ffd15f;
  --orange: #ff9851;
  --pink: #ef6fa8;
  --purple: #8d6be8;
  --danger: #ef5d5d;
  --shadow: 0 22px 60px rgba(40, 66, 78, 0.24);
  --small-shadow: 0 12px 28px rgba(40, 66, 78, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  color: var(--ink);
  font-family: 'Nunito', 'Segoe UI', Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    radial-gradient(circle at 15% 12%, rgba(255, 209, 95, 0.55), transparent 22rem),
    radial-gradient(circle at 83% 8%, rgba(73, 198, 220, 0.42), transparent 26rem),
    linear-gradient(180deg, #9ee7f2 0%, #d8f5dc 52%, #ffe8b7 100%);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  overflow: hidden;
  padding: 24px;
}

.screen.active {
  display: block;
  animation: fadeIn 0.35s ease both;
}

.centered-screen,
.loading-screen,
.result-screen,
.menu-screen {
  place-items: center;
}

.centered-screen.active,
.loading-screen.active,
.result-screen.active,
.menu-screen.active {
  display: grid;
}

.glass {
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.25);
}

.panel {
  width: min(980px, 100%);
  border-radius: 28px;
  padding: 28px;
}

.wide-panel {
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--deep-green);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.04;
  letter-spacing: 0;
}

h1 {
  max-width: 760px;
  font-size: clamp(2.4rem, 7vw, 5.3rem);
}

h2 {
  font-size: clamp(2rem, 5vw, 3.2rem);
}

p {
  color: var(--muted);
  line-height: 1.6;
}

.lead {
  max-width: 640px;
  margin: 18px 0 26px;
  font-size: 1.05rem;
}

.btn,
.icon-btn {
  display: inline-grid;
  place-items: center;
  min-height: 48px;
  cursor: pointer;
  border-radius: 16px;
  color: var(--ink);
  font-weight: 800;
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.btn {
  width: 100%;
  padding: 15px 18px;
  gap: 8px;
}

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

.btn:active,
.icon-btn:active {
  transform: translateY(0) scale(0.98);
}

.primary {
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  box-shadow: 0 12px 24px rgba(255, 152, 81, 0.26);
}

.ghost {
  background: rgba(255, 255, 255, 0.44);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.icon-btn {
  width: 52px;
  height: 52px;
  background: rgba(255, 255, 255, 0.58);
}

.loading-island {
  position: absolute;
  width: min(58vw, 540px);
  aspect-ratio: 1.6;
  border-radius: 50%;
  background: linear-gradient(180deg, #65c970 0 48%, #e7bd6e 49% 100%);
  transform: translateY(-130px);
  filter: drop-shadow(0 28px 35px rgba(42, 93, 86, 0.28));
  animation: floatIsland 3s ease-in-out infinite;
}

.loading-tree {
  position: absolute;
  left: 47%;
  top: 2%;
  width: 42px;
  height: 90px;
  border-radius: 20px;
  background: #9a653c;
}

.loading-tree::before {
  content: "";
  position: absolute;
  left: -44px;
  top: -42px;
  width: 128px;
  height: 96px;
  border-radius: 50%;
  background: #239e58;
}

.loading-water {
  position: absolute;
  inset: auto 10% -22% 10%;
  height: 16px;
  border-radius: 999px;
  background: rgba(73, 198, 220, 0.75);
  animation: waterMove 1.2s ease-in-out infinite alternate;
}

.loading-panel {
  position: relative;
  text-align: center;
  margin-top: 180px;
  max-width: 650px;
}

.loading-bar {
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 48, 66, 0.1);
}

.loading-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--water), var(--yellow));
  transition: width 0.25s ease;
}

.menu-scene {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.menu-island {
  position: absolute;
  right: -8vw;
  bottom: -10vh;
  width: min(52vw, 640px);
  aspect-ratio: 1.22;
  border-radius: 48% 52% 45% 55%;
  background:
    radial-gradient(circle at 40% 26%, #5ec670 0 12%, transparent 13%),
    radial-gradient(circle at 68% 42%, #3fab68 0 10%, transparent 11%),
    linear-gradient(160deg, #77d36f 0 55%, #e3bd75 56% 100%);
  box-shadow: var(--shadow);
}

.menu-panel {
  position: relative;
  margin-right: min(22vw, 260px);
}

.menu-actions {
  display: grid;
  width: min(390px, 100%);
  gap: 12px;
}

.save-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: min(390px, 100%);
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.36);
}

.save-row strong {
  font-size: 1.5rem;
}

.cloud {
  position: absolute;
  width: 150px;
  height: 54px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 38px -20px 0 rgba(255, 255, 255, 0.72), 78px 0 0 rgba(255, 255, 255, 0.68);
  animation: cloudDrift 28s linear infinite;
}

.cloud-a {
  top: 12%;
  left: 8%;
}

.cloud-b {
  top: 22%;
  right: 18%;
  animation-duration: 36s;
}

.bird {
  position: absolute;
  width: 34px;
  height: 16px;
  border-top: 4px solid #315f72;
  border-radius: 50%;
  animation: birdFly 11s linear infinite;
}

.bird::after {
  content: "";
  position: absolute;
  left: 14px;
  width: 34px;
  height: 16px;
  border-top: 4px solid #315f72;
  border-radius: 50%;
}

.bird-a {
  top: 18%;
  left: 22%;
}

.bird-b {
  top: 34%;
  left: 58%;
  animation-duration: 15s;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.character-grid,
.inventory-grid,
.achievement-grid,
.area-grid,
.result-grid {
  display: grid;
  gap: 16px;
}

.character-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.character-card,
.inventory-grid article,
.achievement-card,
.area-card {
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.42);
  box-shadow: var(--small-shadow);
}

.character-card {
  display: grid;
  gap: 10px;
  min-height: 290px;
  padding: 18px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}

.character-card::after {
  content: "";
  position: absolute;
  inset: auto -18px -34px auto;
  width: 115px;
  height: 115px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.26);
}

.character-card.selected {
  outline: 4px solid rgba(255, 209, 95, 0.8);
  transform: translateY(-4px);
}

.character-preview {
  display: block;
  width: 100%;
  min-height: 180px;
  border-radius: 20px;
  background: #eee;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 -20px 35px rgba(23, 48, 66, 0.12);
}

.character-preview i {
  position: absolute;
  right: 16px;
  top: 14px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  font-style: normal;
  font-size: 1.45rem;
  box-shadow: var(--small-shadow);
}

.character-preview::before,
.character-preview::after {
  content: "";
  position: absolute;
}

.character-preview::before {
  left: 50%;
  top: 18%;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: #ffd4a8;
  transform: translateX(-50%);
  box-shadow: inset 0 -8px 0 rgba(120, 75, 42, 0.12);
}

.character-preview.avatar-raka::before {
  box-shadow: inset 0 13px 0 #2f6ad9, inset 0 -8px 0 rgba(120, 75, 42, 0.12);
}

.character-preview.avatar-sari::before {
  box-shadow: inset 0 13px 0 #5b376f, inset 0 -8px 0 rgba(120, 75, 42, 0.12);
}

.character-preview.avatar-bayu::before {
  box-shadow: inset 0 13px 0 #1f805a, inset 0 -8px 0 rgba(120, 75, 42, 0.12);
}

.character-preview::after {
  left: 50%;
  bottom: 16%;
  width: 96px;
  height: 92px;
  border-radius: 44px 44px 22px 22px;
  transform: translateX(-50%);
}

.avatar-raka {
  background: linear-gradient(160deg, #ffe083, #ff9851);
}

.avatar-raka::after {
  background: #3b9be9;
}

.avatar-sari {
  background: linear-gradient(160deg, #ffc2dd, #8d6be8);
}

.avatar-sari::after {
  background: #ef6fa8;
}

.avatar-bayu {
  background: linear-gradient(160deg, #96f1d1, #49c6dc);
}

.avatar-bayu::after {
  background: #48b96b;
}

.world-screen {
  padding: 14px;
}

.hud-top {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto 52px;
  gap: 14px;
  align-items: center;
  height: 78px;
  padding: 12px 14px;
  border-radius: 24px;
}

.brand-mini {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand-mini small {
  display: block;
  color: var(--muted);
}

.mini-logo {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--green), var(--yellow));
  box-shadow: var(--small-shadow);
}

.hud-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hud-stats span {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.44);
  color: var(--muted);
}

.hud-stats strong {
  color: var(--ink);
}

.world-viewport {
  position: relative;
  height: calc(100vh - 106px);
  margin-top: 14px;
  overflow: hidden;
  border-radius: 30px;
  box-shadow: var(--shadow);
  background: var(--water);
}

.world-map {
  position: absolute;
  left: 0;
  top: 0;
  width: 2400px;
  height: 1600px;
  transform-origin: 0 0;
  overflow: hidden;
  border-radius: 34px;
  background:
    radial-gradient(ellipse at 18% 82%, rgba(20, 110, 45, 0.40), transparent 22%),
    radial-gradient(ellipse at 72% 15%, rgba(25, 140, 60, 0.30), transparent 28%),
    radial-gradient(ellipse at 45% 50%, rgba(255, 255, 255, 0.08), transparent 30%),
    #72e067;
}

.terrain,
#objectLayer,
#particleLayer {
  position: absolute;
  inset: 0;
}

.terrain-grass {
  background:
    radial-gradient(ellipse at 15% 80%, rgba(22, 120, 50, 0.38), transparent 18%),
    radial-gradient(ellipse at 68% 18%, rgba(28, 148, 65, 0.30), transparent 22%),
    radial-gradient(ellipse at 42% 52%, rgba(255, 255, 255, 0.10), transparent 28%),
    radial-gradient(ellipse at 8% 38%, rgba(30, 145, 62, 0.24), transparent 20%),
    radial-gradient(ellipse at 88% 70%, rgba(18, 118, 44, 0.22), transparent 24%),
    linear-gradient(148deg, #82e872 0%, #55d878 35%, #46c96e 65%, #88ea7c 100%);
}

.terrain-water {
  clip-path: path("M 1420 0 C 1350 310 1480 510 1310 730 C 1150 940 1210 1150 1390 1600 L 2400 1600 L 2400 0 Z");
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.11) 0 28px, transparent 28px 62px),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.055) 0 20px, transparent 20px 52px),
    linear-gradient(175deg, #38d8f0 0%, #1aa5dc 45%, #0e7bbf 100%);
  animation: waterFlow 6s linear infinite;
}

.terrain-sand {
  clip-path: polygon(68% 0, 76% 0, 77% 15%, 73% 30%, 74% 52%, 69% 75%, 73% 90%, 71% 100%, 63% 100%, 59% 78%, 63% 58%, 59% 36%, 61% 14%);
  background: linear-gradient(180deg, #ffe8a0 0%, #f4d06a 55%, #e8b848 100%);
  opacity: 0.92;
}

.terrain-path {
  clip-path: path("M 150 1288 C 430 1150 620 1150 835 985 C 1060 810 975 615 1240 490 C 1480 370 1630 480 1840 310");
  border: 52px solid rgba(178, 118, 60, 0.55);
  filter: blur(1.5px);
}

.terrain-mountain {
  clip-path: polygon(0 0, 36% 0, 28% 22%, 17% 29%, 7% 21%);
  background: linear-gradient(148deg, #b0c4cc 0%, #7e98a8 55%, #5e7888 100%);
}

.terrain-mountain::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(5% 0, 23% 0, 20% 9%, 14% 13%, 5% 9%);
  background: rgba(255, 255, 255, 0.62);
}

.world-cloud {
  opacity: 0.48;
  z-index: 1;
}

.cloud-c {
  left: 6%;
  top: 8%;
}

.cloud-d {
  right: 20%;
  top: 14%;
  animation-duration: 38s;
}

.bird-c {
  z-index: 8;
  left: 35%;
  top: 12%;
}

.map-object {
  position: absolute;
  display: grid;
  place-items: center;
  width: 86px;
  min-height: 86px;
  border-radius: 22px;
  color: var(--ink);
  text-align: center;
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1.15;
  user-select: none;
  transform: translate(-50%, -50%);
}

.npc {
  background: transparent;
  z-index: 15;
}

.npc .npc-body {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, rgba(255,255,255,0.95), rgba(230,240,255,0.85));
  border: 3px solid rgba(255,255,255,0.92);
  box-shadow:
    0 10px 32px rgba(0,0,0,0.24),
    0 0 0 5px rgba(255,255,255,0.22),
    inset 0 -4px 0 rgba(0,0,0,0.09);
  position: relative;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: pointer;
  overflow: visible;
}

.npc:hover .npc-body {
  transform: scale(1.15) translateY(-6px);
}

.npc-icon {
  font-size: 2.4rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.18));
}

/* ── Color-coded NPC circles by subject ── */
.npc-math .npc-body, .npc-geometry .npc-body, .npc-scale .npc-body {
  background: linear-gradient(145deg, #c8e6ff, #68b8ff);
  border-color: #a0d4ff;
  box-shadow: 0 10px 32px rgba(59,155,233,0.32), 0 0 0 5px rgba(107,184,255,0.2), inset 0 -4px 0 rgba(0,0,0,0.09);
}

.npc-money .npc-body, .npc-fraction .npc-body {
  background: linear-gradient(145deg, #fff3a8, #ffd038);
  border-color: #ffe080;
  box-shadow: 0 10px 32px rgba(255,180,40,0.32), 0 0 0 5px rgba(255,218,80,0.22), inset 0 -4px 0 rgba(0,0,0,0.09);
}

.npc-science .npc-body, .npc-ecosystem .npc-body, .npc-adaptation .npc-body {
  background: linear-gradient(145deg, #b8f5c8, #48dc78);
  border-color: #88eaaa;
  box-shadow: 0 10px 32px rgba(72,185,107,0.32), 0 0 0 5px rgba(100,220,130,0.22), inset 0 -4px 0 rgba(0,0,0,0.09);
}

.npc-language .npc-body, .npc-sentence .npc-body, .npc-proverb .npc-body, .npc-synonym .npc-body {
  background: linear-gradient(145deg, #f8c0f0, #e868d8);
  border-color: #f0a0e0;
  box-shadow: 0 10px 32px rgba(239,111,168,0.32), 0 0 0 5px rgba(240,160,228,0.22), inset 0 -4px 0 rgba(0,0,0,0.09);
}

.npc-space .npc-body, .npc-watercycle .npc-body, .npc-energy .npc-body {
  background: linear-gradient(145deg, #a8eeff, #30c8f8);
  border-color: #78e0ff;
  box-shadow: 0 10px 32px rgba(73,198,220,0.32), 0 0 0 5px rgba(110,220,248,0.22), inset 0 -4px 0 rgba(0,0,0,0.09);
}

.npc-culture .npc-body, .npc-houseculture .npc-body, .npc-history .npc-body {
  background: linear-gradient(145deg, #ffd0a0, #ff8848);
  border-color: #ffb878;
  box-shadow: 0 10px 32px rgba(255,152,81,0.32), 0 0 0 5px rgba(255,180,120,0.22), inset 0 -4px 0 rgba(0,0,0,0.09);
}

.npc-collect .npc-body, .npc-civics .npc-body {
  background: linear-gradient(145deg, #ffb0c0, #ff5070);
  border-color: #ff90a8;
  box-shadow: 0 10px 32px rgba(239,93,93,0.32), 0 0 0 5px rgba(255,140,160,0.22), inset 0 -4px 0 rgba(0,0,0,0.09);
}

.npc::before {
  content: "!";
  position: absolute;
  top: -42px;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffd15f, #ff9851);
  box-shadow: 0 4px 14px rgba(255, 152, 81, 0.55);
  font-weight: 900;
  font-size: 1rem;
  color: white;
  animation: bounce 1.1s ease-in-out infinite;
  z-index: 1;
}

.label-bubble {
  position: absolute;
  top: 90px;
  width: 150px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
  box-shadow:
    0 4px 18px rgba(0, 0, 0, 0.14),
    0 0 0 1.5px rgba(255, 255, 255, 0.8);
  font-size: 0.74rem;
  font-weight: 800;
  text-align: center;
  line-height: 1.45;
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 25;
}

.npc.show .label-bubble {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.label-bubble strong {
  display: block;
  font-size: 0.77rem;
  font-weight: 900;
  margin-bottom: 1px;
}

.label-bubble small {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
}

.npc-collect .npc-body {
  background: linear-gradient(180deg, #ffd4a8 0 30%, #ef6fa8 31% 40%, #ffffff 41% 80%, #ef6fa8 81% 100%);
}
.collectible {
  width: 46px;
  min-height: 46px;
  border-radius: 50%;
  box-shadow: var(--small-shadow);
  animation: collectibleFloat 1.8s ease-in-out infinite;
  font-size: 1.35rem;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.45);
}

.collectible.coin {
  background: radial-gradient(circle at 35% 28%, #fff5a8, var(--yellow) 48%, #e59d2f);
}

.collectible.gem {
  border-radius: 14px;
  rotate: 45deg;
  background: linear-gradient(135deg, #c3f8ff, #48c9e6, #2b6ee8);
}

.collectible.book {
  border-radius: 10px;
  background: linear-gradient(90deg, #ef6fa8 0 22%, #fff4da 23% 100%);
}

.tree {
  width: 100px;
  height: 118px;
  background: transparent;
  box-shadow: none;
  z-index: 5;
}

/* Trunk */
.tree::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 52px;
  background: linear-gradient(90deg, #6b4226 0%, #8b5a33 30%, #a87848 70%, #5c3418 100%);
  border-radius: 8px 8px 4px 4px;
  box-shadow: 
    inset -4px 0 8px rgba(0,0,0,0.3),
    0 4px 10px rgba(0,0,0,0.3);
}

/* Fluffy Canopy Layers */
.tree::before {
  content: "";
  position: absolute;
  top: -10px;
  left: -20px;
  width: 140px;
  height: 95px;
  border-radius: 50px 50px 40px 40px;
  background: 
    radial-gradient(circle at 35% 25%, #62e88e 0%, #35c060 40%, #18883a 80%, #0d5420 100%);
  box-shadow:
    inset -12px -15px 0 rgba(0,0,0,0.15),
    inset 12px 10px 0 rgba(255,255,255,0.25),
    0 12px 25px rgba(12, 60, 25, 0.4);
  animation: treeSway 3.5s ease-in-out infinite alternate;
}

.rock {
  width: 90px;
  height: 65px;
  border-radius: 60% 40% 50% 50% / 70% 60% 40% 30%;
  background: 
    radial-gradient(circle at 30% 20%, #d1e2e8 0%, #a8bcc4 30%, #688294 70%, #455a68 100%);
  box-shadow:
    0 8px 15px rgba(0,0,0,0.25),
    inset -8px -6px 12px rgba(0,0,0,0.3),
    inset 8px 6px 12px rgba(255,255,255,0.4);
}

.house {
  width: 130px;
  height: 100px;
  border-radius: 12px;
  background: linear-gradient(135deg, #fff7d6 0%, #ffe373 50%, #e6b822 100%);
  box-shadow:
    0 15px 35px rgba(0,0,0,0.25),
    inset -5px -5px 15px rgba(180, 110, 0, 0.15),
    inset 5px 5px 15px rgba(255,255,255,0.8);
  z-index: 4;
}

/* Premium Roof */
.house::before {
  content: "";
  position: absolute;
  top: -55px;
  left: -20px;
  width: 170px;
  height: 80px;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: 
    radial-gradient(circle at 50% 100%, #e85b38 0%, #c42d14 60%, #8a1905 100%);
  filter: drop-shadow(0 8px 6px rgba(0,0,0,0.3));
}

/* Door with Depth */
.house::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 58px;
  background: linear-gradient(180deg, #5c3016 0%, #301708 100%);
  border-radius: 20px 20px 0 0;
  box-shadow: 
    inset -4px 0 6px rgba(0,0,0,0.4), 
    inset 4px 0 4px rgba(255,255,255,0.1),
    0 0 0 4px #8c5a35; /* Door frame */
}

.player {
  position: absolute;
  z-index: 20;
  width: 50px;
  height: 60px;
  transform: translate(-50%, -50%);
  transition: filter 0.15s ease;
}

.player-head,
.player-body,
.player-shadow {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.player-head {
  top: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff0d6 0%, #ffd4a8 50%, #e0ac78 100%);
  box-shadow: 
    0 4px 10px rgba(0, 0, 0, 0.15),
    inset -4px -4px 8px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 5;
  animation: floatHead 2s ease-in-out infinite alternate;
}

.player-body {
  bottom: 8px;
  width: 40px;
  height: 25px;
  border-radius: 20px 20px 10px 10px;
  background: linear-gradient(135deg, #4bc0ff 0%, #3b9be9 50%, #1e6ea8 100%);
  position: relative;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  z-index: 4;
}

.player-shadow {
  bottom: -4px;
  width: 40px;
  height: 10px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
  filter: blur(2px);
  animation: shadowPulse 2s ease-in-out infinite alternate;
}

@keyframes floatHead {
  0% { transform: translateX(-50%) translateY(0); }
  100% { transform: translateX(-50%) translateY(-2px); }
}

@keyframes shadowPulse {
  0% { transform: translateX(-50%) scale(1); opacity: 0.8; }
  100% { transform: translateX(-50%) scale(1.1); opacity: 0.5; }
}

/* Character Eyes & Face details */
.player-eyes {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 3;
}

.eye {
  width: 7px;
  height: 7px;
  background: #173042;
  border-radius: 50%;
  position: relative;
  animation: eyeBlink 4s infinite;
}

@keyframes eyeBlink {
  0%, 90%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

.player-blush {
  position: absolute;
  top: 25px;
  left: 50%;
  width: 38px;
  height: 6px;
  transform: translateX(-50%);
  display: flex;
  justify-content: space-between;
  z-index: 2;
  opacity: 0.6;
}

.player-blush::before,
.player-blush::after {
  content: "";
  width: 6px;
  height: 6px;
  background: #ef6fa8;
  border-radius: 50%;
  filter: blur(0.5px);
}

.player-mouth {
  position: absolute;
  top: 24px;
  left: 50%;
  width: 8px;
  height: 4px;
  border-bottom: 2px solid #173042;
  border-radius: 0 0 8px 8px;
  transform: translateX(-50%);
  z-index: 3;
}

/* HAIR & ACCESSORIES DEFINITIONS */
.avatar-raka .player-hair {
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  height: 15px;
  background: #624a2e;
  border-radius: 20px 20px 0 0;
  clip-path: polygon(0% 100%, 15% 40%, 30% 90%, 45% 20%, 60% 85%, 75% 30%, 90% 90%, 100% 100%);
}

.avatar-raka .player-cap {
  position: absolute;
  top: -8px;
  left: 5px;
  width: 32px;
  height: 16px;
  background: #2f6ad9;
  border-radius: 20px 20px 4px 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.avatar-raka .player-cap::before {
  content: "";
  position: absolute;
  bottom: 0;
  right: -10px;
  width: 16px;
  height: 6px;
  background: #174cb5;
  border-radius: 0 6px 6px 0;
}

.avatar-raka .player-shirt {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, #3b9be9, #2578c2);
  box-shadow: inset 0 6px 0 rgba(255, 255, 255, 0.2);
}

/* Sari Styling */
.avatar-sari .player-hair {
  position: absolute;
  top: -5px;
  left: -4px;
  right: -4px;
  height: 22px;
  background: #291c30;
  border-radius: 20px 20px 0 0;
}

.avatar-sari .player-hair::before,
.avatar-sari .player-hair::after {
  content: "";
  position: absolute;
  top: -8px;
  width: 14px;
  height: 14px;
  background: #291c30;
  border-radius: 50%;
  box-shadow: 0 2px 0 #ef6fa8;
}

.avatar-sari .player-hair::before { left: 2px; }
.avatar-sari .player-hair::after { right: 2px; }

.avatar-sari .player-shirt {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, #ef6fa8, #c93e79);
  box-shadow: inset 0 6px 0 rgba(255, 255, 255, 0.2);
}

/* Bayu Styling */
.avatar-bayu .player-hair {
  position: absolute;
  top: -6px;
  left: -2px;
  right: -2px;
  height: 18px;
  background: #3c2a1a;
  border-radius: 20px 20px 10px 10px;
  clip-path: radial-gradient(circle, transparent 20%, #3c2a1a 21%);
  background-size: 8px 8px;
}

.avatar-bayu .player-cap {
  position: absolute;
  top: 14px;
  left: 5px;
  right: 5px;
  height: 12px;
  z-index: 4;
  display: flex;
  justify-content: space-between;
}

.avatar-bayu .player-cap::before,
.avatar-bayu .player-cap::after {
  content: "";
  width: 13px;
  height: 13px;
  border: 2px solid #5d7484;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  box-sizing: border-box;
}

.avatar-bayu .player-shirt {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, #48b96b, #1d8051);
  box-shadow: inset 0 6px 0 rgba(255, 255, 255, 0.2);
}

/* Emote styling */
.player-emote {
  position: absolute;
  top: -45px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: 2px solid var(--purple);
  padding: 6px 8px;
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  font-size: 1.25rem;
  line-height: 1;
  white-space: nowrap;
  animation: emoteFloat 1.2s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

.player-emote::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: white;
  border-right: 2px solid var(--purple);
  border-bottom: 2px solid var(--purple);
}

.player-emote.hidden {
  display: none;
}

@keyframes emoteFloat {
  0% { transform: translateX(-50%) translateY(15px) scale(0.3); opacity: 0; }
  15% { transform: translateX(-50%) translateY(0) scale(1.1); opacity: 1; }
  25% { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
  85% { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
  100% { transform: translateX(-50%) translateY(-15px) scale(0.8); opacity: 0; }
}

/* Walking and celebration states */
.player.walk .player-body {
  animation: walkBob 0.34s ease-in-out infinite;
}

.player.run {
  filter: drop-shadow(0 0 14px rgba(255, 209, 95, 0.9));
}

.player.celebrate .player-head {
  animation: celebrate 0.5s ease-in-out 4;
}

.quest-panel {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 30;
  width: min(380px, calc(100% - 36px));
  padding: 16px;
  border-radius: 22px;
}

.quest-panel small,
.inventory-grid small,
.result-grid span {
  color: var(--muted);
  font-weight: 800;
}

.quest-panel strong {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
}

.quest-panel p {
  margin: 8px 0 12px;
  font-size: 0.92rem;
}

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

.heart {
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, #ff6b7d, #ff9f7d);
  clip-path: polygon(50% 18%, 62% 4%, 82% 4%, 96% 20%, 96% 43%, 78% 68%, 50% 94%, 22% 68%, 4% 43%, 4% 20%, 18% 4%, 38% 4%);
}

.quick-nav {
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 30;
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: 22px;
}

.nav-icon::before,
.nav-icon::after {
  content: "";
  position: absolute;
}

.nav-icon {
  position: relative;
}

.bag-icon::before {
  width: 23px;
  height: 20px;
  border: 4px solid var(--ink);
  border-radius: 5px;
  transform: translateY(4px);
}

.bag-icon::after {
  width: 16px;
  height: 10px;
  border: 4px solid var(--ink);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  transform: translateY(-9px);
}

.star-icon::before {
  width: 28px;
  height: 28px;
  background: var(--ink);
  clip-path: polygon(50% 0, 62% 34%, 98% 35%, 69% 56%, 80% 92%, 50% 70%, 20% 92%, 31% 56%, 2% 35%, 38% 34%);
}

.map-icon::before {
  width: 30px;
  height: 24px;
  border-radius: 4px;
  background: linear-gradient(90deg, transparent 31%, rgba(255, 255, 255, 0.48) 32% 36%, transparent 37% 64%, rgba(255, 255, 255, 0.48) 65% 69%, transparent 70%), var(--ink);
  transform: skewY(-7deg);
}

.joystick-base {
  position: absolute;
  right: 24px;
  bottom: 24px;
  z-index: 32;
  display: none;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  /* Multi-layer premium glass look */
  background:
    radial-gradient(circle at 38% 38%, rgba(255,255,255,0.5), rgba(255,255,255,0.12) 60%),
    rgba(20, 30, 48, 0.55);
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  box-shadow:
    0 0 0 6px rgba(255, 255, 255, 0.08),
    0 8px 40px rgba(0, 0, 0, 0.40),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(12px);
  touch-action: none;
  user-select: none;
}

/* Crosshair guide lines */
.joystick-base::before,
.joystick-base::after {
  content: "";
  position: absolute;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.18);
  pointer-events: none;
}

.joystick-base::before {
  left: 50%;
  top: 12px;
  bottom: 12px;
  width: 2px;
  transform: translateX(-50%);
}

.joystick-base::after {
  top: 50%;
  left: 12px;
  right: 12px;
  height: 2px;
  transform: translateY(-50%);
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #ffffff, #a8c4e6 60%, #4a90d9);
  border: 2px solid rgba(255, 255, 255, 0.6);
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.35),
    0 0 12px rgba(73, 144, 217, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transform: translate(-50%, -50%);
  cursor: grab;
  touch-action: none;
  transition: transform 0.12s ease-out, box-shadow 0.12s ease;
}

.joystick-knob:active {
  background: radial-gradient(circle at 35% 30%, #dde8f5, #3a78c9);
  box-shadow:
    0 3px 10px rgba(0, 0, 0, 0.3),
    0 0 20px rgba(73, 144, 217, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  cursor: grabbing;
}

.mobile-run-btn {
  position: absolute;
  right: 24px;
  bottom: 180px;
  z-index: 32;
  display: none;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 38%, rgba(255,255,255,0.45), rgba(255,255,255,0.1) 60%),
    rgba(20, 30, 48, 0.55);
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.08),
    0 6px 24px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(12px);
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, background 0.18s, box-shadow 0.18s;
  color: white;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.mobile-run-btn.active {
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  border-color: rgba(255, 200, 80, 0.7);
  transform: scale(1.12);
  box-shadow:
    0 0 0 6px rgba(255, 200, 80, 0.2),
    0 6px 24px rgba(255, 152, 81, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.click-marker {
  position: absolute;
  width: 32px;
  height: 16px;
  border: 3px solid var(--yellow);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: clickPulse 0.8s ease-out infinite;
  pointer-events: none;
  z-index: 15;
}

.click-marker.hidden {
  display: none;
}

@keyframes clickPulse {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.8); opacity: 0; }
}

.inventory-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.inventory-grid article {
  display: grid;
  gap: 10px;
  min-height: 170px;
  padding: 20px;
}

.inventory-grid strong {
  font-size: 2rem;
}

.item-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
}

.item-icon.coin {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fff5a8, var(--yellow) 48%, #e59d2f);
}

.item-icon.gem {
  rotate: 45deg;
  background: linear-gradient(135deg, #c3f8ff, #48c9e6, #2b6ee8);
}

.item-icon.book {
  background: linear-gradient(90deg, #ef6fa8 0 22%, #fff4da 23% 100%);
}

.item-icon.badge {
  clip-path: polygon(50% 0, 93% 25%, 88% 75%, 50% 100%, 12% 75%, 7% 25%);
  background: linear-gradient(135deg, var(--yellow), var(--orange));
}

.achievement-grid,
.area-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.achievement-card,
.area-card {
  min-height: 154px;
  padding: 18px;
}

.achievement-card.locked {
  filter: grayscale(0.85);
  opacity: 0.62;
}

.achievement-card strong,
.area-card strong {
  display: block;
  margin-bottom: 8px;
}

.area-card.unlocked {
  outline: 3px solid rgba(72, 185, 107, 0.45);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 45, 55, 0.42);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(720px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border-radius: 28px;
  padding: 26px;
  animation: zoomIn 0.22s ease both;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.reward-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.reward-row span {
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.48);
  color: var(--muted);
  font-weight: 800;
}

.mini-content {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.mini-stage {
  min-height: 210px;
  padding: 18px;
  overflow: hidden;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.4);
}

.mini-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 150px;
  border-radius: 20px;
  background:
    radial-gradient(circle at 28% 24%, rgba(255, 255, 255, 0.5), transparent 35%),
    rgba(255, 255, 255, 0.38);
  font-size: clamp(2rem, 8vw, 4rem);
}

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

.bridge-stage {
  display: grid;
  align-items: end;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
  height: 180px;
}

.block {
  border-radius: 10px 10px 4px 4px;
  background: linear-gradient(180deg, #d99a58, #9e6134);
  animation: riseIn 0.36s ease both;
}

.plant-stage {
  position: relative;
  height: 210px;
  background: linear-gradient(180deg, #8edff4, #d3f7ff 48%, #8a613f 49%);
}

.sun {
  position: absolute;
  right: 22px;
  top: 18px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 26px rgba(255, 209, 95, 0.8);
}

.sprout {
  position: absolute;
  left: 50%;
  bottom: 38px;
  width: 14px;
  height: 72px;
  border-radius: 999px;
  background: #269a59;
}

.sprout::before,
.sprout::after {
  content: "";
  position: absolute;
  top: 20px;
  width: 48px;
  height: 28px;
  border-radius: 50%;
  background: #40bd66;
}

.sprout::before {
  right: 8px;
  transform: rotate(-24deg);
}

.sprout::after {
  left: 8px;
  transform: rotate(24deg);
}

.word-drop {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}

.drop-slot,
.letter-tile {
  display: grid;
  place-items: center;
  height: 58px;
  border-radius: 16px;
  font-size: 1.35rem;
  font-weight: 900;
}

.drop-slot {
  border: 2px dashed rgba(23, 48, 66, 0.35);
  background: rgba(255, 255, 255, 0.35);
}

.letter-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.letter-tile {
  width: 58px;
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  cursor: grab;
  touch-action: manipulation;
}

.letter-tile.selected {
  outline: 4px solid rgba(59, 155, 233, 0.55);
  transform: translateY(-3px);
}

.letter-tile.used {
  opacity: 0.35;
  pointer-events: none;
}

.culture-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.culture-card {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.48);
  font-weight: 800;
  cursor: pointer;
}

.culture-card.selected {
  outline: 3px solid var(--yellow);
}

.toast-layer {
  position: fixed;
  right: 18px;
  top: 96px;
  z-index: 150;
  display: grid;
  gap: 10px;
}

.toast {
  width: min(360px, calc(100vw - 36px));
  padding: 14px 16px;
  border-radius: 18px;
  background: var(--glass-strong);
  box-shadow: var(--small-shadow);
  animation: slideIn 0.24s ease both;
}

.sparkle,
.confetti {
  position: absolute;
  z-index: 70;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  pointer-events: none;
  animation: sparkleFly 0.9s ease forwards;
}

.confetti {
  border-radius: 3px;
  animation-duration: 1.3s;
}

.result-panel {
  max-width: 620px;
  text-align: center;
}

.result-grid {
  grid-template-columns: repeat(3, 1fr);
  margin: 22px 0;
}

.result-grid span {
  display: grid;
  gap: 6px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.42);
}

.result-grid strong {
  color: var(--ink);
  font-size: 1.6rem;
}

.confetti-field::before,
.confetti-field::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle, var(--yellow) 0 5px, transparent 6px),
    radial-gradient(circle, var(--pink) 0 4px, transparent 5px),
    radial-gradient(circle, var(--water) 0 4px, transparent 5px);
  background-position: 12% 16%, 70% 12%, 44% 34%;
  background-size: 220px 240px;
  animation: confettiFall 4s linear infinite;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes zoomIn {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

.click-marker {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 20;
}

.pulse-marker {
  animation: pulseMarkerAnim 0.6s ease-out forwards;
}

@keyframes pulseMarkerAnim {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; border-width: 5px; }
  100% { transform: translate(-50%, -50%) scale(2); opacity: 0; border-width: 1px; }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes floatIsland {
  0%, 100% { transform: translateY(-130px); }
  50% { transform: translateY(-146px); }
}

@keyframes waterMove {
  from { transform: scaleX(0.9); }
  to { transform: scaleX(1.05); }
}

@keyframes cloudDrift {
  from { transform: translateX(0); }
  to { transform: translateX(-80px); }
}

@keyframes birdFly {
  0% { transform: translateX(-30px) translateY(0); }
  50% { transform: translateX(90px) translateY(-18px); }
  100% { transform: translateX(180px) translateY(0); }
}

@keyframes waterFlow {
  from { background-position: 0 0, 0 0; }
  to { background-position: 90px 90px, 0 0; }
}

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

@keyframes collectibleFloat {
  0%, 100% { translate: 0 -4px; }
  50% { translate: 0 8px; }
}

@keyframes walkBob {
  0%, 100% { transform: translateX(-50%) translateY(0) rotate(-2deg); }
  50% { transform: translateX(-50%) translateY(-4px) rotate(2deg); }
}

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

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

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

@keyframes sparkleFly {
  0% { opacity: 1; transform: translateY(0) scale(0.3) rotate(0); }
  100% { opacity: 0; transform: translateY(-130px) scale(1.1) rotate(240deg); }
}

@keyframes confettiFall {
  from { transform: translateY(-20%); }
  to { transform: translateY(100%); }
}

@media (max-width: 980px) {
  .screen {
    padding: 14px;
  }

  .menu-panel {
    margin-right: 0;
  }

  .menu-island {
    opacity: 0.38;
  }

  .character-grid,
  .achievement-grid,
  .area-grid {
    grid-template-columns: 1fr;
  }

  .inventory-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud-top {
    grid-template-columns: 1fr 52px;
    height: auto;
  }

  .hud-stats {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .joystick-base {
    display: block;
  }

  .mobile-run-btn {
    display: flex;
  }

  .quick-nav {
    right: 12px;
    top: 12px;
  }
}

/* Show joystick whenever device supports touch, regardless of screen width */
body.has-touch .joystick-base {
  display: block;
}

body.has-touch .mobile-run-btn {
  display: flex;
}

@media (max-width: 640px) {
  body {
    position: fixed;
    inset: 0;
  }

  .screen {
    padding: 10px;
  }

  .panel {
    padding: 16px;
    border-radius: 24px;
  }

  h1 {
    font-size: 2.55rem;
  }

  .loading-panel {
    margin-top: 125px;
  }

  .menu-panel {
    align-self: end;
    margin-bottom: 8px;
  }

  .lead {
    margin: 12px 0 16px;
    font-size: 0.95rem;
  }

  .menu-actions {
    gap: 9px;
  }

  .btn,
  .icon-btn {
    min-height: 50px;
  }

  .character-card {
    grid-template-columns: 104px 1fr;
    min-height: 128px;
    align-items: center;
  }

  .character-preview {
    min-height: 100px;
    grid-row: span 2;
  }

  .character-preview::before {
    width: 44px;
    height: 44px;
  }

  .character-preview::after {
    width: 66px;
    height: 60px;
  }

  .character-preview i {
    width: 34px;
    height: 34px;
    font-size: 1.05rem;
    right: 8px;
    top: 8px;
  }

  .inventory-grid,
  .choice-grid,
  .culture-grid,
  .result-grid,
  .modal-actions {
    grid-template-columns: 1fr;
  }

  .hud-stats span {
    padding: 8px 9px;
    font-size: 0.8rem;
  }

  .world-screen {
    padding: 8px;
  }

  .hud-top {
    gap: 8px;
    padding: 8px;
    border-radius: 20px;
  }

  .brand-mini strong {
    font-size: 0.92rem;
  }

  .brand-mini small {
    font-size: 0.78rem;
  }

  .mini-logo {
    width: 42px;
    height: 42px;
  }

  .world-viewport {
    height: calc(100dvh - 124px);
    margin-top: 8px;
    border-radius: 22px;
  }

  .quest-panel {
    bottom: 12px;
    left: 12px;
    width: min(285px, calc(100% - 150px));
    min-width: 165px;
    padding: 12px;
  }

  .quest-panel p {
    display: none;
  }

  .toast-layer {
    top: 76px;
  }

  .quick-nav {
    padding: 8px;
    gap: 7px;
  }

  .quick-nav .icon-btn {
    width: 46px;
    height: 46px;
  }

  .joystick-base {
    width: 120px;
    height: 120px;
    right: 12px;
    bottom: 12px;
  }

  .joystick-knob {
    width: 50px;
    height: 50px;
  }

  .mobile-run-btn {
    right: 12px;
    bottom: 148px;
    width: 52px;
    height: 52px;
    font-size: 1.4rem;
  }

  .modal {
    padding: 10px;
    align-items: end;
  }

  .modal-card {
    max-height: 88dvh;
    padding: 18px;
    border-radius: 24px;
  }

  .mini-stage {
    min-height: 150px;
    padding: 12px;
  }

  .word-drop {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .drop-slot,
  .letter-tile {
    height: 50px;
    border-radius: 14px;
  }

  .letter-tile {
    width: 50px;
  }
}

/* Ambient Animations & Extras */
.butterfly {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--pink);
  border-radius: 50%;
  box-shadow: 10px 0 0 var(--pink);
  z-index: 10;
  pointer-events: none;
  animation: flutter 4s ease-in-out infinite alternate;
}

@keyframes flutter {
  0% { transform: translate(0, 0) rotate(0deg) scale(0.8); }
  50% { transform: translate(60px, -40px) rotate(45deg) scale(1.1); }
  100% { transform: translate(120px, 10px) rotate(-30deg) scale(0.9); }
}

.wave-line {
  position: absolute;
  right: 120px;
  bottom: 0;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  border: 4px dashed rgba(255, 255, 255, 0.25);
  pointer-events: none;
  z-index: 1;
  animation: waveWash 8s ease-in-out infinite alternate;
}

@keyframes waveWash {
  0% { transform: scale(0.95) translate(10px, 10px); opacity: 0.3; }
  100% { transform: scale(1.05) translate(-10px, -10px); opacity: 0.6; }
}

.terrain-grass::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0 1px, transparent 2px);
  background-size: 80px 80px;
  opacity: 0.25;
  pointer-events: none;
}

/* Geometry and Fraction custom visuals */
.geometry-visual-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
}

.visual-shape {
  border: 3px solid var(--ink);
  background: linear-gradient(135deg, var(--water), var(--blue));
  border-radius: 12px;
  position: relative;
  box-shadow: var(--small-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

.visual-shape span {
  position: absolute;
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--ink);
  background: white;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--ink);
}

.dim-top {
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
}

.dim-left {
  left: -28px;
  top: 50%;
  transform: translateY(-50%);
}

.fraction-visual-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.fraction-label {
  font-weight: 800;
  font-size: 1.15rem;
  background: rgba(255, 255, 255, 0.6);
  padding: 4px 10px;
  border-radius: 8px;
}

.explanation-text {
  font-size: 0.9rem;
  background: rgba(72, 185, 107, 0.15);
  border-left: 4px solid var(--green);
  padding: 8px 12px;
  border-radius: 0 8px 8px 0;
  margin-top: 10px;
  color: var(--deep-green);
}

.answer-button.correct {
  background: rgba(72, 185, 107, 0.25) !important;
  border: 2px solid var(--green) !important;
  color: var(--deep-green) !important;
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(72, 185, 107, 0.2);
}

.answer-button.wrong {
  background: rgba(239, 93, 93, 0.25) !important;
  border: 2px solid var(--danger) !important;
  color: var(--danger) !important;
}

.glass { background: rgba(255,255,255,0.7); backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.4); }
.panel { padding: 24px; border-radius: 24px; box-shadow: 0 16px 40px rgba(0,0,0,0.15); }
.quest-panel { position: absolute; left: 24px; top: 110px; width: 300px; padding: 20px; z-index: 50; border-radius: 20px; }
