html, body { margin: 0; height: 100%; background: #000; overflow: hidden; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body { font-family: 'Pixelify Sans', system-ui, sans-serif; color: #f4f0e0; }
canvas { display: block; width: 100vw; height: 100vh; image-rendering: pixelated; touch-action: none; }
button { font-family: inherit; }
.hidden { display: none !important; }

#btns { position: fixed; top: calc(6px + env(safe-area-inset-top)); right: calc(6px + env(safe-area-inset-right)); display: flex; gap: 2px;
  background: rgba(16,22,56,0.85); border: 2px solid #f4f0e0; border-radius: 4px; padding: 2px; z-index: 5; }
.icon-btn { background: none; border: none; color: #f4f0e0; font-size: 18px; cursor: pointer; padding: 4px 6px; text-decoration: none; line-height: 1; }

/* Touch buttons */
#pad { display: none; position: fixed; right: calc(14px + env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom));
  width: 240px; height: 190px; z-index: 4; }
body.touch #pad { display: block; }
.pbtn { position: absolute; width: 64px; height: 64px; border-radius: 50%; border: 3px solid rgba(244,240,224,0.7); background: rgba(16,22,56,0.55);
  color: #fff; font: 700 11px 'Pixelify Sans', system-ui, sans-serif; touch-action: none; -webkit-tap-highlight-color: transparent; padding: 0; }
.pbtn.down { background: rgba(248,192,64,0.6); }
.pbtn.main { width: 84px; height: 84px; right: 0; bottom: 0; background: rgba(200,60,40,0.55); font-size: 14px; }
.pbtn[data-act="spc"] { right: 92px; bottom: 6px; background: rgba(60,90,200,0.5); }
.pbtn[data-act="dodge"] { right: 14px; bottom: 96px; background: rgba(60,150,70,0.5); }
.pbtn.small { width: 44px; height: 44px; font-size: 18px; }
.pbtn[data-act="next"] { right: 96px; bottom: 86px; }
.pbtn[data-act="tonic"] { right: 150px; bottom: 120px; }
#rotate { display: none; position: fixed; left: 0; right: 0; top: calc(60px + env(safe-area-inset-top)); text-align: center;
  color: #f8e040; font-size: 15px; pointer-events: none; z-index: 3; }
@media (orientation: portrait) { body.touch #rotate { display: block; } }

/* Dialogue */
#dialog { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom)); width: min(620px, calc(100vw - 28px));
  box-sizing: border-box; background: #101638; border: 3px solid #f4f0e0; border-radius: 6px; box-shadow: 0 0 0 3px #10101c; padding: 12px 16px 14px;
  z-index: 8; cursor: pointer; font-size: 18px; line-height: 1.35; }
body.touch #dialog { bottom: calc(210px + env(safe-area-inset-bottom)); }
@media (orientation: landscape) { body.touch #dialog { bottom: calc(10px + env(safe-area-inset-bottom)); width: min(560px, calc(100vw - 260px)); left: calc(50% - 100px); } }
#dlg-who { color: #f8d040; font-weight: 700; margin-bottom: 4px; }
#dlg-text { min-height: 2.6em; white-space: pre-wrap; }
#dlg-choices { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.choice { text-align: left; background: #1e2a60; color: #f4f0e0; border: 2px solid #5060a0; border-radius: 4px; padding: 6px 10px; font-size: 17px; cursor: pointer; }
.choice.sel, .choice:hover { border-color: #f8d040; background: #2a3a80; }
.choice.sel::before { content: '▶ '; color: #f8d040; }

/* Panels */
#panel { position: fixed; inset: 0; background: rgba(4,4,12,0.6); display: flex; align-items: center; justify-content: center; z-index: 9; }
#panel-box { width: min(720px, calc(100vw - 20px)); max-height: calc(100vh - 20px); overflow-y: auto; box-sizing: border-box; background: #101638;
  border: 3px solid #f4f0e0; border-radius: 6px; box-shadow: 0 0 0 3px #10101c; padding: 12px 16px 16px; font-size: 16px; }
.tabs { display: flex; gap: 6px; align-items: center; position: sticky; top: -12px; background: #101638; padding: 4px 0 8px; margin-top: -4px; z-index: 1; }
.tab { background: #1e2a60; color: #f4f0e0; border: 2px solid #5060a0; border-radius: 4px; padding: 5px 12px; font-size: 16px; cursor: pointer; }
.tab.on { border-color: #f8d040; color: #f8d040; }
.x { margin-left: auto; background: none; border: none; color: #f4f0e0; font-size: 22px; cursor: pointer; }
.ptitle { font-size: 20px; color: #f8d040; }
.muted { color: #a8a8c8; font-size: 14px; }
.small { font-size: 13px; }
h3 { margin: 14px 0 6px; color: #f8d040; font-size: 17px; }
.lvl { font-size: 18px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mbar { display: inline-block; width: 140px; height: 8px; background: #282848; border: 2px solid #10101c; vertical-align: middle; }
.mbar span { display: block; height: 100%; }
.pts { color: #f8d040; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 6px; }
.stat { display: flex; align-items: center; gap: 8px; background: #18204a; border-radius: 4px; padding: 6px 8px; }
.sname { flex: 1; font-weight: 600; }
.sname small { display: block; font-weight: 400; color: #a8a8c8; font-size: 12px; }
.sval { font-size: 20px; min-width: 64px; text-align: right; }
.sval small { font-size: 12px; color: #a8a8c8; }
.stat.up .sval, .up { color: #80e080; }
.stat.down .sval, .down { color: #ff8080; }
.plus { width: 30px; height: 30px; border-radius: 4px; border: 2px solid #f8d040; background: #3a3010; color: #f8d040; font-size: 18px; cursor: pointer; }
.plus:disabled { opacity: 0.25; cursor: default; }
.styles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.style { background: #18204a; border: 2px solid #2a3470; border-radius: 4px; padding: 8px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; }
.style.on { border-color: #f8d040; }
.style.locked { opacity: 0.5; cursor: default; }
.style small { color: #c0c0d8; font-size: 12.5px; }
.style em { color: #f8d040; font-style: normal; font-size: 13px; }
.chip { width: 18px; height: 18px; border: 2px solid #f4f0e0; border-radius: 3px; }
.pm { font-size: 13px; }
.equip, .item button { align-self: flex-start; background: #2a3a80; color: #f4f0e0; border: 2px solid #f8d040; border-radius: 4px; padding: 3px 10px; font-size: 14px; cursor: pointer; }
.item button:disabled { opacity: 0.35; cursor: default; }
.bag, .shop { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #18204a; border-radius: 4px; padding: 8px 10px; }
.item small { display: block; color: #a8a8c8; font-size: 13px; }
.fruits { display: flex; gap: 6px; flex-wrap: wrap; }
.fruit { background: #18204a; border: 2px solid #2a3470; border-radius: 4px; padding: 4px 10px; color: #606080; }
.fruit.have { color: #f8d040; border-color: #f8d040; }
.goal { font-size: 18px; color: #f8d040; }
.keys { padding-left: 18px; line-height: 1.5; margin: 4px 0; }
.title { text-align: center; padding: 8px 4px; }
.title h1 { font-size: 26px; margin: 6px 0 12px; line-height: 1.2; font-weight: 600; }
.title h1 span { font-size: 40px; color: #f8d040; font-weight: 700; text-shadow: 3px 3px 0 #a83820; }
.tbtns { display: flex; gap: 10px; justify-content: center; margin: 16px 0 8px; flex-wrap: wrap; }
.big { background: #c83828; color: #fff; border: 3px solid #f4f0e0; border-radius: 6px; padding: 10px 26px; font-size: 20px; cursor: pointer; box-shadow: 0 3px 0 #10101c; }
.big.alt { background: #2a3a80; }

/* Toasts */
#toasts { position: fixed; top: calc(52px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px;
  align-items: center; z-index: 7; pointer-events: none; width: min(560px, calc(100vw - 20px)); }
.toast { background: rgba(16,22,56,0.94); border: 2px solid #f8d040; border-radius: 4px; padding: 6px 12px; font-size: 15px; text-align: center; transition: opacity 0.5s; }
.toast.out { opacity: 0; }

/* World map tab */
.mapwrap { display: flex; justify-content: center; }
#worldmap { width: min(560px, 100%); image-rendering: pixelated; border: 3px solid #10101c; border-radius: 4px; }
.regions { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; margin-top: 8px; }
.region { background: #18204a; border-radius: 4px; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.region .chip { display: inline-block; width: 12px; height: 12px; vertical-align: middle; margin-right: 4px; }
.region small { color: #a8a8c8; font-size: 12.5px; }
.region.done b { color: #80e080; }
.pbtn[data-act="skl"] { right: 164px; bottom: 26px; width: 58px; height: 58px; background: rgba(140,60,180,0.5); }
