:root {
  --ink: #20162a;
  --paper: #f8f0d8;
  --paper2: #e8d8b0;
  --green: #38a848;
  --green-d: #1e6a2c;
  --red: #d83838;
  --gold: #f8d040;
  --font: 'Press Start 2P', 'Courier New', monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1a2a1a; font-family: var(--font); color: var(--ink); }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; image-rendering: pixelated; display: block; }
.hidden { display: none !important; }
canvas { image-rendering: pixelated; }

.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(16, 24, 16, 0.55); z-index: 20; padding: 12px;
}
.panel {
  background: var(--paper); border: 4px solid var(--ink);
  box-shadow: inset -4px -4px 0 var(--paper2), inset 4px 4px 0 #fffaf0, 6px 6px 0 rgba(0,0,0,0.45);
  padding: 20px; max-width: 100%; max-height: 100%; overflow: auto;
}
h1, h2 { margin: 0 0 10px; line-height: 1.4; text-align: center; }
h1 { font-size: 16px; color: var(--green-d); text-shadow: 2px 2px 0 var(--gold); }
h1 span { color: var(--red); }
h2 { font-size: 13px; }
.sub { font-size: 8px; text-align: center; margin: 0 0 14px; line-height: 1.6; color: #5a4a3a; }
label { display: block; font-size: 8px; margin: 10px 0 6px; }
input {
  width: 100%; font-family: var(--font); font-size: 10px; padding: 8px; border: 3px solid var(--ink);
  background: #fff; outline: none;
}
input:focus { border-color: var(--green); }
.btn {
  font-family: var(--font); font-size: 9px; padding: 10px 12px; border: 3px solid var(--ink); cursor: pointer;
  background: #fff; box-shadow: inset -3px -3px 0 #c8c0a8; color: var(--ink);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { box-shadow: inset 3px 3px 0 #c8c0a8; }
.btn.primary { background: var(--green); color: #fff; box-shadow: inset -3px -3px 0 var(--green-d); }
.btn.small { font-size: 8px; padding: 6px 8px; }
.error { background: #ffd8d8; border: 2px solid var(--red); color: #8a1818; font-size: 8px; padding: 8px; margin-top: 10px; line-height: 1.6; }
.help { font-size: 7px; line-height: 1.8; margin-top: 12px; color: #6a5a4a; text-align: center; }

.auth-panel { width: 360px; text-align: left; }
#logoCanvas { display: block; margin: 0 auto 8px; width: 100%; max-width: 300px; aspect-ratio: 4 / 1; height: auto; }
#authForm .btn { width: 100%; margin-top: 14px; }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; font-family: var(--font); font-size: 9px; padding: 8px; border: 3px solid var(--ink); background: var(--paper2); cursor: pointer; }
.tab.sel { background: var(--gold); }

.custom-panel { width: 620px; }
.custom-body { display: flex; gap: 18px; align-items: flex-start; }
.preview-box { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#previewCanvas { width: 160px; height: 200px; border: 3px solid var(--ink); background: #58a83c; }
.preview-name { font-size: 9px; }
.custom-rows { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.row-label { font-size: 8px; margin-bottom: 5px; }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.swatch { width: 26px; height: 26px; border: 3px solid var(--ink); cursor: pointer; padding: 0; }
.swatch.sel { outline: 3px solid var(--gold); outline-offset: 1px; transform: translateY(-2px); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper .val { flex: 1; text-align: center; font-size: 8px; background: #fff; border: 3px solid var(--ink); padding: 7px 4px; }
.stepper button { font-family: var(--font); font-size: 9px; border: 3px solid var(--ink); background: var(--gold); cursor: pointer; padding: 6px 8px; }
.custom-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
.panel-mini {
  background: rgba(248, 240, 216, 0.95); border: 3px solid var(--ink); padding: 7px 9px; font-size: 8px; line-height: 1.8;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.4);
}
.hud-left { position: absolute; left: 10px; top: 10px; }
.hud-right { position: absolute; right: 10px; top: 10px; display: flex; gap: 6px; align-items: center; }
.clickable { cursor: pointer; }
.icon-btn {
  width: 36px; height: 36px; font-size: 16px; border: 3px solid var(--ink); background: var(--paper); cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.4); padding: 0;
}
.icon-btn:hover { background: var(--gold); }
.icon-btn svg { display: block; margin: 0 auto; color: var(--ink); }
/* tombol kecil Buku Temuan di atas kolom chat, hanya saat di Hutan Anakan */
.finds-btn {
  display: none; font-family: var(--font); font-size: 7px; line-height: 1; padding: 5px 7px; margin-bottom: 4px;
  background: #e4f6d8; color: #1f4a22; border: 2px solid var(--ink); box-shadow: 2px 2px 0 rgba(0,0,0,0.4); cursor: pointer;
}
.finds-btn:hover { background: var(--gold); }
.finds-btn span { color: #b0306a; }
.in-forest .finds-btn { display: inline-block; }
/* notifikasi kecil di atas kolom chat, muncul lalu memudar */
.notes { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; margin-bottom: 4px; pointer-events: none; }
.note {
  background: rgba(16,16,24,0.82); color: #fff; font-size: 7px; line-height: 1.6; padding: 4px 7px; border-left: 3px solid #8ce08c;
  max-width: 100%; animation: noteFade 3s ease-in forwards;
}
.note b { color: var(--gold); }
.note.gold { border-left-color: var(--gold); color: #fff3c0; }
.note.find { border-left-color: #f080c0; color: #ffe0f0; }
@keyframes noteFade { 0% { opacity: 0; transform: translateY(4px); } 8% { opacity: 1; transform: none; } 65% { opacity: 1; } 100% { opacity: 0; } }
.chat { position: absolute; left: 10px; bottom: 10px; width: min(420px, calc(100vw - 20px)); }
.chat-log {
  max-height: 150px; overflow-y: auto; font-size: 8px; line-height: 1.7; color: #fff; text-shadow: 1px 1px 0 #000;
  background: rgba(0,0,0,0.35); padding: 6px 8px; margin-bottom: 6px;
}
.chat-log:empty { display: none; }
.chat-log .sys { color: #f8e070; }
.chat-log .nm { color: #8ce08c; }
#chatInput { font-size: 9px; }

.info-panel { width: 460px; }
.info-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
#infoCanvas { width: 96px; height: 96px; border: 3px solid var(--ink); background: #78c454; flex: none; }
.info-head h2 { text-align: left; margin-bottom: 6px; }
.latin { font-size: 8px; font-style: italic; color: #6a5a4a; margin-bottom: 8px; }
.badge { display: inline-block; font-size: 7px; padding: 5px 7px; border: 2px solid var(--ink); color: #fff; }
.info-table { width: 100%; border-collapse: collapse; font-size: 8px; line-height: 1.6; }
.info-table th { text-align: left; width: 38%; padding: 5px 6px; background: var(--paper2); border: 2px solid var(--ink); vertical-align: top; }
.info-table td { padding: 5px 6px; border: 2px solid var(--ink); background: #fff; }
.facts-title { font-size: 9px; margin: 14px 0 6px; color: var(--green-d); }
.facts { font-size: 8px; line-height: 1.8; padding-left: 16px; margin: 0; }
.facts li { margin-bottom: 6px; }

.dex-panel { width: 640px; }
.dex-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.dex-card { border: 3px solid var(--ink); background: #fff; padding: 6px; text-align: center; font-size: 7px; line-height: 1.5; cursor: pointer; }
.dex-card.locked { background: #d8d0b8; cursor: default; color: #6a5a4a; }
.dex-card canvas { width: 72px; height: 72px; display: block; margin: 0 auto 4px; }
/* Buku Temuan (Hutan Anakan) */
.finds-panel { width: 680px; max-height: 92vh; overflow-y: auto; }
.find-card { cursor: default; }
.find-card canvas { width: 64px; height: 56px; }
.find-card.got { background: #e4f6d8; border-color: #2f7a34; }
.find-card .fname { font-weight: bold; }
.find-card .fhint { font-size: 6px; color: #5a4a3a; margin-top: 3px; line-height: 1.5; }
.find-card.got .fhint { color: #2f7a34; }
.map-panel { width: min(760px, 100%); }
#mapCanvas { display: block; margin: 0 auto; border: 3px solid var(--ink); max-width: 100%; }
.help-panel { width: 460px; }

.touch { position: absolute; inset: auto 0 0 0; height: 0; }
/* tombol arah: kotak polos di kanan bawah */
.dpad { position: absolute; right: 12px; bottom: 12px; width: 162px; height: 162px; }
.dpad button, .tbtns button {
  position: absolute; width: 44px; height: 44px; font-family: var(--font); font-size: 12px; border: 3px solid var(--ink);
  background: rgba(248,240,216,0.85); touch-action: none; padding: 0; box-shadow: inset -3px -3px 0 #c8c0a8;
  -webkit-user-select: none; user-select: none;
}
/* tombol arah bulat */
.dpad button { width: 56px; height: 56px; border-radius: 50%; box-shadow: inset -4px -4px 0 #c8c0a8, 0 2px 0 rgba(0,0,0,0.35); }
.dpad button:active { background: var(--gold); box-shadow: inset 3px 3px 0 #c8a030; }
.dpad [data-k=up] { left: 53px; top: 0; }
.dpad [data-k=left] { left: 0; top: 53px; }
.dpad [data-k=right] { left: 106px; top: 53px; }
.dpad [data-k=down] { left: 53px; top: 106px; }
/* tombol emote joget: kecil, di atas tombol arah (tahan = joget) */
.emote-btn {
  position: absolute; right: 76px; bottom: 182px; width: 34px; height: 34px; border-radius: 50%; padding: 0;
  font-size: 15px; line-height: 1; border: 2px solid var(--ink); background: rgba(248,240,216,0.85);
  box-shadow: inset -3px -3px 0 #c8c0a8, 0 2px 0 rgba(0,0,0,0.35); touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.emote-btn.on { background: #f080c0; box-shadow: inset 3px 3px 0 #b04a88, 0 0 10px #ffd23f; transform: scale(1.08); }
/* tombol aksi di kiri bawah */
.tbtns { position: absolute; left: 14px; bottom: 14px; display: flex; gap: 6px; }
.tbtns button { position: static; width: 44px; height: 44px; font-size: 16px; }
.touch-on .chat { bottom: 66px; width: min(260px, calc(100vw - 190px)); }
.touch-on .chat-log { max-height: 84px; font-size: 7px; }
#hudTicket.warn { color: #c02828; }

.talk-panel { width: 460px; }
.talk-head { display: flex; gap: 14px; align-items: flex-start; }
#talkCanvas { width: 80px; height: 88px; border: 3px solid var(--ink); flex: none; }
.talk-body h2 { text-align: left; color: #8a1f1f; }
.talk-text { font-size: 9px; line-height: 1.9; margin: 0; }
.ticket {
  margin-top: 14px; background: #ffd23f; border: 3px dashed var(--ink); padding: 10px 12px; font-size: 8px; line-height: 1.8;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.3); transform: rotate(-1.5deg);
}
.ticket-top { font-size: 7px; color: #6a4a10; }
.ticket-title { font-size: 10px; color: #174b32; margin: 4px 0; }
.ticket-row { display: flex; justify-content: space-between; gap: 8px; }
.ticket-free { background: #d83838; color: #fff; padding: 0 6px; }

/* layar sedang: tombol menu sedikit lebih kecil agar tidak menimpa panel kiri */
@media (max-width: 860px) and (min-width: 641px) {
  .hud-right { gap: 4px; }
  .hud-right .icon-btn { width: 30px; height: 30px; font-size: 13px; }
  .hud-right .panel-mini { padding: 5px 7px; }
}
@media (max-width: 640px) {
  .custom-body { flex-direction: column; align-items: center; }
  .dex-grid { grid-template-columns: repeat(3, 1fr); }
  .panel { padding: 14px; }
  .hud-right { top: 6px; right: 6px; gap: 3px; }
  .hud-right .icon-btn { width: 26px; height: 26px; font-size: 12px; border-width: 2px; box-shadow: 2px 2px 0 rgba(0,0,0,0.4); }
  .hud-right .panel-mini { padding: 4px 5px; font-size: 7px; border-width: 2px; }
  .hud-left { top: 38px; left: 6px; padding: 4px 6px; font-size: 7px; line-height: 1.7; border-width: 2px; }
  .note { font-size: 6px; padding: 3px 6px; }
  .hud-right .icon-btn svg { width: 11px; height: 11px; }
  .finds-btn { font-size: 6px; padding: 4px 6px; }
}
/* HP sempit: 8 tombol + jumlah online tetap muat satu baris */
@media (max-width: 380px) {
  .hud-right { gap: 2px; right: 4px; }
  .hud-right .icon-btn { width: 24px; height: 24px; font-size: 11px; box-shadow: 1px 1px 0 rgba(0,0,0,0.4); }
  .hud-right .panel-mini { padding: 3px 4px; font-size: 6px; }
  .ol-word { display: none; }
}

.btn.gold { background: var(--gold); box-shadow: inset -3px -3px 0 #c8a030; }
.ride-panel { width: 680px; text-align: center; }
#rideCanvas { width: 100%; max-width: 640px; aspect-ratio: 320 / 150; height: auto; border: 3px solid var(--ink); background: #9bd3ea; touch-action: none; display: block; margin: 0 auto; cursor: pointer; }
.ride-msg { font-size: 9px; line-height: 1.7; min-height: 16px; margin-top: 10px; }
.ride-msg.win { color: #1e6a2c; }
.ride-msg.lose { color: #a02020; }
.ride-levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 0 auto 8px; max-width: 640px; }
.ride-levels .lvl {
  font-family: var(--font); font-size: 8px; padding: 6px 2px; border: 3px solid var(--ink); background: #f8f0d8;
  cursor: pointer; box-shadow: inset -3px -3px 0 #c8c0a8; color: var(--ink);
}
.ride-levels .lvl small { display: block; font-size: 6px; margin-top: 4px; opacity: 0.85; }
.ride-levels .lvl.sel { background: var(--gold); box-shadow: inset 3px 3px 0 #c8a030; }
.ride-levels .lvl.done:not(.sel) { background: #d8f0c0; }
.ride-levels .lvl.locked { opacity: 0.5; cursor: not-allowed; }
.ride-levels .lvl:disabled:not(.locked) { cursor: default; }
