/* Penjaga Rimba — satu layar penuh: kanvas 3D pixel di belakang, HUD di tepi, kartu di tengah */
:root {
  --night: #070a16; --panel: rgba(10, 14, 30, .86); --card: #14182c; --line: #2c3558;
  --ink: #eef1ff; --muted: #a9b2d6; --firefly: #e6ff8a; --amber: #ffcf4a; --bark: #6b4a2e;
  --display: "Pixelify Sans", "Courier New", monospace;
  --body: "Nunito", "Trebuchet MS", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--night); color: var(--ink); font-family: var(--body); overflow: hidden; overscroll-behavior: none; }
#game { position: fixed; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#view { width: 100%; height: 100%; display: block; image-rendering: pixelated; background: var(--night); }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

/* HUD */
.hud { position: absolute; display: flex; gap: 8px; align-items: center; }
.tl { top: calc(10px + env(safe-area-inset-top, 0px)); left: max(12px, env(safe-area-inset-left, 0px)); }
.tr { top: calc(10px + env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-weight: 800; font-size: 15px; display: flex; gap: 6px; align-items: center; }
.chip b { font-family: var(--display); color: var(--amber); font-size: 17px; font-variant-numeric: tabular-nums; }
.chip.net.off { color: #ffb0a0; }
.hbtn { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-weight: 800; font-size: 15px; }
.actions { position: absolute; right: max(18px, calc(env(safe-area-inset-right, 0px) + 12px)); bottom: calc(22px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 14px; align-items: flex-end; }
.round { width: 92px; height: 92px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .25); font-family: var(--display); font-size: 32px; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; background: #7a2a24; }
.round small { font-family: var(--body); font-size: 12px; font-weight: 800; margin-top: 4px; opacity: .9; }
.round.mark { background: #8a5a14; width: 84px; height: 84px; font-size: 28px; }
.round.glow { box-shadow: 0 0 0 4px rgba(255, 207, 74, .5), 0 0 26px rgba(255, 207, 74, .75); border-color: var(--amber); animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.06); } }
.bag { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 6px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px 10px; }
.bag.static { position: static; transform: none; display: inline-flex; margin-bottom: 14px; }
.bag .lbl { font-size: 13px; color: var(--muted); font-weight: 800; margin-right: 2px; }
.slot { width: 42px; height: 42px; border-radius: 9px; border: 2px solid var(--amber); background: #3a3220; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.slot.w2 { width: 90px; }
.slot.empty { border-color: #3d4566; background: #141a30; }
.bubble { position: absolute; top: calc(64px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); max-width: min(560px, 80vw); background: #fffaf0; color: #1d1a14; border-radius: 14px; padding: 10px 16px; font-weight: 800; font-size: 18px; text-align: center; box-shadow: 0 6px 0 rgba(0, 0, 0, .25); }
.bubble small { display: block; margin-top: 4px; font-size: 15px; font-weight: 700; color: #6b5413; }
.bubble.hear { background: #dcecff; color: #0e1d33; }
.banner { position: absolute; top: calc(118px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); background: #5a2a24; border: 1px solid #a0483c; border-radius: 12px; padding: 8px 14px; font-weight: 800; font-size: 15px; }
.toast { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); width: min(520px, 86vw); background: var(--panel); border: 2px solid var(--firefly); border-radius: 18px; padding: 16px 20px; text-align: center; pointer-events: none; }
.toast.stay { pointer-events: auto; }
.toast .ok { margin-top: 12px; padding: 10px 26px; font-size: 18px; }
.toast h3 { font-family: var(--display); color: var(--firefly); font-size: 26px; margin: 0 0 6px; }
.toast p { margin: 0; font-size: 17px; line-height: 1.45; }
.stick { position: absolute; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .28); background: rgba(255, 255, 255, .05); pointer-events: none; }
.knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(255, 255, 255, .4); }

/* Kartu & layar menu */
.modal { position: absolute; inset: 0; background: rgba(3, 5, 12, .55); display: flex; align-items: center; justify-content: center; padding: calc(16px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
#title { background: rgba(3, 5, 12, .25); }
.card { background: var(--card); border: 2px solid var(--bark); border-radius: 20px; padding: 20px 22px; width: min(640px, 100%); max-height: 100%; overflow: auto; }
.card h1 { font-family: var(--display); font-size: 46px; line-height: 1.05; margin: 0 0 8px; color: var(--amber); text-wrap: balance; }
.card h2 { font-family: var(--display); font-size: 30px; margin: 0 0 6px; color: var(--amber); text-wrap: balance; }
.card p { margin: 0 0 12px; color: var(--muted); font-size: 17px; line-height: 1.5; }
.card .lead { font-size: 19px; color: var(--ink); }
.card .save { color: var(--firefly); font-weight: 800; }
.card .ver { margin: 14px 0 0; font-size: 13px; text-align: right; }
.col { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.row { display: flex; gap: 10px; justify-content: space-between; }
.center { text-align: center; margin-top: 14px; }
.go { background: var(--amber); color: #2a1d00; border: 0; border-radius: 14px; padding: 14px 22px; font-weight: 800; font-size: 19px; }
.go.alt { background: #2a3150; color: var(--ink); border: 1px solid var(--line); }
.link { background: none; border: 0; color: var(--muted); font-weight: 800; font-size: 16px; padding: 10px; }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.pick { text-align: left; background: #1c2240; border: 2px solid var(--line); border-radius: 14px; padding: 14px; font-size: 15px; line-height: 1.45; color: var(--muted); }
.pick b { display: block; font-family: var(--display); font-size: 24px; color: var(--ink); }
.pick i { display: block; font-style: normal; color: var(--firefly); margin-bottom: 4px; }
.pick:active { border-color: var(--amber); }
.code { display: flex; gap: 10px; justify-content: center; margin: 12px 0; }
.code span { width: 76px; height: 76px; border-radius: 16px; background: #1c2240; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 44px; }
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 8px 0 6px; }
.keys button { height: 72px; border-radius: 14px; background: #2a3150; border: 1px solid var(--line); font-size: 38px; }
.status { text-align: center; font-weight: 800; color: var(--ink) !important; min-height: 1.5em; }
.status.err { color: #ffb0a0 !important; }
/* pilih level */
.card.wide { width: min(860px, 100%); }
.lvs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 10px 0 6px; }
.lv { background: #1c2240; border: 3px solid var(--line); border-radius: 16px; padding: 10px 10px 12px; text-align: center; display: flex; flex-direction: column; gap: 3px; }
.lv:active { border-color: var(--amber); }
.lv .sky { height: 70px; border-radius: 10px; margin-bottom: 6px; position: relative; overflow: hidden; }
.lv b { font-family: var(--display); font-size: 24px; color: var(--ink); }
.lv i { font-style: normal; color: var(--firefly); font-weight: 800; font-size: 15px; }
.lv span { color: var(--muted); font-size: 14px; }
.lv em { font-style: normal; font-weight: 800; font-size: 17px; color: var(--amber); margin-top: 4px; }
.lv.lock { opacity: .55; }
.lv.lock em { color: var(--muted); }
.l1 .sky { background: linear-gradient(#1c2a66, #2f4a8a); }
.l2 .sky { background: linear-gradient(#10163a, #1d2a5a); }
.l3 .sky { background: linear-gradient(#2a3346, #4a5568); }
.lv .moon { position: absolute; top: 13px; left: 50%; margin-left: -22px; width: 44px; height: 44px; border-radius: 50%; background: #fff3c0; }
.l2 .moon { background: linear-gradient(90deg, #fff3c0 50%, transparent 50%); }
.l3 .moon { background: repeating-linear-gradient(170deg, transparent 0 12px, rgba(220, 230, 245, .4) 12px 14px); inset: 0; width: auto; height: auto; margin: 0; border-radius: 0; }
/* panel alat di sisi kanan: tidak menutupi jalan, Benhat tetap bisa melihat & berjalan */
.toolpanel { position: absolute; top: calc(62px + env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); width: min(320px, 40vw); max-height: calc(100% - 200px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); overflow: auto; background: var(--panel); border: 2px solid var(--bark); border-radius: 16px; padding: 10px 12px; }
.toolpanel h2 { font-family: var(--display); font-size: 20px; margin: 0; color: var(--amber); }
.toolpanel p { margin: 2px 0 8px; font-size: 14px; color: var(--muted); }
.toolpanel .tools { grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0 0 8px; }
.toolpanel .tool { font-size: 24px; padding: 5px 2px; }
.toolpanel .tool span { font-size: 11px; }
.toolpanel .row { align-items: center; }
.toolpanel .bag.static { margin: 0; padding: 4px 6px; gap: 4px; }
.toolpanel .slot { width: 34px; height: 34px; font-size: 18px; }
.toolpanel .slot.w2 { width: 72px; }
.go.small { padding: 10px 14px; font-size: 16px; }
.tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin: 10px 0 12px; }
.tool { background: #241f18; border: 2px solid #4d4434; border-radius: 12px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 30px; position: relative; }
.tool span { font-size: 13px; font-weight: 800; color: #e6dccb; }
.tool i { position: absolute; top: 3px; right: 6px; font-style: normal; font-size: 10px; color: #ffb070; font-weight: 800; }
.tool.sel { border-color: var(--amber); background: #4a3f22; }
.tool.no { opacity: .35; }
.mapwrap { display: flex; justify-content: center; }
#mapc { width: min(420px, 60vh, 100%); aspect-ratio: 1; max-width: 100%; image-rendering: pixelated; border-radius: 10px; border: 2px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin-top: 10px; justify-content: center; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; background: var(--c); }

/* Halaman awal */
.splash { position: absolute; inset: 0; background: #070a16; z-index: 5; }
.splash canvas { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.splashtext { position: absolute; left: 0; right: 0; top: calc(6vh + env(safe-area-inset-top, 0px)); text-align: center; padding: 0 16px; pointer-events: none; }
.splashtext h1 { font-family: var(--display); font-size: clamp(48px, 8.5vw, 104px); line-height: 1; margin: 0; color: var(--amber); text-shadow: 0 5px 0 #7a3e12, 0 10px 24px rgba(0, 0, 0, .6); letter-spacing: 2px; }
.splashtext p { margin: 8px 0 0; font-size: clamp(16px, 2.2vw, 22px); font-weight: 800; color: var(--firefly); text-shadow: 0 2px 6px #000; }
.go.big { position: absolute; left: 50%; bottom: calc(4vh + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); padding: 18px 40px; font-size: 26px; box-shadow: 0 6px 0 #9a6a10, 0 0 30px rgba(255, 207, 74, .6); animation: breathe 1.6s ease-in-out infinite alternate; white-space: nowrap; }
@keyframes breathe { to { box-shadow: 0 6px 0 #9a6a10, 0 0 44px rgba(255, 207, 74, .85); } }
.splash .ver { position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(10px + env(safe-area-inset-bottom, 0px)); margin: 0; color: var(--muted); font-size: 13px; }

/* Adegan penutup */
.ending { position: absolute; inset: 0; background: #070a16; }
.ending canvas { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.endtext { position: absolute; left: 50%; top: calc(18px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); width: min(760px, 90vw); text-align: center; opacity: 0; transition: opacity 1.2s ease; }
.endtext h2 { font-family: var(--display); font-size: clamp(30px, 5vw, 52px); line-height: 1.1; margin: 0 0 6px; color: #fff; text-shadow: 0 3px 0 #b8452f, 0 6px 14px rgba(0, 0, 0, .45); text-wrap: balance; }
.endtext p { margin: 0; font-size: 18px; font-weight: 800; color: #3a2410; }
.endbtns { position: absolute; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; align-items: center; opacity: 0; pointer-events: none; transition: opacity .8s ease; }
.endbtns p { margin: 0; font-weight: 800; color: #3a2410; background: rgba(255, 255, 255, .7); padding: 10px 14px; border-radius: 12px; }
.ending.show-text .endtext, .ending.show-btns .endbtns { opacity: 1; }
.ending.show-btns .endbtns { pointer-events: auto; }
@media (max-width: 560px) {
  .who, .lvs { grid-template-columns: 1fr; }
  .round { width: 74px; height: 74px; font-size: 26px; }
  .round.mark { width: 66px; height: 66px; }
  .card h1 { font-size: 34px; }
  .code span { width: 60px; height: 60px; font-size: 34px; }
}
@media (prefers-reduced-motion: reduce) { .round.glow, .go.big { animation: none; } }
